filename
stringlengths 5
42
| content
stringlengths 15
319k
|
|---|---|
fintype.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 ssrnotations eqtype.
From mathcomp Require Import ssrnat seq choice path div.
(******************************************************************************)
(* Finite types *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines an interface for finite types: *)
(* *)
(* finType == type with finitely many inhabitants *)
(* The HB class is called Finite. *)
(* subFinType P == join of finType and subType P *)
(* The HB class is called SubFinite. *)
(* *)
(* The Finite interface describes Types with finitely many elements, *)
(* supplying a duplicate-free sequence of all the elements. It is a subclass *)
(* of Countable and thus of Choice and Equality. *)
(* *)
(* Bounded integers are supported by the following type and operations: *)
(* *)
(* 'I_n, ordinal n == the finite subType of integers i < n, whose *)
(* enumeration is {0, ..., n.-1} *)
(* 'I_n coerces to nat, so all the integer arithmetic *)
(* functions can be used with 'I_n. *)
(* Ordinal lt_i_n == the element of 'I_n with (nat) value i, given *)
(* lt_i_n : i < n *)
(* nat_of_ord i == the nat value of i : 'I_n (this function is a *)
(* coercion so it is not usually displayed) *)
(* ord_enum n == the explicit increasing sequence of the i : 'I_n *)
(* cast_ord eq_n_m i == the element j : 'I_m with the same value as i : 'I_n *)
(* given eq_n_m : n = m (indeed, i : nat and j : nat *)
(* are convertible) *)
(* ordS n i == the successor of i : 'I_n along the cyclic structure *)
(* of 'I_n, reduces in nat to i.+1 %% n *)
(* ord_pred n i == the predecessor of i : 'I_n along the cyclic *)
(* structure of 'I_n, reduces in nat to (i + n).-1 %% n *)
(* widen_ord le_n_m i == a j : 'I_m with the same value as i : 'I_n, given *)
(* le_n_m : n <= m *)
(* rev_ord i == the complement to n.-1 of i : 'I_n, such that *)
(* i + rev_ord i = n.-1 *)
(* inord k == the i : 'I_n.+1 with value k (n is inferred from the *)
(* context) *)
(* sub_ord k == the i : 'I_n.+1 with value n - k (n is inferred from *)
(* the context) *)
(* ord0 == the i : 'I_n.+1 with value 0 (n is inferred from the *)
(* context) *)
(* ord_max == the i : 'I_n.+1 with value n (n is inferred from the *)
(* context) *)
(* bump h k == k.+1 if k >= h, else k (this is a nat function) *)
(* unbump h k == k.-1 if k > h, else k (this is a nat function) *)
(* lift i j == the j' : 'I_n with value bump i j, where i : 'I_n *)
(* and j : 'I_n.-1 *)
(* unlift i j == None if i = j, else Some j', where j' : 'I_n.-1 has *)
(* value unbump i j, given i, j : 'I_n *)
(* lshift n j == the i : 'I_(m + n) with value j : 'I_m *)
(* rshift m k == the i : 'I_(m + n) with value m + k, k : 'I_n *)
(* unsplit u == either lshift n j or rshift m k, depending on *)
(* whether if u : 'I_m + 'I_n is inl j or inr k *)
(* split i == the u : 'I_m + 'I_n such that i = unsplit u; the *)
(* type 'I_(m + n) of i determines the split *)
(* *)
(* Finally, every type T with a finType structure supports the following *)
(* operations: *)
(* *)
(* enum A == a duplicate-free list of all the x \in A, where A is a *)
(* collective predicate over T *)
(* #|A| == the cardinal of A, i.e., the number of x \in A *)
(* enum_val i == the i'th item of enum A, where i : 'I_(#|A|) *)
(* enum_rank x == the i : 'I_(#|T|) such that enum_val i = x *)
(* enum_rank_in Ax0 x == some i : 'I_(#|A|) such that enum_val i = x if *)
(* x \in A, given Ax0 : x0 \in A *)
(* A \subset B <=> all x \in A satisfy x \in B *)
(* A \proper B <=> all x \in A satisfy x \in B but not the converse *)
(* [disjoint A & B] <=> no x \in A satisfies x \in B *)
(* image f A == the sequence of f x for all x : T such that x \in A *)
(* (where A is an applicative predicate), of length #|A|. *)
(* The codomain of F can be any type, but image f A can *)
(* only be used as a collective predicate if it is an *)
(* eqType *)
(* codom f == a sequence spanning the codomain of f (:= image f T) *)
(* [seq F | x : T in A] := image (fun x : T => F) A *)
(* [seq F | x : T] := [seq F | x <- {: T}] *)
(* [seq F | x in A], [seq F | x] == variants without casts *)
(* iinv im_y == some x such that P x holds and f x = y, given *)
(* im_y : y \in image f P *)
(* invF inj_f y == the x such that f x = y, for inj_j : injective f with *)
(* f : T -> T *)
(* dinjectiveb A f <=> the restriction of f : T -> R to A is injective *)
(* (this is a boolean predicate, R must be an eqType) *)
(* injectiveb f <=> f : T -> R is injective (boolean predicate) *)
(* pred0b A <=> no x : T satisfies x \in A *)
(* [forall x, P] <=> P (in which x can appear) is true for all values of x *)
(* x must range over a finType *)
(* [exists x, P] <=> P is true for some value of x *)
(* [forall (x | C), P] := [forall x, C ==> P] *)
(* [forall x in A, P] := [forall (x | x \in A), P] *)
(* [exists (x | C), P] := [exists x, C && P] *)
(* [exists x in A, P] := [exists (x | x \in A), P] *)
(* and typed variants [forall x : T, P], [forall (x : T | C), P], *)
(* [exists x : T, P], [exists x : T in A, P], etc *)
(* -> The outer brackets can be omitted when nesting finitary quantifiers, *)
(* e.g., [forall i in I, forall j in J, exists a, f i j == a]. *)
(* 'forall_pP <-> view for [forall x, p _], for pP : reflect .. (p _) *)
(* 'exists_pP <-> view for [exists x, p _], for pP : reflect .. (p _) *)
(* 'forall_in_pP <-> view for [forall x in .., p _], for pP as above *)
(* 'exists_in_pP <-> view for [exists x in .., p _], for pP as above *)
(* [pick x | P] == Some x, for an x such that P holds, or None if there *)
(* is no such x *)
(* [pick x : T] == Some x with x : T, provided T is nonempty, else None *)
(* [pick x in A] == Some x, with x \in A, or None if A is empty *)
(* [pick x in A | P] == Some x, with x \in A such that P holds, else None *)
(* [pick x | P & Q] := [pick x | P & Q] *)
(* [pick x in A | P & Q] := [pick x | P & Q] *)
(* and (un)typed variants [pick x : T | P], [pick x : T in A], [pick x], etc *)
(* [arg min_(i < i0 | P) M] == a value i : T minimizing M : nat, 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 *)
(* These are special instances of *)
(* [arg[ord]_(i < i0 | P) F] == a value i : I, minimizing F wrt ord : rel T *)
(* such that for all j : T, ord (F i) (F j) *)
(* subject to the condition P, and provided P i0 *)
(* where I : finType, T : eqType and F : I -> T *)
(* [arg[ord]_(i < i0 in A) F] == an i \in A minimizing F wrt ord, if i0 \in A *)
(* [arg[ord]_(i < i0) F] == an i : T minimizing F wrt ord, given i0 : T *)
(* *)
(* We define the following interfaces and structures: *)
(* Finite.axiom e <-> every x : T occurs exactly once in e : seq T. *)
(* [Finite of T by <:] == a finType structure for T, when T has a subType *)
(* structure over an existing finType. *)
(* We define or propagate the finType structure appropriately for all basic *)
(* types : unit, bool, void, option, prod, sum, sig and sigT. We also define *)
(* a generic type constructor for finite subtypes based on an explicit *)
(* enumeration: *)
(* seq_sub s == the subType of all x \in s, where s : seq T for some *)
(* eqType T; seq_sub s has a canonical finType instance *)
(* when T is a choiceType *)
(* adhoc_seq_sub_choiceType s, adhoc_seq_sub_finType s == *)
(* non-canonical instances for seq_sub s, s : seq T, *)
(* which can be used when T is not a choiceType *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope fin_quant_scope.
Definition finite_axiom (T : eqType) e :=
forall x : T, count_mem x e = 1.
HB.mixin Record isFinite T of Equality T := {
enum_subdef : seq T;
enumP_subdef : finite_axiom enum_subdef
}.
(* Finiteness could be stated more simply by bounding the range of the pickle *)
(* function supplied by the Countable interface, but this would yield *)
(* a useless computational interpretation due to the wasteful Peano integer *)
(* encodings. *)
#[short(type="finType")]
HB.structure Definition Finite := {T of isFinite T & Countable T }.
(* As with Countable, the interface explicitly includes the somewhat redundant*)
(* Equality, Choice and Countable superclasses to ensure the forgetful *)
(* inheritance criterion is met. *)
Module Export FiniteNES.
Module Finite.
HB.lock Definition enum T := isFinite.enum_subdef (Finite.class T).
Notation axiom := finite_axiom.
Lemma uniq_enumP (T : eqType) e : uniq e -> e =i T -> axiom e.
Proof. by move=> Ue sT x; rewrite count_uniq_mem ?sT. Qed.
Section WithCountType.
Variable (T : countType) (n : nat).
Definition count_enum := pmap (@pickle_inv T) (iota 0 n).
Hypothesis ubT : forall x : T, pickle x < n.
Lemma count_enumP : axiom count_enum.
Proof.
apply: uniq_enumP (pmap_uniq (@pickle_invK T) (iota_uniq _ _)) _ => x.
by rewrite mem_pmap -pickleK_inv map_f // mem_iota ubT.
Qed.
End WithCountType.
End Finite.
Canonical finEnum_unlock := Unlockable Finite.enum.unlock.
End FiniteNES.
Section CanonicalFinType.
Variable (T : eqType) (s : seq T).
Definition fin_type of finite_axiom s : Type := T.
Variable (f : finite_axiom s).
Notation fT := (fin_type f).
Definition fin_pickle (x : fT) : nat := index x s.
Definition fin_unpickle (n : nat) : option fT :=
nth None (map some s) n.
Lemma fin_pickleK : pcancel fin_pickle fin_unpickle.
Proof.
move=> x; rewrite /fin_pickle/fin_unpickle.
rewrite -(index_map Some_inj) nth_index ?map_f//.
by apply/count_memPn=> /eqP; rewrite f.
Qed.
HB.instance Definition _ := Equality.on fT.
HB.instance Definition _ := isCountable.Build fT fin_pickleK.
HB.instance Definition _ := isFinite.Build fT f.
End CanonicalFinType.
(* Workaround for the silly syntactic uniformity restriction on coercions; *)
(* this avoids a cross-dependency between finset.v and prime.v for the *)
(* definition of the \pi(A) notation. *)
Definition fin_pred_sort (T : finType) (pT : predType T) := pred_sort pT.
Identity Coercion pred_sort_of_fin : fin_pred_sort >-> pred_sort.
Definition enum_mem T (mA : mem_pred _) := filter mA (Finite.enum T).
Notation enum A := (enum_mem (mem A)).
Definition pick (T : finType) (P : pred T) := ohead (enum P).
Notation "[ 'pick' x | P ]" := (pick (fun x => P%B))
(x name, format "[ 'pick' x | P ]") : form_scope.
Notation "[ 'pick' x : T | P ]" := (pick (fun x : T => P%B))
(x name, only parsing) : form_scope.
Definition pick_true T (x : T) := true.
Reserved Notation "[ 'pick' x : T ]" (x name, format "[ 'pick' x : T ]").
Notation "[ 'pick' x : T ]" := [pick x : T | pick_true x]
(only parsing) : form_scope.
Notation "[ 'pick' x : T ]" := [pick x : T | pick_true _]
(only printing) : form_scope.
Notation "[ 'pick' x ]" := [pick x : _] (x name, only parsing) : form_scope.
Notation "[ 'pick' x | P & Q ]" := [pick x | P && Q ]
(x name, format "[ '[hv ' 'pick' x | P '/ ' & Q ] ']'") : form_scope.
Notation "[ 'pick' x : T | P & Q ]" := [pick x : T | P && Q ]
(x name, only parsing) : form_scope.
Notation "[ 'pick' x 'in' A ]" := [pick x | x \in A]
(x name, format "[ 'pick' x 'in' A ]") : form_scope.
Notation "[ 'pick' x : T 'in' A ]" := [pick x : T | x \in A]
(x name, only parsing) : form_scope.
Notation "[ 'pick' x 'in' A | P ]" := [pick x | x \in A & P ]
(x name, format "[ '[hv ' 'pick' x 'in' A '/ ' | P ] ']'") : form_scope.
Notation "[ 'pick' x : T 'in' A | P ]" := [pick x : T | x \in A & P ]
(x name, only parsing) : form_scope.
Notation "[ 'pick' x 'in' A | P & Q ]" := [pick x in A | P && Q]
(x name, format
"[ '[hv ' 'pick' x 'in' A '/ ' | P '/ ' & Q ] ']'") : form_scope.
Notation "[ 'pick' x : T 'in' A | P & Q ]" := [pick x : T in A | P && Q]
(x name, only parsing) : form_scope.
(* We lock the definitions of card and subset to mitigate divergence of the *)
(* Coq term comparison algorithm. *)
HB.lock Definition card (T : finType) (mA : mem_pred T) := size (enum_mem mA).
Canonical card_unlock := Unlockable card.unlock.
(* A is at level 99 to allow the notation #|G : H| in groups. *)
Notation "#| A |" := (card (mem A))
(A at level 99, format "#| A |") : nat_scope.
Definition pred0b (T : finType) (P : pred T) := #|P| == 0.
Prenex Implicits pred0b.
Module FiniteQuant.
Variant quantified := Quantified of bool.
Delimit Scope fin_quant_scope with Q. (* Bogus, only used to declare scope. *)
Bind Scope fin_quant_scope with quantified.
Notation "F ^*" := (Quantified F).
Section Definitions.
Variable T : finType.
Implicit Types (B : quantified) (x y : T).
Definition quant0b Bp := pred0b [pred x : T | let: F^* := Bp x x in F].
(* The first redundant argument protects the notation from Coq's K-term *)
(* display kludge; the second protects it from simpl and /=. *)
Definition ex B x y := B.
(* Binding the predicate value rather than projecting it prevents spurious *)
(* unfolding of the boolean connectives by unification. *)
Definition all B x y := let: F^* := B in (~~ F)^*.
Definition all_in C B x y := let: F^* := B in (~~ (C ==> F))^*.
Definition ex_in C B x y := let: F^* := B in (C && F)^*.
End Definitions.
Notation "[ x | B ]" := (quant0b (fun x => B x)) (x name).
Notation "[ x : T | B ]" := (quant0b (fun x : T => B x)) (x name).
Module Exports.
Notation ", F" := F^* (at level 200, format ", '/ ' F") : fin_quant_scope.
Notation "[ 'forall' x B ]" := [x | all B]
(x at level 99, format "[ '[hv' 'forall' x B ] ']'") : bool_scope.
Notation "[ 'forall' x : T B ]" := [x : T | all B] (only parsing) : bool_scope.
Notation "[ 'forall' ( x | C ) B ]" := [x | all_in C B]
(x at level 99,
format "[ '[hv' '[' 'forall' ( x '/ ' | C ) ']' B ] ']'") : bool_scope.
Notation "[ 'forall' ( x : T | C ) B ]" := [x : T | all_in C B]
(x at level 99, only parsing) : bool_scope.
Notation "[ 'forall' x 'in' A B ]" := [x | all_in (x \in A) B]
(format "[ '[hv' '[' 'forall' x '/ ' 'in' A ']' B ] ']'") : bool_scope.
Notation "[ 'forall' x : T 'in' A B ]" := [x : T | all_in (x \in A) B]
(only parsing) : bool_scope.
Notation ", 'forall' x B" := [x | all B]^*
(at level 200, x at level 99,
format ", '/ ' 'forall' x B") : fin_quant_scope.
Notation ", 'forall' x : T B" := [x : T | all B]^*
(only parsing) : fin_quant_scope.
Notation ", 'forall' ( x | C ) B" := [x | all_in C B]^*
(x at level 99,
format ", '/ ' '[' 'forall' ( x '/ ' | C ) ']' B") : fin_quant_scope.
Notation ", 'forall' ( x : T | C ) B" := [x : T | all_in C B]^*
(only parsing) : fin_quant_scope.
Notation ", 'forall' x 'in' A B" := [x | all_in (x \in A) B]^*
(format ", '/ ' '[' 'forall' x '/ ' 'in' A ']' B") : bool_scope.
Notation ", 'forall' x : T 'in' A B" := [x : T | all_in (x \in A) B]^*
(only parsing) : bool_scope.
Notation "[ 'exists' x B ]" := (~~ [x | ex B])
(x at level 99,
format "[ '[hv' 'exists' x B ] ']'") : bool_scope.
Notation "[ 'exists' x : T B ]" := (~~ [x : T | ex B]) (only parsing) : bool_scope.
Notation "[ 'exists' ( x | C ) B ]" := (~~ [x | ex_in C B])
(x at level 99,
format "[ '[hv' '[' 'exists' ( x '/ ' | C ) ']' B ] ']'") : bool_scope.
Notation "[ 'exists' ( x : T | C ) B ]" := (~~ [x : T | ex_in C B])
(only parsing) : bool_scope.
Notation "[ 'exists' x 'in' A B ]" := (~~ [x | ex_in (x \in A) B])
(format "[ '[hv' '[' 'exists' x '/ ' 'in' A ']' B ] ']'") : bool_scope.
Notation "[ 'exists' x : T 'in' A B ]" := (~~ [x : T | ex_in (x \in A) B])
(only parsing) : bool_scope.
Notation ", 'exists' x B" := (~~ [x | ex B])^*
(x at level 99, format ", '/ ' 'exists' x B") : fin_quant_scope.
Notation ", 'exists' x : T B" := (~~ [x : T | ex B])^*
(only parsing) : fin_quant_scope.
Notation ", 'exists' ( x | C ) B" := (~~ [x | ex_in C B])^*
(x at level 99,
format ", '/ ' '[' 'exists' ( x '/ ' | C ) ']' B") : fin_quant_scope.
Notation ", 'exists' ( x : T | C ) B" := (~~ [x : T | ex_in C B])^*
(only parsing) : fin_quant_scope.
Notation ", 'exists' x 'in' A B" := (~~ [x | ex_in (x \in A) B])^*
(format ", '/ ' '[' 'exists' x '/ ' 'in' A ']' B") : bool_scope.
Notation ", 'exists' x : T 'in' A B" := (~~ [x : T | ex_in (x \in A) B])^*
(only parsing) : bool_scope.
End Exports.
End FiniteQuant.
Export FiniteQuant.Exports.
Definition disjoint T (A B : mem_pred _) := @pred0b T (predI A B).
Notation "[ 'disjoint' A & B ]" := (disjoint (mem A) (mem B))
(format "'[hv' [ 'disjoint' '/ ' A '/' & B ] ']'") : bool_scope.
HB.lock
Definition subset (T : finType) (A B : mem_pred T) : bool := pred0b (predD A B).
Canonical subset_unlock := Unlockable subset.unlock.
Notation "A \subset B" := (subset (mem A) (mem B))
(at level 70, no associativity) : bool_scope.
Definition proper T A B := @subset T A B && ~~ subset B A.
Notation "A \proper B" := (proper (mem A) (mem B))
(at level 70, no associativity) : bool_scope.
(* image, xinv, inv, and ordinal operations will be defined later. *)
Section OpsTheory.
Variable T : finType.
Implicit Types (A B C D : {pred T}) (P Q : pred T) (x y : T) (s : seq T).
Lemma enumP : Finite.axiom (Finite.enum T).
Proof. by rewrite unlock; apply: enumP_subdef. Qed.
Section EnumPick.
Variable P : pred T.
Lemma enumT : enum T = Finite.enum T.
Proof. exact: filter_predT. Qed.
Lemma mem_enum A : enum A =i A.
Proof. by move=> x; rewrite mem_filter andbC -has_pred1 has_count enumP. Qed.
Lemma enum_uniq A : uniq (enum A).
Proof.
by apply/filter_uniq/count_mem_uniq => x; rewrite enumP -enumT mem_enum.
Qed.
Lemma enum0 : enum pred0 = Nil T. Proof. exact: filter_pred0. Qed.
Lemma enum1 x : enum (pred1 x) = [:: x].
Proof.
rewrite [enum _](all_pred1P x _ _); first by rewrite size_filter enumP.
by apply/allP=> y; rewrite mem_enum.
Qed.
Variant pick_spec : option T -> Type :=
| Pick x of P x : pick_spec (Some x)
| Nopick of P =1 xpred0 : pick_spec None.
Lemma pickP : pick_spec (pick P).
Proof.
rewrite /pick; case: (enum _) (mem_enum P) => [|x s] Pxs /=.
by right; apply: fsym.
by left; rewrite -[P _]Pxs mem_head.
Qed.
End EnumPick.
Lemma eq_enum A B : A =i B -> enum A = enum B.
Proof. by move=> eqAB; apply: eq_filter. Qed.
Lemma eq_pick P Q : P =1 Q -> pick P = pick Q.
Proof. by move=> eqPQ; rewrite /pick (eq_enum eqPQ). Qed.
Lemma cardE A : #|A| = size (enum A).
Proof. by rewrite unlock. Qed.
Lemma eq_card A B : A =i B -> #|A| = #|B|.
Proof. by move=> eqAB; rewrite !cardE (eq_enum eqAB). Qed.
Lemma eq_card_trans A B n : #|A| = n -> B =i A -> #|B| = n.
Proof. by move <-; apply: eq_card. Qed.
Lemma card0 : #|@pred0 T| = 0. Proof. by rewrite cardE enum0. Qed.
Lemma cardT : #|T| = size (enum T). Proof. by rewrite cardE. Qed.
Lemma card1 x : #|pred1 x| = 1.
Proof. by rewrite cardE enum1. Qed.
Lemma eq_card0 A : A =i pred0 -> #|A| = 0.
Proof. exact: eq_card_trans card0. Qed.
Lemma eq_cardT A : A =i predT -> #|A| = size (enum T).
Proof. exact: eq_card_trans cardT. Qed.
Lemma eq_card1 x A : A =i pred1 x -> #|A| = 1.
Proof. exact: eq_card_trans (card1 x). Qed.
Lemma cardUI A B : #|[predU A & B]| + #|[predI A & B]| = #|A| + #|B|.
Proof. by rewrite !cardE !size_filter count_predUI. Qed.
Lemma cardID B A : #|[predI A & B]| + #|[predD A & B]| = #|A|.
Proof.
rewrite -cardUI addnC [#|predI _ _|]eq_card0 => [|x] /=.
by apply: eq_card => x; rewrite !inE andbC -andb_orl orbN.
by rewrite !inE -!andbA andbC andbA andbN.
Qed.
Lemma cardC A : #|A| + #|[predC A]| = #|T|.
Proof. by rewrite !cardE !size_filter count_predC. Qed.
Lemma cardU1 x A : #|[predU1 x & A]| = (x \notin A) + #|A|.
Proof.
case Ax: (x \in A).
by apply: eq_card => y /[1!inE]/=; case: eqP => // ->.
rewrite /= -(card1 x) -cardUI addnC.
rewrite [#|predI _ _|]eq_card0 => [|y /=]; first exact: eq_card.
by rewrite !inE; case: eqP => // ->.
Qed.
Lemma card2 x y : #|pred2 x y| = (x != y).+1.
Proof. by rewrite cardU1 card1 addn1. Qed.
Lemma cardC1 x : #|predC1 x| = #|T|.-1.
Proof. by rewrite -(cardC (pred1 x)) card1. Qed.
Lemma cardD1 x A : #|A| = (x \in A) + #|[predD1 A & x]|.
Proof.
case Ax: (x \in A); last first.
by apply: eq_card => y /[!inE]/=; case: eqP => // ->.
rewrite /= -(card1 x) -cardUI addnC /=.
rewrite [#|predI _ _|]eq_card0 => [|y]; last by rewrite !inE; case: eqP.
by apply: eq_card => y /[!inE]; case: eqP => // ->.
Qed.
Lemma max_card A : #|A| <= #|T|.
Proof. by rewrite -(cardC A) leq_addr. Qed.
Lemma card_size s : #|s| <= size s.
Proof.
elim: s => [|x s IHs] /=; first by rewrite card0.
by rewrite cardU1 /=; case: (~~ _) => //; apply: leqW.
Qed.
Lemma card_uniqP s : reflect (#|s| = size s) (uniq s).
Proof.
elim: s => [|x s IHs]; first by left; apply: card0.
rewrite cardU1 /= /addn; case: {+}(x \in s) => /=.
by right=> card_Ssz; have:= card_size s; rewrite card_Ssz ltnn.
by apply: (iffP IHs) => [<-| [<-]].
Qed.
Lemma card0_eq A : #|A| = 0 -> A =i pred0.
Proof. by move=> A0 x; apply/idP => Ax; rewrite (cardD1 x) Ax in A0. Qed.
Lemma fintype0 : T -> #|T| <> 0. Proof. by move=> x /card0_eq/(_ x). Qed.
Lemma pred0P P : reflect (P =1 pred0) (pred0b P).
Proof. by apply: (iffP eqP); [apply: card0_eq | apply: eq_card0]. Qed.
Lemma pred0Pn P : reflect (exists x, P x) (~~ pred0b P).
Proof.
case: (pickP P) => [x Px | P0].
by rewrite (introN (pred0P P)) => [|P0]; [left; exists x | rewrite P0 in Px].
by rewrite -lt0n eq_card0 //; right=> [[x]]; rewrite P0.
Qed.
Lemma card_gt0P A : reflect (exists i, i \in A) (#|A| > 0).
Proof. by rewrite lt0n; apply: pred0Pn. Qed.
Lemma card_le1P {A} : reflect {in A, forall x, A =i pred1 x} (#|A| <= 1).
Proof.
apply: (iffP idP) => [A1 x xA y|]; last first.
by have [/= x xA /(_ _ xA)/eq_card1->|/eq_card0->//] := pickP [in A].
move: A1; rewrite (cardD1 x) xA ltnS leqn0 => /eqP/card0_eq/(_ y).
by rewrite !inE; have [->|]:= eqP.
Qed.
Lemma mem_card1 A : #|A| = 1 -> {x | A =i pred1 x}.
Proof.
move=> A1; have /card_gt0P/sigW[x xA]: #|A| > 0 by rewrite A1.
by exists x; apply/card_le1P; rewrite ?A1.
Qed.
Lemma card1P A : reflect (exists x, A =i pred1 x) (#|A| == 1).
Proof.
by apply: (iffP idP) => [/eqP/mem_card1[x inA]|[x /eq_card1/eqP//]]; exists x.
Qed.
Lemma card_le1_eqP A :
reflect {in A &, forall x, all_equal_to x} (#|A| <= 1).
Proof.
apply: (iffP card_le1P) => [Ale1 x y xA yA /=|all_eq x xA y].
by apply/eqP; rewrite -[_ == _]/(y \in pred1 x) -Ale1.
by rewrite inE; case: (altP (y =P x)) => [->//|]; exact/contra_neqF/all_eq.
Qed.
Lemma fintype_le1P : reflect (forall x : T, all_equal_to x) (#|T| <= 1).
Proof. apply: (iffP (card_le1_eqP {:T})); [exact: in2T | exact: in2W]. Qed.
Lemma fintype1 : #|T| = 1 -> {x : T | all_equal_to x}.
Proof.
by move=> /mem_card1[x ex]; exists x => y; suff: y \in T by rewrite ex => /eqP.
Qed.
Lemma fintype1P : reflect (exists x, all_equal_to x) (#|T| == 1).
Proof.
apply: (iffP idP) => [/eqP/fintype1|] [x eqx]; first by exists x.
by apply/card1P; exists x => y; rewrite eqx !inE eqxx.
Qed.
Lemma subsetE A B : (A \subset B) = pred0b [predD A & B].
Proof. by rewrite unlock. Qed.
Lemma subsetP A B : reflect {subset A <= B} (A \subset B).
Proof.
rewrite unlock; apply: (iffP (pred0P _)) => [AB0 x | sAB x /=].
by apply/implyP; apply/idPn; rewrite negb_imply andbC [_ && _]AB0.
by rewrite andbC -negb_imply; apply/negbF/implyP; apply: sAB.
Qed.
Lemma subsetPn A B :
reflect (exists2 x, x \in A & x \notin B) (~~ (A \subset B)).
Proof.
rewrite unlock; apply: (iffP (pred0Pn _)) => [[x] | [x Ax nBx]].
by case/andP; exists x.
by exists x; rewrite /= nBx.
Qed.
Lemma subset_leq_card A B : A \subset B -> #|A| <= #|B|.
Proof.
move=> sAB.
rewrite -(cardID A B) [#|predI _ _|](@eq_card _ A) ?leq_addr //= => x.
by rewrite !inE andbC; case Ax: (x \in A) => //; apply: subsetP Ax.
Qed.
Lemma subxx_hint (mA : mem_pred T) : subset mA mA.
Proof.
by case: mA => A; have:= introT (subsetP A A); rewrite !unlock => ->.
Qed.
Hint Resolve subxx_hint : core.
(* The parametrization by predType makes it easier to apply subxx. *)
Lemma subxx (pT : predType T) (pA : pT) : pA \subset pA.
Proof. by []. Qed.
Lemma eq_subset A B : A =i B -> subset (mem A) =1 subset (mem B).
Proof.
move=> eqAB [C]; rewrite !unlock; congr (_ == 0).
by apply: eq_card => x; rewrite inE /= eqAB.
Qed.
Lemma eq_subset_r A B :
A =i B -> (@subset T)^~ (mem A) =1 (@subset T)^~ (mem B).
Proof.
move=> eqAB [C]; rewrite !unlock; congr (_ == 0).
by apply: eq_card => x; rewrite !inE /= eqAB.
Qed.
Lemma eq_subxx A B : A =i B -> A \subset B.
Proof. by move/eq_subset->. Qed.
Lemma subset_predT A : A \subset T.
Proof. exact/subsetP. Qed.
Lemma predT_subset A : T \subset A -> forall x, x \in A.
Proof. by move/subsetP=> allA x; apply: allA. Qed.
Lemma subset_pred1 A x : (pred1 x \subset A) = (x \in A).
Proof. by apply/subsetP/idP=> [-> // | Ax y /eqP-> //]; apply: eqxx. Qed.
Lemma subset_eqP A B : reflect (A =i B) ((A \subset B) && (B \subset A)).
Proof.
apply: (iffP andP) => [[sAB sBA] x| eqAB]; last by rewrite !eq_subxx.
by apply/idP/idP; apply: subsetP.
Qed.
Lemma subset_cardP A B : #|A| = #|B| -> reflect (A =i B) (A \subset B).
Proof.
move=> eqcAB; case: (subsetP A B) (subset_eqP A B) => //= sAB.
case: (subsetP B A) => [//|[]] x Bx; apply/idPn => Ax.
case/idP: (ltnn #|A|); rewrite {2}eqcAB (cardD1 x B) Bx /=.
apply: subset_leq_card; apply/subsetP=> y Ay; rewrite inE /= andbC.
by rewrite sAB //; apply/eqP => eqyx; rewrite -eqyx Ay in Ax.
Qed.
Lemma subset_leqif_card A B : A \subset B -> #|A| <= #|B| ?= iff (B \subset A).
Proof.
move=> sAB; split; [exact: subset_leq_card | apply/eqP/idP].
by move/subset_cardP=> sABP; rewrite (eq_subset_r (sABP sAB)).
by move=> sBA; apply: eq_card; apply/subset_eqP; rewrite sAB.
Qed.
Lemma subset_trans A B C : A \subset B -> B \subset C -> A \subset C.
Proof.
by move/subsetP=> sAB /subsetP=> sBC; apply/subsetP=> x /sAB; apply: sBC.
Qed.
Lemma subset_all s A : (s \subset A) = all [in A] s.
Proof. exact: (sameP (subsetP _ _) allP). Qed.
Lemma subset_cons s x : s \subset x :: s.
Proof. by apply/subsetP => y /[!inE] ->; rewrite orbT. Qed.
Lemma subset_cons2 s1 s2 x : s1 \subset s2 -> x :: s1 \subset x :: s2.
Proof.
by move=> ?; apply/subsetP => y /[!inE]; case: eqP => // _; apply: subsetP.
Qed.
Lemma subset_catl s s' : s \subset s ++ s'.
Proof. by apply/subsetP=> x xins; rewrite mem_cat xins. Qed.
Lemma subset_catr s s' : s \subset s' ++ s.
Proof. by apply/subsetP => x xins; rewrite mem_cat xins orbT. Qed.
Lemma subset_cat2 s1 s2 s3 : s1 \subset s2 -> s3 ++ s1 \subset s3 ++ s2.
Proof.
move=> /subsetP s12; apply/subsetP => x.
by rewrite !mem_cat => /orP[->|/s12->]; rewrite ?orbT.
Qed.
Lemma filter_subset p s : [seq a <- s | p a] \subset s.
Proof. by apply/subsetP=> x; rewrite mem_filter => /andP[]. Qed.
Lemma subset_filter p s1 s2 :
s1 \subset s2 -> [seq a <- s1 | p a] \subset [seq a <- s2 | p a].
Proof.
by move/subsetP=> s12; apply/subsetP=> x; rewrite !mem_filter=> /andP[-> /s12].
Qed.
Lemma properE A B : A \proper B = (A \subset B) && ~~ (B \subset A).
Proof. by []. Qed.
Lemma properP A B :
reflect (A \subset B /\ (exists2 x, x \in B & x \notin A)) (A \proper B).
Proof. by rewrite properE; apply: (iffP andP) => [] [-> /subsetPn]. Qed.
Lemma proper_sub A B : A \proper B -> A \subset B.
Proof. by case/andP. Qed.
Lemma proper_subn A B : A \proper B -> ~~ (B \subset A).
Proof. by case/andP. Qed.
Lemma proper_trans A B C : A \proper B -> B \proper C -> A \proper C.
Proof.
case/properP=> sAB [x Bx nAx] /properP[sBC [y Cy nBy]].
rewrite properE (subset_trans sAB) //=; apply/subsetPn; exists y => //.
by apply: contra nBy; apply: subsetP.
Qed.
Lemma proper_sub_trans A B C : A \proper B -> B \subset C -> A \proper C.
Proof.
case/properP=> sAB [x Bx nAx] sBC; rewrite properE (subset_trans sAB) //.
by apply/subsetPn; exists x; rewrite ?(subsetP _ _ sBC).
Qed.
Lemma sub_proper_trans A B C : A \subset B -> B \proper C -> A \proper C.
Proof.
move=> sAB /properP[sBC [x Cx nBx]]; rewrite properE (subset_trans sAB) //.
by apply/subsetPn; exists x => //; apply: contra nBx; apply: subsetP.
Qed.
Lemma proper_card A B : A \proper B -> #|A| < #|B|.
Proof.
by case/andP=> sAB nsBA; rewrite ltn_neqAle !(subset_leqif_card sAB) andbT.
Qed.
Lemma proper_irrefl A : ~~ (A \proper A).
Proof. by rewrite properE subxx. Qed.
Lemma properxx A : (A \proper A) = false.
Proof. by rewrite properE subxx. Qed.
Lemma eq_proper A B : A =i B -> proper (mem A) =1 proper (mem B).
Proof.
move=> eAB [C]; congr (_ && _); first exact: (eq_subset eAB).
by rewrite (eq_subset_r eAB).
Qed.
Lemma eq_proper_r A B :
A =i B -> (@proper T)^~ (mem A) =1 (@proper T)^~ (mem B).
Proof.
move=> eAB [C]; congr (_ && _); first exact: (eq_subset_r eAB).
by rewrite (eq_subset eAB).
Qed.
Lemma card_geqP {A n} :
reflect (exists s, [/\ uniq s, size s = n & {subset s <= A}]) (n <= #|A|).
Proof.
apply: (iffP idP) => [n_le_A|[s] [uniq_s size_s /subsetP subA]]; last first.
by rewrite -size_s -(card_uniqP _ uniq_s); exact: subset_leq_card.
exists (take n (enum A)); rewrite take_uniq ?enum_uniq // size_take.
split => //; last by move => x /mem_take; rewrite mem_enum.
case: (ltnP n (size (enum A))) => // size_A.
by apply/eqP; rewrite eqn_leq size_A -cardE n_le_A.
Qed.
Lemma card_gt1P A :
reflect (exists x y, [/\ x \in A, y \in A & x != y]) (1 < #|A|).
Proof.
apply: (iffP card_geqP) => [[s] []|[x] [y] [xA yA xDy]].
case: s => [|a [|b []]]//= /[!(inE, andbT)] aDb _ subD.
by exists a, b; rewrite aDb !subD ?inE ?eqxx ?orbT.
by exists [:: x; y]; rewrite /= !inE xDy; split=> // z /[!inE] /pred2P[]->.
Qed.
Lemma card_gt2P A :
reflect (exists x y z,
[/\ x \in A, y \in A & z \in A] /\ [/\ x != y, y != z & z != x])
(2 < #|A|).
Proof.
apply: (iffP card_geqP) => [[s] []|[x] [y] [z] [[xD yD zD] [xDy xDz yDz]]].
case: s => [|x [|y [|z []]]]//=; rewrite !inE !andbT negb_or -andbA.
case/and3P => xDy xDz yDz _ subA.
by exists x, y, z; rewrite xDy yDz eq_sym xDz !subA ?inE ?eqxx ?orbT.
exists [:: x; y; z]; rewrite /= !inE negb_or xDy xDz eq_sym yDz; split=> // u.
by rewrite !inE => /or3P [] /eqP->.
Qed.
Lemma disjoint_sym A B : [disjoint A & B] = [disjoint B & A].
Proof. by congr (_ == 0); apply: eq_card => x; apply: andbC. Qed.
Lemma eq_disjoint A B : A =i B -> disjoint (mem A) =1 disjoint (mem B).
Proof.
by move=> eqAB [C]; congr (_ == 0); apply: eq_card => x; rewrite !inE eqAB.
Qed.
Lemma eq_disjoint_r A B : A =i B ->
(@disjoint T)^~ (mem A) =1 (@disjoint T)^~ (mem B).
Proof.
by move=> eqAB [C]; congr (_ == 0); apply: eq_card => x; rewrite !inE eqAB.
Qed.
Lemma subset_disjoint A B : (A \subset B) = [disjoint A & [predC B]].
Proof. by rewrite disjoint_sym unlock. Qed.
Lemma disjoint_subset A B : [disjoint A & B] = (A \subset [predC B]).
Proof.
by rewrite subset_disjoint; apply: eq_disjoint_r => x; rewrite !inE /= negbK.
Qed.
Lemma disjointFr A B x : [disjoint A & B] -> x \in A -> x \in B = false.
Proof. by move/pred0P/(_ x) => /=; case: (x \in A). Qed.
Lemma disjointFl A B x : [disjoint A & B] -> x \in B -> x \in A = false.
Proof. rewrite disjoint_sym; exact: disjointFr. Qed.
Lemma disjointWl A B C :
A \subset B -> [disjoint B & C] -> [disjoint A & C].
Proof. by rewrite 2!disjoint_subset; apply: subset_trans. Qed.
Lemma disjointWr A B C : A \subset B -> [disjoint C & B] -> [disjoint C & A].
Proof. rewrite ![[disjoint C & _]]disjoint_sym. exact:disjointWl. Qed.
Lemma disjointW A B C D :
A \subset B -> C \subset D -> [disjoint B & D] -> [disjoint A & C].
Proof.
by move=> subAB subCD BD; apply/(disjointWl subAB)/(disjointWr subCD).
Qed.
Lemma disjoint0 A : [disjoint pred0 & A].
Proof. exact/pred0P. Qed.
Lemma eq_disjoint0 A B : A =i pred0 -> [disjoint A & B].
Proof. by move/eq_disjoint->; apply: disjoint0. Qed.
Lemma disjoint1 x A : [disjoint pred1 x & A] = (x \notin A).
Proof.
apply/negbRL/(sameP (pred0Pn _))=> /=.
apply: introP => [Ax | notAx [_ /andP[/eqP->]]]; last exact: negP.
by exists x; rewrite inE eqxx.
Qed.
Lemma eq_disjoint1 x A B :
A =i pred1 x -> [disjoint A & B] = (x \notin B).
Proof. by move/eq_disjoint->; apply: disjoint1. Qed.
Lemma disjointU A B C :
[disjoint predU A B & C] = [disjoint A & C] && [disjoint B & C].
Proof.
case: [disjoint A & C] / (pred0P (xpredI A C)) => [A0 | nA0] /=.
by congr (_ == 0); apply: eq_card => x; rewrite [x \in _]andb_orl A0.
apply/pred0P=> nABC; case: nA0 => x; apply/idPn=> /=; move/(_ x): nABC.
by rewrite [_ x]andb_orl; case/norP.
Qed.
Lemma disjointU1 x A B :
[disjoint predU1 x A & B] = (x \notin B) && [disjoint A & B].
Proof. by rewrite disjointU disjoint1. Qed.
Lemma disjoint_cons x s B :
[disjoint x :: s & B] = (x \notin B) && [disjoint s & B].
Proof. exact: disjointU1. Qed.
Lemma disjoint_has s A : [disjoint s & A] = ~~ has [in A] s.
Proof.
apply/negbRL; apply/pred0Pn/hasP => [[x /andP[]]|[x]]; exists x => //.
exact/andP.
Qed.
Lemma disjoint_cat s1 s2 A :
[disjoint s1 ++ s2 & A] = [disjoint s1 & A] && [disjoint s2 & A].
Proof. by rewrite !disjoint_has has_cat negb_or. Qed.
End OpsTheory.
Lemma map_subset {T T' : finType} (s1 s2 : seq T) (f : T -> T') :
s1 \subset s2 -> [seq f x | x <- s1 ] \subset [seq f x | x <- s2].
Proof.
move=> s1s2; apply/subsetP => _ /mapP[y] /[swap] -> ys1.
by apply/mapP; exists y => //; move/subsetP : s1s2; exact.
Qed.
#[global] Hint Resolve subxx_hint : core.
Arguments pred0P {T P}.
Arguments pred0Pn {T P}.
Arguments card_le1P {T A}.
Arguments card_le1_eqP {T A}.
Arguments card1P {T A}.
Arguments fintype_le1P {T}.
Arguments fintype1P {T}.
Arguments subsetP {T A B}.
Arguments subsetPn {T A B}.
Arguments subset_eqP {T A B}.
Arguments card_uniqP {T s}.
Arguments card_geqP {T A n}.
Arguments card_gt0P {T A}.
Arguments card_gt1P {T A}.
Arguments card_gt2P {T A}.
Arguments properP {T A B}.
(**********************************************************************)
(* *)
(* Boolean quantifiers for finType *)
(* *)
(**********************************************************************)
Section QuantifierCombinators.
Variables (T : finType) (P : pred T) (PP : T -> Prop).
Hypothesis viewP : forall x, reflect (PP x) (P x).
Lemma existsPP : reflect (exists x, PP x) [exists x, P x].
Proof. by apply: (iffP pred0Pn) => -[x /viewP]; exists x. Qed.
Lemma forallPP : reflect (forall x, PP x) [forall x, P x].
Proof. by apply: (iffP pred0P) => /= allP x; have /viewP//=-> := allP x. Qed.
End QuantifierCombinators.
Notation "'exists_ view" := (existsPP (fun _ => view))
(at level 4, right associativity, format "''exists_' view").
Notation "'forall_ view" := (forallPP (fun _ => view))
(at level 4, right associativity, format "''forall_' view").
Section Quantifiers.
Variables (T : finType) (rT : T -> eqType).
Implicit Types (D P : pred T) (f : forall x, rT x).
Lemma forallP P : reflect (forall x, P x) [forall x, P x].
Proof. exact: 'forall_idP. Qed.
Lemma eqfunP f1 f2 : reflect (forall x, f1 x = f2 x) [forall x, f1 x == f2 x].
Proof. exact: 'forall_eqP. Qed.
Lemma forall_inP D P : reflect (forall x, D x -> P x) [forall (x | D x), P x].
Proof. exact: 'forall_implyP. Qed.
Lemma forall_inPP D P PP : (forall x, reflect (PP x) (P x)) ->
reflect (forall x, D x -> PP x) [forall (x | D x), P x].
Proof. by move=> vP; apply: (iffP (forall_inP _ _)) => /(_ _ _) /vP. Qed.
Lemma eqfun_inP D f1 f2 :
reflect {in D, forall x, f1 x = f2 x} [forall (x | x \in D), f1 x == f2 x].
Proof. exact: (forall_inPP _ (fun=> eqP)). Qed.
Lemma existsP P : reflect (exists x, P x) [exists x, P x].
Proof. exact: 'exists_idP. Qed.
Lemma existsb P (x : T) : P x -> [exists x, P x].
Proof. by move=> Px; apply/existsP; exists x. Qed.
Lemma exists_eqP f1 f2 :
reflect (exists x, f1 x = f2 x) [exists x, f1 x == f2 x].
Proof. exact: 'exists_eqP. Qed.
Lemma exists_inP D P : reflect (exists2 x, D x & P x) [exists (x | D x), P x].
Proof. by apply: (iffP 'exists_andP) => [[x []] | [x]]; exists x. Qed.
Lemma exists_inb D P (x : T) : D x -> P x -> [exists (x | D x), P x].
Proof. by move=> Dx Px; apply/exists_inP; exists x. Qed.
Lemma exists_inPP D P PP : (forall x, reflect (PP x) (P x)) ->
reflect (exists2 x, D x & PP x) [exists (x | D x), P x].
Proof. by move=> vP; apply: (iffP (exists_inP _ _)) => -[x?/vP]; exists x. Qed.
Lemma exists_eq_inP D f1 f2 :
reflect (exists2 x, D x & f1 x = f2 x) [exists (x | D x), f1 x == f2 x].
Proof. exact: (exists_inPP _ (fun=> eqP)). Qed.
Lemma eq_existsb P1 P2 : P1 =1 P2 -> [exists x, P1 x] = [exists x, P2 x].
Proof. by move=> eqP12; congr (_ != 0); apply: eq_card. Qed.
Lemma eq_existsb_in D P1 P2 :
(forall x, D x -> P1 x = P2 x) ->
[exists (x | D x), P1 x] = [exists (x | D x), P2 x].
Proof. by move=> eqP12; apply: eq_existsb => x; apply: andb_id2l => /eqP12. Qed.
Lemma eq_forallb P1 P2 : P1 =1 P2 -> [forall x, P1 x] = [forall x, P2 x].
Proof. by move=> eqP12; apply/negb_inj/eq_existsb=> /= x; rewrite eqP12. Qed.
Lemma eq_forallb_in D P1 P2 :
(forall x, D x -> P1 x = P2 x) ->
[forall (x | D x), P1 x] = [forall (x | D x), P2 x].
Proof.
by move=> eqP12; apply: eq_forallb => i; case Di: (D i); rewrite // eqP12.
Qed.
Lemma existsbWl P Q : [exists x, P x && Q x] -> [exists x, P x].
Proof. move => /existsP ; case => x /andP [H _] ; apply/existsP ; by exists x. Qed.
Lemma existsbWr P Q : [exists x, P x && Q x] -> [exists x, Q x].
Proof. move => /existsP ; case => x /andP [_ H] ; apply/existsP ; by exists x. Qed.
Lemma negb_forall P : ~~ [forall x, P x] = [exists x, ~~ P x].
Proof. by []. Qed.
Lemma negb_forall_in D P :
~~ [forall (x | D x), P x] = [exists (x | D x), ~~ P x].
Proof. by apply: eq_existsb => x; rewrite negb_imply. Qed.
Lemma negb_exists P : ~~ [exists x, P x] = [forall x, ~~ P x].
Proof. by apply/negbLR/esym/eq_existsb=> x; apply: negbK. Qed.
Lemma negb_exists_in D P :
~~ [exists (x | D x), P x] = [forall (x | D x), ~~ P x].
Proof. by rewrite negb_exists; apply/eq_forallb => x; rewrite [~~ _]fun_if. Qed.
Lemma existsPn P :
reflect (forall x, ~~ P x) (~~ [exists x, P x]).
Proof. rewrite negb_exists. exact: forallP. Qed.
Lemma forallPn P :
reflect (exists x, ~~ P x) (~~ [forall x, P x]).
Proof. rewrite negb_forall. exact: existsP. Qed.
Lemma exists_inPn D P :
reflect (forall x, x \in D -> ~~ P x) (~~ [exists x in D, P x]).
Proof. rewrite negb_exists_in. exact: forall_inP. Qed.
Lemma forall_inPn D P :
reflect (exists2 x, x \in D & ~~ P x) (~~ [forall x in D, P x]).
Proof. rewrite negb_forall_in. exact: exists_inP. Qed.
End Quantifiers.
Arguments forallP {T P}.
Arguments eqfunP {T rT f1 f2}.
Arguments forall_inP {T D P}.
Arguments eqfun_inP {T rT D f1 f2}.
Arguments existsP {T P}.
Arguments existsb {T P}.
Arguments exists_eqP {T rT f1 f2}.
Arguments exists_inP {T D P}.
Arguments exists_inb {T D P}.
Arguments exists_eq_inP {T rT D f1 f2}.
Arguments existsPn {T P}.
Arguments exists_inPn {T D P}.
Arguments forallPn {T P}.
Arguments forall_inPn {T D P}.
Notation "'exists_in_ view" := (exists_inPP _ (fun _ => view))
(at level 4, right associativity, format "''exists_in_' view").
Notation "'forall_in_ view" := (forall_inPP _ (fun _ => view))
(at level 4, right associativity, format "''forall_in_' view").
(**********************************************************************)
(* *)
(* Boolean injectivity test for functions with a finType domain *)
(* *)
(**********************************************************************)
Section Injectiveb.
Variables (aT : finType) (rT : eqType).
Implicit Type (f : aT -> rT) (D : {pred aT}).
Definition dinjectiveb f D := uniq (map f (enum D)).
Definition injectiveb f := dinjectiveb f aT.
Lemma dinjectivePn f D :
reflect (exists2 x, x \in D & exists2 y, y \in [predD1 D & x] & f x = f y)
(~~ dinjectiveb f D).
Proof.
apply: (iffP idP) => [injf | [x Dx [y Dxy eqfxy]]]; last first.
move: Dx; rewrite -(mem_enum D) => /rot_to[i E defE].
rewrite /dinjectiveb -(rot_uniq i) -map_rot defE /=; apply/nandP; left.
rewrite inE /= -(mem_enum D) -(mem_rot i) defE inE in Dxy.
rewrite andb_orr andbC andbN in Dxy.
by rewrite eqfxy map_f //; case/andP: Dxy.
pose p := [pred x in D | [exists (y | y \in [predD1 D & x]), f x == f y]].
case: (pickP p) => [x /= /andP[Dx /exists_inP[y Dxy /eqP eqfxy]] | no_p].
by exists x; last exists y.
rewrite /dinjectiveb map_inj_in_uniq ?enum_uniq // in injf => x y Dx Dy eqfxy.
apply: contraNeq (negbT (no_p x)) => ne_xy /=; rewrite -mem_enum Dx.
by apply/existsP; exists y; rewrite /= !inE eq_sym ne_xy -mem_enum Dy eqfxy /=.
Qed.
Lemma dinjectiveP f D : reflect {in D &, injective f} (dinjectiveb f D).
Proof.
rewrite -[dinjectiveb f D]negbK.
case: dinjectivePn=> [noinjf | injf]; constructor.
case: noinjf => x Dx [y /andP[neqxy /= Dy] eqfxy] injf.
by case/eqP: neqxy; apply: injf.
move=> x y Dx Dy /= eqfxy; apply/eqP; apply/idPn=> nxy; case: injf.
by exists x => //; exists y => //=; rewrite inE /= eq_sym nxy.
Qed.
Lemma eq_dinjectiveb f1 f2 D1 D2 :
f1 =1 f2 -> D1 =i D2 -> dinjectiveb f1 D1 = dinjectiveb f2 D2.
Proof.
move=> ef eD; rewrite /dinjectiveb (eq_enum eD).
by under eq_map => x do rewrite ef.
Qed.
Lemma injectivePn f :
reflect (exists x, exists2 y, x != y & f x = f y) (~~ injectiveb f).
Proof.
apply: (iffP (dinjectivePn _ _)) => [[x _ [y nxy eqfxy]] | [x [y nxy eqfxy]]];
by exists x => //; exists y => //; rewrite inE /= andbT eq_sym in nxy *.
Qed.
Lemma injectiveP f : reflect (injective f) (injectiveb f).
Proof.
by apply: (iffP (dinjectiveP _ _)) => injf x y => [|_ _]; apply: injf.
Qed.
Lemma eq_injectiveb f1 f2 : f1 =1 f2 -> injectiveb f1 = injectiveb f2.
Proof. move=> ?; exact: eq_dinjectiveb. Qed.
End Injectiveb.
Definition image_mem T T' f mA : seq T' := map f (@enum_mem T mA).
Notation image f A := (image_mem f (mem A)).
Notation "[ 'seq' F | x 'in' A ]" := (image (fun x => F) A)
(x binder, format "'[hv' [ 'seq' F '/ ' | x 'in' A ] ']'") : seq_scope.
Notation "[ 'seq' F | x ]" :=
[seq F | x in pred_of_simpl (@pred_of_argType
(* kludge for getting the type of x *)
match _, (fun x => I) with
| T, f
=> match match f return T -> True with f' => f' end with
| _ => T
end
end)]
(x binder, only parsing) : seq_scope.
Notation "[ 'seq' F | x : T ]" :=
[seq F | x in pred_of_simpl (@pred_of_argType T)]
(x binder, only printing,
format "'[hv' [ 'seq' F '/ ' | x : T ] ']'") : seq_scope.
Notation "[ 'seq' F , x ]" := [seq F | x ]
(x binder, only parsing) : seq_scope.
Definition codom T T' f := @image_mem T T' f (mem T).
Section Image.
Variable T : finType.
Implicit Type A : {pred T}.
Section SizeImage.
Variables (T' : Type) (f : T -> T').
Lemma size_image A : size (image f A) = #|A|.
Proof. by rewrite size_map -cardE. Qed.
Lemma size_codom : size (codom f) = #|T|.
Proof. exact: size_image. Qed.
Lemma codomE : codom f = map f (enum T).
Proof. by []. Qed.
End SizeImage.
Variables (T' : eqType) (f : T -> T').
Lemma imageP A y : reflect (exists2 x, x \in A & y = f x) (y \in image f A).
Proof.
by apply: (iffP mapP) => [] [x Ax y_fx]; exists x; rewrite // mem_enum in Ax *.
Qed.
Lemma codomP y : reflect (exists x, y = f x) (y \in codom f).
Proof. by apply: (iffP (imageP _ y)) => [][x]; exists x. Qed.
Remark iinv_proof A y : y \in image f A -> {x | x \in A & f x = y}.
Proof.
move=> fy; pose b x := A x && (f x == y).
case: (pickP b) => [x /andP[Ax /eqP] | nfy]; first by exists x.
by case/negP: fy => /imageP[x Ax fx_y]; case/andP: (nfy x); rewrite fx_y.
Qed.
Definition iinv A y fAy := s2val (@iinv_proof A y fAy).
Lemma f_iinv A y fAy : f (@iinv A y fAy) = y.
Proof. exact: s2valP' (iinv_proof fAy). Qed.
Lemma mem_iinv A y fAy : @iinv A y fAy \in A.
Proof. exact: s2valP (iinv_proof fAy). Qed.
Lemma in_iinv_f A : {in A &, injective f} ->
forall x fAfx, x \in A -> @iinv A (f x) fAfx = x.
Proof.
by move=> injf x fAfx Ax; apply: injf => //; [apply: mem_iinv | apply: f_iinv].
Qed.
Lemma preim_iinv A B y fAy : preim f B (@iinv A y fAy) = B y.
Proof. by rewrite /= f_iinv. Qed.
Lemma image_f A x : x \in A -> f x \in image f A.
Proof. by move=> Ax; apply/imageP; exists x. Qed.
Lemma codom_f x : f x \in codom f.
Proof. exact: image_f. Qed.
Lemma image_codom A : {subset image f A <= codom f}.
Proof. by move=> _ /imageP[x _ ->]; apply: codom_f. Qed.
Lemma image_pred0 : image f pred0 =i pred0.
Proof. by move=> x; rewrite /image_mem /= enum0. Qed.
Section Injective.
Hypothesis injf : injective f.
Lemma mem_image A x : (f x \in image f A) = (x \in A).
Proof. by rewrite mem_map ?mem_enum. Qed.
Lemma pre_image A : [preim f of image f A] =i A.
Proof. by move=> x; rewrite inE /= mem_image. Qed.
Lemma image_iinv A y (fTy : y \in codom f) :
(y \in image f A) = (iinv fTy \in A).
Proof. by rewrite -mem_image ?f_iinv. Qed.
Lemma iinv_f x fTfx : @iinv T (f x) fTfx = x.
Proof. by apply: in_iinv_f; first apply: in2W. Qed.
Lemma image_pre (B : pred T') : image f [preim f of B] =i [predI B & codom f].
Proof. by move=> y; rewrite /image_mem -filter_map /= mem_filter -enumT. Qed.
Lemma bij_on_codom (x0 : T) : {on [pred y in codom f], bijective f}.
Proof.
pose g y := iinv (valP (insigd (codom_f x0) y)).
by exists g => [x fAfx | y fAy]; first apply: injf; rewrite f_iinv insubdK.
Qed.
Lemma bij_on_image A (x0 : T) : {on [pred y in image f A], bijective f}.
Proof. exact: subon_bij (@image_codom A) (bij_on_codom x0). Qed.
End Injective.
Fixpoint preim_seq s :=
if s is y :: s' then
(if pick (preim f (pred1 y)) is Some x then cons x else id) (preim_seq s')
else [::].
Lemma map_preim (s : seq T') : {subset s <= codom f} -> map f (preim_seq s) = s.
Proof.
elim: s => //= y s IHs; case: pickP => [x /eqP fx_y | nfTy] fTs.
by rewrite /= fx_y IHs // => z s_z; apply: fTs; apply: predU1r.
by case/imageP: (fTs y (mem_head y s)) => x _ fx_y; case/eqP: (nfTy x).
Qed.
End Image.
Prenex Implicits codom iinv.
Arguments imageP {T T' f A y}.
Arguments codomP {T T' f y}.
Lemma flatten_imageP (aT : finType) (rT : eqType)
(A : aT -> seq rT) (P : {pred aT}) (y : rT) :
reflect (exists2 x, x \in P & y \in A x) (y \in flatten [seq A x | x in P]).
Proof.
by apply: (iffP flatten_mapP) => [][x Px]; exists x; rewrite ?mem_enum in Px *.
Qed.
Arguments flatten_imageP {aT rT A P y}.
Section CardFunImage.
Variables (T T' : finType) (f : T -> T').
Implicit Type A : {pred T}.
Lemma leq_image_card A : #|image f A| <= #|A|.
Proof. by rewrite (cardE A) -(size_map f) card_size. Qed.
Lemma card_in_image A : {in A &, injective f} -> #|image f A| = #|A|.
Proof.
move=> injf; rewrite (cardE A) -(size_map f); apply/card_uniqP.
by rewrite map_inj_in_uniq ?enum_uniq // => x y; rewrite !mem_enum; apply: injf.
Qed.
Lemma image_injP A : reflect {in A &, injective f} (#|image f A| == #|A|).
Proof.
apply: (iffP eqP) => [eqfA |]; last exact: card_in_image.
by apply/dinjectiveP; apply/card_uniqP; rewrite size_map -cardE.
Qed.
Lemma leq_card_in A : {in A &, injective f} -> #|A| <= #|T'|.
Proof. by move=> /card_in_image <-; rewrite max_card. Qed.
Hypothesis injf : injective f.
Lemma card_image A : #|image f A| = #|A|.
Proof. by apply: card_in_image; apply: in2W. Qed.
Lemma card_codom : #|codom f| = #|T|.
Proof. exact: card_image. Qed.
Lemma card_preim (B : {pred T'}) : #|[preim f of B]| = #|[predI codom f & B]|.
Proof.
rewrite -card_image /=; apply: eq_card => y.
by rewrite [y \in _]image_pre !inE andbC.
Qed.
Lemma leq_card : #|T| <= #|T'|. Proof. exact: (leq_card_in (in2W _)). Qed.
Hypothesis card_range : #|T| >= #|T'|.
Let eq_card : #|T| = #|T'|. Proof. by apply/eqP; rewrite eqn_leq leq_card. Qed.
Lemma inj_card_onto y : y \in codom f.
Proof. by move: y; apply/subset_cardP; rewrite ?card_codom ?subset_predT. Qed.
Lemma inj_card_bij : bijective f.
Proof.
by exists (fun y => iinv (inj_card_onto y)) => y; rewrite ?iinv_f ?f_iinv.
Qed.
End CardFunImage.
Arguments image_injP {T T' f A}.
Arguments leq_card_in [T T'] f.
Arguments leq_card [T T'] f.
Lemma bij_eq_card (T T' : finType) (f : T -> T') : bijective f -> #|T| = #|T'|.
Proof. by move=> [g /can_inj/leq_card + /can_inj/leq_card]; case: ltngtP. Qed.
Section FinCancel.
Variables (T : finType) (f g : T -> T).
Section Inv.
Hypothesis injf : injective f.
Lemma injF_onto y : y \in codom f. Proof. exact: inj_card_onto. Qed.
Definition invF y := iinv (injF_onto y).
Lemma invF_f : cancel f invF. Proof. by move=> x; apply: iinv_f. Qed.
Lemma f_invF : cancel invF f. Proof. by move=> y; apply: f_iinv. Qed.
Lemma injF_bij : bijective f. Proof. exact: inj_card_bij. Qed.
End Inv.
Hypothesis fK : cancel f g.
Lemma canF_sym : cancel g f.
Proof. exact/(bij_can_sym (injF_bij (can_inj fK))). Qed.
Lemma canF_LR x y : x = g y -> f x = y.
Proof. exact: canLR canF_sym. Qed.
Lemma canF_RL x y : g x = y -> x = f y.
Proof. exact: canRL canF_sym. Qed.
Lemma canF_eq x y : (f x == y) = (x == g y).
Proof. exact: (can2_eq fK canF_sym). Qed.
Lemma canF_invF : g =1 invF (can_inj fK).
Proof. by move=> y; apply: (canLR fK); rewrite f_invF. Qed.
End FinCancel.
Section EqImage.
Variables (T : finType) (T' : Type).
Lemma eq_image (A B : {pred T}) (f g : T -> T') :
A =i B -> f =1 g -> image f A = image g B.
Proof.
by move=> eqAB eqfg; rewrite /image_mem (eq_enum eqAB) (eq_map eqfg).
Qed.
Lemma eq_codom (f g : T -> T') : f =1 g -> codom f = codom g.
Proof. exact: eq_image. Qed.
Lemma eq_invF f g injf injg : f =1 g -> @invF T f injf =1 @invF T g injg.
Proof.
by move=> eq_fg x; apply: (canLR (invF_f injf)); rewrite eq_fg f_invF.
Qed.
End EqImage.
(* Standard finTypes *)
Lemma unit_enumP : Finite.axiom [::tt]. Proof. by case. Qed.
HB.instance Definition _ := isFinite.Build unit unit_enumP.
Lemma card_unit : #|{: unit}| = 1. Proof. by rewrite cardT enumT unlock. Qed.
Lemma bool_enumP : Finite.axiom [:: true; false]. Proof. by case. Qed.
HB.instance Definition _ := isFinite.Build bool bool_enumP.
Lemma card_bool : #|{: bool}| = 2. Proof. by rewrite cardT enumT unlock. Qed.
Lemma void_enumP : Finite.axiom (Nil void). Proof. by case. Qed.
HB.instance Definition _ := isFinite.Build void void_enumP.
Lemma card_void : #|{: void}| = 0. Proof. by rewrite cardT enumT unlock. Qed.
Local Notation enumF T := (Finite.enum T).
Section OptionFinType.
Variable T : finType.
Definition option_enum := None :: map some (enumF T).
Lemma option_enumP : Finite.axiom option_enum.
Proof. by case=> [x|]; rewrite /= count_map (count_pred0, enumP). Qed.
HB.instance Definition _ := isFinite.Build (option T) option_enumP.
Lemma card_option : #|{: option T}| = #|T|.+1.
Proof. by rewrite !cardT !enumT [in LHS]unlock /= !size_map. Qed.
End OptionFinType.
Section TransferFinTypeFromCount.
Variables (eT : countType) (fT : finType) (f : eT -> fT).
Lemma pcan_enumP g : pcancel f g -> Finite.axiom (undup (pmap g (enumF fT))).
Proof.
move=> fK x; rewrite count_uniq_mem ?undup_uniq // mem_undup.
by rewrite mem_pmap -fK map_f // -enumT mem_enum.
Qed.
Definition PCanIsFinite g fK := @isFinite.Build _ _ (@pcan_enumP g fK).
Definition CanIsFinite g (fK : cancel f g) := PCanIsFinite (can_pcan fK).
End TransferFinTypeFromCount.
Section TransferFinType.
Variables (eT : Type) (fT : finType) (f : eT -> fT).
HB.instance Definition _ (g : fT -> option eT) (fK : pcancel f g) :=
isFinite.Build (pcan_type fK) (@pcan_enumP (pcan_type fK) fT f g fK).
HB.instance Definition _ (g : fT -> eT) (fK : cancel f g) :=
isFinite.Build (can_type fK) (@pcan_enumP (can_type fK) fT f _ (can_pcan fK)).
End TransferFinType.
#[short(type="subFinType")]
HB.structure Definition SubFinite (T : Type) (P : pred T) :=
{ sT of Finite sT & isSub T P sT }.
Section SubFinType.
Variables (T : choiceType) (P : pred T).
Import Finite.
Implicit Type sT : subFinType P.
Lemma codom_val sT x : (x \in codom (val : sT -> T)) = P x.
Proof.
by apply/codomP/idP=> [[u ->]|Px]; last exists (Sub x Px); rewrite ?valP ?SubK.
Qed.
End SubFinType.
HB.factory Record SubCountable_isFinite (T : finType) P (sT : Type)
of SubCountable T P sT := { }.
HB.builders Context (T : finType) (P : pred T) (sT : Type)
(a : SubCountable_isFinite T P sT).
Definition sub_enum : seq sT := pmap insub (enumF T).
Lemma mem_sub_enum u : u \in sub_enum.
Proof. by rewrite mem_pmap_sub -enumT mem_enum. Qed.
Lemma sub_enum_uniq : uniq sub_enum.
Proof. by rewrite pmap_sub_uniq // -enumT enum_uniq. Qed.
Lemma val_sub_enum : map val sub_enum = enum P.
Proof.
rewrite pmap_filter; last exact: insubK.
by apply: eq_filter => x; apply: isSome_insub.
Qed.
HB.instance Definition SubFinMixin := isFinite.Build sT
(Finite.uniq_enumP sub_enum_uniq mem_sub_enum).
HB.end.
(* This assumes that T has a subCountType structure over a type that *)
(* has a finType structure. *)
HB.instance Definition _ (T : finType) (P : pred T) (sT : subType P) :=
(SubCountable_isFinite.Build _ _ (sub_type sT)).
Notation "[ 'Finite' 'of' T 'by' <: ]" := (Finite.copy T%type (sub_type T%type))
(format "[ 'Finite' 'of' T 'by' <: ]") : form_scope.
Section SubCountable_isFiniteTheory.
Variables (T : finType) (P : pred T) (sfT : subFinType P).
Lemma card_sub : #|sfT| = #|[pred x | P x]|.
Proof. by rewrite -(eq_card (codom_val sfT)) (card_image val_inj). Qed.
Lemma eq_card_sub (A : {pred sfT}) : A =i predT -> #|A| = #|[pred x | P x]|.
Proof. exact: eq_card_trans card_sub. Qed.
End SubCountable_isFiniteTheory.
(* (* Regression for the subFinType stack *) *)
(* Record myb : Type := MyB {myv : bool; _ : ~~ myv}. *)
(* HB.instance Definition myb_sub : isSub bool (fun x => ~~ x) myb := *)
(* [isSub for myv]. *)
(* HB.instance Definition _ := [Finite of myb by <:]. *)
(* Check [subFinType of myb]. *)
(* Check [finType of myb]. *)
Section CardSig.
Variables (T : finType) (P : pred T).
HB.instance Definition _ := [Finite of {x | P x} by <:].
Lemma card_sig : #|{: {x | P x}}| = #|[pred x | P x]|.
Proof. exact: card_sub. Qed.
End CardSig.
(* Subtype for an explicit enumeration. *)
Section SeqSubType.
Variables (T : eqType) (s : seq T).
Record seq_sub : Type := SeqSub {ssval : T; ssvalP : in_mem ssval (@mem T _ s)}.
HB.instance Definition _ := [isSub for ssval].
HB.instance Definition _ := [Equality of seq_sub by <:].
Definition seq_sub_enum : seq seq_sub := undup (pmap insub s).
Lemma mem_seq_sub_enum x : x \in seq_sub_enum.
Proof. by rewrite mem_undup mem_pmap -valK map_f ?ssvalP. Qed.
Lemma val_seq_sub_enum : uniq s -> map val seq_sub_enum = s.
Proof.
move=> Us; rewrite /seq_sub_enum undup_id ?pmap_sub_uniq //.
rewrite (pmap_filter (insubK _)); apply/all_filterP.
by apply/allP => x; rewrite isSome_insub.
Qed.
Definition seq_sub_pickle x := index x seq_sub_enum.
Definition seq_sub_unpickle n := nth None (map some seq_sub_enum) n.
Lemma seq_sub_pickleK : pcancel seq_sub_pickle seq_sub_unpickle.
Proof.
rewrite /seq_sub_unpickle => x.
by rewrite (nth_map x) ?nth_index ?index_mem ?mem_seq_sub_enum.
Qed.
Definition seq_sub_isCountable := isCountable.Build seq_sub seq_sub_pickleK.
Fact seq_sub_axiom : Finite.axiom seq_sub_enum.
Proof. exact: Finite.uniq_enumP (undup_uniq _) mem_seq_sub_enum. Qed.
Definition seq_sub_isFinite := isFinite.Build seq_sub seq_sub_axiom.
(* Beware: these are not the canonical instances, as they are not consistent *)
(* with the generic sub_choiceType canonical instance. *)
Definition adhoc_seq_sub_choiceType : choiceType := pcan_type seq_sub_pickleK.
Definition adhoc_seq_sub_countType := HB.pack_for countType seq_sub
seq_sub_isCountable (Choice.class adhoc_seq_sub_choiceType).
Definition adhoc_seq_sub_finType := HB.pack_for finType seq_sub
seq_sub_isFinite seq_sub_isCountable (Choice.class adhoc_seq_sub_choiceType).
End SeqSubType.
Section SeqReplace.
Variables (T : eqType).
Implicit Types (s : seq T).
Lemma seq_sub_default s : size s > 0 -> seq_sub s.
Proof. by case: s => // x s _; exists x; rewrite mem_head. Qed.
Lemma seq_subE s (s_gt0 : size s > 0) :
s = map val (map (insubd (seq_sub_default s_gt0)) s : seq (seq_sub s)).
Proof. by rewrite -map_comp map_id_in// => x x_in_s /=; rewrite insubdK. Qed.
End SeqReplace.
Notation in_sub_seq s_gt0 := (insubd (seq_sub_default s_gt0)).
Section SeqFinType.
Variables (T : choiceType) (s : seq T).
Local Notation sT := (seq_sub s).
HB.instance Definition _ := [Choice of sT by <:].
HB.instance Definition _ : isCountable sT := seq_sub_isCountable s.
HB.instance Definition _ : isFinite sT := seq_sub_isFinite s.
Lemma card_seq_sub : uniq s -> #|{:sT}| = size s.
Proof.
by move=> Us; rewrite cardE enumT -(size_map val) unlock val_seq_sub_enum.
Qed.
End SeqFinType.
Section Extrema.
Variant extremum_spec {T : eqType} (ord : rel T) {I : finType}
(P : pred I) (F : I -> T) : I -> Type :=
ExtremumSpec (i : I) of P i & (forall j : I, P j -> ord (F i) (F j)) :
extremum_spec ord P F i.
Let arg_pred {T : eqType} ord {I : finType} (P : pred I) (F : I -> T) :=
[pred i | P i & [forall (j | P j), ord (F i) (F j)]].
Section Extremum.
Context {T : eqType} {I : finType} (ord : rel T).
Context (i0 : I) (P : pred I) (F : I -> T).
Definition extremum := odflt i0 (pick (arg_pred ord P F)).
Hypothesis ord_refl : reflexive ord.
Hypothesis ord_trans : transitive ord.
Hypothesis ord_total : total ord.
Hypothesis Pi0 : P i0.
Lemma extremumP : extremum_spec ord P F extremum.
Proof.
rewrite /extremum; case: pickP => [i /andP[Pi /'forall_implyP/= min_i] | no_i].
by split=> // j; apply/implyP.
have := sort_sorted ord_total [seq F i | i <- enum P].
set s := sort _ _ => ss; have s_gt0 : size s > 0
by rewrite size_sort size_map -cardE; apply/card_gt0P; exists i0.
pose t0 := nth (F i0) s 0; have: t0 \in s by rewrite mem_nth.
rewrite mem_sort => /mapP/sig2_eqW[it0]; rewrite mem_enum => it0P def_t0.
have /negP[/=] := no_i it0; rewrite [P _]it0P/=; apply/'forall_implyP=> j Pj.
have /(nthP (F i0))[k g_lt <-] : F j \in s by rewrite mem_sort map_f ?mem_enum.
by rewrite -def_t0 sorted_leq_nth.
Qed.
End Extremum.
Section ExtremumIn.
Context {T : eqType} {I : finType} (ord : rel T).
Context (i0 : I) (P : pred I) (F : I -> T).
Hypothesis ord_refl : {in P, reflexive (relpre F ord)}.
Hypothesis ord_trans : {in P & P & P, transitive (relpre F ord)}.
Hypothesis ord_total : {in P &, total (relpre F ord)}.
Hypothesis Pi0 : P i0.
Lemma extremum_inP : extremum_spec ord P F (extremum ord i0 P F).
Proof.
rewrite /extremum; case: pickP => [i /andP[Pi /'forall_implyP/= min_i] | no_i].
by split=> // j; apply/implyP.
pose TP := seq_sub [seq F i | i <- enum P].
have FPP (iP : {i | P i}) : F (proj1_sig iP) \in [seq F i | i <- enum P].
by rewrite map_f// mem_enum; apply: valP.
pose FP := SeqSub (FPP _).
have []//= := @extremumP _ _ (relpre val ord) (exist P i0 Pi0) xpredT FP.
- by move=> [/= _/mapP[i iP ->]]; apply: ord_refl; rewrite mem_enum in iP.
- move=> [/= _/mapP[j jP ->]] [/= _/mapP[i iP ->]] [/= _/mapP[k kP ->]].
by apply: ord_trans; rewrite !mem_enum in iP jP kP.
- move=> [/= _/mapP[i iP ->]] [/= _/mapP[j jP ->]].
by apply: ord_total; rewrite !mem_enum in iP jP.
- rewrite /FP => -[/= i Pi] _ /(_ (exist _ _ _))/= ordF.
have /negP/negP/= := no_i i; rewrite Pi/= negb_forall => /existsP/sigW[j].
by rewrite negb_imply => /andP[Pj]; rewrite ordF.
Qed.
End ExtremumIn.
Notation "[ 'arg[' ord ]_( i < i0 | P ) F ]" :=
(extremum ord i0 (fun i => P%B) (fun i => F))
(ord, i, i0 at level 10,
format "[ 'arg[' ord ]_( i < i0 | P ) F ]") : nat_scope.
Notation "[ 'arg[' ord ]_( i < i0 'in' A ) F ]" :=
[arg[ord]_(i < i0 | i \in A) F]
(format "[ 'arg[' ord ]_( i < i0 'in' A ) F ]") : nat_scope.
Notation "[ 'arg[' ord ]_( i < i0 ) F ]" := [arg[ord]_(i < i0 | true) F]
(format "[ 'arg[' ord ]_( i < i0 ) F ]") : nat_scope.
Section ArgMinMax.
Variables (I : finType) (i0 : I) (P : pred I) (F : I -> nat) (Pi0 : P i0).
Definition arg_min := extremum leq i0 P F.
Definition arg_max := extremum geq i0 P F.
Lemma arg_minnP : extremum_spec leq P F arg_min.
Proof. by apply: extremumP => //; [apply: leq_trans|apply: leq_total]. Qed.
Lemma arg_maxnP : extremum_spec geq P F arg_max.
Proof.
apply: extremumP => //; first exact: leqnn.
by move=> n m p mn np; apply: leq_trans mn.
by move=> ??; apply: leq_total.
Qed.
End ArgMinMax.
End Extrema.
Notation "[ 'arg' 'min_' ( i < i0 | P ) F ]" :=
(arg_min i0 (fun i => P%B) (fun i => F))
(i, i0 at level 10,
format "[ 'arg' 'min_' ( i < i0 | P ) F ]") : nat_scope.
Notation "[ 'arg' 'min_' ( i < i0 'in' A ) F ]" :=
[arg min_(i < i0 | i \in A) F]
(format "[ 'arg' 'min_' ( i < i0 'in' A ) F ]") : nat_scope.
Notation "[ 'arg' 'min_' ( i < i0 ) F ]" := [arg min_(i < i0 | true) F]
(format "[ 'arg' 'min_' ( i < i0 ) F ]") : nat_scope.
Notation "[ 'arg' 'max_' ( i > i0 | P ) F ]" :=
(arg_max i0 (fun i => P%B) (fun i => F))
(i, i0 at level 10,
format "[ 'arg' 'max_' ( i > i0 | P ) F ]") : nat_scope.
Notation "[ 'arg' 'max_' ( i > i0 'in' A ) F ]" :=
[arg max_(i > i0 | i \in A) F]
(format "[ 'arg' 'max_' ( i > i0 'in' A ) F ]") : nat_scope.
Notation "[ 'arg' 'max_' ( i > i0 ) F ]" := [arg max_(i > i0 | true) F]
(format "[ 'arg' 'max_' ( i > i0 ) F ]") : nat_scope.
(**********************************************************************)
(* *)
(* Ordinal finType : {0, ... , n-1} *)
(* *)
(**********************************************************************)
Section OrdinalSub.
Variable n : nat.
Inductive ordinal : predArgType := Ordinal m of m < n.
Coercion nat_of_ord i := let: Ordinal m _ := i in m.
HB.instance Definition _ := [isSub of ordinal for nat_of_ord].
HB.instance Definition _ := [Countable of ordinal by <:].
Lemma ltn_ord (i : ordinal) : i < n. Proof. exact: valP i. Qed.
Lemma ord_inj : injective nat_of_ord. Proof. exact: val_inj. Qed.
Definition ord_enum : seq ordinal := pmap insub (iota 0 n).
Lemma val_ord_enum : map val ord_enum = iota 0 n.
Proof.
rewrite pmap_filter; last exact: insubK.
by apply/all_filterP; apply/allP=> i; rewrite mem_iota isSome_insub.
Qed.
Lemma ord_enum_uniq : uniq ord_enum.
Proof. by rewrite pmap_sub_uniq ?iota_uniq. Qed.
Lemma mem_ord_enum i : i \in ord_enum.
Proof. by rewrite -(mem_map ord_inj) val_ord_enum mem_iota ltn_ord. Qed.
HB.instance Definition _ := isFinite.Build ordinal
(Finite.uniq_enumP ord_enum_uniq mem_ord_enum).
End OrdinalSub.
Notation "''I_' n" := (ordinal n)
(at level 0, n at level 2, format "''I_' n").
#[global] Hint Resolve ltn_ord : core.
Section OrdinalEnum.
Variable n : nat.
Lemma val_enum_ord : map val (enum 'I_n) = iota 0 n.
Proof. by rewrite enumT unlock val_ord_enum. Qed.
Lemma size_enum_ord : size (enum 'I_n) = n.
Proof. by rewrite -(size_map val) val_enum_ord size_iota. Qed.
Lemma card_ord : #|'I_n| = n.
Proof. by rewrite cardE size_enum_ord. Qed.
Lemma nth_enum_ord i0 m : m < n -> nth i0 (enum 'I_n) m = m :> nat.
Proof.
by move=> ?; rewrite -(nth_map _ 0) (size_enum_ord, val_enum_ord) // nth_iota.
Qed.
Lemma nth_ord_enum (i0 i : 'I_n) : nth i0 (enum 'I_n) i = i.
Proof. by apply: val_inj; apply: nth_enum_ord. Qed.
Lemma index_enum_ord (i : 'I_n) : index i (enum 'I_n) = i.
Proof.
by rewrite -[in LHS](nth_ord_enum i i) index_uniq ?(enum_uniq, size_enum_ord).
Qed.
Lemma mask_enum_ord m :
mask m (enum 'I_n) = [seq i <- enum 'I_n | nth false m (val i)].
Proof.
rewrite mask_filter ?enum_uniq//; apply: eq_filter => i.
by rewrite in_mask ?enum_uniq ?mem_enum// index_enum_ord.
Qed.
End OrdinalEnum.
Lemma enum_ord0 : enum 'I_0 = [::].
Proof. by apply/eqP; rewrite -size_eq0 size_enum_ord. Qed.
Lemma widen_ord_proof n m (i : 'I_n) : n <= m -> i < m.
Proof. exact: leq_trans. Qed.
Definition widen_ord n m le_n_m i := Ordinal (@widen_ord_proof n m i le_n_m).
Lemma cast_ord_proof n m (i : 'I_n) : n = m -> i < m.
Proof. by move <-. Qed.
Definition cast_ord n m eq_n_m i := Ordinal (@cast_ord_proof n m i eq_n_m).
Lemma cast_ord_id n eq_n i : cast_ord eq_n i = i :> 'I_n.
Proof. exact: val_inj. Qed.
Lemma cast_ord_comp n1 n2 n3 eq_n2 eq_n3 i :
@cast_ord n2 n3 eq_n3 (@cast_ord n1 n2 eq_n2 i) =
cast_ord (etrans eq_n2 eq_n3) i.
Proof. exact: val_inj. Qed.
Lemma cast_ordK n1 n2 eq_n :
cancel (@cast_ord n1 n2 eq_n) (cast_ord (esym eq_n)).
Proof. by move=> i; apply: val_inj. Qed.
Lemma cast_ordKV n1 n2 eq_n :
cancel (cast_ord (esym eq_n)) (@cast_ord n1 n2 eq_n).
Proof. by move=> i; apply: val_inj. Qed.
Lemma cast_ord_inj n1 n2 eq_n : injective (@cast_ord n1 n2 eq_n).
Proof. exact: can_inj (cast_ordK eq_n). Qed.
Fact ordS_subproof n (i : 'I_n) : i.+1 %% n < n.
Proof. by case: n i => [|n] [m m_lt]//=; rewrite ltn_pmod. Qed.
Definition ordS n (i : 'I_n) := Ordinal (ordS_subproof i).
Fact ord_pred_subproof n (i : 'I_n) : (i + n).-1 %% n < n.
Proof. by case: n i => [|n] [m m_lt]//=; rewrite ltn_pmod. Qed.
Definition ord_pred n (i : 'I_n) := Ordinal (ord_pred_subproof i).
Lemma ordSK n : cancel (@ordS n) (@ord_pred n).
Proof.
move=> [i ilt]; apply/val_inj => /=.
case: (ltngtP i.+1) (ilt) => // [Silt|<-]; last by rewrite modnn/= modn_small.
by rewrite [i.+1 %% n]modn_small// addSn/= modnDr modn_small.
Qed.
Lemma ord_predK n : cancel (@ord_pred n) (@ordS n).
Proof.
move=> [[|i] ilt]; apply/val_inj => /=.
by rewrite [n.-1 %% n]modn_small// prednK// modnn.
by rewrite modnDr [i %% n]modn_small ?modn_small// ltnW.
Qed.
Lemma ordS_bij n : bijective (@ordS n).
Proof. exact: (Bijective (@ordSK n) (@ord_predK n)). Qed.
Lemma ordS_inj n : injective (@ordS n).
Proof. exact: (bij_inj (ordS_bij n)). Qed.
Lemma ord_pred_bij n : bijective (@ord_pred n).
Proof. exact (Bijective (@ord_predK n) (@ordSK n)). Qed.
Lemma ord_pred_inj n : injective (@ord_pred n).
Proof. exact: (bij_inj (ord_pred_bij n)). Qed.
Lemma rev_ord_proof n (i : 'I_n) : n - i.+1 < n.
Proof. by case: n i => [|n] [i lt_i_n] //; rewrite ltnS subSS leq_subr. Qed.
Definition rev_ord n i := Ordinal (@rev_ord_proof n i).
Lemma rev_ordK {n} : involutive (@rev_ord n).
Proof.
by case: n => [|n] [i lti] //; apply: val_inj; rewrite /= !subSS subKn.
Qed.
Lemma rev_ord_inj {n} : injective (@rev_ord n).
Proof. exact: inv_inj rev_ordK. Qed.
Lemma inj_leq m n (f : 'I_m -> 'I_n) : injective f -> m <= n.
Proof. by move=> /leq_card; rewrite !card_ord. Qed.
Arguments inj_leq [m n] f _.
(* bijection between any finType T and the Ordinal finType of its cardinal *)
Lemma enum_rank_subproof (T : finType) x0 (A : {pred T}) : x0 \in A -> 0 < #|A|.
Proof. by move=> Ax0; rewrite (cardD1 x0) Ax0. Qed.
HB.lock
Definition enum_rank_in (T : finType) x0 (A : {pred T}) (Ax0 : x0 \in A) x :=
insubd (Ordinal (@enum_rank_subproof T x0 [eta A] Ax0)) (index x (enum A)).
Canonical unlockable_enum_rank_in := Unlockable enum_rank_in.unlock.
Section EnumRank.
Variable T : finType.
Implicit Type A : {pred T}.
Definition enum_rank x := @enum_rank_in T x T (erefl true) x.
Lemma enum_default A : 'I_(#|A|) -> T.
Proof. by rewrite cardE; case: (enum A) => [|//] []. Qed.
Definition enum_val A i := nth (@enum_default [eta A] i) (enum A) i.
Prenex Implicits enum_val.
Lemma enum_valP A i : @enum_val A i \in A.
Proof. by rewrite -mem_enum mem_nth -?cardE. Qed.
Lemma enum_val_nth A x i : @enum_val A i = nth x (enum A) i.
Proof. by apply: set_nth_default; rewrite cardE in i *; apply: ltn_ord. Qed.
Lemma nth_image T' y0 (f : T -> T') A (i : 'I_#|A|) :
nth y0 (image f A) i = f (enum_val i).
Proof. by rewrite -(nth_map _ y0) // -cardE. Qed.
Lemma nth_codom T' y0 (f : T -> T') (i : 'I_#|T|) :
nth y0 (codom f) i = f (enum_val i).
Proof. exact: nth_image. Qed.
Lemma nth_enum_rank_in x00 x0 A Ax0 :
{in A, cancel (@enum_rank_in T x0 A Ax0) (nth x00 (enum A))}.
Proof.
move=> x Ax; rewrite enum_rank_in.unlock insubdK ?nth_index ?mem_enum //.
by rewrite cardE [_ \in _]index_mem mem_enum.
Qed.
Lemma nth_enum_rank x0 : cancel enum_rank (nth x0 (enum T)).
Proof. by move=> x; apply: nth_enum_rank_in. Qed.
Lemma enum_rankK_in x0 A Ax0 :
{in A, cancel (@enum_rank_in T x0 A Ax0) enum_val}.
Proof. by move=> x; apply: nth_enum_rank_in. Qed.
Lemma enum_rankK : cancel enum_rank enum_val.
Proof. by move=> x; apply: enum_rankK_in. Qed.
Lemma enum_valK_in x0 A Ax0 : cancel enum_val (@enum_rank_in T x0 A Ax0).
Proof.
move=> x; apply: ord_inj; rewrite enum_rank_in.unlock insubdK; last first.
by rewrite cardE [_ \in _]index_mem mem_nth // -cardE.
by rewrite index_uniq ?enum_uniq // -cardE.
Qed.
Lemma enum_valK : cancel enum_val enum_rank.
Proof. by move=> x; apply: enum_valK_in. Qed.
Lemma enum_rank_inj : injective enum_rank.
Proof. exact: can_inj enum_rankK. Qed.
Lemma enum_val_inj A : injective (@enum_val A).
Proof. by move=> i; apply: can_inj (enum_valK_in (enum_valP i)) (i). Qed.
Lemma enum_val_bij_in x0 A : x0 \in A -> {on A, bijective (@enum_val A)}.
Proof.
move=> Ax0; exists (enum_rank_in Ax0) => [i _|]; last exact: enum_rankK_in.
exact: enum_valK_in.
Qed.
Lemma eq_enum_rank_in (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) :
{in A, enum_rank_in Ax0 =1 enum_rank_in Ay0}.
Proof. by move=> x xA; apply: enum_val_inj; rewrite !enum_rankK_in. Qed.
Lemma enum_rank_in_inj (x0 y0 : T) A (Ax0 : x0 \in A) (Ay0 : y0 \in A) :
{in A &, forall x y, enum_rank_in Ax0 x = enum_rank_in Ay0 y -> x = y}.
Proof. by move=> x y xA yA /(congr1 enum_val); rewrite !enum_rankK_in. Qed.
Lemma enum_rank_bij : bijective enum_rank.
Proof. by move: enum_rankK enum_valK; exists (@enum_val T). Qed.
Lemma enum_val_bij : bijective (@enum_val T).
Proof. by move: enum_rankK enum_valK; exists enum_rank. Qed.
(* Due to the limitations of the Coq unification patterns, P can only be *)
(* inferred from the premise of this lemma, not its conclusion. As a result *)
(* this lemma will only be usable in forward chaining style. *)
Lemma fin_all_exists U (P : forall x : T, U x -> Prop) :
(forall x, exists u, P x u) -> (exists u, forall x, P x (u x)).
Proof.
move=> ex_u; pose Q m x := enum_rank x < m -> {ux | P x ux}.
suffices: forall m, m <= #|T| -> exists w : forall x, Q m x, True.
case/(_ #|T|)=> // w _; pose u x := sval (w x (ltn_ord _)).
by exists u => x; rewrite {}/u; case: (w x _).
elim=> [|m IHm] ltmX; first by have w x: Q 0 x by []; exists w.
have{IHm} [w _] := IHm (ltnW ltmX); pose i := Ordinal ltmX.
have [u Pu] := ex_u (enum_val i); suffices w' x: Q m.+1 x by exists w'.
rewrite /Q ltnS leq_eqVlt (val_eqE _ i); case: eqP => [def_i _ | _ /w //].
by rewrite -def_i enum_rankK in u Pu; exists u.
Qed.
Lemma fin_all_exists2 U (P Q : forall x : T, U x -> Prop) :
(forall x, exists2 u, P x u & Q x u) ->
(exists2 u, forall x, P x (u x) & forall x, Q x (u x)).
Proof.
move=> ex_u; have (x): exists u, P x u /\ Q x u by have [u] := ex_u x; exists u.
by case/fin_all_exists=> u /all_and2[]; exists u.
Qed.
End EnumRank.
Arguments enum_val_inj {T A} [i1 i2] : rename.
Arguments enum_rank_inj {T} [x1 x2].
Prenex Implicits enum_val enum_rank enum_valK enum_rankK.
Lemma enum_rank_ord n i : enum_rank i = cast_ord (esym (card_ord n)) i.
Proof.
apply: val_inj; rewrite /enum_rank enum_rank_in.unlock.
by rewrite insubdK ?index_enum_ord // card_ord [_ \in _]ltn_ord.
Qed.
Lemma enum_val_ord n i : enum_val i = cast_ord (card_ord n) i.
Proof.
by apply: canLR (@enum_rankK _) _; apply: val_inj; rewrite enum_rank_ord.
Qed.
(* The integer bump / unbump operations. *)
Definition bump h i := (h <= i) + i.
Definition unbump h i := i - (h < i).
Lemma bumpK h : cancel (bump h) (unbump h).
Proof.
rewrite /bump /unbump => i.
have [le_hi | lt_ih] := leqP h i; first by rewrite ltnS le_hi subn1.
by rewrite ltnNge ltnW ?subn0.
Qed.
Lemma neq_bump h i : h != bump h i.
Proof.
rewrite /bump eqn_leq; have [le_hi | lt_ih] := leqP h i.
by rewrite ltnNge le_hi andbF.
by rewrite leqNgt lt_ih.
Qed.
Lemma unbumpKcond h i : bump h (unbump h i) = (i == h) + i.
Proof.
rewrite /bump /unbump leqNgt -subSKn.
case: (ltngtP i h) => /= [-> | ltih | ->] //; last by rewrite ltnn.
by rewrite subn1 /= leqNgt !(ltn_predK ltih, ltih, add1n).
Qed.
Lemma unbumpK {h} : {in predC1 h, cancel (unbump h) (bump h)}.
Proof. by move=> i /negbTE-neq_h_i; rewrite unbumpKcond neq_h_i. Qed.
Lemma bumpDl h i k : bump (k + h) (k + i) = k + bump h i.
Proof. by rewrite /bump leq_add2l addnCA. Qed.
Lemma bumpS h i : bump h.+1 i.+1 = (bump h i).+1.
Proof. exact: addnS. Qed.
Lemma unbumpDl h i k : unbump (k + h) (k + i) = k + unbump h i.
Proof.
apply: (can_inj (bumpK (k + h))).
by rewrite bumpDl !unbumpKcond eqn_add2l addnCA.
Qed.
Lemma unbumpS h i : unbump h.+1 i.+1 = (unbump h i).+1.
Proof. exact: unbumpDl 1. Qed.
Lemma leq_bump h i j : (i <= bump h j) = (unbump h i <= j).
Proof.
rewrite /bump leq_subLR.
case: (leqP i h) (leqP h j) => [le_i_h | lt_h_i] [le_h_j | lt_j_h] //.
by rewrite leqW (leq_trans le_i_h).
by rewrite !(leqNgt i) ltnW (leq_trans _ lt_h_i).
Qed.
Lemma leq_bump2 h i j : (bump h i <= bump h j) = (i <= j).
Proof. by rewrite leq_bump bumpK. Qed.
Lemma bumpC h1 h2 i :
bump h1 (bump h2 i) = bump (bump h1 h2) (bump (unbump h2 h1) i).
Proof.
rewrite {1 5}/bump -leq_bump addnCA; congr (_ + (_ + _)).
rewrite 2!leq_bump /unbump /bump; case: (leqP h1 h2) => [le_h12 | lt_h21].
by rewrite subn0 ltnS le_h12 subn1.
by rewrite subn1 (ltn_predK lt_h21) (leqNgt h1) lt_h21 subn0.
Qed.
(* The lift operations on ordinals; to avoid a messy dependent type, *)
(* unlift is a partial operation (returns an option). *)
Lemma lift_subproof n h (i : 'I_n.-1) : bump h i < n.
Proof. by case: n i => [[]|n] //= i; rewrite -addnS (leq_add (leq_b1 _)). Qed.
Definition lift n (h : 'I_n) (i : 'I_n.-1) := Ordinal (lift_subproof h i).
Lemma unlift_subproof n (h : 'I_n) (u : {j | j != h}) : unbump h (val u) < n.-1.
Proof.
case: n h u => [|n h] [] //= j ne_jh.
rewrite -(leq_bump2 h.+1) bumpS unbumpK // /bump.
case: (ltngtP n h) => [|_|eq_nh]; rewrite ?(leqNgt _ h) ?ltn_ord //.
by rewrite ltn_neqAle [j <= _](valP j) {2}eq_nh andbT.
Qed.
Definition unlift n (h i : 'I_n) :=
omap (fun u : {j | j != h} => Ordinal (unlift_subproof u)) (insub i).
Variant unlift_spec n h i : option 'I_n.-1 -> Type :=
| UnliftSome j of i = lift h j : unlift_spec h i (Some j)
| UnliftNone of i = h : unlift_spec h i None.
Lemma unliftP n (h i : 'I_n) : unlift_spec h i (unlift h i).
Proof.
rewrite /unlift; case: insubP => [u nhi | ] def_i /=; constructor.
by apply: val_inj; rewrite /= def_i unbumpK.
by rewrite negbK in def_i; apply/eqP.
Qed.
Lemma neq_lift n (h : 'I_n) i : h != lift h i.
Proof. exact: neq_bump. Qed.
Lemma eq_liftF n (h : 'I_n) i : (h == lift h i) = false.
Proof. exact/negbTE/neq_lift. Qed.
Lemma lift_eqF n (h : 'I_n) i : (lift h i == h) = false.
Proof. by rewrite eq_sym eq_liftF. Qed.
Lemma unlift_none n (h : 'I_n) : unlift h h = None.
Proof. by case: unliftP => // j Dh; case/eqP: (neq_lift h j). Qed.
Lemma unlift_some n (h i : 'I_n) :
h != i -> {j | i = lift h j & unlift h i = Some j}.
Proof.
rewrite eq_sym => /eqP neq_ih.
by case Dui: (unlift h i) / (unliftP h i) => [j Dh|//]; exists j.
Qed.
Lemma lift_inj n (h : 'I_n) : injective (lift h).
Proof. by move=> i1 i2 [/(can_inj (bumpK h))/val_inj]. Qed.
Arguments lift_inj {n h} [i1 i2] eq_i12h : rename.
Lemma liftK n (h : 'I_n) : pcancel (lift h) (unlift h).
Proof. by move=> i; case: (unlift_some (neq_lift h i)) => j /lift_inj->. Qed.
(* Shifting and splitting indices, for cutting and pasting arrays *)
Lemma lshift_subproof m n (i : 'I_m) : i < m + n.
Proof. by apply: leq_trans (valP i) _; apply: leq_addr. Qed.
Lemma rshift_subproof m n (i : 'I_n) : m + i < m + n.
Proof. by rewrite ltn_add2l. Qed.
Definition lshift m n (i : 'I_m) := Ordinal (lshift_subproof n i).
Definition rshift m n (i : 'I_n) := Ordinal (rshift_subproof m i).
Lemma lshift_inj m n : injective (@lshift m n).
Proof. by move=> ? ? /(f_equal val) /= /val_inj. Qed.
Lemma rshift_inj m n : injective (@rshift m n).
Proof. by move=> ? ? /(f_equal val) /addnI /val_inj. Qed.
Lemma eq_lshift m n i j : (@lshift m n i == @lshift m n j) = (i == j).
Proof. by rewrite (inj_eq (@lshift_inj _ _)). Qed.
Lemma eq_rshift m n i j : (@rshift m n i == @rshift m n j) = (i == j).
Proof. by rewrite (inj_eq (@rshift_inj _ _)). Qed.
Lemma eq_lrshift m n i j : (@lshift m n i == @rshift m n j) = false.
Proof.
apply/eqP=> /(congr1 val)/= def_i; have := ltn_ord i.
by rewrite def_i -ltn_subRL subnn.
Qed.
Lemma eq_rlshift m n i j : (@rshift m n i == @lshift m n j) = false.
Proof. by rewrite eq_sym eq_lrshift. Qed.
Definition eq_shift := (eq_lshift, eq_rshift, eq_lrshift, eq_rlshift).
Lemma split_subproof m n (i : 'I_(m + n)) : i >= m -> i - m < n.
Proof. by move/subSn <-; rewrite leq_subLR. Qed.
Definition split {m n} (i : 'I_(m + n)) : 'I_m + 'I_n :=
match ltnP (i) m with
| LtnNotGeq lt_i_m => inl _ (Ordinal lt_i_m)
| GeqNotLtn ge_i_m => inr _ (Ordinal (split_subproof ge_i_m))
end.
Variant split_spec m n (i : 'I_(m + n)) : 'I_m + 'I_n -> bool -> Type :=
| SplitLo (j : 'I_m) of i = j :> nat : split_spec i (inl _ j) true
| SplitHi (k : 'I_n) of i = m + k :> nat : split_spec i (inr _ k) false.
Lemma splitP m n (i : 'I_(m + n)) : split_spec i (split i) (i < m).
Proof.
(* We need to prevent the case on ltnP from rewriting the hidden constructor *)
(* argument types of the match branches exposed by unfolding split. If the *)
(* match representation is changed to omit these then this proof could reduce *)
(* to by rewrite /split; case: ltnP; [left | right. rewrite subnKC]. *)
set lt_i_m := i < m; rewrite /split.
by case: _ _ _ _ {-}_ lt_i_m / ltnP; [left | right; rewrite subnKC].
Qed.
Variant split_ord_spec m n (i : 'I_(m + n)) : 'I_m + 'I_n -> bool -> Type :=
| SplitOrdLo (j : 'I_m) of i = lshift _ j : split_ord_spec i (inl _ j) true
| SplitOrdHi (k : 'I_n) of i = rshift _ k : split_ord_spec i (inr _ k) false.
Lemma split_ordP m n (i : 'I_(m + n)) : split_ord_spec i (split i) (i < m).
Proof. by case: splitP; [left|right]; apply: val_inj. Qed.
Definition unsplit {m n} (jk : 'I_m + 'I_n) :=
match jk with inl j => lshift n j | inr k => rshift m k end.
Lemma ltn_unsplit m n (jk : 'I_m + 'I_n) : (unsplit jk < m) = jk.
Proof. by case: jk => [j|k]; rewrite /= ?ltn_ord // ltnNge leq_addr. Qed.
Lemma splitK {m n} : cancel (@split m n) unsplit.
Proof. by move=> i; case: split_ordP. Qed.
Lemma unsplitK {m n} : cancel (@unsplit m n) split.
Proof.
by move=> [j|k]; case: split_ordP => ? /eqP; rewrite eq_shift// => /eqP->.
Qed.
Section OrdinalPos.
Variable n' : nat.
Local Notation n := n'.+1.
Definition ord0 := Ordinal (ltn0Sn n').
Definition ord_max := Ordinal (ltnSn n').
Lemma leq_ord (i : 'I_n) : i <= n'. Proof. exact: valP i. Qed.
Lemma sub_ord_proof m : n' - m < n.
Proof. by rewrite ltnS leq_subr. Qed.
Definition sub_ord m := Ordinal (sub_ord_proof m).
Lemma sub_ordK (i : 'I_n) : n' - (n' - i) = i.
Proof. by rewrite subKn ?leq_ord. Qed.
Definition inord m : 'I_n := insubd ord0 m.
Lemma inordK m : m < n -> inord m = m :> nat.
Proof. by move=> lt_m; rewrite val_insubd lt_m. Qed.
Lemma inord_val (i : 'I_n) : inord i = i.
Proof. by rewrite /inord /insubd valK. Qed.
Lemma enum_ordSl : enum 'I_n = ord0 :: map (lift ord0) (enum 'I_n').
Proof.
apply: (inj_map val_inj); rewrite val_enum_ord /= -map_comp.
by rewrite (map_comp (addn 1)) val_enum_ord -iotaDl.
Qed.
Lemma enum_ordSr :
enum 'I_n = rcons (map (widen_ord (leqnSn _)) (enum 'I_n')) ord_max.
Proof.
apply: (inj_map val_inj); rewrite val_enum_ord.
rewrite -[in iota _ _]addn1 iotaD/= cats1 map_rcons; congr (rcons _ _).
by rewrite -map_comp/= (@eq_map _ _ _ val) ?val_enum_ord.
Qed.
Lemma lift_max (i : 'I_n') : lift ord_max i = i :> nat.
Proof. by rewrite /= /bump leqNgt ltn_ord. Qed.
Lemma lift0 (i : 'I_n') : lift ord0 i = i.+1 :> nat. Proof. by []. Qed.
End OrdinalPos.
Arguments ord0 {n'}.
Arguments ord_max {n'}.
Arguments inord {n'}.
Arguments sub_ord {n'}.
Arguments sub_ordK {n'}.
Arguments inord_val {n'}.
Lemma ord1 : all_equal_to (ord0 : 'I_1).
Proof. by case=> [[] // ?]; apply: val_inj. Qed.
(* Product of two fintypes which is a fintype *)
Section ProdFinType.
Variable T1 T2 : finType.
Definition prod_enum := [seq (x1, x2) | x1 <- enum T1, x2 <- enum T2].
Lemma predX_prod_enum (A1 : {pred T1}) (A2 : {pred T2}) :
count [predX A1 & A2] prod_enum = #|A1| * #|A2|.
Proof.
rewrite !cardE !size_filter -!enumT /prod_enum.
elim: (enum T1) => //= x1 s1 IHs; rewrite count_cat {}IHs count_map /preim /=.
by case: (x1 \in A1); rewrite ?count_pred0.
Qed.
Lemma prod_enumP : Finite.axiom prod_enum.
Proof.
by case=> x1 x2; rewrite (predX_prod_enum (pred1 x1) (pred1 x2)) !card1.
Qed.
HB.instance Definition _ := isFinite.Build (T1 * T2)%type prod_enumP.
Lemma cardX (A1 : {pred T1}) (A2 : {pred T2}) :
#|[predX A1 & A2]| = #|A1| * #|A2|.
Proof. by rewrite -predX_prod_enum unlock size_filter unlock. Qed.
Lemma card_prod : #|{: T1 * T2}| = #|T1| * #|T2|.
Proof. by rewrite -cardX; apply: eq_card; case. Qed.
Lemma eq_card_prod (A : {pred (T1 * T2)}) : A =i predT -> #|A| = #|T1| * #|T2|.
Proof. exact: eq_card_trans card_prod. Qed.
End ProdFinType.
Section TagFinType.
Variables (I : finType) (T_ : I -> finType).
Definition tag_enum :=
flatten [seq [seq Tagged T_ x | x <- enumF (T_ i)] | i <- enumF I].
Lemma tag_enumP : Finite.axiom tag_enum.
Proof.
case=> i x; rewrite -(enumP i) /tag_enum -enumT.
elim: (enum I) => //= j e IHe.
rewrite count_cat count_map {}IHe; congr (_ + _).
rewrite -size_filter -cardE /=; case: eqP => [-> | ne_j_i].
by apply: (@eq_card1 _ x) => y; rewrite -topredE /= tagged_asE ?eqxx.
by apply: eq_card0 => y.
Qed.
HB.instance Definition _ := isFinite.Build {i : I & T_ i} tag_enumP.
Lemma card_tagged :
#|{: {i : I & T_ i}}| = sumn (map (fun i => #|T_ i|) (enum I)).
Proof.
rewrite cardE !enumT [in LHS]unlock size_flatten /shape -map_comp.
by congr (sumn _); apply: eq_map => i; rewrite /= size_map -enumT -cardE.
Qed.
End TagFinType.
Section SumFinType.
Variables T1 T2 : finType.
Definition sum_enum :=
[seq inl _ x | x <- enumF T1] ++ [seq inr _ y | y <- enumF T2].
Lemma sum_enum_uniq : uniq sum_enum.
Proof.
rewrite cat_uniq -!enumT !(enum_uniq, map_inj_uniq); try by move=> ? ? [].
by rewrite andbT; apply/hasP=> [[_ /mapP[x _ ->] /mapP[]]].
Qed.
Lemma mem_sum_enum u : u \in sum_enum.
Proof. by case: u => x; rewrite mem_cat -!enumT map_f ?mem_enum ?orbT. Qed.
HB.instance Definition sum_isFinite := isFinite.Build (T1 + T2)%type
(Finite.uniq_enumP sum_enum_uniq mem_sum_enum).
Lemma card_sum : #|{: T1 + T2}| = #|T1| + #|T2|.
Proof. by rewrite !cardT !enumT [in LHS]unlock size_cat !size_map. Qed.
End SumFinType.
|
Locus.lean
|
/-
Copyright (c) 2024 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import Mathlib.RingTheory.Spectrum.Prime.Topology
import Mathlib.RingTheory.Etale.Kaehler
import Mathlib.RingTheory.Support
/-!
# Unramified locus of an algebra
## Main results
- `Algebra.unramifiedLocus` : The set of primes that is unramified over the base.
- `Algebra.basicOpen_subset_unramifiedLocus_iff` :
`D(f)` is contained in the unramified locus if and only if `A_f` is unramified over `R`.
- `Algebra.unramifiedLocus_eq_univ_iff` :
The unramified locus is the whole spectrum if and only if `A` is unramified over `R`.
- `Algebra.isOpen_unramifiedLocus` :
If `A` is (essentially) of finite type over `R`, then the unramified locus is open.
-/
universe u
namespace Algebra
section
variable {R A B : Type*} [CommRing R] [CommRing A] [CommRing B] [Algebra R A] [Algebra A B]
[Algebra R B] [IsScalarTower R A B]
variable (R) in
/-- We say that an `R`-algebra `A` is unramified at a prime `q` of `A`
if `A_q` is formally unramified over `R`.
If `A` is of finite type over `R` and `q` is lying over `p`, then this is equivalent to
`ΞΊ(q)/ΞΊ(p)` being separable and `pA_q = qA_q`.
See `Algebra.isUnramifiedAt_iff_map_eq` in `RingTheory.Unramified.LocalRing` -/
abbrev IsUnramifiedAt (q : Ideal A) [q.IsPrime] : Prop :=
FormallyUnramified R (Localization.AtPrime q)
variable (R A) in
/-- `Algebra.unramifiedLocus R A` is the set of primes `p` of `A` that are unramified. -/
def unramifiedLocus : Set (PrimeSpectrum A) :=
{ p | IsUnramifiedAt R p.asIdeal }
lemma IsUnramifiedAt.comp
(p : Ideal A) (P : Ideal B) [P.LiesOver p] [p.IsPrime] [P.IsPrime]
[IsUnramifiedAt R p] [IsUnramifiedAt A P] : IsUnramifiedAt R P := by
have : FormallyUnramified (Localization.AtPrime p) (Localization.AtPrime P) :=
.of_comp A _ _
exact FormallyUnramified.comp R (Localization.AtPrime p) _
variable (R) in
lemma IsUnramifiedAt.of_restrictScalars (P : Ideal B) [P.IsPrime]
[IsUnramifiedAt R P] : IsUnramifiedAt A P :=
FormallyUnramified.of_comp R _ _
end
section
variable {R A : Type u} [CommRing R] [CommRing A] [Algebra R A]
lemma unramifiedLocus_eq_compl_support :
unramifiedLocus R A = (Module.support A Ξ©[AβR])αΆ := by
ext p
simp only [Set.mem_compl_iff, Module.notMem_support_iff]
have := IsLocalizedModule.iso p.asIdeal.primeCompl
(KaehlerDifferential.map R R A (Localization.AtPrime p.asIdeal))
exact (Algebra.formallyUnramified_iff _ _).trans this.subsingleton_congr.symm
lemma basicOpen_subset_unramifiedLocus_iff {f : A} :
β(PrimeSpectrum.basicOpen f) β unramifiedLocus R A β
Algebra.FormallyUnramified R (Localization.Away f) := by
rw [unramifiedLocus_eq_compl_support, Set.subset_compl_comm,
PrimeSpectrum.basicOpen_eq_zeroLocus_compl, compl_compl,
β LocalizedModule.subsingleton_iff_support_subset, Algebra.formallyUnramified_iff]
exact (IsLocalizedModule.iso (.powers f)
(KaehlerDifferential.map R R A (Localization.Away f))).subsingleton_congr
lemma unramifiedLocus_eq_univ_iff :
unramifiedLocus R A = Set.univ β Algebra.FormallyUnramified R A := by
rw [unramifiedLocus_eq_compl_support, compl_eq_comm, Set.compl_univ, eq_comm,
Module.support_eq_empty_iff, Algebra.formallyUnramified_iff]
lemma isOpen_unramifiedLocus [EssFiniteType R A] : IsOpen (unramifiedLocus R A) := by
rw [unramifiedLocus_eq_compl_support, Module.support_eq_zeroLocus]
exact (PrimeSpectrum.isClosed_zeroLocus _).isOpen_compl
end
end Algebra
|
CommMon_.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.CategoryTheory.Monoidal.Cartesian.Mon_
/-!
# Yoneda embedding of `CommMon_ C`
-/
assert_not_exists MonoidWithZero
open CategoryTheory MonoidalCategory Limits Opposite CartesianMonoidalCategory Mon_Class
universe w v u
variable {C : Type u} [Category.{v} C] [CartesianMonoidalCategory C] [BraidedCategory C] {X : C}
variable (X) in
/-- If `X` represents a presheaf of commutative monoids, then `X` is a commutative monoid object. -/
lemma IsCommMon.ofRepresentableBy (F : Cα΅α΅ β₯€ CommMonCat) (Ξ± : (F β forget _).RepresentableBy X) :
letI : Mon_Class X := .ofRepresentableBy X (F β forgetβ CommMonCat MonCat) Ξ±
IsCommMon X := by
letI : Mon_Class X := .ofRepresentableBy X (F β forgetβ CommMonCat MonCat) Ξ±
have : ΞΌ = Ξ±.homEquiv.symm (Ξ±.homEquiv (fst X X) * Ξ±.homEquiv (snd X X)) := rfl
constructor
simp_rw [this, β Ξ±.homEquiv.apply_eq_iff_eq, Ξ±.homEquiv_comp, Functor.comp_map,
ConcreteCategory.forget_map_eq_coe, Equiv.apply_symm_apply, map_mul,
β ConcreteCategory.forget_map_eq_coe, β Functor.comp_map, β Ξ±.homEquiv_comp, op_tensorObj,
Functor.comp_obj, braiding_hom_fst, braiding_hom_snd, _root_.mul_comm]
|
FreeNonUnitalNonAssocAlgebra.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Algebra.Free
import Mathlib.Algebra.MonoidAlgebra.Basic
/-!
# Free algebras
Given a semiring `R` and a type `X`, we construct the free non-unital, non-associative algebra on
`X` with coefficients in `R`, together with its universal property. The construction is valuable
because it can be used to build free algebras with more structure, e.g., free Lie algebras.
Note that elsewhere we have a construction of the free unital, associative algebra. This is called
`FreeAlgebra`.
## Main definitions
* `FreeNonUnitalNonAssocAlgebra`
* `FreeNonUnitalNonAssocAlgebra.lift`
* `FreeNonUnitalNonAssocAlgebra.of`
## Implementation details
We construct the free algebra as the magma algebra, with coefficients in `R`, of the free magma on
`X`. However we regard this as an implementation detail and thus deliberately omit the lemmas
`of_apply` and `lift_apply`, and we mark `FreeNonUnitalNonAssocAlgebra` and `lift` as
irreducible once we have established the universal property.
## Tags
free algebra, non-unital, non-associative, free magma, magma algebra, universal property,
forgetful functor, adjoint functor
-/
universe u v w
noncomputable section
variable (R : Type u) (X : Type v) [Semiring R]
/--
If `Ξ±` is a type, and `R` is a semiring, then `FreeNonUnitalNonAssocAlgebra R Ξ±` is the free
non-unital non-associative `R`-algebra generated by `Ξ±`.
This is an `R`-algebra equipped with a function
`FreeNonUnitalNonAssocAlgebra.of R : Ξ± β FreeNonUnitalNonAssocAlgebra R Ξ±` which has
the following universal property: if `A` is any `R`-algebra, and `f : Ξ± β A` is any function,
then this function is the composite of `FreeNonUnitalNonAssocAlgebra.of R`
and a unique non-unital `R`-algebra homomorphism
`FreeNonUnitalNonAssocAlgebra.lift R f : FreeNonUnitalNonAssocAlgebra R Ξ± βββ[R] A`.
A typical element of `FreeNonUnitalNonAssocAlgebra R Ξ±` is an `R`-linear combination of
nonempty formal (non-commutative, non-associative) products of elements of `Ξ±`.
For example if `x` and `y` are terms of type `Ξ±` and
`a`, `b` are terms of type `R` then `(3 * a * a) β’ (x * (y * x)) + (2 * b + 1) β’ (y * x)` is a
"typical" element of `FreeNonUnitalNonAssocAlgebra R Ξ±`.
-/
abbrev FreeNonUnitalNonAssocAlgebra :=
MonoidAlgebra R (FreeMagma X)
namespace FreeNonUnitalNonAssocAlgebra
variable {X}
/-- The embedding of `X` into the free algebra with coefficients in `R`. -/
def of : X β FreeNonUnitalNonAssocAlgebra R X :=
MonoidAlgebra.ofMagma R _ β FreeMagma.of
variable {A : Type w} [NonUnitalNonAssocSemiring A]
variable [Module R A] [IsScalarTower R A A] [SMulCommClass R A A]
/-- The functor `X β¦ FreeNonUnitalNonAssocAlgebra R X` from the category of types to the
category of non-unital, non-associative algebras over `R` is adjoint to the forgetful functor in the
other direction. -/
def lift : (X β A) β (FreeNonUnitalNonAssocAlgebra R X βββ[R] A) :=
FreeMagma.lift.trans (MonoidAlgebra.liftMagma R)
@[simp]
theorem lift_symm_apply (F : FreeNonUnitalNonAssocAlgebra R X βββ[R] A) :
(lift R).symm F = F β of R := rfl
@[simp]
theorem of_comp_lift (f : X β A) : lift R f β of R = f :=
(lift R).left_inv f
@[simp]
theorem lift_unique (f : X β A) (F : FreeNonUnitalNonAssocAlgebra R X βββ[R] A) :
F β of R = f β F = lift R f :=
(lift R).symm_apply_eq
@[simp]
theorem lift_of_apply (f : X β A) (x) : lift R f (of R x) = f x :=
congr_fun (of_comp_lift _ f) x
@[simp]
theorem lift_comp_of (F : FreeNonUnitalNonAssocAlgebra R X βββ[R] A) : lift R (F β of R) = F :=
(lift R).apply_symm_apply F
@[ext]
theorem hom_ext {Fβ Fβ : FreeNonUnitalNonAssocAlgebra R X βββ[R] A}
(h : β x, Fβ (of R x) = Fβ (of R x)) : Fβ = Fβ :=
(lift R).symm.injective <| funext h
end FreeNonUnitalNonAssocAlgebra
|
EssentialImage.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.NatIso
import Mathlib.CategoryTheory.ObjectProperty.ClosedUnderIsomorphisms
import Mathlib.CategoryTheory.ObjectProperty.FullSubcategory
/-!
# Essential image of a functor
The essential image `essImage` of a functor consists of the objects in the target category which
are isomorphic to an object in the image of the object function.
This, for instance, allows us to talk about objects belonging to a subcategory expressed as a
functor rather than a subtype, preserving the principle of equivalence. For example this lets us
define exponential ideals.
The essential image can also be seen as a subcategory of the target category, and witnesses that
a functor decomposes into an essentially surjective functor and a fully faithful functor.
(TODO: show that this decomposition forms an orthogonal factorisation system).
-/
universe vβ vβ vβ uβ uβ uβ
noncomputable section
namespace CategoryTheory
variable {C : Type uβ} {D : Type uβ} {E : Type uβ}
[Category.{vβ} C] [Category.{vβ} D] [Category.{vβ} E] {F : C β₯€ D} {G : D β₯€ E}
namespace Functor
/-- The essential image of a functor `F` consists of those objects in the target category which are
isomorphic to an object in the image of the function `F.obj`. In other words, this is the closure
under isomorphism of the function `F.obj`.
This is the "non-evil" way of describing the image of a functor.
-/
def essImage (F : C β₯€ D) : ObjectProperty D := fun Y => β X : C, Nonempty (F.obj X β
Y)
/-- Get the witnessing object that `Y` is in the subcategory given by `F`. -/
def essImage.witness {Y : D} (h : F.essImage Y) : C :=
h.choose
/-- Extract the isomorphism between `F.obj h.witness` and `Y` itself. -/
def essImage.getIso {Y : D} (h : F.essImage Y) : F.obj h.witness β
Y :=
Classical.choice h.choose_spec
/-- Being in the essential image is a "hygienic" property: it is preserved under isomorphism. -/
theorem essImage.ofIso {Y Y' : D} (h : Y β
Y') (hY : essImage F Y) : essImage F Y' :=
hY.imp fun _ => Nonempty.map (Β· βͺβ« h)
instance : F.essImage.IsClosedUnderIsomorphisms where
of_iso e h := essImage.ofIso e h
/-- If `Y` is in the essential image of `F` then it is in the essential image of `F'` as long as
`F β
F'`.
-/
theorem essImage.ofNatIso {F' : C β₯€ D} (h : F β
F') {Y : D} (hY : essImage F Y) :
essImage F' Y :=
hY.imp fun X => Nonempty.map fun t => h.symm.app X βͺβ« t
/-- Isomorphic functors have equal essential images. -/
theorem essImage_eq_of_natIso {F' : C β₯€ D} (h : F β
F') : essImage F = essImage F' :=
funext fun _ => propext β¨essImage.ofNatIso h, essImage.ofNatIso h.symmβ©
/-- An object in the image is in the essential image. -/
theorem obj_mem_essImage (F : D β₯€ C) (Y : D) : essImage F (F.obj Y) :=
β¨Y, β¨Iso.refl _β©β©
/-- The essential image of a functor, interpreted as a full subcategory of the target category. -/
abbrev EssImageSubcategory (F : C β₯€ D) := F.essImage.FullSubcategory
/-- The essential image as a subcategory has a fully faithful inclusion into the target category. -/
@[deprecated "use F.essImage.ΞΉ" (since := "2025-03-04")]
def essImageInclusion (F : C β₯€ D) : F.EssImageSubcategory β₯€ D :=
F.essImage.ΞΉ
lemma essImage_ext (F : C β₯€ D) {X Y : F.EssImageSubcategory} (f g : X βΆ Y)
(h : F.essImage.ΞΉ.map f = F.essImage.ΞΉ.map g) : f = g :=
F.essImage.ΞΉ.map_injective h
/--
Given a functor `F : C β₯€ D`, we have an (essentially surjective) functor from `C` to the essential
image of `F`.
-/
@[simps!]
def toEssImage (F : C β₯€ D) : C β₯€ F.EssImageSubcategory :=
F.essImage.lift F (obj_mem_essImage _)
/-- The functor `F` factorises through its essential image, where the first functor is essentially
surjective and the second is fully faithful.
-/
@[simps!]
def toEssImageCompΞΉ (F : C β₯€ D) : F.toEssImage β F.essImage.ΞΉ β
F :=
ObjectProperty.liftCompΞΉIso _ _ _
@[deprecated (since := "2025-03-04")] alias toEssImageCompEssentialImageInclusio :=
toEssImageCompΞΉ
/-- A functor `F : C β₯€ D` is essentially surjective if every object of `D` is in the essential
image of `F`. In other words, for every `Y : D`, there is some `X : C` with `F.obj X β
Y`. -/
@[stacks 001C]
class EssSurj (F : C β₯€ D) : Prop where
/-- All the objects of the target category are in the essential image. -/
mem_essImage (Y : D) : F.essImage Y
instance EssSurj.toEssImage : EssSurj F.toEssImage where
mem_essImage := fun β¨_, hYβ© =>
β¨_, β¨β¨_, _, hY.getIso.hom_inv_id, hY.getIso.inv_hom_idβ©β©β©
theorem essSurj_of_surj (h : Function.Surjective F.obj) : EssSurj F where
mem_essImage Y := by
obtain β¨X, rflβ© := h Y
apply obj_mem_essImage
section EssSurj
variable (F)
variable [F.EssSurj]
/-- Given an essentially surjective functor, we can find a preimage for every object `Y` in the
codomain. Applying the functor to this preimage will yield an object isomorphic to `Y`, see
`obj_obj_preimage_iso`. -/
def objPreimage (Y : D) : C :=
essImage.witness (@EssSurj.mem_essImage _ _ _ _ F _ Y)
/-- Applying an essentially surjective functor to a preimage of `Y` yields an object that is
isomorphic to `Y`. -/
def objObjPreimageIso (Y : D) : F.obj (F.objPreimage Y) β
Y :=
Functor.essImage.getIso _
/-- The induced functor of a faithful functor is faithful. -/
instance Faithful.toEssImage (F : C β₯€ D) [Faithful F] : Faithful F.toEssImage := by
dsimp only [Functor.toEssImage]
infer_instance
/-- The induced functor of a full functor is full. -/
instance Full.toEssImage (F : C β₯€ D) [Full F] : Full F.toEssImage := by
dsimp only [Functor.toEssImage]
infer_instance
instance instEssSurjId : EssSurj (π C) where
mem_essImage Y := β¨Y, β¨Iso.refl _β©β©
lemma essSurj_of_iso {F G : C β₯€ D} [EssSurj F] (Ξ± : F β
G) : EssSurj G where
mem_essImage Y := Functor.essImage.ofNatIso Ξ± (EssSurj.mem_essImage Y)
instance essSurj_comp (F : C β₯€ D) (G : D β₯€ E) [F.EssSurj] [G.EssSurj] :
(F β G).EssSurj where
mem_essImage Z := β¨_, β¨G.mapIso (F.objObjPreimageIso _) βͺβ« G.objObjPreimageIso Zβ©β©
lemma essSurj_of_comp_fully_faithful (F : C β₯€ D) (G : D β₯€ E) [(F β G).EssSurj]
[G.Faithful] [G.Full] : F.EssSurj where
mem_essImage X := β¨_, β¨G.preimageIso ((F β G).objObjPreimageIso (G.obj X))β©β©
variable {F} {X : E}
/-- Pre-composing by an essentially surjective functor doesn't change the essential image. -/
lemma essImage_comp_apply_of_essSurj : (F β G).essImage X β G.essImage X where
mp := fun β¨Y, β¨eβ©β© β¦ β¨F.obj Y, β¨eβ©β©
mpr := fun β¨Y, β¨eβ©β© β¦
let β¨Z, β¨e'β©β© := Functor.EssSurj.mem_essImage Y; β¨Z, β¨(G.mapIso e').trans eβ©β©
/-- Pre-composing by an essentially surjective functor doesn't change the essential image. -/
@[simp] lemma essImage_comp_of_essSurj : (F β G).essImage = G.essImage :=
funext fun _X β¦ propext essImage_comp_apply_of_essSurj
end EssSurj
variable {J C D : Type*} [Category J] [Category C] [Category D]
(G : J β₯€ D) (F : C β₯€ D) [F.Full] [F.Faithful] (hG : β j, F.essImage (G.obj j))
/-- Lift a functor `G : J β₯€ D` to the essential image of a fully functor `F : C β₯€ D` to a functor
`G' : J β₯€ C` such that `G' β F β
G`. See `essImage.liftFunctorCompIso`. -/
@[simps] def essImage.liftFunctor : J β₯€ C where
obj j := F.toEssImage.objPreimage β¨G.obj j, hG jβ©
-- TODO: `map` isn't type-correct:
-- It conflates `β¨G.obj i, hG iβ© βΆ β¨G.obj j, hG jβ©` and `G.obj i βΆ G.obj j`.
map {i j} f := F.preimage <|
(F.toEssImage.objObjPreimageIso β¨G.obj i, hG iβ©).hom β« G.map f β«
(F.toEssImage.objObjPreimageIso β¨G.obj j, hG jβ©).inv
map_id i := F.map_injective <| by
simpa [-Iso.hom_inv_id] using (F.toEssImage.objObjPreimageIso β¨G.obj i, hG iβ©).hom_inv_id
map_comp {i j k} f g := F.map_injective <| by
simp only [Functor.map_comp, Category.assoc, Functor.map_preimage]
congr 2
symm
convert (F.toEssImage.objObjPreimageIso β¨G.obj j, hG jβ©).inv_hom_id_assoc (G.map g β«
(F.toEssImage.objObjPreimageIso β¨G.obj k, hG kβ©).inv)
/-- A functor `G : J β₯€ D` to the essential image of a fully functor `F : C β₯€ D` does factor through
`essImage.liftFunctor G F hG`. -/
@[simps!] def essImage.liftFunctorCompIso : essImage.liftFunctor G F hG β F β
G :=
NatIso.ofComponents
(fun i β¦ F.essImage.ΞΉ.mapIso (F.toEssImage.objObjPreimageIso β¨G.obj i, hG _β©))
fun {i j} f β¦ by
simp only [Functor.comp_obj, liftFunctor_obj, Functor.comp_map, liftFunctor_map,
Functor.map_preimage, Functor.mapIso_hom, ObjectProperty.ΞΉ_map, Category.assoc]
congr 1
convert Category.comp_id _
exact (F.toEssImage.objObjPreimageIso β¨G.obj j, hG jβ©).inv_hom_id
end Functor
end CategoryTheory
|
superscript.lean
|
import Mathlib.Util.Superscript
import Mathlib.Tactic.UnsetOption
import Lean.PrettyPrinter
section
local syntax:arg term:max noWs superscript(term) : term
local macro_rules | `($a:term$b:superscript) => `($a ^ $b)
variable (foo : Nat)
example : 2Β² = 4 := rfl
example : 2ΒΉβΆ = 65536 := rfl
example (n : Nat) : nβ½Β²β»ΒΉβΎ βΊ βΆ /- not done yet... -/ βΊ αΆ α΅α΅ = n ^ (7 + foo) := rfl
example : (fun n => 2βΏβΊΒΉ) 15 = 2ΒΉβΆ := rfl
/--
info: aβ±
---
info: aΒ³β·
---
info: aβ½ΒΉ βΊ ΒΉβΎ
-/
#guard_msgs in
run_cmd do
let a := Lean.mkIdent `a
let i := Lean.mkIdent `i
Lean.logInfo <| β `(term| $a$i:superscript)
let lit β `(term| 37)
Lean.logInfo <| β `(term| $a$lit:superscript)
let one_plus_one β `(term| (1 + 1))
Lean.logInfo <| β `(term| $a$one_plus_one:superscript)
-- TODO: fix this
/--
error: Not a superscript: 'Ξ±'
---
info: aΞ±
-/
#guard_msgs in
run_cmd Lean.Elab.Command.liftTermElabM do
let a := Lean.mkIdent `a
let Ξ± := Lean.mkIdent `Ξ±
-- note: this only raises the error if we format non-lazily
Lean.logInfo <| β Lean.PrettyPrinter.ppTerm <| β `(term| $a$Ξ±:superscript)
end
section
local macro:arg a:term:max b:subscript(term) : term => `($a $(β¨b.raw[0]β©))
example (a : Nat β Nat) (h : β i, 1 β€ (a)α΅’) : 2 β€ a β + a β :=
Nat.add_le_add hβββ (h)β
/--
info: (a)α΅’
---
info: (a)ββ
---
info: (a)ββ β ββ
-/
#guard_msgs in
run_cmd do
let a := Lean.mkIdent `a
let i := Lean.mkIdent `i
Lean.logInfo <| β `(term| ($a)$i:subscript)
let lit β `(term| 37)
Lean.logInfo <| β `(term| ($a)$lit:subscript)
let one_plus_one β `(term| (1 + 1))
Lean.logInfo <| β `(term| ($a)$one_plus_one:subscript)
/--
error: Not a subscript: 'Ξ±'
---
info: (a)Ξ±
-/
#guard_msgs in
run_cmd Lean.Elab.Command.liftTermElabM do
let a := Lean.mkIdent `a
let Ξ± := Lean.mkIdent `Ξ±
-- note: this only raises the error if we format non-lazily
Lean.logInfo <| β Lean.PrettyPrinter.ppTerm <| β `(term| ($a)$Ξ±:subscript)
end
section delab
open Lean PrettyPrinter.Delaborator SubExpr
open Mathlib.Tactic (delabSubscript delabSuperscript)
private def checkSubscript {Ξ± : Type} (_ : Ξ±) := ()
local syntax:arg "testsub(" noWs subscript(term) noWs ")" : term
local macro_rules | `(testsub($a:subscript)) => `(checkSubscript $a)
private def checkSuperscript {Ξ± : Type} (_ : Ξ±) := ()
local syntax:arg "testsup(" noWs superscript(term) noWs ")" : term
local macro_rules | `(testsup($a:superscript)) => `(checkSuperscript $a)
@[app_delab checkSubscript]
private def delabCheckSubscript : Delab := withOverApp 2 do
let sub β withAppArg delabSubscript
`(testsub($sub:subscript))
@[app_delab checkSuperscript]
private def delabCheckSuperscript : Delab := withOverApp 2 do
let sup β withAppArg delabSuperscript
`(testsup($sup:superscript))
universe u v
/-- `Ξ±` can not be subscripted or superscripted. -/
private def Ξ± {Ξ³ : Type u} {Ξ΄ : Type v} : Ξ³ β Ξ΄ β Ξ΄ := fun _ β¦ id
/-- `Ξ²` can be both subscripted and superscripted. -/
private def Ξ² {Ξ³ : Type u} {Ξ΄ : Type v} : Ξ³ β Ξ΄ β Ξ΄ := fun _ β¦ id
/-- `d` can not be subscripted, so we create an alias for `id`. -/
private abbrev ID {Ξ³ : Sort u} := @id Ξ³
variable (n : Nat)
/-- info: checkSubscript testsub(β) : Unit -/
#guard_msgs in #check checkSubscript (checkSubscript 1)
/-- info: checkSubscript testsup(ΒΉ) : Unit -/
#guard_msgs in #check checkSubscript (checkSuperscript 1)
/-- info: checkSuperscript testsup(ΒΉ) : Unit -/
#guard_msgs in #check checkSuperscript (checkSuperscript 1)
/-- info: checkSuperscript testsub(β) : Unit -/
#guard_msgs in #check checkSuperscript (checkSubscript 1)
section subscript
/-- info: testsub(βββββ
βββββ ββ βββββ
βββββ) : Unit -/
#guard_msgs in #check testsub(βββββ
βββββ ββ βββββ
βββββ)
/-- info: testsub(ᡦ β ββ β β β β β ββ) : Unit -/
#guard_msgs in #check testsub(ᡦ β ββ β β β β β ββ)
/-- info: testsub(ᡦ) : Unit -/
#guard_msgs in #check testsub(ᡦ)
/-- info: testsub(ᡦ ββ) : Unit -/
#guard_msgs in #check testsub(ᡦ ββ)
/-- info: testsub(ᡦ ᡦ ᡦ ᡦ) : Unit -/
#guard_msgs in #check testsub(ᡦ ᡦ ᡦ ᡦ)
/-- info: testsub(Ιͺα΄
Ιͺα΄
ββ) : Unit -/
#guard_msgs in #check testsub(Ιͺα΄
Ιͺα΄
ββ)
end subscript
section superscript
/-- info: testsup(ΒΉΒ²Β³β΄β΅βΆβ·βΈβΉβ° βΌβΌ ΒΉΒ²Β³β΄β΅βΆβ·βΈβΉβ°) : Unit -/
#guard_msgs in #check testsup(ΒΉΒ²Β³β΄β΅βΆβ·βΈβΉβ° βΌβΌ ΒΉΒ²Β³β΄β΅βΆβ·βΈβΉβ°)
/-- info: testsup(α΅ βΏ β½ΒΉ βΊ Β² β» Β³ βΌ β°βΎ) : Unit -/
#guard_msgs in #check testsup(α΅ βΏ β½ΒΉ βΊ Β² β» Β³ βΌ β°βΎ)
/-- info: testsup(α΅) : Unit -/
#guard_msgs in #check testsup(α΅)
/-- info: testsup(α΅ β½βΎ) : Unit -/
#guard_msgs in #check testsup(α΅ β½βΎ)
/-- info: testsup(α΅ α΅ α΅ α΅) : Unit -/
#guard_msgs in #check testsup(α΅ α΅ α΅ α΅)
/-- info: testsup(β±α΅ β±α΅ Β³β·) : Unit -/
#guard_msgs in #check testsup(β±α΅ β±α΅ Β³β·)
end superscript
private def card {Ξ³ : Sort u} := @id Ξ³
local prefix:arg "#" => card
private def factorial {Ξ³ : Sort u} := @id Ξ³
local notation:10000 n "!" => factorial n
abbrev Nat' := Nat
def Nat'.Ξ³ : Nat' β Nat' := id
variable (n x_x : Nat')
section no_subscript
/-- info: checkSubscript x_x : Unit -/
#guard_msgs in #check checkSubscript x_x
/-- info: checkSubscript (Ξ± 0 0) : Unit -/
#guard_msgs in #check checkSubscript (Ξ± 0 0)
/-- info: checkSubscript (0 * 1) : Unit -/
#guard_msgs in #check checkSubscript (0 * 1)
/-- info: checkSubscript (0 ^ 1) : Unit -/
#guard_msgs in #check checkSubscript (0 ^ 1)
/-- info: checkSubscript [1] : Unit -/
#guard_msgs in #check checkSubscript [1]
/-- info: checkSubscript #n : Unit -/
#guard_msgs in #check checkSubscript #n
/-- info: checkSubscript 2! : Unit -/
#guard_msgs in #check checkSubscript 2!
/- The delaborator should reject dot notation. -/
open Nat' (Ξ³) in
/-- info: checkSubscript n.Ξ³ : Unit -/
#guard_msgs in #check testsub(α΅§ β)
/- The delaborator should reject metavariables. -/
set_option pp.mvars false in
/-- info: checkSubscript ?_ : Unit -/
#guard_msgs in #check checkSubscript ?_
/- The delaborator should reject because `n` is shadowed and `β` can not be
subscripted. -/
variable {x} (hx : x = testsub(β)) (n : True) in
/-- info: hx : x = checkSubscript nβ -/
#guard_msgs in #check hx
end no_subscript
section no_superscript
/-- info: checkSuperscript x_x : Unit -/
#guard_msgs in #check checkSuperscript x_x
/-- info: checkSuperscript (Ξ± 0 0) : Unit -/
#guard_msgs in #check checkSuperscript (Ξ± 0 0)
/-- info: checkSuperscript (0 * 1) : Unit -/
#guard_msgs in #check checkSuperscript (0 * 1)
/-- info: checkSuperscript (0 ^ 1) : Unit -/
#guard_msgs in #check checkSuperscript (0 ^ 1)
/-- info: checkSuperscript [1] : Unit -/
#guard_msgs in #check checkSuperscript [1]
/-- info: checkSuperscript #n : Unit -/
#guard_msgs in #check checkSuperscript #n
/-- info: checkSuperscript 2! : Unit -/
#guard_msgs in #check checkSuperscript 2!
/- The delaborator should reject dot notation. -/
open Nat' (Ξ³) in
/-- info: checkSuperscript n.Ξ³ : Unit -/
#guard_msgs in #check testsup(α΅ βΏ)
/- The delaborator should reject metavariables. -/
set_option pp.mvars false in
/-- info: checkSuperscript ?_ : Unit -/
#guard_msgs in #check checkSuperscript ?_
/- The delaborator should reject because `n` is shadowed and `β` can not be
superscripted. -/
variable {x} (hx : x = testsup(βΏ)) (n : True) in
/-- info: hx : x = checkSuperscript nβ -/
#guard_msgs in #check hx
end no_superscript
end delab
|
Sqrt.lean
|
/-
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
-/
import Mathlib.Data.Nat.Basic
import Batteries.Data.Nat.Basic
/-!
# Properties of the natural number square root function.
-/
namespace Nat
/- We don't want to import the algebraic hierarchy in this file. -/
assert_not_exists Monoid
variable {m n a : β}
/-!
### `sqrt`
See [Wikipedia, *Methods of computing square roots*]
(https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Binary_numeral_system_(base_2)).
-/
private lemma iter_fp_bound (n k : β) :
let iter_next (n guess : β) := (guess + n / guess) / 2;
sqrt.iter n k β€ iter_next n (sqrt.iter n k) := by
intro iter_next
unfold sqrt.iter
if h : (k + n / k) / 2 < k then
simpa [if_pos h] using iter_fp_bound _ _
else
grind
private lemma AM_GM : {a b : β} β (4 * a * b β€ (a + b) * (a + b))
| 0, _ => by rw [Nat.mul_zero, Nat.zero_mul]; exact zero_le _
| _, 0 => by rw [Nat.mul_zero]; exact zero_le _
| a + 1, b + 1 => by
simpa only [Nat.mul_add, Nat.add_mul, show (4 : β) = 1 + 1 + 1 + 1 from rfl, Nat.one_mul,
Nat.mul_one, Nat.add_assoc, Nat.add_left_comm, Nat.add_le_add_iff_left]
using Nat.add_le_add_right (@AM_GM a b) 4
-- These two lemmas seem like they belong to `Batteries.Data.Nat.Basic`.
lemma sqrt.iter_sq_le (n guess : β) : sqrt.iter n guess * sqrt.iter n guess β€ n := by
unfold sqrt.iter
let next := (guess + n / guess) / 2
if h : next < guess then
simpa only [next, dif_pos h] using sqrt.iter_sq_le n next
else
apply Nat.mul_le_of_le_div
grind
lemma sqrt.lt_iter_succ_sq (n guess : β) (hn : n < (guess + 1) * (guess + 1)) :
n < (sqrt.iter n guess + 1) * (sqrt.iter n guess + 1) := by
unfold sqrt.iter
-- m was `next`
let m := (guess + n / guess) / 2
dsimp
split_ifs with h
Β· suffices n < (m + 1) * (m + 1) by
simpa only [dif_pos h] using sqrt.lt_iter_succ_sq n m this
refine Nat.lt_of_mul_lt_mul_left ?_ (a := 4 * (guess * guess))
apply Nat.lt_of_le_of_lt AM_GM
rw [show (4 : β) = 2 * 2 from rfl]
rw [Nat.mul_mul_mul_comm 2, Nat.mul_mul_mul_comm (2 * guess)]
refine Nat.mul_self_lt_mul_self (?_ : _ < _ * ((_ / 2) + 1))
rw [β add_div_right _ (by decide), Nat.mul_comm 2, Nat.mul_assoc,
show guess + n / guess + 2 = (guess + n / guess + 1) + 1 from rfl]
have aux_lemma {a : β} : a β€ 2 * ((a + 1) / 2) := by omega
refine lt_of_lt_of_le ?_ (Nat.mul_le_mul_left _ aux_lemma)
rw [Nat.add_assoc, Nat.mul_add]
exact Nat.add_lt_add_left (lt_mul_div_succ _ (lt_of_le_of_lt (Nat.zero_le m) h)) _
Β· exact hn
private def IsSqrt (n q : β) : Prop :=
q * q β€ n β§ n < (q + 1) * (q + 1)
/-
Sketch of proof:
Up to rounding, in terms of the definition of `sqrt.iter`,
* By AM-GM inequality, `nextΒ² β₯ n` giving one of the bounds.
* When we terminated, we have `guess β₯ next` from which we deduce the other bound `n β₯ nextΒ²`.
To turn this into a lean proof we need to manipulate, use properties of natural number division etc.
-/
private lemma sqrt_isSqrt (n : β) : IsSqrt n (sqrt n) := by
match n with
| 0 => simp [IsSqrt, sqrt]
| 1 => simp [IsSqrt, sqrt]
| n + 2 =>
have h : Β¬ (n + 2) β€ 1 := by simp
simp only [IsSqrt, sqrt, h, ite_false]
refine β¨sqrt.iter_sq_le _ _, sqrt.lt_iter_succ_sq _ _ ?_β©
simp only [Nat.mul_add, Nat.add_mul, Nat.one_mul, Nat.mul_one, β Nat.add_assoc]
rw [Nat.lt_add_one_iff, Nat.add_assoc, β Nat.mul_two]
refine le_trans (Nat.le_of_eq (div_add_mod' (n + 2) 2).symm) ?_
rw [Nat.add_comm, Nat.add_le_add_iff_right, add_mod_right]
simp only [Nat.zero_lt_two, add_div_right, succ_mul_succ]
refine le_trans (b := 1) ?_ ?_ <;> grind
lemma sqrt_le (n : β) : sqrt n * sqrt n β€ n := (sqrt_isSqrt n).left
lemma sqrt_le' (n : β) : sqrt n ^ 2 β€ n := by simpa [Nat.pow_two] using sqrt_le n
lemma lt_succ_sqrt (n : β) : n < succ (sqrt n) * succ (sqrt n) := (sqrt_isSqrt n).right
lemma lt_succ_sqrt' (n : β) : n < succ (sqrt n) ^ 2 := by simpa [Nat.pow_two] using lt_succ_sqrt n
lemma sqrt_le_add (n : β) : n β€ sqrt n * sqrt n + sqrt n + sqrt n := by
rw [β succ_mul]; exact le_of_lt_succ (lt_succ_sqrt n)
lemma le_sqrt : m β€ sqrt n β m * m β€ n :=
β¨fun h β¦ le_trans (mul_self_le_mul_self h) (sqrt_le n),
fun h β¦ le_of_lt_succ <| Nat.mul_self_lt_mul_self_iff.1 <| lt_of_le_of_lt h (lt_succ_sqrt n)β©
lemma le_sqrt' : m β€ sqrt n β m ^ 2 β€ n := by simpa only [Nat.pow_two] using le_sqrt
lemma sqrt_lt : sqrt m < n β m < n * n := by simp only [β not_le, le_sqrt]
lemma sqrt_lt' : sqrt m < n β m < n ^ 2 := by simp only [β not_le, le_sqrt']
lemma sqrt_le_self (n : β) : sqrt n β€ n := le_trans (le_mul_self _) (sqrt_le n)
@[gcongr]
lemma sqrt_le_sqrt (h : m β€ n) : sqrt m β€ sqrt n := le_sqrt.2 (le_trans (sqrt_le _) h)
@[simp, grind =] lemma sqrt_zero : sqrt 0 = 0 := rfl
@[simp, grind =] lemma sqrt_one : sqrt 1 = 1 := rfl
lemma sqrt_eq_zero : sqrt n = 0 β n = 0 :=
β¨fun h β¦ have := @sqrt_lt n 1; by grind, by grindβ©
lemma eq_sqrt : a = sqrt n β a * a β€ n β§ n < (a + 1) * (a + 1) :=
β¨fun e β¦ e.symm βΈ sqrt_isSqrt n,
fun β¨hβ, hββ© β¦ le_antisymm (le_sqrt.2 hβ) (le_of_lt_succ <| sqrt_lt.2 hβ)β©
lemma eq_sqrt' : a = sqrt n β a ^ 2 β€ n β§ n < (a + 1) ^ 2 := by
simpa only [Nat.pow_two] using eq_sqrt
lemma le_three_of_sqrt_eq_one (h : sqrt n = 1) : n β€ 3 :=
le_of_lt_succ <| (@sqrt_lt n 2).1 <| by grind
lemma sqrt_lt_self (h : 1 < n) : sqrt n < n :=
sqrt_lt.2 <| by have := Nat.mul_lt_mul_of_pos_left h (lt_of_succ_lt h); grind
@[grind =]
lemma sqrt_pos : 0 < sqrt n β 0 < n :=
le_sqrt
lemma sqrt_add_eq (n : β) (h : a β€ n + n) : sqrt (n * n + a) = n :=
le_antisymm
(le_of_lt_succ <| sqrt_lt.2 <| by grind)
(le_sqrt.2 <| by grind)
lemma sqrt_add_eq' (n : β) (h : a β€ n + n) : sqrt (n ^ 2 + a) = n := by
simpa [Nat.pow_two] using sqrt_add_eq n h
@[simp]
lemma sqrt_eq (n : β) : sqrt (n * n) = n := sqrt_add_eq n (zero_le _)
@[simp]
lemma sqrt_eq' (n : β) : sqrt (n ^ 2) = n := sqrt_add_eq' n (zero_le _)
lemma sqrt_succ_le_succ_sqrt (n : β) : sqrt n.succ β€ n.sqrt.succ :=
le_of_lt_succ <| sqrt_lt.2 <| (have := sqrt_le_add n; by grind)
lemma add_one_sqrt_le_of_ne_zero {n : β} (hn : n β 0) : (n + 1).sqrt β€ n :=
le_induction le_rfl (fun n _ ih β¦ le_trans n.succ.sqrt_succ_le_succ_sqrt (succ_le_succ ih)) n
(Nat.pos_of_ne_zero hn)
lemma exists_mul_self (x : β) : (β n, n * n = x) β sqrt x * sqrt x = x :=
β¨fun β¨n, hnβ© β¦ by rw [β hn, sqrt_eq], fun h β¦ β¨sqrt x, hβ©β©
lemma exists_mul_self' (x : β) : (β n, n ^ 2 = x) β sqrt x ^ 2 = x := by
simpa only [Nat.pow_two] using exists_mul_self x
lemma sqrt_mul_sqrt_lt_succ (n : β) : sqrt n * sqrt n < n + 1 :=
Nat.lt_succ_iff.mpr (sqrt_le _)
lemma sqrt_mul_sqrt_lt_succ' (n : β) : sqrt n ^ 2 < n + 1 :=
Nat.lt_succ_iff.mpr (sqrt_le' _)
lemma succ_le_succ_sqrt (n : β) : n + 1 β€ (sqrt n + 1) * (sqrt n + 1) :=
le_of_pred_lt (lt_succ_sqrt _)
lemma succ_le_succ_sqrt' (n : β) : n + 1 β€ (sqrt n + 1) ^ 2 :=
le_of_pred_lt (lt_succ_sqrt' _)
/-- There are no perfect squares strictly between mΒ² and (m+1)Β² -/
lemma not_exists_sq (hl : m * m < n) (hr : n < (m + 1) * (m + 1)) : Β¬β t, t * t = n := by
rintro β¨t, rflβ©
have h1 : m < t := Nat.mul_self_lt_mul_self_iff.1 hl
have h2 : t < m + 1 := Nat.mul_self_lt_mul_self_iff.1 hr
grind
lemma not_exists_sq' : m ^ 2 < n β n < (m + 1) ^ 2 β Β¬β t, t ^ 2 = n := by
simpa only [Nat.pow_two] using not_exists_sq
end Nat
|
Coeff.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.CharP.Defs
import Mathlib.Algebra.MonoidAlgebra.Support
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.Algebra.Regular.Basic
import Mathlib.Data.Nat.Choose.Sum
/-!
# Theory of univariate polynomials
The theorems include formulas for computing coefficients, such as
`coeff_add`, `coeff_sum`, `coeff_mul`
-/
noncomputable section
open Finsupp Finset AddMonoidAlgebra
open Polynomial
namespace Polynomial
universe u v
variable {R : Type u} {S : Type v} {a b : R} {n m : β}
variable [Semiring R] {p q r : R[X]}
section Coeff
@[simp]
theorem coeff_add (p q : R[X]) (n : β) : coeff (p + q) n = coeff p n + coeff q n := by
rcases p with β¨β©
rcases q with β¨β©
simp_rw [β ofFinsupp_add, coeff]
exact Finsupp.add_apply _ _ _
@[simp]
theorem coeff_smul [SMulZeroClass S R] (r : S) (p : R[X]) (n : β) :
coeff (r β’ p) n = r β’ coeff p n := by
rcases p with β¨β©
simp_rw [β ofFinsupp_smul, coeff]
exact Finsupp.smul_apply _ _ _
theorem support_smul [SMulZeroClass S R] (r : S) (p : R[X]) :
support (r β’ p) β support p := by
intro i hi
simp? [mem_support_iff] at hi β’ says simp only [mem_support_iff, coeff_smul, ne_eq] at hi β’
contrapose! hi
simp [hi]
open scoped Pointwise in
theorem card_support_mul_le : #(p * q).support β€ #p.support * #q.support := by
calc #(p * q).support
_ = #(p.toFinsupp * q.toFinsupp).support := by rw [β support_toFinsupp, toFinsupp_mul]
_ β€ #(p.toFinsupp.support + q.toFinsupp.support) :=
Finset.card_le_card (AddMonoidAlgebra.support_mul p.toFinsupp q.toFinsupp)
_ β€ #p.support * #q.support := Finset.card_imageβ_le ..
/-- `Polynomial.sum` as a linear map. -/
@[simps]
def lsum {R A M : Type*} [Semiring R] [Semiring A] [AddCommMonoid M] [Module R A] [Module R M]
(f : β β A ββ[R] M) : A[X] ββ[R] M where
toFun p := p.sum (f Β· Β·)
map_add' p q := sum_add_index p q _ (fun n => (f n).map_zero) fun n _ _ => (f n).map_add _ _
map_smul' c p := by
rw [sum_eq_of_subset (f Β· Β·) (fun n => (f n).map_zero) (support_smul c p)]
simp only [sum_def, Finset.smul_sum, coeff_smul, LinearMap.map_smul, RingHom.id_apply]
variable (R) in
/-- The nth coefficient, as a linear map. -/
def lcoeff (n : β) : R[X] ββ[R] R where
toFun p := coeff p n
map_add' p q := coeff_add p q n
map_smul' r p := coeff_smul r p n
@[simp]
theorem lcoeff_apply (n : β) (f : R[X]) : lcoeff R n f = coeff f n :=
rfl
@[simp]
theorem finset_sum_coeff {ΞΉ : Type*} (s : Finset ΞΉ) (f : ΞΉ β R[X]) (n : β) :
coeff (β b β s, f b) n = β b β s, coeff (f b) n :=
map_sum (lcoeff R n) _ _
lemma coeff_list_sum (l : List R[X]) (n : β) :
l.sum.coeff n = (l.map (lcoeff R n)).sum :=
map_list_sum (lcoeff R n) _
lemma coeff_list_sum_map {ΞΉ : Type*} (l : List ΞΉ) (f : ΞΉ β R[X]) (n : β) :
(l.map f).sum.coeff n = (l.map (fun a => (f a).coeff n)).sum := by
simp_rw [coeff_list_sum, List.map_map, Function.comp_def, lcoeff_apply]
@[simp]
theorem coeff_sum [Semiring S] (n : β) (f : β β R β S[X]) :
coeff (p.sum f) n = p.sum fun a b => coeff (f a b) n := by
rcases p with β¨β©
simp [Polynomial.sum, support_ofFinsupp, coeff_ofFinsupp]
/-- Decomposes the coefficient of the product `p * q` as a sum
over `antidiagonal`. A version which sums over `range (n + 1)` can be obtained
by using `Finset.Nat.sum_antidiagonal_eq_sum_range_succ`. -/
theorem coeff_mul (p q : R[X]) (n : β) :
coeff (p * q) n = β x β antidiagonal n, coeff p x.1 * coeff q x.2 := by
rcases p with β¨pβ©; rcases q with β¨qβ©
simp_rw [β ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_apply_antidiagonal p q n _ Finset.mem_antidiagonal
@[simp]
theorem mul_coeff_zero (p q : R[X]) : coeff (p * q) 0 = coeff p 0 * coeff q 0 := by simp [coeff_mul]
theorem mul_coeff_one (p q : R[X]) :
coeff (p * q) 1 = coeff p 0 * coeff q 1 + coeff p 1 * coeff q 0 := by
rw [coeff_mul, Nat.antidiagonal_eq_map]
simp [sum_range_succ]
/-- `constantCoeff p` returns the constant term of the polynomial `p`,
defined as `coeff p 0`. This is a ring homomorphism. -/
@[simps]
def constantCoeff : R[X] β+* R where
toFun p := coeff p 0
map_one' := coeff_one_zero
map_mul' := mul_coeff_zero
map_zero' := coeff_zero 0
map_add' p q := coeff_add p q 0
lemma constantCoeff_surjective : Function.Surjective (constantCoeff (R := R)) :=
fun x β¦ β¨C x, by simpβ©
theorem isUnit_C {x : R} : IsUnit (C x) β IsUnit x :=
β¨fun h => (congr_arg IsUnit coeff_C_zero).mp (h.map <| @constantCoeff R _), fun h => h.map Cβ©
theorem coeff_mul_X_zero (p : R[X]) : coeff (p * X) 0 = 0 := by simp
theorem coeff_X_mul_zero (p : R[X]) : coeff (X * p) 0 = 0 := by simp
theorem coeff_C_mul_X_pow (x : R) (k n : β) :
coeff (C x * X ^ k : R[X]) n = if n = k then x else 0 := by
rw [C_mul_X_pow_eq_monomial, coeff_monomial]
congr 1
simp [eq_comm]
theorem coeff_C_mul_X (x : R) (n : β) : coeff (C x * X : R[X]) n = if n = 1 then x else 0 := by
rw [β pow_one X, coeff_C_mul_X_pow]
@[simp]
theorem coeff_C_mul (p : R[X]) : coeff (C a * p) n = a * coeff p n := by
rcases p with β¨pβ©
simp_rw [β monomial_zero_left, β ofFinsupp_single, β ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.single_zero_mul_apply p a n
theorem C_mul' (a : R) (f : R[X]) : C a * f = a β’ f := by
ext
rw [coeff_C_mul, coeff_smul, smul_eq_mul]
@[simp]
theorem coeff_mul_C (p : R[X]) (n : β) (a : R) : coeff (p * C a) n = coeff p n * a := by
rcases p with β¨pβ©
simp_rw [β monomial_zero_left, β ofFinsupp_single, β ofFinsupp_mul, coeff]
exact AddMonoidAlgebra.mul_single_zero_apply p a n
@[simp] lemma coeff_mul_natCast {a k : β} :
coeff (p * (a : R[X])) k = coeff p k * (βa : R) := coeff_mul_C _ _ _
@[simp] lemma coeff_natCast_mul {a k : β} :
coeff ((a : R[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_ofNat {a k : β} [Nat.AtLeastTwo a] :
coeff (p * (ofNat(a) : R[X])) k = coeff p k * ofNat(a) := coeff_mul_C _ _ _
@[simp] lemma coeff_ofNat_mul {a k : β} [Nat.AtLeastTwo a] :
coeff ((ofNat(a) : R[X]) * p) k = ofNat(a) * coeff p k := coeff_C_mul _
@[simp] lemma coeff_mul_intCast [Ring S] {p : S[X]} {a : β€} {k : β} :
coeff (p * (a : S[X])) k = coeff p k * (βa : S) := coeff_mul_C _ _ _
@[simp] lemma coeff_intCast_mul [Ring S] {p : S[X]} {a : β€} {k : β} :
coeff ((a : S[X]) * p) k = a * coeff p k := coeff_C_mul _
@[simp]
theorem coeff_X_pow (k n : β) : coeff (X ^ k : R[X]) n = if n = k then 1 else 0 := by
simp only [one_mul, RingHom.map_one, β coeff_C_mul_X_pow]
theorem coeff_X_pow_self (n : β) : coeff (X ^ n : R[X]) n = 1 := by simp
section Fewnomials
open Finset
theorem support_binomial {k m : β} (hkm : k β m) {x y : R} (hx : x β 0) (hy : y β 0) :
support (C x * X ^ k + C y * X ^ m) = {k, m} := by
apply subset_antisymm (support_binomial' k m x y)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm, if_neg hkm.symm, mul_zero, zero_add,
add_zero, Ne, hx, hy, not_false_eq_true, and_true]
theorem support_trinomial {k m n : β} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x β 0)
(hy : y β 0) (hz : z β 0) :
support (C x * X ^ k + C y * X ^ m + C z * X ^ n) = {k, m, n} := by
apply subset_antisymm (support_trinomial' k m n x y z)
simp_rw [insert_subset_iff, singleton_subset_iff, mem_support_iff, coeff_add, coeff_C_mul,
coeff_X_pow_self, mul_one, coeff_X_pow, if_neg hkm.ne, if_neg hkm.ne', if_neg hmn.ne,
if_neg hmn.ne', if_neg (hkm.trans hmn).ne, if_neg (hkm.trans hmn).ne', mul_zero, add_zero,
zero_add, Ne, hx, hy, hz, not_false_eq_true, and_true]
theorem card_support_binomial {k m : β} (h : k β m) {x y : R} (hx : x β 0) (hy : y β 0) :
#(support (C x * X ^ k + C y * X ^ m)) = 2 := by
rw [support_binomial h hx hy, card_insert_of_notMem (mt mem_singleton.mp h), card_singleton]
theorem card_support_trinomial {k m n : β} (hkm : k < m) (hmn : m < n) {x y z : R} (hx : x β 0)
(hy : y β 0) (hz : z β 0) : #(support (C x * X ^ k + C y * X ^ m + C z * X ^ n)) = 3 := by
rw [support_trinomial hkm hmn hx hy hz,
card_insert_of_notMem
(mt mem_insert.mp (not_or_intro hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),
card_insert_of_notMem (mt mem_singleton.mp hmn.ne), card_singleton]
end Fewnomials
@[simp]
theorem coeff_mul_X_pow (p : R[X]) (n d : β) :
coeff (p * Polynomial.X ^ n) (d + n) = coeff p d := by
rw [coeff_mul, Finset.sum_eq_single (d, n), coeff_X_pow, if_pos rfl, mul_one]
all_goals grind [mem_antidiagonal, coeff_X_pow, mul_zero]
@[simp]
theorem coeff_X_pow_mul (p : R[X]) (n d : β) :
coeff (Polynomial.X ^ n * p) (d + n) = coeff p d := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow]
theorem coeff_mul_X_pow' (p : R[X]) (n d : β) :
(p * X ^ n).coeff d = ite (n β€ d) (p.coeff (d - n)) 0 := by
split_ifs with h
Β· rw [β tsub_add_cancel_of_le h, coeff_mul_X_pow, add_tsub_cancel_right]
Β· refine (coeff_mul _ _ _).trans (Finset.sum_eq_zero fun x hx => ?_)
rw [coeff_X_pow, if_neg, mul_zero]
exact ((le_of_add_le_right (mem_antidiagonal.mp hx).le).trans_lt <| not_le.mp h).ne
theorem coeff_X_pow_mul' (p : R[X]) (n d : β) :
(X ^ n * p).coeff d = ite (n β€ d) (p.coeff (d - n)) 0 := by
rw [(commute_X_pow p n).eq, coeff_mul_X_pow']
@[simp]
theorem coeff_mul_X (p : R[X]) (n : β) : coeff (p * X) (n + 1) = coeff p n := by
simpa only [pow_one] using coeff_mul_X_pow p 1 n
@[simp]
theorem coeff_X_mul (p : R[X]) (n : β) : coeff (X * p) (n + 1) = coeff p n := by
rw [(commute_X p).eq, coeff_mul_X]
theorem coeff_mul_monomial (p : R[X]) (n d : β) (r : R) :
coeff (p * monomial n r) (d + n) = coeff p d * r := by
rw [β C_mul_X_pow_eq_monomial, β X_pow_mul, β mul_assoc, coeff_mul_C, coeff_mul_X_pow]
theorem coeff_monomial_mul (p : R[X]) (n d : β) (r : R) :
coeff (monomial n r * p) (d + n) = r * coeff p d := by
rw [β C_mul_X_pow_eq_monomial, mul_assoc, coeff_C_mul, X_pow_mul, coeff_mul_X_pow]
-- This can already be proved by `simp`.
theorem coeff_mul_monomial_zero (p : R[X]) (d : β) (r : R) :
coeff (p * monomial 0 r) d = coeff p d * r :=
coeff_mul_monomial p 0 d r
-- This can already be proved by `simp`.
theorem coeff_monomial_zero_mul (p : R[X]) (d : β) (r : R) :
coeff (monomial 0 r * p) d = r * coeff p d :=
coeff_monomial_mul p 0 d r
theorem mul_X_pow_eq_zero {p : R[X]} {n : β} (H : p * X ^ n = 0) : p = 0 :=
ext fun k => (coeff_mul_X_pow p n k).symm.trans <| ext_iff.1 H (k + n)
theorem isRegular_X_pow (n : β) : IsRegular (X ^ n : R[X]) := by
suffices IsLeftRegular (X^n : R[X]) from
β¨this, this.right_of_commute (fun p => commute_X_pow p n)β©
intro P Q (hPQ : X^n * P = X^n * Q)
ext i
rw [β coeff_X_pow_mul P n i, hPQ, coeff_X_pow_mul Q n i]
@[simp] theorem isRegular_X : IsRegular (X : R[X]) := pow_one (X : R[X]) βΈ isRegular_X_pow 1
theorem coeff_X_add_C_pow (r : R) (n k : β) :
((X + C r) ^ n).coeff k = r ^ (n - k) * (n.choose k : R) := by
rw [(commute_X (C r : R[X])).add_pow, β lcoeff_apply, map_sum]
simp only [lcoeff_apply, β C_eq_natCast, β C_pow, coeff_mul_C]
rw [Finset.sum_eq_single k, coeff_X_pow_self, one_mul]
Β· intro _ _ h
simp [coeff_X_pow, h.symm]
Β· simp only [coeff_X_pow_self, one_mul, not_lt, Finset.mem_range]
intro h
rw [Nat.choose_eq_zero_of_lt h, Nat.cast_zero, mul_zero]
theorem coeff_X_add_one_pow (R : Type*) [Semiring R] (n k : β) :
((X + 1) ^ n).coeff k = (n.choose k : R) := by rw [β C_1, coeff_X_add_C_pow, one_pow, one_mul]
theorem coeff_one_add_X_pow (R : Type*) [Semiring R] (n k : β) :
((1 + X) ^ n).coeff k = (n.choose k : R) := by rw [add_comm _ X, coeff_X_add_one_pow]
theorem C_dvd_iff_dvd_coeff (r : R) (Ο : R[X]) : C r β£ Ο β β i, r β£ Ο.coeff i := by
constructor
Β· rintro β¨Ο, rflβ© c
rw [coeff_C_mul]
apply dvd_mul_right
Β· intro h
choose c hc using h
classical
let c' : β β R := fun i => if i β Ο.support then c i else 0
let Ο : R[X] := β i β Ο.support, monomial i (c' i)
use Ο
ext i
simp only [c', Ο, coeff_C_mul, mem_support_iff, coeff_monomial, finset_sum_coeff,
Finset.sum_ite_eq']
split_ifs with hi
Β· rw [hc]
Β· rw [Classical.not_not] at hi
rwa [mul_zero]
theorem smul_eq_C_mul (a : R) : a β’ p = C a * p := by simp [ext_iff]
theorem update_eq_add_sub_coeff {R : Type*} [Ring R] (p : R[X]) (n : β) (a : R) :
p.update n a = p + Polynomial.C (a - p.coeff n) * Polynomial.X ^ n := by
ext
rw [coeff_update_apply, coeff_add, coeff_C_mul_X_pow]
split_ifs with h <;> simp [h]
end Coeff
section cast
theorem natCast_coeff_zero {n : β} {R : Type*} [Semiring R] : (n : R[X]).coeff 0 = n := by
simp only [coeff_natCast_ite, ite_true]
@[norm_cast]
theorem natCast_inj {m n : β} {R : Type*} [Semiring R] [CharZero R] :
(βm : R[X]) = βn β m = n := by
constructor
Β· intro h
apply_fun fun p => p.coeff 0 at h
simpa using h
Β· rintro rfl
rfl
@[simp]
theorem intCast_coeff_zero {i : β€} {R : Type*} [Ring R] : (i : R[X]).coeff 0 = i := by
cases i <;> simp
@[norm_cast]
theorem intCast_inj {m n : β€} {R : Type*} [Ring R] [CharZero R] : (βm : R[X]) = βn β m = n := by
constructor
Β· intro h
apply_fun fun p => p.coeff 0 at h
simpa using h
Β· rintro rfl
rfl
end cast
instance charZero [CharZero R] : CharZero R[X] where cast_injective _x _y := natCast_inj.mp
instance charP {p : β} [CharP R p] : CharP R[X] p where
cast_eq_zero_iff n := by
rw [β CharP.cast_eq_zero_iff R, β C_inj (R := R), map_natCast, C_0]
end Polynomial
|
Final.lean
|
/-
Copyright (c) 2025 Robin Carlier. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Robin Carlier
-/
import Mathlib.CategoryTheory.Join.Basic
import Mathlib.CategoryTheory.Limits.Final
import Mathlib.CategoryTheory.Limits.IsConnected
/-!
# (Co)Finality of the inclusions in joins of category
This file records the fact that `inclLeft C D : C β₯€ C β D` is initial if `C` is connected.
Dually, `inclRight : C β₯€ C β D` is final if `D` is connected.
-/
namespace CategoryTheory.Join
variable (C D : Type*) [Category C] [Category D]
/-- The category of `Join.inclLeft C D`-costructured arrows with target `right d` is equivalent to
`C`. -/
def costructuredArrowEquiv (d : D) : CostructuredArrow (inclLeft C D) (right d) β C where
functor := CostructuredArrow.proj (inclLeft C D) (right d)
inverse :=
{ obj c := .mk (edge c d)
map f := CostructuredArrow.homMk f }
unitIso := NatIso.ofComponents (fun _ β¦ CostructuredArrow.isoMk (Iso.refl _))
counitIso := NatIso.ofComponents (fun _ β¦ Iso.refl _)
/-- The category of `Join.inclRight C D`-structured arrows with source `left c` is equivalent to
`D`. -/
def structuredArrowEquiv (c : C) : StructuredArrow (left c) (inclRight C D) β D where
functor := StructuredArrow.proj (left c) (inclRight C D)
inverse :=
{ obj d := .mk (edge c d)
map f := StructuredArrow.homMk f }
unitIso := NatIso.ofComponents (fun _ β¦ StructuredArrow.isoMk (Iso.refl _))
counitIso := NatIso.ofComponents (fun _ β¦ Iso.refl _)
instance [IsConnected C] : (inclLeft C D).Initial where
out x := match x with
|.left _ => isConnected_of_isTerminal _ CostructuredArrow.mkIdTerminal
|.right d => isConnected_of_equivalent (costructuredArrowEquiv C D d).symm
instance [IsConnected D] : (inclRight C D).Final where
out x := match x with
|.left c => isConnected_of_equivalent (structuredArrowEquiv C D c).symm
|.right _ => isConnected_of_isInitial _ (StructuredArrow.mkIdInitial (T := inclRight C D))
end CategoryTheory.Join
|
gproduct.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 bigop finset fingroup morphism.
From mathcomp Require Import quotient action finfun.
(******************************************************************************)
(* Partial, semidirect, central, and direct products. *)
(* ++ Internal products, with A, B : {set gT}, are partial operations : *)
(* partial_product A B == A * B if A is a group normalised by the group B, *)
(* and the empty set otherwise. *)
(* A ><| B == A * B if this is a semi-direct product (i.e., if A *)
(* is normalised by B and intersects it trivially). *)
(* A \* B == A * B if this is a central product ([A, B] = 1). *)
(* A \x B == A * B if this is a direct product. *)
(* [complements to K in G] == set of groups H s.t. K * H = G and K :&: H = 1. *)
(* [splits G, over K] == [complements to K in G] is not empty. *)
(* remgr A B x == the right remainder in B of x mod A, i.e., *)
(* some element of (A :* x) :&: B. *)
(* divgr A B x == the "division" in B of x by A: for all x, *)
(* x = divgr A B x * remgr A B x. *)
(* ++ External products : *)
(* pairg1, pair1g == the isomorphisms aT1 -> aT1 * aT2, aT2 -> aT1 * aT2. *)
(* (aT1 * aT2 has a direct product group structure.) *)
(* dfung1 i == the morphism gT i -> {dffun forall j, gt j} where *)
(* gT : I -> finGroupType is a family of finite groups. *)
(* sdprod_by to == the semidirect product defined by to : groupAction H K. *)
(* This is a finGroupType; the actual semidirect product is *)
(* the total set [set: sdprod_by to] on that type. *)
(* sdpair[12] to == the isomorphisms injecting K and H into *)
(* sdprod_by to = sdpair1 to @* K ><| sdpair2 to @* H. *)
(* External central products (with identified centers) will be defined later *)
(* in file center.v. *)
(* ++ Morphisms on product groups: *)
(* pprodm nAB fJ fAB == the morphism extending fA and fB on A <*> B when *)
(* nAB : B \subset 'N(A), *)
(* fJ : {in A & B, morph_act 'J 'J fA fB}, and *)
(* fAB : {in A :&: B, fA =1 fB}. *)
(* sdprodm defG fJ == the morphism extending fA and fB on G, given *)
(* defG : A ><| B = G and *)
(* fJ : {in A & B, morph_act 'J 'J fA fB}. *)
(* xsdprodm fHKact == the total morphism on sdprod_by to induced by *)
(* fH : {morphism H >-> rT}, fK : {morphism K >-> rT}, *)
(* with to : groupAction K H, *)
(* given fHKact : morph_act to 'J fH fK. *)
(* cprodm defG cAB fAB == the morphism extending fA and fB on G, when *)
(* defG : A \* B = G, *)
(* cAB : fB @* B \subset 'C(fB @* A), *)
(* and fAB : {in A :&: B, fA =1 fB}. *)
(* dprodm defG cAB == the morphism extending fA and fB on G, when *)
(* defG : A \x B = G and *)
(* cAB : fA @* B \subset 'C(fA @* A) *)
(* mulgm (x, y) == x * y; mulgm is an isomorphism from setX A B to G *)
(* iff A \x B = G . *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Defs.
Variables gT : finGroupType.
Implicit Types A B C : {set gT}.
Definition partial_product A B :=
if A == 1 then B else if B == 1 then A else
if [&& group_set A, group_set B & B \subset 'N(A)] then A * B else set0.
Definition semidirect_product A B :=
if A :&: B \subset 1%G then partial_product A B else set0.
Definition central_product A B :=
if B \subset 'C(A) then partial_product A B else set0.
Definition direct_product A B :=
if A :&: B \subset 1%G then central_product A B else set0.
Definition complements_to_in A B :=
[set K : {group gT} | A :&: K == 1 & A * K == B].
Definition splits_over B A := complements_to_in A B != set0.
(* Product remainder functions -- right variant only. *)
Definition remgr A B x := repr (A :* x :&: B).
Definition divgr A B x := x * (remgr A B x)^-1.
End Defs.
Arguments partial_product _ _%_g _%_g : clear implicits.
Arguments semidirect_product _ _%_g _%_g : clear implicits.
Arguments central_product _ _%_g _%_g : clear implicits.
Arguments complements_to_in _ _%_g _%_g.
Arguments splits_over _ _%_g _%_g.
Arguments remgr _ _%_g _%_g _%_g.
Arguments divgr _ _%_g _%_g _%_g.
Arguments direct_product : clear implicits.
Notation pprod := (partial_product _).
Notation sdprod := (semidirect_product _).
Notation cprod := (central_product _).
Notation dprod := (direct_product _).
Notation "G ><| H" := (sdprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "G \* H" := (cprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "G \x H" := (dprod G H)%g
(at level 40, left associativity) : group_scope.
Notation "[ 'complements' 'to' A 'in' B ]" := (complements_to_in A B)
(format "[ 'complements' 'to' A 'in' B ]") : group_scope.
Notation "[ 'splits' B , 'over' A ]" := (splits_over B A)
(format "[ 'splits' B , 'over' A ]") : group_scope.
(* Prenex Implicits remgl divgl. *)
Prenex Implicits remgr divgr.
Section InternalProd.
Variable gT : finGroupType.
Implicit Types A B C : {set gT}.
Implicit Types G H K L M : {group gT}.
Local Notation pprod := (partial_product gT).
Local Notation sdprod := (semidirect_product gT) (only parsing).
Local Notation cprod := (central_product gT) (only parsing).
Local Notation dprod := (direct_product gT) (only parsing).
Lemma pprod1g : left_id 1 pprod.
Proof. by move=> A; rewrite /pprod eqxx. Qed.
Lemma pprodg1 : right_id 1 pprod.
Proof. by move=> A; rewrite /pprod eqxx; case: eqP. Qed.
Variant are_groups A B : Prop := AreGroups K H of A = K & B = H.
Lemma group_not0 G : set0 <> G.
Proof. by move/setP/(_ 1); rewrite inE group1. Qed.
Lemma mulg0 : right_zero (@set0 gT) mulg.
Proof.
by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE.
Qed.
Lemma mul0g : left_zero (@set0 gT) mulg.
Proof.
by move=> A; apply/setP=> x; rewrite inE; apply/imset2P=> [[y z]]; rewrite inE.
Qed.
Lemma pprodP A B G :
pprod A B = G -> [/\ are_groups A B, A * B = G & B \subset 'N(A)].
Proof.
have Gnot0 := @group_not0 G; rewrite /pprod; do 2?case: eqP => [-> ->| _].
- by rewrite mul1g norms1; split; first exists 1%G G.
- by rewrite mulg1 sub1G; split; first exists G 1%G.
by case: and3P => // [[gA gB ->]]; split; first exists (Group gA) (Group gB).
Qed.
Lemma pprodE K H : H \subset 'N(K) -> pprod K H = K * H.
Proof.
move=> nKH; rewrite /pprod nKH !groupP /=.
by do 2?case: eqP => [-> | _]; rewrite ?mulg1 ?mul1g.
Qed.
Lemma pprodEY K H : H \subset 'N(K) -> pprod K H = K <*> H.
Proof. by move=> nKH; rewrite pprodE ?norm_joinEr. Qed.
Lemma pprodW A B G : pprod A B = G -> A * B = G. Proof. by case/pprodP. Qed.
Lemma pprodWC A B G : pprod A B = G -> B * A = G.
Proof. by case/pprodP=> _ <- /normC. Qed.
Lemma pprodWY A B G : pprod A B = G -> A <*> B = G.
Proof. by case/pprodP=> [[K H -> ->] <- /norm_joinEr]. Qed.
Lemma pprodJ A B x : pprod A B :^ x = pprod (A :^ x) (B :^ x).
Proof.
rewrite /pprod !conjsg_eq1 !group_setJ normJ conjSg -conjsMg.
by do 3?case: ifP => // _; apply: conj0g.
Qed.
(* Properties of the remainders *)
Lemma remgrMl K B x y : y \in K -> remgr K B (y * x) = remgr K B x.
Proof. by move=> Ky; rewrite {1}/remgr rcosetM rcoset_id. Qed.
Lemma remgrP K B x : (remgr K B x \in K :* x :&: B) = (x \in K * B).
Proof.
set y := _ x; apply/idP/mulsgP=> [|[g b Kg Bb x_gb]].
rewrite inE rcoset_sym mem_rcoset => /andP[Kxy' By].
by exists (x * y^-1) y; rewrite ?mulgKV.
by apply: (mem_repr b); rewrite inE rcoset_sym mem_rcoset x_gb mulgK Kg.
Qed.
Lemma remgr1 K H x : x \in K -> remgr K H x = 1.
Proof. by move=> Kx; rewrite /remgr rcoset_id ?repr_group. Qed.
Lemma divgr_eq A B x : x = divgr A B x * remgr A B x.
Proof. by rewrite mulgKV. Qed.
Lemma divgrMl K B x y : x \in K -> divgr K B (x * y) = x * divgr K B y.
Proof. by move=> Hx; rewrite /divgr remgrMl ?mulgA. Qed.
Lemma divgr_id K H x : x \in K -> divgr K H x = x.
Proof. by move=> Kx; rewrite /divgr remgr1 // invg1 mulg1. Qed.
Lemma mem_remgr K B x : x \in K * B -> remgr K B x \in B.
Proof. by rewrite -remgrP => /setIP[]. Qed.
Lemma mem_divgr K B x : x \in K * B -> divgr K B x \in K.
Proof. by rewrite -remgrP inE rcoset_sym mem_rcoset => /andP[]. Qed.
Section DisjointRem.
Variables K H : {group gT}.
Hypothesis tiKH : K :&: H = 1.
Lemma remgr_id x : x \in H -> remgr K H x = x.
Proof.
move=> Hx; apply/eqP; rewrite eq_mulgV1 (sameP eqP set1gP) -tiKH inE.
rewrite -mem_rcoset groupMr ?groupV // -in_setI remgrP.
by apply: subsetP Hx; apply: mulG_subr.
Qed.
Lemma remgrMid x y : x \in K -> y \in H -> remgr K H (x * y) = y.
Proof. by move=> Kx Hy; rewrite remgrMl ?remgr_id. Qed.
Lemma divgrMid x y : x \in K -> y \in H -> divgr K H (x * y) = x.
Proof. by move=> Kx Hy; rewrite /divgr remgrMid ?mulgK. Qed.
End DisjointRem.
(* Intersection of a centraliser with a disjoint product. *)
Lemma subcent_TImulg K H A :
K :&: H = 1 -> A \subset 'N(K) :&: 'N(H) -> 'C_K(A) * 'C_H(A) = 'C_(K * H)(A).
Proof.
move=> tiKH /subsetIP[nKA nHA]; apply/eqP.
rewrite group_modl ?subsetIr // eqEsubset setSI ?mulSg ?subsetIl //=.
apply/subsetP=> _ /setIP[/mulsgP[x y Kx Hy ->] cAxy].
rewrite inE cAxy mem_mulg // inE Kx /=.
apply/centP=> z Az; apply/commgP/conjg_fixP.
move/commgP/conjg_fixP/(congr1 (divgr K H)): (centP cAxy z Az).
by rewrite conjMg !divgrMid ?memJ_norm // (subsetP nKA, subsetP nHA).
Qed.
(* Complements, and splitting. *)
Lemma complP H A B :
reflect (A :&: H = 1 /\ A * H = B) (H \in [complements to A in B]).
Proof. by apply: (iffP setIdP); case; split; apply/eqP. Qed.
Lemma splitsP B A :
reflect (exists H, H \in [complements to A in B]) [splits B, over A].
Proof. exact: set0Pn. Qed.
Lemma complgC H K G :
(H \in [complements to K in G]) = (K \in [complements to H in G]).
Proof.
rewrite !inE setIC; congr (_ && _).
by apply/eqP/eqP=> defG; rewrite -(comm_group_setP _) // defG groupP.
Qed.
Section NormalComplement.
Variables K H G : {group gT}.
Hypothesis complH_K : H \in [complements to K in G].
Lemma remgrM : K <| G -> {in G &, {morph remgr K H : x y / x * y}}.
Proof.
case/normalP=> _; case/complP: complH_K => tiKH <- nK_KH x y KHx KHy.
rewrite {1}(divgr_eq K H y) mulgA (conjgCV x) {2}(divgr_eq K H x) -2!mulgA.
rewrite mulgA remgrMid //; last by rewrite groupMl mem_remgr.
by rewrite groupMl !(=^~ mem_conjg, nK_KH, mem_divgr).
Qed.
Lemma divgrM : H \subset 'C(K) -> {in G &, {morph divgr K H : x y / x * y}}.
Proof.
move=> cKH; have /complP[_ defG] := complH_K.
have nsKG: K <| G by rewrite -defG -cent_joinEr // normalYl cents_norm.
move=> x y Gx Gy; rewrite {1}/divgr remgrM // invMg -!mulgA (mulgA y).
by congr (_ * _); rewrite -(centsP cKH) ?groupV ?(mem_remgr, mem_divgr, defG).
Qed.
End NormalComplement.
(* Semi-direct product *)
Lemma sdprod1g : left_id 1 sdprod.
Proof. by move=> A; rewrite /sdprod subsetIl pprod1g. Qed.
Lemma sdprodg1 : right_id 1 sdprod.
Proof. by move=> A; rewrite /sdprod subsetIr pprodg1. Qed.
Lemma sdprodP A B G :
A ><| B = G -> [/\ are_groups A B, A * B = G, B \subset 'N(A) & A :&: B = 1].
Proof.
rewrite /sdprod; case: ifP => [trAB | _ /group_not0[] //].
case/pprodP=> gAB defG nBA; split=> {defG nBA}//.
by case: gAB trAB => H K -> -> /trivgP.
Qed.
Lemma sdprodE K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K * H.
Proof. by move=> nKH tiKH; rewrite /sdprod tiKH subxx pprodE. Qed.
Lemma sdprodEY K H : H \subset 'N(K) -> K :&: H = 1 -> K ><| H = K <*> H.
Proof. by move=> nKH tiKH; rewrite sdprodE ?norm_joinEr. Qed.
Lemma sdprodWpp A B G : A ><| B = G -> pprod A B = G.
Proof. by case/sdprodP=> [[K H -> ->] <- /pprodE]. Qed.
Lemma sdprodW A B G : A ><| B = G -> A * B = G.
Proof. by move/sdprodWpp/pprodW. Qed.
Lemma sdprodWC A B G : A ><| B = G -> B * A = G.
Proof. by move/sdprodWpp/pprodWC. Qed.
Lemma sdprodWY A B G : A ><| B = G -> A <*> B = G.
Proof. by move/sdprodWpp/pprodWY. Qed.
Lemma sdprodJ A B x : (A ><| B) :^ x = A :^ x ><| B :^ x.
Proof.
rewrite /sdprod -conjIg sub_conjg conjs1g -pprodJ.
by case: ifP => _ //; apply: imset0.
Qed.
Lemma sdprod_context G K H : K ><| H = G ->
[/\ K <| G, H \subset G, K * H = G, H \subset 'N(K) & K :&: H = 1].
Proof.
case/sdprodP=> _ <- nKH tiKH.
by rewrite /normal mulG_subl mulG_subr mulG_subG normG.
Qed.
Lemma sdprod_compl G K H : K ><| H = G -> H \in [complements to K in G].
Proof. by case/sdprodP=> _ mulKH _ tiKH; apply/complP. Qed.
Lemma sdprod_normal_complP G K H :
K <| G -> reflect (K ><| H = G) (K \in [complements to H in G]).
Proof.
case/andP=> _ nKG; rewrite complgC.
apply: (iffP idP); [case/complP=> tiKH mulKH | exact: sdprod_compl].
by rewrite sdprodE ?(subset_trans _ nKG) // -mulKH mulG_subr.
Qed.
Lemma sdprod_card G A B : A ><| B = G -> (#|A| * #|B|)%N = #|G|.
Proof. by case/sdprodP=> [[H K -> ->] <- _ /TI_cardMg]. Qed.
Lemma sdprod_isom G A B :
A ><| B = G ->
{nAB : B \subset 'N(A) | isom B (G / A) (restrm nAB (coset A))}.
Proof.
case/sdprodP=> [[K H -> ->] <- nKH tiKH].
by exists nKH; rewrite quotientMidl quotient_isom.
Qed.
Lemma sdprod_isog G A B : A ><| B = G -> B \isog G / A.
Proof. by case/sdprod_isom=> nAB; apply: isom_isog. Qed.
Lemma sdprod_subr G A B M : A ><| B = G -> M \subset B -> A ><| M = A <*> M.
Proof.
case/sdprodP=> [[K H -> ->] _ nKH tiKH] sMH.
by rewrite sdprodEY ?(subset_trans sMH) //; apply/trivgP; rewrite -tiKH setIS.
Qed.
Lemma index_sdprod G A B : A ><| B = G -> #|B| = #|G : A|.
Proof.
case/sdprodP=> [[K H -> ->] <- _ tiHK].
by rewrite indexMg -indexgI setIC tiHK indexg1.
Qed.
Lemma index_sdprodr G A B M :
A ><| B = G -> M \subset B -> #|B : M| = #|G : A <*> M|.
Proof.
move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] mulKH nKH _] defG sMH.
rewrite -!divgS //=; last by rewrite -genM_join gen_subG -mulKH mulgS.
by rewrite -(sdprod_card defG) -(sdprod_card (sdprod_subr defG sMH)) divnMl.
Qed.
Lemma quotient_sdprodr_isom G A B M :
A ><| B = G -> M <| B ->
{f : {morphism B / M >-> coset_of (A <*> M)} |
isom (B / M) (G / (A <*> M)) f
& forall L, L \subset B -> f @* (L / M) = A <*> L / (A <*> M)}.
Proof.
move=> defG nsMH; have [defA defB]: A = <<A>>%G /\ B = <<B>>%G.
by have [[K1 H1 -> ->] _ _ _] := sdprodP defG; rewrite /= !genGid.
do [rewrite {}defA {}defB; move: {A}<<A>>%G {B}<<B>>%G => K H] in defG nsMH *.
have [[nKH /isomP[injKH imKH]] sMH] := (sdprod_isom defG, normal_sub nsMH).
have [[nsKG sHG mulKH _ _] nKM] := (sdprod_context defG, subset_trans sMH nKH).
have nsKMG: K <*> M <| G.
by rewrite -quotientYK // -mulKH -quotientK ?cosetpre_normal ?quotient_normal.
have [/= f inj_f im_f] := third_isom (joing_subl K M) nsKG nsKMG.
rewrite quotientYidl //= -imKH -(restrm_quotientE nKH sMH) in f inj_f im_f.
have /domP[h [_ ker_h _ im_h]]: 'dom (f \o quotm _ nsMH) = H / M.
by rewrite ['dom _]morphpre_quotm injmK.
have{} im_h L: L \subset H -> h @* (L / M) = K <*> L / (K <*> M).
move=> sLH; have [sLG sKKM] := (subset_trans sLH sHG, joing_subl K M).
rewrite im_h morphim_comp morphim_quotm [_ @* L]restrm_quotientE ?im_f //.
rewrite quotientY ?(normsG sKKM) ?(subset_trans sLG) ?normal_norm //.
by rewrite (quotientS1 sKKM) joing1G.
exists h => //; apply/isomP; split; last by rewrite im_h //= (sdprodWY defG).
by rewrite ker_h injm_comp ?injm_quotm.
Qed.
Lemma quotient_sdprodr_isog G A B M :
A ><| B = G -> M <| B -> B / M \isog G / (A <*> M).
Proof.
move=> defG; case/sdprodP: defG (defG) => [[K H -> ->] _ _ _] => defG nsMH.
by have [h /isom_isog->] := quotient_sdprodr_isom defG nsMH.
Qed.
Lemma sdprod_modl A B G H :
A ><| B = G -> A \subset H -> A ><| (B :&: H) = G :&: H.
Proof.
case/sdprodP=> {A B} [[A B -> ->]] <- nAB tiAB sAH.
rewrite -group_modl ?sdprodE ?subIset ?nAB //.
by rewrite setIA tiAB (setIidPl _) ?sub1G.
Qed.
Lemma sdprod_modr A B G H :
A ><| B = G -> B \subset H -> (H :&: A) ><| B = H :&: G.
Proof.
case/sdprodP=> {A B}[[A B -> ->]] <- nAB tiAB sAH.
rewrite -group_modr ?sdprodE ?normsI // ?normsG //.
by rewrite -setIA tiAB (setIidPr _) ?sub1G.
Qed.
Lemma subcent_sdprod B C G A :
B ><| C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) ><| 'C_C(A) = 'C_G(A).
Proof.
case/sdprodP=> [[H K -> ->] <- nHK tiHK] nHKA {B C G}.
rewrite sdprodE ?subcent_TImulg ?normsIG //.
by rewrite -setIIl tiHK (setIidPl (sub1G _)).
Qed.
Lemma sdprod_recl n G K H K1 :
#|G| <= n -> K ><| H = G -> K1 \proper K -> H \subset 'N(K1) ->
exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K1 ><| H = G1].
Proof.
move=> leGn; case/sdprodP=> _ defG nKH tiKH ltK1K nK1H.
have tiK1H: K1 :&: H = 1 by apply/trivgP; rewrite -tiKH setSI ?proper_sub.
exists (K1 <*> H)%G; rewrite /= -defG sdprodE // norm_joinEr //.
rewrite ?mulSg ?proper_sub ?(leq_trans _ leGn) //=.
by rewrite -defG ?TI_cardMg // ltn_pmul2r ?proper_card.
Qed.
Lemma sdprod_recr n G K H H1 :
#|G| <= n -> K ><| H = G -> H1 \proper H ->
exists G1 : {group gT}, [/\ #|G1| < n, G1 \subset G & K ><| H1 = G1].
Proof.
move=> leGn; case/sdprodP=> _ defG nKH tiKH ltH1H.
have [sH1H _] := andP ltH1H; have nKH1 := subset_trans sH1H nKH.
have tiKH1: K :&: H1 = 1 by apply/trivgP; rewrite -tiKH setIS.
exists (K <*> H1)%G; rewrite /= -defG sdprodE // norm_joinEr //.
rewrite ?mulgS // ?(leq_trans _ leGn) //=.
by rewrite -defG ?TI_cardMg // ltn_pmul2l ?proper_card.
Qed.
Lemma mem_sdprod G A B x : A ><| B = G -> x \in G ->
exists y, exists z,
[/\ y \in A, z \in B, x = y * z &
{in A & B, forall u t, x = u * t -> u = y /\ t = z}].
Proof.
case/sdprodP=> [[K H -> ->{A B}] <- _ tiKH] /mulsgP[y z Ky Hz ->{x}].
exists y; exists z; split=> // u t Ku Ht eqyzut.
move: (congr1 (divgr K H) eqyzut) (congr1 (remgr K H) eqyzut).
by rewrite !remgrMid // !divgrMid.
Qed.
(* Central product *)
Lemma cprod1g : left_id 1 cprod.
Proof. by move=> A; rewrite /cprod cents1 pprod1g. Qed.
Lemma cprodg1 : right_id 1 cprod.
Proof. by move=> A; rewrite /cprod sub1G pprodg1. Qed.
Lemma cprodP A B G :
A \* B = G -> [/\ are_groups A B, A * B = G & B \subset 'C(A)].
Proof. by rewrite /cprod; case: ifP => [cAB /pprodP[] | _ /group_not0[]]. Qed.
Lemma cprodE G H : H \subset 'C(G) -> G \* H = G * H.
Proof. by move=> cGH; rewrite /cprod cGH pprodE ?cents_norm. Qed.
Lemma cprodEY G H : H \subset 'C(G) -> G \* H = G <*> H.
Proof. by move=> cGH; rewrite cprodE ?cent_joinEr. Qed.
Lemma cprodWpp A B G : A \* B = G -> pprod A B = G.
Proof. by case/cprodP=> [[K H -> ->] <- /cents_norm/pprodE]. Qed.
Lemma cprodW A B G : A \* B = G -> A * B = G.
Proof. by move/cprodWpp/pprodW. Qed.
Lemma cprodWC A B G : A \* B = G -> B * A = G.
Proof. by move/cprodWpp/pprodWC. Qed.
Lemma cprodWY A B G : A \* B = G -> A <*> B = G.
Proof. by move/cprodWpp/pprodWY. Qed.
Lemma cprodJ A B x : (A \* B) :^ x = A :^ x \* B :^ x.
Proof.
by rewrite /cprod centJ conjSg -pprodJ; case: ifP => _ //; apply: imset0.
Qed.
Lemma cprod_normal2 A B G : A \* B = G -> A <| G /\ B <| G.
Proof.
case/cprodP=> [[K H -> ->] <- cKH]; rewrite -cent_joinEr //.
by rewrite normalYl normalYr !cents_norm // centsC.
Qed.
Lemma bigcprodW I (r : seq I) P F G :
\big[cprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G.
Proof.
elim/big_rec2: _ G => // i A B _ IH G /cprodP[[_ H _ defB] <- _].
by rewrite (IH H) defB.
Qed.
Lemma bigcprodWY I (r : seq I) P F G :
\big[cprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G.
Proof.
elim/big_rec2: _ G => [|i A B _ IH G]; first by rewrite gen0.
case/cprodP => [[K H -> defB] <- cKH].
by rewrite -[<<_>>]joing_idr (IH H) ?cent_joinEr -?defB.
Qed.
Lemma triv_cprod A B : (A \* B == 1) = (A == 1) && (B == 1).
Proof.
case A1: (A == 1); first by rewrite (eqP A1) cprod1g.
apply/eqP=> /cprodP[[G H defA ->]] /eqP.
by rewrite defA trivMg -defA A1.
Qed.
Lemma cprod_ntriv A B : A != 1 -> B != 1 ->
A \* B =
if [&& group_set A, group_set B & B \subset 'C(A)] then A * B else set0.
Proof.
move=> A1 B1; rewrite /cprod; case: ifP => cAB; rewrite ?cAB ?andbF //=.
by rewrite /pprod -if_neg A1 -if_neg B1 cents_norm.
Qed.
Lemma trivg0 : (@set0 gT == 1) = false.
Proof. by rewrite eqEcard cards0 cards1 andbF. Qed.
Lemma group0 : group_set (@set0 gT) = false.
Proof. by rewrite /group_set inE. Qed.
Lemma cprod0g A : set0 \* A = set0.
Proof. by rewrite /cprod centsC sub0set /pprod group0 trivg0 !if_same. Qed.
Lemma cprodC : commutative cprod.
Proof.
rewrite /cprod => A B; case: ifP => cAB; rewrite centsC cAB // /pprod.
by rewrite andbCA normC !cents_norm // 1?centsC //; do 2!case: eqP => // ->.
Qed.
Lemma cprodA : associative cprod.
Proof.
move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !cprod1g.
case B1: (B == 1); first by rewrite (eqP B1) cprod1g cprodg1.
case C1: (C == 1); first by rewrite (eqP C1) !cprodg1.
rewrite !(triv_cprod, cprod_ntriv) ?{}A1 ?{}B1 ?{}C1 //.
case: isgroupP => [[G ->{A}] | _]; last by rewrite group0.
case: (isgroupP B) => [[H ->{B}] | _]; last by rewrite group0.
case: (isgroupP C) => [[K ->{C}] | _]; last by rewrite group0 !andbF.
case cGH: (H \subset 'C(G)); case cHK: (K \subset 'C(H)); last first.
- by rewrite group0.
- by rewrite group0 /= mulG_subG cGH andbF.
- by rewrite group0 /= centM subsetI cHK !andbF.
rewrite /= mulgA mulG_subG centM subsetI cGH cHK andbT -(cent_joinEr cHK).
by rewrite -(cent_joinEr cGH) !groupP.
Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {set gT} 1 cprod
cprodA cprodC cprod1g.
Lemma cprod_modl A B G H :
A \* B = G -> A \subset H -> A \* (B :&: H) = G :&: H.
Proof.
case/cprodP=> [[U V -> -> {A B}]] defG cUV sUH.
by rewrite cprodE; [rewrite group_modl ?defG | rewrite subIset ?cUV].
Qed.
Lemma cprod_modr A B G H :
A \* B = G -> B \subset H -> (H :&: A) \* B = H :&: G.
Proof. by rewrite -!(cprodC B) !(setIC H); apply: cprod_modl. Qed.
Lemma bigcprodYP (I : finType) (P : pred I) (H : I -> {group gT}) :
reflect (forall i j, P i -> P j -> i != j -> H i \subset 'C(H j))
(\big[cprod/1]_(i | P i) H i == (\prod_(i | P i) H i)%G).
Proof.
apply: (iffP eqP) => [defG i j Pi Pj neq_ij | cHH].
rewrite (bigD1 j) // (bigD1 i) /= ?cprodA in defG; last exact/andP.
by case/cprodP: defG => [[K _ /cprodP[//]]].
set Q := P; have sQP: subpred Q P by []; have [n leQn] := ubnP #|Q|.
elim: n => // n IHn in (Q) leQn sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0.
rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *.
rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]].
rewrite bigprodGE cprodEY // gen_subG; apply/bigcupsP=> j /andP[neq_ji Qj].
by rewrite cHH ?sQP.
Qed.
Lemma bigcprodEY I r (P : pred I) (H : I -> {group gT}) G :
abelian G -> (forall i, P i -> H i \subset G) ->
\big[cprod/1]_(i <- r | P i) H i = (\prod_(i <- r | P i) H i)%G.
Proof.
move=> cGG sHG; apply/eqP; rewrite !(big_tnth _ _ r).
by apply/bigcprodYP=> i j Pi Pj _; rewrite (sub_abelian_cent2 cGG) ?sHG.
Qed.
Lemma perm_bigcprod (I : eqType) r1 r2 (A : I -> {set gT}) G x :
\big[cprod/1]_(i <- r1) A i = G -> {in r1, forall i, x i \in A i} ->
perm_eq r1 r2 ->
\prod_(i <- r1) x i = \prod_(i <- r2) x i.
Proof.
elim: r1 r2 G => [|i r1 IHr] r2 G defG Ax eq_r12.
by rewrite perm_sym in eq_r12; rewrite (perm_small_eq _ eq_r12) ?big_nil.
have /rot_to[n r3 Dr2]: i \in r2 by rewrite -(perm_mem eq_r12) mem_head.
transitivity (\prod_(j <- rot n r2) x j).
rewrite Dr2 !big_cons in defG Ax *; have [[_ G1 _ defG1] _ _] := cprodP defG.
rewrite (IHr r3 G1) //; first by case/allP/andP: Ax => _ /allP.
by rewrite -(perm_cons i) -Dr2 perm_sym perm_rot perm_sym.
rewrite -(cat_take_drop n r2) [in LHS]cat_take_drop in eq_r12 *.
rewrite (perm_big _ eq_r12) !big_cat /= !(big_nth i) !big_mkord in defG *.
have /cprodP[[G1 G2 defG1 defG2] _ /centsP-> //] := defG.
rewrite defG2 -(bigcprodW defG2) mem_prodg // => k _; apply: Ax.
by rewrite (perm_mem eq_r12) mem_cat orbC mem_nth.
rewrite defG1 -(bigcprodW defG1) mem_prodg // => k _; apply: Ax.
by rewrite (perm_mem eq_r12) mem_cat mem_nth.
Qed.
Lemma reindex_bigcprod (I J : finType) (h : J -> I) P (A : I -> {set gT}) G x :
{on SimplPred P, bijective h} -> \big[cprod/1]_(i | P i) A i = G ->
{in SimplPred P, forall i, x i \in A i} ->
\prod_(i | P i) x i = \prod_(j | P (h j)) x (h j).
Proof.
case=> h1 hK h1K defG Ax; have [e big_e [Ue mem_e] _] := big_enumP P.
rewrite -!big_e in defG *; rewrite -(big_map h P x) -[RHS]big_filter filter_map.
apply: perm_bigcprod defG _ _ => [i|]; first by rewrite mem_e => /Ax.
have [r _ [Ur /= mem_r] _] := big_enumP; apply: uniq_perm Ue _ _ => [|i].
by rewrite map_inj_in_uniq // => i j; rewrite !mem_r ; apply: (can_in_inj hK).
rewrite mem_e; apply/idP/mapP=> [Pi|[j r_j ->]]; last by rewrite -mem_r.
by exists (h1 i); rewrite ?mem_r h1K.
Qed.
(* Direct product *)
Lemma dprod1g : left_id 1 dprod.
Proof. by move=> A; rewrite /dprod subsetIl cprod1g. Qed.
Lemma dprodg1 : right_id 1 dprod.
Proof. by move=> A; rewrite /dprod subsetIr cprodg1. Qed.
Lemma dprodP A B G :
A \x B = G -> [/\ are_groups A B, A * B = G, B \subset 'C(A) & A :&: B = 1].
Proof.
rewrite /dprod; case: ifP => trAB; last by case/group_not0.
by case/cprodP=> gAB; split=> //; case: gAB trAB => ? ? -> -> /trivgP.
Qed.
Lemma dprodE G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G * H.
Proof. by move=> cGH trGH; rewrite /dprod trGH sub1G cprodE. Qed.
Lemma dprodEY G H : H \subset 'C(G) -> G :&: H = 1 -> G \x H = G <*> H.
Proof. by move=> cGH trGH; rewrite /dprod trGH subxx cprodEY. Qed.
Lemma dprodEcp A B : A :&: B = 1 -> A \x B = A \* B.
Proof. by move=> trAB; rewrite /dprod trAB subxx. Qed.
Lemma dprodEsd A B : B \subset 'C(A) -> A \x B = A ><| B.
Proof. by rewrite /dprod /cprod => ->. Qed.
Lemma dprodWcp A B G : A \x B = G -> A \* B = G.
Proof. by move=> defG; have [_ _ _ /dprodEcp <-] := dprodP defG. Qed.
Lemma dprodWsd A B G : A \x B = G -> A ><| B = G.
Proof. by move=> defG; have [_ _ /dprodEsd <-] := dprodP defG. Qed.
Lemma dprodW A B G : A \x B = G -> A * B = G.
Proof. by move/dprodWsd/sdprodW. Qed.
Lemma dprodWC A B G : A \x B = G -> B * A = G.
Proof. by move/dprodWsd/sdprodWC. Qed.
Lemma dprodWY A B G : A \x B = G -> A <*> B = G.
Proof. by move/dprodWsd/sdprodWY. Qed.
Lemma cprod_card_dprod G A B :
A \* B = G -> #|A| * #|B| <= #|G| -> A \x B = G.
Proof. by case/cprodP=> [[K H -> ->] <- cKH] /cardMg_TI; apply: dprodE. Qed.
Lemma dprodJ A B x : (A \x B) :^ x = A :^ x \x B :^ x.
Proof.
rewrite /dprod -conjIg sub_conjg conjs1g -cprodJ.
by case: ifP => _ //; apply: imset0.
Qed.
Lemma dprod_normal2 A B G : A \x B = G -> A <| G /\ B <| G.
Proof. by move/dprodWcp/cprod_normal2. Qed.
Lemma dprodYP K H : reflect (K \x H = K <*> H) (H \subset 'C(K) :\: K^#).
Proof.
rewrite subsetD -setI_eq0 setIDA setD_eq0 setIC subG1 /=.
by apply: (iffP andP) => [[cKH /eqP/dprodEY->] | /dprodP[_ _ -> ->]].
Qed.
Lemma dprodC : commutative dprod.
Proof. by move=> A B; rewrite /dprod setIC cprodC. Qed.
Lemma dprodWsdC A B G : A \x B = G -> B ><| A = G.
Proof. by rewrite dprodC => /dprodWsd. Qed.
Lemma dprodA : associative dprod.
Proof.
move=> A B C; case A1: (A == 1); first by rewrite (eqP A1) !dprod1g.
case B1: (B == 1); first by rewrite (eqP B1) dprod1g dprodg1.
case C1: (C == 1); first by rewrite (eqP C1) !dprodg1.
rewrite /dprod (fun_if (cprod A)) (fun_if (cprod^~ C)) -cprodA.
rewrite -(cprodC set0) !cprod0g cprod_ntriv ?B1 ?{}C1 //.
case: and3P B1 => [[] | _ _]; last by rewrite cprodC cprod0g !if_same.
case/isgroupP=> H ->; case/isgroupP=> K -> {B C}; move/cent_joinEr=> eHK H1.
rewrite cprod_ntriv ?trivMg ?{}A1 ?{}H1 // mulG_subG.
case: and4P => [[] | _]; last by rewrite !if_same.
case/isgroupP=> G ->{A} _ cGH _; rewrite cprodEY // -eHK.
case trGH: (G :&: H \subset _); case trHK: (H :&: K \subset _); last first.
- by rewrite !if_same.
- rewrite if_same; case: ifP => // trG_HK; case/negP: trGH.
by apply: subset_trans trG_HK; rewrite setIS ?joing_subl.
- rewrite if_same; case: ifP => // trGH_K; case/negP: trHK.
by apply: subset_trans trGH_K; rewrite setSI ?joing_subr.
do 2![case: ifP] => // trGH_K trG_HK; [case/negP: trGH_K | case/negP: trG_HK].
apply: subset_trans trHK; rewrite subsetI subsetIr -{2}(mulg1 H) -mulGS.
rewrite setIC group_modl ?joing_subr //= cent_joinEr // -eHK.
by rewrite -group_modr ?joing_subl //= setIC -(normC (sub1G _)) mulSg.
apply: subset_trans trGH; rewrite subsetI subsetIl -{2}(mul1g H) -mulSG.
rewrite setIC group_modr ?joing_subl //= eHK -(cent_joinEr cGH).
by rewrite -group_modl ?joing_subr //= setIC (normC (sub1G _)) mulgS.
Qed.
HB.instance Definition _ := Monoid.isComLaw.Build {set gT} 1 dprod
dprodA dprodC dprod1g.
Lemma bigdprodWcp I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> \big[cprod/1]_(i <- r | P i) F i = G.
Proof.
elim/big_rec2: _ G => // i A B _ IH G /dprodP[[K H -> defB] <- cKH _].
by rewrite (IH H) // cprodE -defB.
Qed.
Lemma bigdprodW I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> \prod_(i <- r | P i) F i = G.
Proof. by move/bigdprodWcp; apply: bigcprodW. Qed.
Lemma bigdprodWY I (r : seq I) P F G :
\big[dprod/1]_(i <- r | P i) F i = G -> << \bigcup_(i <- r | P i) F i >> = G.
Proof. by move/bigdprodWcp; apply: bigcprodWY. Qed.
Lemma bigdprodYP (I : finType) (P : pred I) (F : I -> {group gT}) :
reflect (forall i, P i ->
(\prod_(j | P j && (j != i)) F j)%G \subset 'C(F i) :\: (F i)^#)
(\big[dprod/1]_(i | P i) F i == (\prod_(i | P i) F i)%G).
Proof.
apply: (iffP eqP) => [defG i Pi | dxG].
rewrite !(bigD1 i Pi) /= in defG; have [[_ G' _ defG'] _ _ _] := dprodP defG.
by apply/dprodYP; rewrite -defG defG' bigprodGE (bigdprodWY defG').
set Q := P; have sQP: subpred Q P by []; have [n leQn] := ubnP #|Q|.
elim: n => // n IHn in (Q) leQn sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0.
rewrite (cardD1x Qi) add1n ltnS !(bigD1 i Qi) /= in leQn *.
rewrite {}IHn {n leQn}// => [|j /andP[/sQP //]].
apply/dprodYP; apply: subset_trans (dxG i (sQP i Qi)); rewrite !bigprodGE.
by apply: genS; apply/bigcupsP=> j /andP[Qj ne_ji]; rewrite (bigcup_max j) ?sQP.
Qed.
Lemma dprod_modl A B G H :
A \x B = G -> A \subset H -> A \x (B :&: H) = G :&: H.
Proof.
case/dprodP=> [[U V -> -> {A B}]] defG cUV trUV sUH.
rewrite dprodEcp; first by apply: cprod_modl; rewrite ?cprodE.
by rewrite setIA trUV (setIidPl _) ?sub1G.
Qed.
Lemma dprod_modr A B G H :
A \x B = G -> B \subset H -> (H :&: A) \x B = H :&: G.
Proof. by rewrite -!(dprodC B) !(setIC H); apply: dprod_modl. Qed.
Lemma subcent_dprod B C G A :
B \x C = G -> A \subset 'N(B) :&: 'N(C) -> 'C_B(A) \x 'C_C(A) = 'C_G(A).
Proof.
move=> defG; have [_ _ cBC _] := dprodP defG; move: defG.
by rewrite !dprodEsd 1?(centSS _ _ cBC) ?subsetIl //; apply: subcent_sdprod.
Qed.
Lemma dprod_card A B G : A \x B = G -> (#|A| * #|B|)%N = #|G|.
Proof. by case/dprodP=> [[H K -> ->] <- _]; move/TI_cardMg. Qed.
Lemma bigdprod_card I r (P : pred I) E G :
\big[dprod/1]_(i <- r | P i) E i = G ->
(\prod_(i <- r | P i) #|E i|)%N = #|G|.
Proof.
elim/big_rec2: _ G => [G <- | i A B _ IH G defG]; first by rewrite cards1.
have [[_ H _ defH] _ _ _] := dprodP defG.
by rewrite -(dprod_card defG) (IH H) defH.
Qed.
Lemma bigcprod_card_dprod I r (P : pred I) (A : I -> {set gT}) G :
\big[cprod/1]_(i <- r | P i) A i = G ->
\prod_(i <- r | P i) #|A i| <= #|G| ->
\big[dprod/1]_(i <- r | P i) A i = G.
Proof.
elim: r G => [|i r IHr]; rewrite !(big_nil, big_cons) //; case: ifP => _ // G.
case/cprodP=> [[K H -> defH]]; rewrite defH => <- cKH leKH_G.
have /implyP := leq_trans leKH_G (dvdn_leq _ (dvdn_cardMg K H)).
rewrite muln_gt0 leq_pmul2l !cardG_gt0 //= => /(IHr H defH){}defH.
by rewrite defH dprodE // cardMg_TI // -(bigdprod_card defH).
Qed.
Lemma bigcprod_coprime_dprod (I : finType) (P : pred I) (A : I -> {set gT}) G :
\big[cprod/1]_(i | P i) A i = G ->
(forall i j, P i -> P j -> i != j -> coprime #|A i| #|A j|) ->
\big[dprod/1]_(i | P i) A i = G.
Proof.
move=> defG coA; set Q := P in defG *; have sQP: subpred Q P by [].
have [m leQm] := ubnP #|Q|; elim: m => // m IHm in (Q) leQm G defG sQP *.
have [i Qi | Q0] := pickP Q; last by rewrite !big_pred0 in defG *.
move: defG; rewrite !(bigD1 i Qi) /= => /cprodP[[Hi Gi defAi defGi] <-].
rewrite defAi defGi => cHGi.
have{} defGi: \big[dprod/1]_(j | Q j && (j != i)) A j = Gi.
by apply: IHm => [||j /andP[/sQP]] //; rewrite (cardD1x Qi) in leQm.
rewrite defGi dprodE // coprime_TIg // -defAi -(bigdprod_card defGi).
elim/big_rec: _ => [|j n /andP[neq_ji Qj] IHn]; first exact: coprimen1.
by rewrite coprimeMr coprime_sym coA ?sQP.
Qed.
Lemma mem_dprod G A B x : A \x B = G -> x \in G ->
exists y, exists z,
[/\ y \in A, z \in B, x = y * z &
{in A & B, forall u t, x = u * t -> u = y /\ t = z}].
Proof.
move=> defG; have [_ _ cBA _] := dprodP defG.
by apply: mem_sdprod; rewrite -dprodEsd.
Qed.
Lemma mem_bigdprod (I : finType) (P : pred I) F G x :
\big[dprod/1]_(i | P i) F i = G -> x \in G ->
exists c, [/\ forall i, P i -> c i \in F i, x = \prod_(i | P i) c i
& forall e, (forall i, P i -> e i \in F i) ->
x = \prod_(i | P i) e i ->
forall i, P i -> e i = c i].
Proof.
move=> defG; rewrite -(bigdprodW defG) => /prodsgP[c Fc ->].
have [r big_r [_ mem_r] _] := big_enumP P.
exists c; split=> // e Fe eq_ce i Pi; rewrite -!{}big_r in defG eq_ce.
have{Pi}: i \in r by rewrite mem_r.
have{mem_r}: all P r by apply/allP=> j; rewrite mem_r.
elim: r G defG eq_ce => // j r IHr G.
rewrite !big_cons inE /= => /dprodP[[K H defK defH] _ _].
rewrite defK defH => tiFjH eq_ce /andP[Pj Pr].
suffices{i IHr} eq_cej: c j = e j.
case/predU1P=> [-> //|]; apply: IHr defH _ Pr.
by apply: (mulgI (c j)); rewrite eq_ce eq_cej.
rewrite !(big_nth j) !big_mkord in defH eq_ce.
move/(congr1 (divgr K H)): eq_ce; move/bigdprodW: defH => defH.
move/(all_nthP j) in Pr.
by rewrite !divgrMid // -?defK -?defH ?mem_prodg // => *; rewrite ?Fc ?Fe ?Pr.
Qed.
Lemma comm_prodG I r (G : I -> {group gT}) (P : {pred I}) :
{in P &, forall i j, commute (G i) (G j)} ->
(\prod_(i <- r | P i) G i)%G = \prod_(i <- r | P i) G i :> {set gT}.
Proof.
elim: r => /= [|i {}r IHr]; rewrite !(big_nil, big_cons)//=.
case: ifP => //= Pi Gcomm; rewrite comm_joingE {}IHr// /commute.
elim: r => [|j r IHr]; first by rewrite big_nil mulg1 mul1g.
by rewrite big_cons; case: ifP => //= Pj; rewrite mulgA Gcomm// -!mulgA IHr.
Qed.
End InternalProd.
Arguments complP {gT H A B}.
Arguments splitsP {gT B A}.
Arguments sdprod_normal_complP {gT G K H}.
Arguments dprodYP {gT K H}.
Arguments bigdprodYP {gT I P F}.
Section MorphimInternalProd.
Variables (gT rT : finGroupType) (D : {group gT}) (f : {morphism D >-> rT}).
Section OneProd.
Variables G H K : {group gT}.
Hypothesis sGD : G \subset D.
Lemma morphim_pprod : pprod K H = G -> pprod (f @* K) (f @* H) = f @* G.
Proof.
case/pprodP=> _ defG mKH; rewrite pprodE ?morphim_norms //.
by rewrite -morphimMl ?(subset_trans _ sGD) -?defG // mulG_subl.
Qed.
Lemma morphim_coprime_sdprod :
K ><| H = G -> coprime #|K| #|H| -> f @* K ><| f @* H = f @* G.
Proof.
rewrite /sdprod => defG coHK; move: defG.
by rewrite !coprime_TIg ?coprime_morph // !subxx; apply: morphim_pprod.
Qed.
Lemma injm_sdprod : 'injm f -> K ><| H = G -> f @* K ><| f @* H = f @* G.
Proof.
move=> inj_f; case/sdprodP=> _ defG nKH tiKH.
by rewrite /sdprod -injmI // tiKH morphim1 subxx morphim_pprod // pprodE.
Qed.
Lemma morphim_cprod : K \* H = G -> f @* K \* f @* H = f @* G.
Proof.
case/cprodP=> _ defG cKH; rewrite /cprod morphim_cents // morphim_pprod //.
by rewrite pprodE // cents_norm // centsC.
Qed.
Lemma injm_dprod : 'injm f -> K \x H = G -> f @* K \x f @* H = f @* G.
Proof.
move=> inj_f; case/dprodP=> _ defG cHK tiKH.
by rewrite /dprod -injmI // tiKH morphim1 subxx morphim_cprod // cprodE.
Qed.
Lemma morphim_coprime_dprod :
K \x H = G -> coprime #|K| #|H| -> f @* K \x f @* H = f @* G.
Proof.
rewrite /dprod => defG coHK; move: defG.
by rewrite !coprime_TIg ?coprime_morph // !subxx; apply: morphim_cprod.
Qed.
End OneProd.
Implicit Type G : {group gT}.
Lemma morphim_bigcprod I r (P : pred I) (H : I -> {group gT}) G :
G \subset D -> \big[cprod/1]_(i <- r | P i) H i = G ->
\big[cprod/1]_(i <- r | P i) f @* H i = f @* G.
Proof.
elim/big_rec2: _ G => [|i fB B Pi def_fB] G sGD defG.
by rewrite -defG morphim1.
case/cprodP: defG (defG) => [[Hi Gi -> defB] _ _]; rewrite defB => defG.
rewrite (def_fB Gi) //; first exact: morphim_cprod.
by apply: subset_trans sGD; case/cprod_normal2: defG => _ /andP[].
Qed.
Lemma injm_bigdprod I r (P : pred I) (H : I -> {group gT}) G :
G \subset D -> 'injm f -> \big[dprod/1]_(i <- r | P i) H i = G ->
\big[dprod/1]_(i <- r | P i) f @* H i = f @* G.
Proof.
move=> sGD injf; elim/big_rec2: _ G sGD => [|i fB B Pi def_fB] G sGD defG.
by rewrite -defG morphim1.
case/dprodP: defG (defG) => [[Hi Gi -> defB] _ _ _]; rewrite defB => defG.
rewrite (def_fB Gi) //; first exact: injm_dprod.
by apply: subset_trans sGD; case/dprod_normal2: defG => _ /andP[].
Qed.
Lemma morphim_coprime_bigdprod (I : finType) P (H : I -> {group gT}) G :
G \subset D -> \big[dprod/1]_(i | P i) H i = G ->
(forall i j, P i -> P j -> i != j -> coprime #|H i| #|H j|) ->
\big[dprod/1]_(i | P i) f @* H i = f @* G.
Proof.
move=> sGD /bigdprodWcp defG coH; have def_fG := morphim_bigcprod sGD defG.
by apply: bigcprod_coprime_dprod => // i j *; rewrite coprime_morph ?coH.
Qed.
End MorphimInternalProd.
Section QuotientInternalProd.
Variables (gT : finGroupType) (G K H M : {group gT}).
Hypothesis nMG: G \subset 'N(M).
Lemma quotient_pprod : pprod K H = G -> pprod (K / M) (H / M) = G / M.
Proof. exact: morphim_pprod. Qed.
Lemma quotient_coprime_sdprod :
K ><| H = G -> coprime #|K| #|H| -> (K / M) ><| (H / M) = G / M.
Proof. exact: morphim_coprime_sdprod. Qed.
Lemma quotient_cprod : K \* H = G -> (K / M) \* (H / M) = G / M.
Proof. exact: morphim_cprod. Qed.
Lemma quotient_coprime_dprod :
K \x H = G -> coprime #|K| #|H| -> (K / M) \x (H / M) = G / M.
Proof. exact: morphim_coprime_dprod. Qed.
End QuotientInternalProd.
Section ExternalDirProd.
Variables gT1 gT2 : finGroupType.
Definition extprod_mulg (x y : gT1 * gT2) := (x.1 * y.1, x.2 * y.2).
Definition extprod_invg (x : gT1 * gT2) := (x.1^-1, x.2^-1).
Lemma extprod_mul1g : left_id (1, 1) extprod_mulg.
Proof. by case=> x1 x2; congr (_, _); apply: mul1g. Qed.
Lemma extprod_mulVg : left_inverse (1, 1) extprod_invg extprod_mulg.
Proof. by move=> x; congr (_, _); apply: mulVg. Qed.
Lemma extprod_mulgA : associative extprod_mulg.
Proof. by move=> x y z; congr (_, _); apply: mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build (gT1 * gT2)%type
extprod_mulgA extprod_mul1g extprod_mulVg.
Lemma group_setX (H1 : {group gT1}) (H2 : {group gT2}) : group_set (setX H1 H2).
Proof.
apply/group_setP; split; first by rewrite !inE !group1.
by case=> [x1 x2] [y1 y2] /[!inE] /andP[Hx1 Hx2] /andP[Hy1 Hy2] /[!groupM].
Qed.
Canonical setX_group H1 H2 := Group (group_setX H1 H2).
Definition pairg1 x : gT1 * gT2 := (x, 1).
Definition pair1g x : gT1 * gT2 := (1, x).
Lemma pairg1_morphM : {morph pairg1 : x y / x * y}.
Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed.
Canonical pairg1_morphism := @Morphism _ _ setT _ (in2W pairg1_morphM).
Lemma pair1g_morphM : {morph pair1g : x y / x * y}.
Proof. by move=> x y /=; rewrite {2}/mulg /= /extprod_mulg /= mul1g. Qed.
Canonical pair1g_morphism := @Morphism _ _ setT _ (in2W pair1g_morphM).
Lemma fst_morphM : {morph (@fst gT1 gT2) : x y / x * y}.
Proof. by move=> x y. Qed.
Lemma snd_morphM : {morph (@snd gT1 gT2) : x y / x * y}.
Proof. by move=> x y. Qed.
Canonical fst_morphism := @Morphism _ _ setT _ (in2W fst_morphM).
Canonical snd_morphism := @Morphism _ _ setT _ (in2W snd_morphM).
Lemma injm_pair1g : 'injm pair1g.
Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; apply: set11. Qed.
Lemma injm_pairg1 : 'injm pairg1.
Proof. by apply/subsetP=> x /morphpreP[_ /set1P[->]]; apply: set11. Qed.
Lemma morphim_pairg1 (H1 : {set gT1}) : pairg1 @* H1 = setX H1 1.
Proof. by rewrite -imset2_pair imset2_set1r morphimEsub ?subsetT. Qed.
Lemma morphim_pair1g (H2 : {set gT2}) : pair1g @* H2 = setX 1 H2.
Proof. by rewrite -imset2_pair imset2_set1l morphimEsub ?subsetT. Qed.
Lemma morphim_fstX (H1: {set gT1}) (H2 : {group gT2}) :
[morphism of fun x => x.1] @* setX H1 H2 = H1.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP=> x0 /[1!inE] /andP[Hx1 _] ->.
move=> Hx1; apply/imsetP; exists (x, 1); last by trivial.
by rewrite in_setX Hx1 /=.
Qed.
Lemma morphim_sndX (H1: {group gT1}) (H2 : {set gT2}) :
[morphism of fun x => x.2] @* setX H1 H2 = H2.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP=> x0 /[1!inE] /andP[_ Hx2] ->.
move=> Hx2; apply/imsetP; exists (1, x); last by [].
by rewrite in_setX Hx2 andbT.
Qed.
Lemma setX_prod (H1 : {set gT1}) (H2 : {set gT2}) :
setX H1 1 * setX 1 H2 = setX H1 H2.
Proof.
apply/setP=> [[x y]]; rewrite !inE /=.
apply/imset2P/andP=> [[[x1 u1] [v1 y1]] | [Hx Hy]].
rewrite !inE /= => /andP[Hx1 /eqP->] /andP[/eqP-> Hx] [-> ->].
by rewrite mulg1 mul1g.
exists (x, 1 : gT2) (1 : gT1, y); rewrite ?inE ?Hx ?eqxx //.
by rewrite /mulg /= /extprod_mulg /= mulg1 mul1g.
Qed.
Lemma setX_dprod (H1 : {group gT1}) (H2 : {group gT2}) :
setX H1 1 \x setX 1 H2 = setX H1 H2.
Proof.
rewrite dprodE ?setX_prod //.
apply/centsP=> [[x u]] /[!inE]/= /andP[/eqP-> _] [v y].
by rewrite !inE /= => /andP[_ /eqP->]; congr (_, _); rewrite ?mul1g ?mulg1.
apply/trivgP; apply/subsetP=> [[x y]]; rewrite !inE /= -!andbA.
by case/and4P=> _ /eqP-> /eqP->; rewrite eqxx.
Qed.
Lemma isog_setX1 (H1 : {group gT1}) : isog H1 (setX H1 1).
Proof.
apply/isogP; exists [morphism of restrm (subsetT H1) pairg1].
by rewrite injm_restrm ?injm_pairg1.
by rewrite morphim_restrm morphim_pairg1 setIid.
Qed.
Lemma isog_set1X (H2 : {group gT2}) : isog H2 (setX 1 H2).
Proof.
apply/isogP; exists [morphism of restrm (subsetT H2) pair1g].
by rewrite injm_restrm ?injm_pair1g.
by rewrite morphim_restrm morphim_pair1g setIid.
Qed.
Lemma setX_gen (H1 : {set gT1}) (H2 : {set gT2}) :
1 \in H1 -> 1 \in H2 -> <<setX H1 H2>> = setX <<H1>> <<H2>>.
Proof.
move=> H1_1 H2_1; apply/eqP.
rewrite eqEsubset gen_subG setXS ?subset_gen //.
(* TODO: investigate why the occurrence selection changed *)
rewrite -[in X in X \subset _]setX_prod.
rewrite -morphim_pair1g -morphim_pairg1 !morphim_gen ?subsetT //.
by rewrite morphim_pair1g morphim_pairg1 mul_subG // genS // setXS ?sub1set.
Qed.
End ExternalDirProd.
Section ExternalDirDepProd.
Variables (I : finType) (gT : I -> finGroupType).
Notation gTn := {dffun forall i, gT i}.
Implicit Types (H : forall i, {group gT i}) (x y : {dffun forall i, gT i}).
Definition extnprod_mulg (x y : gTn) : gTn := [ffun i => (x i * y i)%g].
Definition extnprod_invg (x : gTn) : gTn := [ffun i => (x i)^-1%g].
Lemma extnprod_mul1g : left_id [ffun=> 1%g] extnprod_mulg.
Proof. by move=> x; apply/ffunP => i; rewrite !ffunE mul1g. Qed.
Lemma extnprod_mulVg : left_inverse [ffun=> 1%g] extnprod_invg extnprod_mulg.
Proof. by move=> x; apply/ffunP => i; rewrite !ffunE mulVg. Qed.
Lemma extnprod_mulgA : associative extnprod_mulg.
Proof. by move=> x y z; apply/ffunP => i; rewrite !ffunE mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build {dffun forall i : I, gT i}
extnprod_mulgA extnprod_mul1g extnprod_mulVg.
Lemma oneg_ffun i : (1 : gTn) i = 1. Proof. by rewrite ffunE. Qed.
Lemma mulg_ffun i (x y : gTn) : (x * y) i = x i * y i.
Proof. by rewrite ffunE. Qed.
Lemma invg_ffun i (x : gTn) : x^-1 i = (x i)^-1.
Proof. by rewrite ffunE. Qed.
Lemma prodg_ffun T (r : seq T) (F : T -> gTn) (P : {pred T}) i :
(\prod_(t <- r | P t) F t) i = \prod_(t <- r | P t) F t i.
Proof. exact: (big_morph _ (@mulg_ffun i) (@oneg_ffun i)). Qed.
Lemma group_setXn H : group_set (setXn H).
Proof.
by apply/group_setP; split=> [|x y] /[!inE]/= => [|/forallP xH /forallP yH];
apply/forallP => i; rewrite ?ffunE (group1, groupM)// ?xH ?yH.
Qed.
Canonical setXn_group H := Group (group_setXn H).
Definition dfung1 i (g : gT i) : gTn := finfun (dfwith (fun=> 1 : gT _) g).
Lemma dfung1_id i (g : gT i) : dfung1 g i = g.
Proof. by rewrite ffunE dfwith_in. Qed.
Lemma dfung1_dflt i (g : gT i) j : i != j -> dfung1 g j = 1.
Proof. by move=> ij; rewrite ffunE dfwith_out. Qed.
Lemma dfung1_morphM i : {morph @dfung1 i : g h / g * h}.
Proof.
move=> g h; apply/ffunP=> j; have [{j}<-|nij] := eqVneq i j.
by rewrite !(dfung1_id, ffunE).
by rewrite !(dfung1_dflt, ffunE)// mulg1.
Qed.
Canonical dfung1_morphism i := @Morphism _ _ setT _ (in2W (@dfung1_morphM i)).
Lemma dffunM i : {morph (fun x => x i) : x y / x * y}.
Proof. by move=> x y; rewrite !ffunE. Qed.
Canonical dffun_morphism i := @Morphism _ _ setT _ (in2W (@dffunM i)).
Lemma injm_dfung1 i : 'injm (@dfung1 i).
Proof.
apply/subsetP => x /morphpreP[_ /set1P /ffunP/=/(_ i)].
by rewrite !(ffunE, dfung1_id) => ->; apply: set11.
Qed.
Lemma group_set_dfwith H i (G : {group gT i}) j :
group_set (dfwith (H : forall k, {set gT k}) (G : {set _}) j).
Proof.
have [<-|ij] := eqVneq i j; first by rewrite !dfwith_in// groupP.
by rewrite !dfwith_out // groupP.
Qed.
Canonical group_dfwith H i G j := Group (@group_set_dfwith H i G j).
Lemma group_dfwithE H i G j : @group_dfwith H i G j = dfwith H G j.
Proof.
by apply/val_inj; have [<-|nij]/= := eqVneq i j;
[rewrite !dfwith_in|rewrite !dfwith_out].
Qed.
Fact set1gXn_key : unit. Proof. by []. Qed.
Definition set1gXn {i} (H : {set gT i}) : {set {dffun forall i : I, gT i}} :=
locked_with set1gXn_key (setXn (dfwith (fun i0 : I => [1 gT _]%g) H)).
Lemma set1gXnE {i} (H : {set gT i}) :
set1gXn H = setXn (dfwith (fun i0 : I => [1 gT _]%g) H).
Proof. by rewrite /set1gXn unlock. Qed.
Lemma set1gXnP {i} (H : {set gT i}) x :
reflect (exists2 h, h \in H & x = dfung1 h) (x \in set1gXn H).
Proof.
rewrite set1gXnE/=; apply: (iffP setXnP) => [xP|[h hH ->] j]; last first.
by rewrite ffunE; case: dfwithP => [|k ?]; rewrite (dfwith_in, dfwith_out).
exists (x i); first by have := xP i; rewrite dfwith_in.
apply/ffunP => j; have := xP j; rewrite ffunE.
case: dfwithP => // [xiH|k neq_ik]; first by rewrite dfwith_in.
by move=> /set1gP->; rewrite dfwith_out.
Qed.
Lemma morphim_dfung1 i (G : {set gT i}) : @dfung1 i @* G = set1gXn G.
Proof.
by rewrite morphimEsub//=; apply/setP=> /= x; apply/imsetP/set1gXnP.
Qed.
Lemma morphim_dffunXn i H : dffun_morphism i @* setXn H = H i.
Proof.
apply/eqP; rewrite eqEsubset morphimE setTI /=.
apply/andP; split; apply/subsetP=> x.
by case/imsetP => x0 /[1!inE] /forallP/(_ i)/= ? ->.
move=> Hx1; apply/imsetP; exists (dfung1 x); last by rewrite dfung1_id.
by rewrite in_setXn; apply/forallP => j /[!ffunE]; case: dfwithP.
Qed.
Lemma set1gXn_group_set {i} (H : {group gT i}) : group_set (set1gXn H).
Proof. by rewrite set1gXnE; exact: group_setXn. Qed.
Canonical groupXn1 {i} (H : {group gT i}) := Group (set1gXn_group_set H).
Lemma setXn_prod H : \prod_i set1gXn (H i) = setXn H.
Proof.
apply/setP => /= x; apply/prodsgP /setXnP => [[/= f fH {x}-> i]|xH /=].
rewrite prodg_ffun group_prod// => j _.
by have /set1gXnP[x xH ->] := fH j isT; rewrite ffunE; case: dfwithP.
exists (fun i => dfung1 (x i)) => [i _|]; first by apply/set1gXnP; exists (x i).
apply/ffunP => i; rewrite prodg_ffun (big_only1 i) ?dfung1_id//.
by move=> j ij _; rewrite dfung1_dflt.
Qed.
Lemma set1gXn_commute (H : forall i, {group gT i}) i j :
commute (set1gXn (H i)) (set1gXn (H j)).
Proof.
have [-> //|neqij] := eqVneq j i.
apply/centC/centsP => _ /set1gXnP [hi hiH ->] _ /set1gXnP [hj hjH ->].
apply/ffunP => k; rewrite !ffunE.
by case: dfwithP => [|?]; rewrite ?mulg1 ?mul1g// dfwith_out// mulg1 mul1g.
Qed.
Lemma setXn_dprod H : \big[dprod/1]_i set1gXn (H i) = setXn H.
Proof.
rewrite -setXn_prod//=.
suff -> : \big[dprod/1]_i groupXn1 (H i) = (\prod_i groupXn1 (H i))%G.
by rewrite comm_prodG//=; apply: in2W; apply: set1gXn_commute.
apply/eqP; apply/bigdprodYP => i //= _; rewrite subsetD.
apply/andP; split.
rewrite comm_prodG; last by apply: in2W; apply: set1gXn_commute.
apply/centsP => _ /prodsgP[/= h_ h_P ->] _ /set1gXnP [h hH ->].
apply/ffunP => j; rewrite !ffunE/=.
rewrite (big_morph _ (@dffunM j) (_ : _ = 1)) ?ffunE//.
case: dfwithP => {j} [|? ?]; last by rewrite mulg1 mul1g.
rewrite big1 ?mulg1 ?mul1g// => j neq_ji.
by have /set1gXnP[? _ ->] := h_P j neq_ji; rewrite ffunE dfwith_out.
rewrite -setI_eq0 -subset0; apply/subsetP => /= x; rewrite !inE.
rewrite comm_prodG; last by apply: in2W; apply: set1gXn_commute.
move=> /and3P[+ + /set1gXnP [h _ x_h]]; rewrite {x}x_h.
move=> /prodsgP[x_ x_P /ffunP/(_ i)]; rewrite ffunE dfwith_in => {h}->.
apply: contra_neqT => _; apply/ffunP => j; rewrite !ffunE/=.
case: dfwithP => // {j}; rewrite (big_morph _ (@dffunM i) (_ : _ = 1)) ?ffunE//.
rewrite big1// => j neq_ji.
by have /set1gXnP[g gH /ffunP->] := x_P _ neq_ji; rewrite ffunE dfwith_out.
Qed.
Lemma isog_setXn i (G : {group gT i}) : G \isog set1gXn G.
Proof.
apply/(@isogP _ _ G); exists [morphism of restrm (subsetT G) (@dfung1 i)].
by rewrite injm_restrm ?injm_dfung1.
by rewrite morphim_restrm morphim_dfung1 setIid.
Qed.
Lemma setXn_gen H : (forall i, 1 \in H i) ->
<<setXn H>> = setXn (fun i => <<H i>>).
Proof.
move=> H1; apply/eqP; rewrite eqEsubset gen_subG setXnS/=; last first.
by move=> ?; rewrite subset_gen.
rewrite -[in X in X \subset _]setXn_prod; under eq_bigr do
rewrite -morphim_dfung1 morphim_gen ?subsetT// morphim_dfung1.
rewrite prod_subG// => i; rewrite genS // set1gXnE setXnS // => j.
by case: dfwithP => // k _; rewrite sub1set.
Qed.
End ExternalDirDepProd.
Lemma groupX0 (gT : 'I_0 -> finGroupType) (G : forall i, {group gT i}) :
setXn G = 1%g.
Proof.
by apply/setP => ?; apply/setXnP/set1P => [_|_ []//]; apply/ffunP => -[].
Qed.
Section ExternalSDirProd.
Variables (aT rT : finGroupType) (D : {group aT}) (R : {group rT}).
(* The pair (a, x) denotes the product sdpair2 a * sdpair1 x *)
Inductive sdprod_by (to : groupAction D R) : predArgType :=
SdPair (ax : aT * rT) of ax \in setX D R.
Coercion pair_of_sd to (u : sdprod_by to) := let: SdPair ax _ := u in ax.
Variable to : groupAction D R.
Notation sdT := (sdprod_by to).
Notation sdval := (@pair_of_sd to).
HB.instance Definition _ := [isSub for sdval].
#[hnf] HB.instance Definition _ := [Finite of sdT by <:].
Definition sdprod_one := SdPair to (group1 _).
Lemma sdprod_inv_proof (u : sdT) : (u.1^-1, to u.2^-1 u.1^-1) \in setX D R.
Proof.
by case: u => [[a x]] /= /setXP[Da Rx]; rewrite inE gact_stable !groupV ?Da.
Qed.
Definition sdprod_inv u := SdPair to (sdprod_inv_proof u).
Lemma sdprod_mul_proof (u v : sdT) :
(u.1 * v.1, to u.2 v.1 * v.2) \in setX D R.
Proof.
case: u v => [[a x] /= /setXP[Da Rx]] [[b y] /= /setXP[Db Ry]].
by rewrite inE !groupM //= gact_stable.
Qed.
Definition sdprod_mul u v := SdPair to (sdprod_mul_proof u v).
Lemma sdprod_mul1g : left_id sdprod_one sdprod_mul.
Proof.
move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _.
by rewrite gact1 // !mul1g.
Qed.
Lemma sdprod_mulVg : left_inverse sdprod_one sdprod_inv sdprod_mul.
Proof.
move=> u; apply: val_inj; case: u => [[a x] /=]; case/setXP=> Da _.
by rewrite actKVin ?mulVg.
Qed.
Lemma sdprod_mulgA : associative sdprod_mul.
Proof.
move=> u v w; apply: val_inj; case: u => [[a x]] /=; case/setXP=> Da Rx.
case: v w => [[b y]] /=; case/setXP=> Db Ry [[c z]] /=; case/setXP=> Dc Rz.
by rewrite !(actMin to) // gactM ?gact_stable // !mulgA.
Qed.
HB.instance Definition _ := isMulGroup.Build sdT
sdprod_mulgA sdprod_mul1g sdprod_mulVg.
Definition sdprod_groupType : finGroupType := sdT.
Definition sdpair1 x := insubd sdprod_one (1, x) : sdT.
Definition sdpair2 a := insubd sdprod_one (a, 1) : sdT.
Lemma sdpair1_morphM : {in R &, {morph sdpair1 : x y / x * y}}.
Proof.
move=> x y Rx Ry; apply: val_inj.
by rewrite /= !val_insubd !inE !group1 !groupM ?Rx ?Ry //= mulg1 act1.
Qed.
Lemma sdpair2_morphM : {in D &, {morph sdpair2 : a b / a * b}}.
Proof.
move=> a b Da Db; apply: val_inj.
by rewrite /= !val_insubd !inE !group1 !groupM ?Da ?Db //= mulg1 gact1.
Qed.
Canonical sdpair1_morphism := Morphism sdpair1_morphM.
Canonical sdpair2_morphism := Morphism sdpair2_morphM.
Lemma injm_sdpair1 : 'injm sdpair1.
Proof.
apply/subsetP=> x /setIP[Rx].
by rewrite !inE -val_eqE val_insubd inE Rx group1 /=; case/andP.
Qed.
Lemma injm_sdpair2 : 'injm sdpair2.
Proof.
apply/subsetP=> a /setIP[Da].
by rewrite !inE -val_eqE val_insubd inE Da group1 /=; case/andP.
Qed.
Lemma sdpairE (u : sdT) : u = sdpair2 u.1 * sdpair1 u.2.
Proof.
apply: val_inj; case: u => [[a x] /= /setXP[Da Rx]].
by rewrite !val_insubd !inE Da Rx !(group1, gact1) // mulg1 mul1g.
Qed.
Lemma sdpair_act : {in R & D,
forall x a, sdpair1 (to x a) = sdpair1 x ^ sdpair2 a}.
Proof.
move=> x a Rx Da; apply: val_inj.
rewrite /= !val_insubd !inE !group1 gact_stable ?Da ?Rx //=.
by rewrite !mul1g mulVg invg1 mulg1 actKVin ?mul1g.
Qed.
Lemma sdpair_setact (G : {set rT}) a : G \subset R -> a \in D ->
sdpair1 @* (to^~ a @: G) = (sdpair1 @* G) :^ sdpair2 a.
Proof.
move=> sGR Da; have GtoR := subsetP sGR; apply/eqP.
rewrite eqEcard cardJg !(card_injm injm_sdpair1) //; last first.
by apply/subsetP=> _ /imsetP[x Gx ->]; rewrite gact_stable ?GtoR.
rewrite (card_imset _ (act_inj _ _)) leqnn andbT.
apply/subsetP=> _ /morphimP[xa Rxa /imsetP[x Gx def_xa ->]].
rewrite mem_conjg -morphV // -sdpair_act ?groupV // def_xa actKin //.
by rewrite mem_morphim ?GtoR.
Qed.
Lemma im_sdpair_norm : sdpair2 @* D \subset 'N(sdpair1 @* R).
Proof.
apply/subsetP=> _ /morphimP[a _ Da ->].
rewrite inE -sdpair_setact // morphimS //.
by apply/subsetP=> _ /imsetP[x Rx ->]; rewrite gact_stable.
Qed.
Lemma im_sdpair_TI : (sdpair1 @* R) :&: (sdpair2 @* D) = 1.
Proof.
apply/trivgP; apply/subsetP=> _ /setIP[/morphimP[x _ Rx ->]].
case/morphimP=> a _ Da /eqP; rewrite inE -!val_eqE.
by rewrite !val_insubd !inE Da Rx !group1 /eq_op /= eqxx; case/andP.
Qed.
Lemma im_sdpair : (sdpair1 @* R) * (sdpair2 @* D) = setT.
Proof.
apply/eqP; rewrite -subTset -(normC im_sdpair_norm).
apply/subsetP=> /= u _; rewrite [u]sdpairE.
by case: u => [[a x] /= /setXP[Da Rx]]; rewrite mem_mulg ?mem_morphim.
Qed.
Lemma sdprod_sdpair : sdpair1 @* R ><| sdpair2 @* D = setT.
Proof. by rewrite sdprodE ?(im_sdpair_norm, im_sdpair, im_sdpair_TI). Qed.
Variables (A : {set aT}) (G : {set rT}).
Lemma gacentEsd : 'C_(|to)(A) = sdpair1 @*^-1 'C(sdpair2 @* A).
Proof.
apply/setP=> x; apply/idP/idP.
case/setIP=> Rx /afixP cDAx; rewrite mem_morphpre //.
apply/centP=> _ /morphimP[a Da Aa ->]; red.
by rewrite conjgC -sdpair_act // cDAx // inE Da.
case/morphpreP=> Rx cAx; rewrite inE Rx; apply/afixP=> a /setIP[Da Aa].
apply: (injmP injm_sdpair1); rewrite ?gact_stable /= ?sdpair_act //=.
by rewrite /conjg (centP cAx) ?mulKg ?mem_morphim.
Qed.
Hypotheses (sAD : A \subset D) (sGR : G \subset R).
Lemma astabEsd : 'C(G | to) = sdpair2 @*^-1 'C(sdpair1 @* G).
Proof.
have ssGR := subsetP sGR; apply/setP=> a; apply/idP/idP=> [cGa|].
rewrite mem_morphpre ?(astab_dom cGa) //.
apply/centP=> _ /morphimP[x Rx Gx ->]; symmetry.
by rewrite conjgC -sdpair_act ?(astab_act cGa) ?(astab_dom cGa).
case/morphpreP=> Da cGa; rewrite !inE Da; apply/subsetP=> x Gx; rewrite inE.
apply/eqP; apply: (injmP injm_sdpair1); rewrite ?gact_stable ?ssGR //=.
by rewrite sdpair_act ?ssGR // /conjg -(centP cGa) ?mulKg ?mem_morphim ?ssGR.
Qed.
Lemma astabsEsd : 'N(G | to) = sdpair2 @*^-1 'N(sdpair1 @* G).
Proof.
apply/setP=> a; apply/idP/idP=> [nGa|].
have Da := astabs_dom nGa; rewrite mem_morphpre // inE sub_conjg.
apply/subsetP=> _ /morphimP[x Rx Gx ->].
by rewrite mem_conjgV -sdpair_act // mem_morphim ?gact_stable ?astabs_act.
case/morphpreP=> Da nGa; rewrite !inE Da; apply/subsetP=> x Gx.
have Rx := subsetP sGR _ Gx; have Rxa: to x a \in R by rewrite gact_stable.
rewrite inE -sub1set -(injmSK injm_sdpair1) ?morphim_set1 ?sub1set //=.
by rewrite sdpair_act ?memJ_norm ?mem_morphim.
Qed.
Lemma actsEsd : [acts A, on G | to] = (sdpair2 @* A \subset 'N(sdpair1 @* G)).
Proof. by rewrite sub_morphim_pre -?astabsEsd. Qed.
End ExternalSDirProd.
Section ProdMorph.
Variables gT rT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H K : {group gT}.
Implicit Types C D : {set rT}.
Implicit Type L : {group rT}.
Section defs.
Variables (A B : {set gT}) (fA fB : gT -> FinGroup.sort rT).
Definition pprodm of B \subset 'N(A) & {in A & B, morph_act 'J 'J fA fB}
& {in A :&: B, fA =1 fB} :=
fun x => fA (divgr A B x) * fB (remgr A B x).
End defs.
Section Props.
Variables H K : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis nHK : K \subset 'N(H).
Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}.
Hypothesis eqfHK : {in H :&: K, fH =1 fK}.
Local Notation f := (pprodm nHK actf eqfHK).
Lemma pprodmE x a : x \in H -> a \in K -> f (x * a) = fH x * fK a.
Proof.
move=> Hx Ka; have: x * a \in H * K by rewrite mem_mulg.
rewrite -remgrP inE /f rcoset_sym mem_rcoset /divgr -mulgA groupMl //.
case/andP; move: (remgr H K _) => b Hab Kb; rewrite morphM // -mulgA.
have Kab: a * b^-1 \in K by rewrite groupM ?groupV.
by congr (_ * _); rewrite eqfHK 1?inE ?Hab // -morphM // mulgKV.
Qed.
Lemma pprodmEl : {in H, f =1 fH}.
Proof. by move=> x Hx; rewrite -(mulg1 x) pprodmE // morph1 !mulg1. Qed.
Lemma pprodmEr : {in K, f =1 fK}.
Proof. by move=> a Ka; rewrite -(mul1g a) pprodmE // morph1 !mul1g. Qed.
Lemma pprodmM : {in H <*> K &, {morph f: x y / x * y}}.
Proof.
move=> xa yb; rewrite norm_joinEr //.
move=> /imset2P[x a Ha Ka ->{xa}] /imset2P[y b Hy Kb ->{yb}].
have Hya: y ^ a^-1 \in H by rewrite -mem_conjg (normsP nHK).
rewrite mulgA -(mulgA x) (conjgCV a y) (mulgA x) -mulgA !pprodmE 1?groupMl //.
by rewrite morphM // actf ?groupV ?morphV // morphM // !mulgA mulgKV invgK.
Qed.
Canonical pprodm_morphism := Morphism pprodmM.
Lemma morphim_pprodm A B :
A \subset H -> B \subset K -> f @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite [f @* _]morphimEsub /=; last first.
by rewrite norm_joinEr // mulgSS.
apply/setP=> y; apply/imsetP/idP=> [[_ /mulsgP[x a Ax Ba ->] ->{y}] |].
have Hx := subsetP sAH x Ax; have Ka := subsetP sBK a Ba.
by rewrite pprodmE // imset2_f ?mem_morphim.
case/mulsgP=> _ _ /morphimP[x Hx Ax ->] /morphimP[a Ka Ba ->] ->{y}.
by exists (x * a); rewrite ?mem_mulg ?pprodmE.
Qed.
Lemma morphim_pprodml A : A \subset H -> f @* A = fH @* A.
Proof.
by move=> sAH; rewrite -{1}(mulg1 A) morphim_pprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_pprodmr B : B \subset K -> f @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_pprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_pprodm : 'ker f = [set x * a^-1 | x in H, a in K & fH x == fK a].
Proof.
apply/setP=> y; rewrite 3!inE {1}norm_joinEr //=.
apply/andP/imset2P=> [[/mulsgP[x a Hx Ka ->{y}]]|[x a Hx]].
rewrite pprodmE // => fxa1.
by exists x a^-1; rewrite ?invgK // inE groupVr ?morphV // eq_mulgV1 invgK.
case/setIdP=> Kx /eqP fx ->{y}.
by rewrite imset2_f ?pprodmE ?groupV ?morphV // fx mulgV.
Qed.
Lemma injm_pprodm :
'injm f = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K].
Proof.
apply/idP/and3P=> [injf | [injfH injfK]].
rewrite eq_sym -{1}morphimIdom -(morphim_pprodml (subsetIl _ _)) injmI //.
rewrite morphim_pprodml // morphim_pprodmr //=; split=> //.
apply/injmP=> x y Hx Hy /=; rewrite -!pprodmEl //.
by apply: (injmP injf); rewrite ?mem_gen ?inE ?Hx ?Hy.
apply/injmP=> a b Ka Kb /=; rewrite -!pprodmEr //.
by apply: (injmP injf); rewrite ?mem_gen //; apply/setUP; right.
move/eqP=> fHK; rewrite ker_pprodm; apply/subsetP=> y.
case/imset2P=> x a Hx /setIdP[Ka /eqP fxa] ->.
have: fH x \in fH @* K by rewrite -fHK inE {2}fxa !mem_morphim.
case/morphimP=> z Hz Kz /(injmP injfH) def_x.
rewrite def_x // eqfHK ?inE ?Hz // in fxa.
by rewrite def_x // (injmP injfK _ _ Kz Ka fxa) mulgV set11.
Qed.
End Props.
Section Sdprodm.
Variables H K G : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H ><| K = G.
Hypothesis actf : {in H & K, morph_act 'J 'J fH fK}.
Lemma sdprodm_norm : K \subset 'N(H).
Proof. by case/sdprodP: eqHK_G. Qed.
Lemma sdprodm_sub : G \subset H <*> K.
Proof. by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr. Qed.
Lemma sdprodm_eqf : {in H :&: K, fH =1 fK}.
Proof.
by case/sdprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1.
Qed.
Definition sdprodm :=
restrm sdprodm_sub (pprodm sdprodm_norm actf sdprodm_eqf).
Canonical sdprodm_morphism := Eval hnf in [morphism of sdprodm].
Lemma sdprodmE a b : a \in H -> b \in K -> sdprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma sdprodmEl a : a \in H -> sdprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma sdprodmEr b : b \in K -> sdprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_sdprodm A B :
A \subset H -> B \subset K -> sdprodm @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite /sdprodm morphim_restrm /= (setIidPr _) ?morphim_pprodm //.
by case/sdprodP: eqHK_G => _ <- _ _; apply: mulgSS.
Qed.
Lemma im_sdprodm : sdprodm @* G = fH @* H * fK @* K.
Proof. by rewrite -morphim_sdprodm //; case/sdprodP: eqHK_G => _ ->. Qed.
Lemma morphim_sdprodml A : A \subset H -> sdprodm @* A = fH @* A.
Proof.
by move=> sHA; rewrite -{1}(mulg1 A) morphim_sdprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_sdprodmr B : B \subset K -> sdprodm @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_sdprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_sdprodm :
'ker sdprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof.
rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left.
by case/sdprodP: eqHK_G => _ <- nHK _; rewrite norm_joinEr.
Qed.
Lemma injm_sdprodm :
'injm sdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite ker_sdprodm -(ker_pprodm sdprodm_norm actf sdprodm_eqf) injm_pprodm.
congr [&& _, _ & _ == _]; have [_ _ _ tiHK] := sdprodP eqHK_G.
by rewrite -morphimIdom tiHK morphim1.
Qed.
End Sdprodm.
Section Cprodm.
Variables H K G : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H \* K = G.
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Hypothesis eqfHK : {in H :&: K, fH =1 fK}.
Lemma cprodm_norm : K \subset 'N(H).
Proof. by rewrite cents_norm //; case/cprodP: eqHK_G. Qed.
Lemma cprodm_sub : G \subset H <*> K.
Proof. by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr. Qed.
Lemma cprodm_actf : {in H & K, morph_act 'J 'J fH fK}.
Proof.
case/cprodP: eqHK_G => _ _ cHK a b Ha Kb /=.
by rewrite /conjg -(centsP cHK b) // -(centsP cfHK (fK b)) ?mulKg ?mem_morphim.
Qed.
Definition cprodm := restrm cprodm_sub (pprodm cprodm_norm cprodm_actf eqfHK).
Canonical cprodm_morphism := Eval hnf in [morphism of cprodm].
Lemma cprodmE a b : a \in H -> b \in K -> cprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma cprodmEl a : a \in H -> cprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma cprodmEr b : b \in K -> cprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_cprodm A B :
A \subset H -> B \subset K -> cprodm @* (A * B) = fH @* A * fK @* B.
Proof.
move=> sAH sBK; rewrite [LHS]morphim_restrm /= (setIidPr _) ?morphim_pprodm //.
by case/cprodP: eqHK_G => _ <- _; apply: mulgSS.
Qed.
Lemma im_cprodm : cprodm @* G = fH @* H * fK @* K.
Proof.
by have [_ defHK _] := cprodP eqHK_G; rewrite -{2}defHK morphim_cprodm.
Qed.
Lemma morphim_cprodml A : A \subset H -> cprodm @* A = fH @* A.
Proof.
by move=> sHA; rewrite -{1}(mulg1 A) morphim_cprodm ?sub1G // morphim1 mulg1.
Qed.
Lemma morphim_cprodmr B : B \subset K -> cprodm @* B = fK @* B.
Proof.
by move=> sBK; rewrite -{1}(mul1g B) morphim_cprodm ?sub1G // morphim1 mul1g.
Qed.
Lemma ker_cprodm : 'ker cprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof.
rewrite ker_restrm (setIidPr _) ?subIset ?ker_pprodm //; apply/orP; left.
by case/cprodP: eqHK_G => _ <- cHK; rewrite cent_joinEr.
Qed.
Lemma injm_cprodm :
'injm cprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == fH @* K].
Proof.
by rewrite ker_cprodm -(ker_pprodm cprodm_norm cprodm_actf eqfHK) injm_pprodm.
Qed.
End Cprodm.
Section Dprodm.
Variables G H K : {group gT}.
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis eqHK_G : H \x K = G.
Hypothesis cfHK : fK @* K \subset 'C(fH @* H).
Lemma dprodm_cprod : H \* K = G.
Proof.
by rewrite -eqHK_G /dprod; case/dprodP: eqHK_G => _ _ _ ->; rewrite subxx.
Qed.
Lemma dprodm_eqf : {in H :&: K, fH =1 fK}.
Proof. by case/dprodP: eqHK_G => _ _ _ -> _ /set1P->; rewrite !morph1. Qed.
Definition dprodm := cprodm dprodm_cprod cfHK dprodm_eqf.
Canonical dprodm_morphism := Eval hnf in [morphism of dprodm].
Lemma dprodmE a b : a \in H -> b \in K -> dprodm (a * b) = fH a * fK b.
Proof. exact: pprodmE. Qed.
Lemma dprodmEl a : a \in H -> dprodm a = fH a.
Proof. exact: pprodmEl. Qed.
Lemma dprodmEr b : b \in K -> dprodm b = fK b.
Proof. exact: pprodmEr. Qed.
Lemma morphim_dprodm A B :
A \subset H -> B \subset K -> dprodm @* (A * B) = fH @* A * fK @* B.
Proof. exact: morphim_cprodm. Qed.
Lemma im_dprodm : dprodm @* G = fH @* H * fK @* K.
Proof. exact: im_cprodm. Qed.
Lemma morphim_dprodml A : A \subset H -> dprodm @* A = fH @* A.
Proof. exact: morphim_cprodml. Qed.
Lemma morphim_dprodmr B : B \subset K -> dprodm @* B = fK @* B.
Proof. exact: morphim_cprodmr. Qed.
Lemma ker_dprodm : 'ker dprodm = [set a * b^-1 | a in H, b in K & fH a == fK b].
Proof. exact: ker_cprodm. Qed.
Lemma injm_dprodm :
'injm dprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite injm_cprodm -(morphimIdom fH K).
by case/dprodP: eqHK_G => _ _ _ ->; rewrite morphim1.
Qed.
End Dprodm.
Lemma isog_dprod A B G C D L :
A \x B = G -> C \x D = L -> isog A C -> isog B D -> isog G L.
Proof.
move=> defG {C D} /dprodP[[C D -> ->] defL cCD trCD].
case/dprodP: defG (defG) => {A B} [[A B -> ->] defG _ _] dG defC defD.
case/isogP: defC defL cCD trCD => fA injfA <-{C}.
case/isogP: defD => fB injfB <-{D} defL cCD trCD.
apply/isogP; exists (dprodm_morphism dG cCD).
by rewrite injm_dprodm injfA injfB trCD eqxx.
by rewrite /= -{2}defG morphim_dprodm.
Qed.
End ProdMorph.
Section ExtSdprodm.
Variables gT aT rT : finGroupType.
Variables (H : {group gT}) (K : {group aT}) (to : groupAction K H).
Variables (fH : {morphism H >-> rT}) (fK : {morphism K >-> rT}).
Hypothesis actf : {in H & K, morph_act to 'J fH fK}.
Local Notation fsH := (fH \o invm (injm_sdpair1 to)).
Local Notation fsK := (fK \o invm (injm_sdpair2 to)).
Let DgH := sdpair1 to @* H.
Let DgK := sdpair2 to @* K.
Lemma xsdprodm_dom1 : DgH \subset 'dom fsH.
Proof. by rewrite ['dom _]morphpre_invm. Qed.
Local Notation gH := (restrm xsdprodm_dom1 fsH).
Lemma xsdprodm_dom2 : DgK \subset 'dom fsK.
Proof. by rewrite ['dom _]morphpre_invm. Qed.
Local Notation gK := (restrm xsdprodm_dom2 fsK).
Lemma im_sdprodm1 : gH @* DgH = fH @* H.
Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed.
Lemma im_sdprodm2 : gK @* DgK = fK @* K.
Proof. by rewrite morphim_restrm setIid morphim_comp im_invm. Qed.
Lemma xsdprodm_act : {in DgH & DgK, morph_act 'J 'J gH gK}.
Proof.
move=> fh fk; case/morphimP=> h _ Hh ->{fh}; case/morphimP=> k _ Kk ->{fk}.
by rewrite /= -sdpair_act // /restrm /= !invmE ?actf ?gact_stable.
Qed.
Definition xsdprodm := sdprodm (sdprod_sdpair to) xsdprodm_act.
Canonical xsdprod_morphism := [morphism of xsdprodm].
Lemma im_xsdprodm : xsdprodm @* setT = fH @* H * fK @* K.
Proof. by rewrite -im_sdpair morphim_sdprodm // im_sdprodm1 im_sdprodm2. Qed.
Lemma injm_xsdprodm :
'injm xsdprodm = [&& 'injm fH, 'injm fK & fH @* H :&: fK @* K == 1].
Proof.
rewrite injm_sdprodm im_sdprodm1 im_sdprodm2 !subG1 /=.
rewrite (ker_restrm xsdprodm_dom1) (ker_restrm xsdprodm_dom2) /= !ker_comp.
rewrite !morphpre_invm !morphimIim.
by rewrite !morphim_injm_eq1 ?subsetIl ?injm_sdpair1 ?injm_sdpair2.
Qed.
End ExtSdprodm.
Section DirprodIsom.
Variable gT : finGroupType.
Implicit Types G H : {group gT}.
Definition mulgm : gT * gT -> _ := uncurry mulg.
Lemma imset_mulgm (A B : {set gT}) : mulgm @: setX A B = A * B.
Proof. by rewrite -curry_imset2X. Qed.
Lemma mulgmP H1 H2 G : reflect (H1 \x H2 = G) (misom (setX H1 H2) G mulgm).
Proof.
apply: (iffP misomP) => [[pM /isomP[injf /= <-]] | ].
have /dprodP[_ /= defX cH12] := setX_dprod H1 H2.
rewrite -{4}defX {}defX => /(congr1 (fun A => morphm pM @* A)).
move/(morphimS (morphm_morphism pM)): cH12 => /=.
have sH1H: setX H1 1 \subset setX H1 H2 by rewrite setXS ?sub1G.
have sH2H: setX 1 H2 \subset setX H1 H2 by rewrite setXS ?sub1G.
rewrite morphim1 injm_cent ?injmI //= subsetI => /andP[_].
by rewrite !morphimEsub //= !imset_mulgm mulg1 mul1g; apply: dprodE.
case/dprodP=> _ defG cH12 trH12.
have fM: morphic (setX H1 H2) mulgm.
apply/morphicP=> [[x1 x2] [y1 y2] /setXP[_ Hx2] /setXP[Hy1 _]].
by rewrite /= mulgA -(mulgA x1) -(centsP cH12 x2) ?mulgA.
exists fM; apply/isomP; split; last by rewrite morphimEsub //= imset_mulgm.
apply/subsetP=> [[x1 x2]]; rewrite !inE /= andbC -eq_invg_mul.
case: eqP => //= <-; rewrite groupV -in_setI trH12 => /set1P->.
by rewrite invg1 eqxx.
Qed.
End DirprodIsom.
Arguments mulgmP {gT H1 H2 G}.
Prenex Implicits mulgm.
|
Continuity.lean
|
/-
Copyright (c) 2025 Jireh Loreaux. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jireh Loreaux
-/
import Mathlib.Analysis.CStarAlgebra.ContinuousFunctionalCalculus.Isometric
import Mathlib.Topology.MetricSpace.UniformConvergence
import Mathlib.Topology.UniformSpace.CompactConvergence
/-! # Continuity of the continuous functional calculus in each variable
The continuous functional calculus is a map which takes a pair `a : A` (`A` is a Cβ-algebra) and
a function `f : C(spectrum R a, R)` where `a` satisfies some predicate `p`, depending on `R` and
returns another element of the algebra `A`. This is the map `cfcHom`. The class
`ContinuousFunctionalCalculus` declares that `cfcHom` is a continuous map from `C(spectrum R a, R)`
to `A`. However, users generally interact with the continuous functional calculus through `cfc`,
which operates on bare functions `f : R β R` instead and takes a junk value when `f` is not
continuous on the spectrum of `a`. In this file we provide some lemma concerning the continuity
of `cfc`, subject to natural hypotheses.
However, the continuous functional calculus is *also* continuous in the variable `a`, but there
are some conditions that must be satisfied. In particular, given a function `f : R β R` the map
`a β¦ cfc f a` is continuous so long as `a` varies over a collection of elements satisfying the
predicate `p` and their spectra are collectively contained in a compact set on which `f` is
continuous. Moreover, it is required that the continuous functional calculus be the isometric
variant.
Under the assumption of `IsometricContinuousFunctionalCalculus`, we show that the continuous
functional calculus is Lipschitz with constant 1 in the variable `f : R βα΅€[{spectrum R a}] R`
on the set of functions which are continuous on the spectrum of `a`. Combining this with the
continuity of the continuous functional calculus in the variable `a`, we obtain a joint continuity
result for `cfc` in both variables.
Finally, all of this is developed for both the unital and non-unital functional calculi.
The continuity results in the function variable are valid for all scalar rings, but the continuity
results in the variable `a` come in two flavors: those for `RCLike π` and those for `ββ₯0`.
## Main results
+ `tendsto_cfc_fun`: If `F : X β R β R` tends to `f : R β R` uniformly on the spectrum of `a`, and
all these functions are continuous on the spectrum, then `fun x β¦ cfc (F x) a` tends
to `cfc f a`.
+ `Filter.Tendsto.cfc`: If `f : π β π` is continuous on a compact set `s` and `a : X β A` tends to
`aβ : A` along a filter `l` (such that eventually `a x` satisfies the predicate `p` associated to
`π` and has spectrum contained in `s`, as does `aβ`), then `fun x β¦ cfc f (a x)` tends to
`cfc f aβ`.
+ `lipschitzOnWith_cfc_fun`: The function `f β¦ cfc f a` is Lipschitz with constant with constant 1
with respect to supremum metric (on `R βα΅€[{spectrum R a}] R`) on those functions which are
continuous on the spectrum.
+ `continuousOn_cfc`: For `f : π β π` continuous on a compact set `s`, `cfc f` is continuous on the
set of `a : A` satisfying the predicate `p` (associated to `π`) and whose `π`-spectrum is
contained in `s`.
+ `continuousOn_cfc_setProd`: Let `s : Set π` be a compact set and consider pairs
`(f, a) : (π β π) Γ A` where `f` is continuous on `s` and `spectrum π a β s` and `a` satisfies
the predicate `p a` for the continuous functional calculus. Then `cfc` is jointly continuous in
both variables (i.e., continuous in its uncurried form) on this set of pairs when the function
space is equipped with the topology of uniform convergence on `s`.
+ Versions of all of the above for non-unital algebras, and versions over `ββ₯0` as well.
-/
open scoped UniformConvergence NNReal
open Filter Topology
section Unital
section Left
section Generic
variable {X R A : Type*} {p : A β Prop} [CommSemiring R] [StarRing R] [MetricSpace R]
[IsTopologicalSemiring R] [ContinuousStar R] [Ring A] [StarRing A]
[TopologicalSpace A] [Algebra R A] [ContinuousFunctionalCalculus R A p]
/-- If `F : X β R β R` tends to `f : R β R` uniformly on the spectrum of `a`, and all
these functions are continuous on the spectrum, then `fun x β¦ cfc (F x) a` tends
to `cfc f a`. -/
theorem tendsto_cfc_fun {l : Filter X} {F : X β R β R} {f : R β R} {a : A}
(h_tendsto : TendstoUniformlyOn F f l (spectrum R a))
(hF : βαΆ x in l, ContinuousOn (F x) (spectrum R a)) :
Tendsto (fun x β¦ cfc (F x) a) l (π (cfc f a)) := by
open scoped ContinuousFunctionalCalculus in
obtain (rfl | hl) := l.eq_or_neBot
Β· simp
have hf := h_tendsto.continuousOn hF
by_cases ha : p a
Β· let s : Set X := {x | ContinuousOn (F x) (spectrum R a)}
rw [β tendsto_comap'_iff (i := ((β) : s β X)) (by simpa)]
conv =>
enter [1, x]
rw [Function.comp_apply, cfc_apply (hf := x.2)]
rw [cfc_apply ..]
apply cfcHom_continuous _ |>.tendsto _ |>.comp
rw [hf.tendsto_restrict_iff_tendstoUniformlyOn Subtype.property]
intro t
simp only [eventually_comap, Subtype.forall]
peel h_tendsto t with ht x _
aesop
Β· simpa [cfc_apply_of_not_predicate a ha] using tendsto_const_nhds
/-- If `f : X β R β R` tends to `f xβ` uniformly (along `π xβ`) on the spectrum of `a`,
and each `f x` is continuous on the spectrum of `a`, then `fun x β¦ cfc (f x) a` is
continuous at `xβ`. -/
theorem continuousAt_cfc_fun [TopologicalSpace X] {f : X β R β R} {a : A}
{xβ : X} (h_tendsto : TendstoUniformlyOn f (f xβ) (π xβ) (spectrum R a))
(hf : βαΆ x in π xβ, ContinuousOn (f x) (spectrum R a)) :
ContinuousAt (fun x β¦ cfc (f x) a) xβ :=
tendsto_cfc_fun h_tendsto hf
/-- If `f : X β R β R` tends to `f xβ` uniformly (along `π[s] xβ`) on the spectrum of `a`,
and eventually each `f x` is continuous on the spectrum of `a`, then `fun x β¦ cfc (f x) a` is
continuous at `xβ` within `s`. -/
theorem continuousWithinAt_cfc_fun [TopologicalSpace X] {f : X β R β R} {a : A}
{xβ : X} {s : Set X} (h_tendsto : TendstoUniformlyOn f (f xβ) (π[s] xβ) (spectrum R a))
(hf : βαΆ x in π[s] xβ, ContinuousOn (f x) (spectrum R a)) :
ContinuousWithinAt (fun x β¦ cfc (f x) a) s xβ :=
tendsto_cfc_fun h_tendsto hf
open UniformOnFun in
/-- If `f : X β R β R` is continuous on `s : Set X` in the topology on
`X β R βα΅€[{spectrum R a}] β R`, and each `f` is continuous on the spectrum, then `x β¦ cfc (f x) a`
is continuous on `s` also. -/
theorem ContinuousOn.cfc_fun [TopologicalSpace X] {f : X β R β R} {a : A} {s : Set X}
(h_cont : ContinuousOn (fun x β¦ ofFun {spectrum R a} (f x)) s)
(hf : β x β s, ContinuousOn (f x) (spectrum R a) := by cfc_cont_tac) :
ContinuousOn (fun x β¦ cfc (f x) a) s := by
rw [ContinuousOn] at h_cont β’
simp only [ContinuousWithinAt, UniformOnFun.tendsto_iff_tendstoUniformlyOn, Set.mem_singleton_iff,
Function.comp_def, toFun_ofFun, forall_eq] at h_cont
refine fun x hx β¦ continuousWithinAt_cfc_fun (h_cont x hx) ?_
filter_upwards [self_mem_nhdsWithin] with x hx
exact hf x hx
open UniformOnFun in
/-- If `f : X β R β R` is continuous in the topology on `X β R βα΅€[{spectrum R a}] β R`,
and each `f` is continuous on the spectrum, then `x β¦ cfc (f x) a` is continuous. -/
theorem Continuous.cfc_fun [TopologicalSpace X] (f : X β R β R) (a : A)
(h_cont : Continuous (fun x β¦ ofFun {spectrum R a} (f x)))
(hf : β x, ContinuousOn (f x) (spectrum R a) := by cfc_cont_tac) :
Continuous fun x β¦ cfc (f x) a := by
rw [β continuousOn_univ] at h_cont β’
exact h_cont.cfc_fun (fun x _ β¦ hf x)
end Generic
section Isometric
variable {X R A : Type*} {p : A β Prop} [CommSemiring R] [StarRing R] [MetricSpace R]
[IsTopologicalSemiring R] [ContinuousStar R] [Ring A] [StarRing A]
[MetricSpace A] [Algebra R A] [IsometricContinuousFunctionalCalculus R A p]
variable (R) in
open UniformOnFun in
open scoped ContinuousFunctionalCalculus in
/-- The function `f β¦ cfc f a` is Lipschitz with constant 1 with respect to
supremum metric (on `R βα΅€[{spectrum R a}] R`) on those functions which are continuous on
the spectrum. -/
lemma lipschitzOnWith_cfc_fun (a : A) :
LipschitzOnWith 1 (fun f β¦ cfc (toFun {spectrum R a} f) a)
{f | ContinuousOn (toFun {spectrum R a} f) (spectrum R a)} := by
by_cases ha : p a
Β· intro f hf g hg
simp only
rw [cfc_apply .., cfc_apply .., isometry_cfcHom (R := R) a ha |>.edist_eq]
simp only [ENNReal.coe_one, one_mul]
rw [edist_continuousRestrict_of_singleton hf hg]
Β· simpa [cfc_apply_of_not_predicate a ha] using LipschitzWith.const' 0 |>.lipschitzOnWith
open UniformOnFun in
open scoped ContinuousFunctionalCalculus in
/-- The function `f β¦ cfc f a` is Lipschitz with constant 1 with respect to
supremum metric (on `R βα΅€[{s}] R`) on those functions which are continuous on a set `s` containing
the spectrum. -/
lemma lipschitzOnWith_cfc_fun_of_subset (a : A) {s : Set R} (hs : spectrum R a β s) :
LipschitzOnWith 1 (fun f β¦ cfc (toFun {s} f) a)
{f | ContinuousOn (toFun {s} f) (s)} := by
have hβ := lipschitzOnWith_cfc_fun R a
have hβ := lipschitzWith_one_ofFun_toFun' (π := {spectrum R a}) (π := {s}) (Ξ² := R) (by simpa)
have hβ := hβ.lipschitzOnWith (s := {f | ContinuousOn (toFun {s} f) (s)})
simpa using hβ.comp hβ (fun f hf β¦ hf.mono hs)
end Isometric
end Left
section Right
section RCLike
variable {X π A : Type*} {p : A β Prop} [RCLike π] [NormedRing A] [StarRing A]
[NormedAlgebra π A] [IsometricContinuousFunctionalCalculus π A p]
[ContinuousStar A]
/-- `cfcHomSuperset` is continuous in the variable `a : A` when `s : Set π` is compact and `a`
varies over elements whose spectrum is contained in `s`, all of which satisfy the predicate `p`. -/
theorem continuous_cfcHomSuperset_left
[TopologicalSpace X] {s : Set π} (hs : IsCompact s) (f : C(s, π))
(a : X β A) (ha_cont : Continuous a) (ha : β x, spectrum π (a x) β s)
(ha' : β x, p (a x) := by cfc_tac) :
Continuous (fun x β¦ cfcHomSuperset (ha' x) (ha x) f) := by
open scoped ContinuousFunctionalCalculus in
have : CompactSpace s := by rwa [isCompact_iff_compactSpace] at hs
induction f using ContinuousMap.induction_on_of_compact with
| const r =>
have : ContinuousMap.const s r = algebraMap π C(s, π) r := rfl
simpa only [this, AlgHomClass.commutes] using continuous_const
| id =>
simp only [cfcHomSuperset_id]
fun_prop
| star_id =>
simp only [map_star, cfcHomSuperset_id]
fun_prop
| add f g hf hg => simpa using hf.add hg
| mul f g hf hg => simpa using hf.mul hg
| frequently f hf =>
apply continuous_of_uniform_approx_of_continuous
rw [Metric.uniformity_basis_dist_le.forall_iff (by aesop)]
intro Ξ΅ hΞ΅
simp only [Set.mem_setOf_eq, dist_eq_norm]
obtain β¨g, hg, g_contβ© := frequently_iff.mp hf (Metric.closedBall_mem_nhds f hΞ΅)
simp only [Metric.mem_closedBall, dist_comm g, dist_eq_norm] at hg
refine β¨_, g_cont, fun x β¦ ?_β©
rw [β map_sub, cfcHomSuperset_apply]
rw [isometry_cfcHom (R := π) _ (ha' x) |>.norm_map_of_map_zero (map_zero (cfcHom (ha' x)))]
rw [ContinuousMap.norm_le _ hΞ΅.le] at hg β’
aesop
variable (A) in
/-- For `f : π β π` continuous on a compact set `s`, `cfc f` is continuous on the set of `a : A`
satisfying the predicate `p` (associated to `π`) and whose `π`-spectrum is contained in `s`. -/
theorem continuousOn_cfc {s : Set π} (hs : IsCompact s) (f : π β π)
(hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousOn (cfc f) {a | p a β§ spectrum π a β s} :=
continuousOn_iff_continuous_restrict.mpr <| by
convert continuous_cfcHomSuperset_left hs β¨_, hf.restrictβ©
((β) : {a | p a β§ spectrum π a β s} β A) continuous_subtype_val (fun x β¦ x.2.2) with x
rw [cfcHomSuperset_apply, Set.restrict_apply, cfc_apply _ _ x.2.1 (hf.mono x.2.2)]
congr!
open UniformOnFun in
/-- Let `s : Set π` be a compact set and consider pairs `(f, a) : (π β π) Γ A` where `f` is
continuous on `s` and `spectrum π a β s` and `a` satisfies the predicate `p a` for the continuous
functional calculus.
Then `cfc` is jointly continuous in both variables (i.e., continuous in its uncurried form) on this
set of pairs when the function space is equipped with the topology of uniform convergence on `s`. -/
theorem continuousOn_cfc_setProd {s : Set π} (hs : IsCompact s) :
ContinuousOn (fun fa : (π βα΅€[{s}] π) Γ A β¦ cfc (toFun {s} fa.1) fa.2)
({f | ContinuousOn (toFun {s} f) s} ΓΛ’ {a | p a β§ spectrum π a β s}) :=
continuousOn_prod_of_continuousOn_lipschitzOnWith _ 1
(fun f hf β¦ continuousOn_cfc A hs ((toFun {s}) f) hf)
(fun a β¨_, ha'β© β¦ lipschitzOnWith_cfc_fun_of_subset a ha')
/-- If `f : π β π` is continuous on a compact set `s` and `a : X β A` tends to `aβ : A` along a
filter `l` (such that eventually `a x` satisfies the predicate `p` associated to `π` and has
spectrum contained in `s`, as does `aβ`), then `fun x β¦ cfc f (a x)` tends to `cfc f aβ`. -/
protected theorem Filter.Tendsto.cfc {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} {aβ : A} {l : Filter X} (ha_tendsto : Tendsto a l (π aβ))
(ha : βαΆ x in l, spectrum π (a x) β s) (ha' : βαΆ x in l, p (a x))
(haβ : spectrum π aβ β s) (haβ' : p aβ) (hf : ContinuousOn f s := by cfc_cont_tac) :
Tendsto (fun x β¦ cfc f (a x)) l (π (cfc f aβ)) := by
apply continuousOn_cfc A hs f |>.continuousWithinAt β¨haβ', haββ© |>.tendsto.comp
rw [tendsto_nhdsWithin_iff]
exact β¨ha_tendsto, ha'.and haβ©
/-- If `f : π β π` is continuous on a compact set `s` and `a : X β A` is continuous at `xβ`, and
eventually `a x` satisfies the predicate `p` associated to `π` and has spectrum contained in `s`),
then `fun x β¦ cfc f (a x)` is continuous at `xβ`. -/
protected theorem ContinuousAt.cfc [TopologicalSpace X] {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} {xβ : X} (ha_cont : ContinuousAt a xβ)
(ha : βαΆ x in π xβ, spectrum π (a x) β s) (ha' : βαΆ x in π xβ, p (a x))
(hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousAt (fun x β¦ cfc f (a x)) xβ :=
ha_cont.tendsto.cfc hs f ha ha' ha.self_of_nhds ha'.self_of_nhds
/-- If `f : π β π` is continuous on a compact set `s` and `a : X β A` is continuous at `xβ` within
a set `t : Set X`, and eventually `a x` satisfies the predicate `p` associated to `π` and has
spectrum contained in `s`), then `fun x β¦ cfc f (a x)` is continuous at `xβ` within `t`. -/
protected theorem ContinuousWithinAt.cfc [TopologicalSpace X] {s : Set π} (hs : IsCompact s)
(f : π β π) {a : X β A} {xβ : X} {t : Set X} (hxβ : xβ β t)
(ha_cont : ContinuousWithinAt a t xβ) (ha : βαΆ x in π[t] xβ, spectrum π (a x) β s)
(ha' : βαΆ x in π[t] xβ, p (a x)) (hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousWithinAt (fun x β¦ cfc f (a x)) t xβ :=
ha_cont.tendsto.cfc hs f ha ha' (ha.self_of_nhdsWithin hxβ) (ha'.self_of_nhdsWithin hxβ)
/-- If `f : π β π` is continuous on a compact set `s` and `a : X β A` is continuous on `t : Set X`,
and `a x` satisfies the predicate `p` associated to `π` and has spectrum contained in `s` for all
`x β t`, then `fun x β¦ cfc f (a x)` is continuous on `t`. -/
protected theorem ContinuousOn.cfc [TopologicalSpace X] {s : Set π} (hs : IsCompact s)
(f : π β π) {a : X β A} {t : Set X} (ha_cont : ContinuousOn a t)
(ha : β x β t, spectrum π (a x) β s) (ha' : β x β t, p (a x))
(hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousOn (fun x β¦ cfc f (a x)) t := by
rw [ContinuousOn] at ha_cont β’
refine fun x hx β¦ (ha_cont x hx).cfc hs f hx ?_ ?_ hf
all_goals filter_upwards [self_mem_nhdsWithin] with x hx
exacts [ha x hx, ha' x hx]
/-- `cfc` is continuous in the variable `a : A` when `s : Set π` is compact and `a` varies over
elements whose spectrum is contained in `s`, all of which satisfy the predicate `p`, and the
function `f` is continuous on the spectrum of `a`. -/
protected theorem Continuous.cfc [TopologicalSpace X] {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} (ha_cont : Continuous a) (ha : β x, spectrum π (a x) β s)
(hf : ContinuousOn f s := by cfc_cont_tac) (ha' : β x, p (a x) := by cfc_tac) :
Continuous (fun x β¦ cfc f (a x)) := by
rw [β continuousOn_univ] at ha_cont β’
exact ha_cont.cfc hs f (fun x _ β¦ ha x) (fun x _ β¦ ha' x)
end RCLike
section NNReal
variable {X A : Type*} [NormedRing A] [StarRing A]
[NormedAlgebra β A] [IsometricContinuousFunctionalCalculus β A IsSelfAdjoint]
[ContinuousStar A] [PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass β A]
[T2Space A] [IsTopologicalRing A]
variable (A) in
/-- A version of `continuousOn_cfc` over `ββ₯0` instead of `RCLike π`. -/
theorem continuousOn_cfc_nnreal {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) (hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousOn (cfc f) {a : A | 0 β€ a β§ spectrum ββ₯0 a β s} := by
have : {a : A | 0 β€ a β§ spectrum ββ₯0 a β s}.EqOn (cfc f) (cfc (fun x : β β¦ f x.toNNReal)) :=
fun a ha β¦ cfc_nnreal_eq_real _ ha.1
refine ContinuousOn.congr ?_ this
replace hf : ContinuousOn (fun x β¦ f x.toNNReal : β β β) (NNReal.toReal '' s) := by
apply hf.ofReal_map_toNNReal
rw [Set.mapsTo_image_iff]
intro x hx
simpa
refine continuousOn_cfc A (hs.image NNReal.continuous_coe) _ hf |>.mono fun a ha β¦ ?_
simp only [Set.mem_setOf_eq, nonneg_iff_isSelfAdjoint_and_spectrumRestricts] at ha β’
refine β¨ha.1.1, ?_β©
rw [β ha.1.2.algebraMap_image]
exact Set.image_mono ha.2
open UniformOnFun in
/-- Let `s : Set ββ₯0` be a compact set and consider pairs `(f, a) : (ββ₯0 β ββ₯0) Γ A` where `f` is
continuous on `s` and `spectrum ββ₯0 a β s` and `0 β€ a`.
Then `cfc` is jointly continuous in both variables (i.e., continuous in its uncurried form) on this
set of pairs when the function space is equipped with the topology of uniform convergence on `s`. -/
theorem continuousOn_cfc_nnreal_setProd {s : Set ββ₯0} (hs : IsCompact s) :
ContinuousOn (fun fa : (ββ₯0 βα΅€[{s}] ββ₯0) Γ A β¦ cfc (toFun {s} fa.1) fa.2)
({f | ContinuousOn (toFun {s} f) s} ΓΛ’ {a | 0 β€ a β§ spectrum ββ₯0 a β s}) :=
continuousOn_prod_of_continuousOn_lipschitzOnWith _ 1
(fun f hf β¦ continuousOn_cfc_nnreal A hs ((toFun {s}) f) hf)
(fun a β¨_, ha'β© β¦ lipschitzOnWith_cfc_fun_of_subset a ha')
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `a : X β A` tends to `aβ : A` along a
filter `l` (such that eventually `0 β€ a x` and has spectrum contained in `s`, as does `aβ`), then
`fun x β¦ cfc f (a x)` tends to `cfc f aβ`. -/
theorem Filter.Tendsto.cfc_nnreal {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} {aβ : A} {l : Filter X} (ha_tendsto : Tendsto a l (π aβ))
(ha : βαΆ x in l, spectrum ββ₯0 (a x) β s) (ha' : βαΆ x in l, 0 β€ a x)
(haβ : spectrum ββ₯0 aβ β s) (haβ' : 0 β€ aβ) (hf : ContinuousOn f s := by cfc_cont_tac) :
Tendsto (fun x β¦ cfc f (a x)) l (π (cfc f aβ)) := by
apply continuousOn_cfc_nnreal A hs f |>.continuousWithinAt β¨haβ', haββ© |>.tendsto.comp
rw [tendsto_nhdsWithin_iff]
exact β¨ha_tendsto, ha'.and haβ©
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `a : X β A` is continuous at `xβ`, and
eventually `0 β€ a x` and has spectrum contained in `s`), then `fun x β¦ cfc f (a x)` is continuous
at `xβ`. -/
theorem ContinuousAt.cfc_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} {xβ : X} (ha_cont : ContinuousAt a xβ)
(ha : βαΆ x in π xβ, spectrum ββ₯0 (a x) β s) (ha' : βαΆ x in π xβ, 0 β€ a x)
(hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousAt (fun x β¦ cfc f (a x)) xβ :=
ha_cont.tendsto.cfc_nnreal hs f ha ha' ha.self_of_nhds ha'.self_of_nhds
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `a : X β A` is continuous at `xβ`
within a set `t : Set X`, and eventually `0 β€ a x` and has spectrum contained in `s`), then
`fun x β¦ cfc f (a x)` is continuous at `xβ` within `t`. -/
theorem ContinuousWithinAt.cfc_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} {xβ : X} {t : Set X} (hxβ : xβ β t)
(ha_cont : ContinuousWithinAt a t xβ) (ha : βαΆ x in π[t] xβ, spectrum ββ₯0 (a x) β s)
(ha' : βαΆ x in π[t] xβ, 0 β€ a x) (hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousWithinAt (fun x β¦ cfc f (a x)) t xβ :=
ha_cont.tendsto.cfc_nnreal hs f ha ha' (ha.self_of_nhdsWithin hxβ) (ha'.self_of_nhdsWithin hxβ)
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `a : X β A` is continuous on
`t : Set X`, and `0 β€ a x` and has spectrum contained in `s` for all `x β t`, then
`fun x β¦ cfc f (a x)` is continuous on `t`. -/
theorem ContinuousOn.cfc_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} {t : Set X} (ha_cont : ContinuousOn a t)
(ha : β x β t, spectrum ββ₯0 (a x) β s) (ha' : β x β t, 0 β€ a x)
(hf : ContinuousOn f s := by cfc_cont_tac) :
ContinuousOn (fun x β¦ cfc f (a x)) t := by
rw [ContinuousOn] at ha_cont β’
refine fun x hx β¦ (ha_cont x hx).cfc_nnreal hs f hx ?_ ?_ hf
all_goals filter_upwards [self_mem_nhdsWithin] with x hx
exacts [ha x hx, ha' x hx]
/-- `cfc` is continuous in the variable `a : A` when `s : Set ββ₯0` is compact and `a` varies over
nonnegative elements whose spectrum is contained in `s`, and the function `f` is
continuous on `s`. -/
theorem Continuous.cfc_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s) (f : ββ₯0 β ββ₯0)
{a : X β A} (ha_cont : Continuous a) (ha : β x, spectrum ββ₯0 (a x) β s)
(hf : ContinuousOn f s := by cfc_cont_tac) (ha' : β x, 0 β€ a x := by cfc_tac) :
Continuous (fun x β¦ cfc f (a x)) := by
rw [β continuousOn_univ] at ha_cont β’
exact ha_cont.cfc_nnreal hs f (fun x _ β¦ ha x) (fun x _ β¦ ha' x)
end NNReal
end Right
end Unital
section NonUnital
section Left
section Generic
variable {X R A : Type*} {p : A β Prop} [CommSemiring R] [StarRing R] [MetricSpace R] [Nontrivial R]
[IsTopologicalSemiring R] [ContinuousStar R] [NonUnitalRing A] [StarRing A]
[TopologicalSpace A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
[NonUnitalContinuousFunctionalCalculus R A p]
/-- If `F : X β R β R` tends to `f : R β R` uniformly on the spectrum of `a`, and all
these functions are continuous on the spectrum and map zero to itself, then
`fun x β¦ cfcβ (F x) a` tends to `cfcβ f a`. -/
theorem tendsto_cfcβ_fun {l : Filter X} {F : X β R β R} {f : R β R} {a : A}
(h_tendsto : TendstoUniformlyOn F f l (quasispectrum R a))
(hF : βαΆ x in l, ContinuousOn (F x) (quasispectrum R a)) (hF0 : βαΆ x in l, F x 0 = 0) :
Tendsto (fun x β¦ cfcβ (F x) a) l (π (cfcβ f a)) := by
open scoped NonUnitalContinuousFunctionalCalculus in
obtain (rfl | hl) := l.eq_or_neBot
Β· simp
have hf := h_tendsto.continuousOn hF
have hf0 : f 0 = 0 := Eq.symm <|
tendsto_nhds_unique (tendsto_const_nhds.congr' <| .symm hF0) <|
h_tendsto.tendsto_at (quasispectrum.zero_mem R a)
by_cases ha : p a
Β· let s : Set X := {x | ContinuousOn (F x) (quasispectrum R a) β§ F x 0 = 0}
have hs : s β l := hF.and hF0
rw [β tendsto_comap'_iff (i := ((β) : s β X)) (by simpa)]
conv =>
enter [1, x]
rw [Function.comp_apply, cfcβ_apply (hf := x.2.1) (hf0 := x.2.2)]
rw [cfcβ_apply ..]
apply cfcβHom_continuous _ |>.tendsto _ |>.comp
rw [ContinuousMapZero.isEmbedding_toContinuousMap.isInducing.tendsto_nhds_iff]
change Tendsto (fun x : s β¦ (β¨_, x.2.1.restrictβ© : C(quasispectrum R a, R))) _
(π β¨_, hf.restrictβ©)
rw [hf.tendsto_restrict_iff_tendstoUniformlyOn (fun x β¦ x.2.1)]
intro t
simp only [eventually_comap, Subtype.forall]
peel h_tendsto t with ht x _
aesop
Β· simpa [cfcβ_apply_of_not_predicate a ha] using tendsto_const_nhds
/-- If `f : X β R β R` tends to `f xβ` uniformly (along `π xβ`) on the spectrum of `a`,
and each `f x` is continuous on the spectrum of `a` and maps zero to itself, then
`fun x β¦ cfcβ (f x) a` is continuous at `xβ`. -/
theorem continuousAt_cfcβ_fun [TopologicalSpace X] {f : X β R β R} {a : A}
{xβ : X} (h_tendsto : TendstoUniformlyOn f (f xβ) (π xβ) (quasispectrum R a))
(hf : βαΆ x in π xβ, ContinuousOn (f x) (quasispectrum R a))
(hf0 : βαΆ x in π xβ, f x 0 = 0) :
ContinuousAt (fun x β¦ cfcβ (f x) a) xβ :=
tendsto_cfcβ_fun h_tendsto hf hf0
/-- If `f : X β R β R` tends to `f xβ` uniformly (along `π[s] xβ`) on the spectrum of `a`,
and eventually each `f x` is continuous on the spectrum of `a` and maps zero to itself, then
`fun x β¦ cfcβ (f x) a` is continuous at `xβ` within `s`. -/
theorem continuousWithinAt_cfcβ_fun [TopologicalSpace X] {f : X β R β R} {a : A}
{xβ : X} {s : Set X} (h_tendsto : TendstoUniformlyOn f (f xβ) (π[s] xβ) (quasispectrum R a))
(hf : βαΆ x in π[s] xβ, ContinuousOn (f x) (quasispectrum R a))
(hf0 : βαΆ x in π[s] xβ, f x 0 = 0 := by cfc_zero_tac) :
ContinuousWithinAt (fun x β¦ cfcβ (f x) a) s xβ :=
tendsto_cfcβ_fun h_tendsto hf hf0
open UniformOnFun in
/-- If `f : X β R β R` is continuous on `s : Set X` in the topology on
`X β R βα΅€[{spectrum R a}] β R`, and for each `x β s`, `f x` is continuous on the spectrum and
maps zero to itself, then `x β¦ cfcβ (f x) a` is continuous on `s` also. -/
theorem ContinuousOn.cfcβ_fun [TopologicalSpace X] {f : X β R β R} {a : A} {s : Set X}
(h_cont : ContinuousOn (fun x β¦ ofFun {quasispectrum R a} (f x)) s)
(hf : β x β s, ContinuousOn (f x) (quasispectrum R a))
(hf0 : β x β s, f x 0 = 0) :
ContinuousOn (fun x β¦ cfcβ (f x) a) s := by
rw [ContinuousOn] at h_cont β’
simp only [ContinuousWithinAt, UniformOnFun.tendsto_iff_tendstoUniformlyOn, Set.mem_singleton_iff,
Function.comp_def, toFun_ofFun, forall_eq] at h_cont
refine fun x hx β¦ continuousWithinAt_cfcβ_fun (h_cont x hx) ?_ ?_
all_goals filter_upwards [self_mem_nhdsWithin] with x hx
exacts [hf x hx, hf0 x hx]
open UniformOnFun in
/-- If `f : X β R β R` is continuous in the topology on `X β R βα΅€[{spectrum R a}] β R`,
and each `f` is continuous on the spectrum and maps zero to itself, then
`x β¦ cfcβ (f x) a` is continuous. -/
theorem Continuous.cfcβ_fun [TopologicalSpace X] (f : X β R β R) (a : A)
(h_cont : Continuous (fun x β¦ ofFun {quasispectrum R a} (f x)))
(hf : β x, ContinuousOn (f x) (quasispectrum R a) := by cfc_cont_tac)
(hf0 : β x, f x 0 = 0 := by cfc_zero_tac) :
Continuous fun x β¦ cfcβ (f x) a := by
rw [β continuousOn_univ] at h_cont β’
exact h_cont.cfcβ_fun (fun x _ β¦ hf x) (fun x _ β¦ hf0 x)
end Generic
section Isometric
variable {X R A : Type*} {p : A β Prop} [CommSemiring R] [StarRing R] [MetricSpace R] [Nontrivial R]
[IsTopologicalSemiring R] [ContinuousStar R] [NonUnitalRing A] [StarRing A]
[MetricSpace A] [Module R A] [SMulCommClass R A A] [IsScalarTower R A A]
[NonUnitalIsometricContinuousFunctionalCalculus R A p]
variable (R) in
open UniformOnFun in
open scoped NonUnitalContinuousFunctionalCalculus in
/-- The function `f β¦ cfcβ f a` is Lipschitz with constant 1 with respect to
supremum metric (on `R βα΅€[{quasispectrum R a}] R`) on those functions which are continuous on
the quasispectrum and map zero to itself. -/
lemma lipschitzOnWith_cfcβ_fun (a : A) :
LipschitzOnWith 1 (fun f β¦ cfcβ (toFun {quasispectrum R a} f) a)
{f | ContinuousOn (toFun {quasispectrum R a} f) (quasispectrum R a) β§ f 0 = 0} := by
by_cases ha : p a
Β· rintro f β¨hf, hf0β© g β¨hg, hg0β©
simp only
rw [cfcβ_apply .., cfcβ_apply .., isometry_cfcβHom (R := R) a ha |>.edist_eq]
simp only [ENNReal.coe_one, one_mul]
rw [β ContinuousMapZero.isometry_toContinuousMap.edist_eq,
edist_continuousRestrict_of_singleton hf hg]
Β· simpa [cfcβ_apply_of_not_predicate a ha] using LipschitzWith.const' 0 |>.lipschitzOnWith
open UniformOnFun in
open scoped ContinuousFunctionalCalculus in
/-- The function `f β¦ cfcβ f a` is Lipschitz with constant 1 with respect to
supremum metric (on `R βα΅€[{s}] R`) on those functions which are continuous on a set `s` containing
the quasispectrum and map zero to itself. -/
lemma lipschitzOnWith_cfcβ_fun_of_subset (a : A) {s : Set R} (hs : quasispectrum R a β s) :
LipschitzOnWith 1 (fun f β¦ cfcβ (toFun {s} f) a)
{f | ContinuousOn (toFun {s} f) (s) β§ f 0 = 0} := by
have hβ := lipschitzWith_one_ofFun_toFun' (π := {quasispectrum R a}) (π := {s}) (Ξ² := R)
(by simpa)
have hβ := hβ.lipschitzOnWith (s := {f | ContinuousOn (toFun {s} f) (s) β§ f 0 = 0})
simpa using lipschitzOnWith_cfcβ_fun R a |>.comp hβ (fun f β¦ .imp_left fun hf β¦ hf.mono hs)
end Isometric
end Left
section Right
section RCLike
variable {X π A : Type*} {p : A β Prop} [RCLike π] [NonUnitalNormedRing A] [StarRing A]
[NormedSpace π A] [IsScalarTower π A A] [SMulCommClass π A A] [ContinuousStar A]
[NonUnitalIsometricContinuousFunctionalCalculus π A p]
open scoped NonUnitalContinuousFunctionalCalculus ContinuousMapZero in
/-- `cfcβHomSuperset` is continuous in the variable `a : A` when `s : Set π` is compact and `a`
varies over elements whose spectrum is contained in `s`, all of which satisfy the predicate `p`. -/
theorem continuous_cfcβHomSuperset_left
[TopologicalSpace X] {s : Set π} (hs : IsCompact s) [hs0 : Fact (0 β s)]
(f : C(s, π)β) {a : X β A} (ha_cont : Continuous a)
(ha : β x, quasispectrum π (a x) β s) (ha' : β x, p (a x) := by cfc_tac) :
Continuous (fun x β¦ cfcβHomSuperset (ha' x) (ha x) f) := by
have : CompactSpace s := by rwa [isCompact_iff_compactSpace] at hs
induction f using ContinuousMapZero.induction_on_of_compact with
| h0 => rfl
| zero => simpa [map_zero] using continuous_const
| id => simpa only [cfcβHomSuperset_id']
| star_id => simp only [map_star, cfcβHomSuperset_id']; fun_prop
| add f g hf hg => simpa only [map_add] using hf.add hg
| mul f g hf hg => simpa only [map_mul] using hf.mul hg
| smul r f hf => simpa only [map_smul] using hf.const_smul r
| frequently f hf =>
apply continuous_of_uniform_approx_of_continuous
rw [Metric.uniformity_basis_dist_le.forall_iff (by aesop)]
intro Ξ΅ hΞ΅
simp only [Set.mem_setOf_eq, dist_eq_norm]
obtain β¨g, hg, g_contβ© := frequently_iff.mp hf (Metric.closedBall_mem_nhds f hΞ΅)
simp only [Metric.mem_closedBall, dist_comm g, dist_eq_norm] at hg
refine β¨_, g_cont, fun x β¦ ?_β©
rw [β map_sub, cfcβHomSuperset_apply]
rw [isometry_cfcβHom (R := π) _ (ha' x) |>.norm_map_of_map_zero (map_zero (cfcβHom (ha' x)))]
rw [ContinuousMapZero.norm_def, ContinuousMap.norm_le _ hΞ΅.le] at hg β’
aesop
variable (A) in
/-- For `f : π β π` continuous on a set `s` for which `f 0 = 0`, `cfcβ f` is continuous on the
set of `a : A` satisfying the predicate `p` (associated to `π`) and whose `π`-quasispectrum is
contained in `s`. -/
theorem continuousOn_cfcβ {s : Set π} (hs : IsCompact s) (f : π β π)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousOn (cfcβ f Β· : A β A) {a | p a β§ quasispectrum π a β s} := by
by_cases hs0 : 0 β s
Β· rw [continuousOn_iff_continuous_restrict]
convert continuous_cfcβHomSuperset_left hs (hs0 := β¨hs0β©) β¨β¨_, hf.restrictβ©, hf0β©
(X := {a : A | p a β§ quasispectrum π a β s}) continuous_subtype_val (fun x β¦ x.2.2) with x
rw [cfcβHomSuperset_apply, Set.restrict_apply, cfcβ_apply _ _ (hf.mono x.2.2) hf0 x.2.1]
congr!
Β· convert continuousOn_empty _
rw [Set.eq_empty_iff_forall_notMem]
exact fun a ha β¦ hs0 <| ha.2 <| quasispectrum.zero_mem π a
open UniformOnFun in
/-- Let `s : Set π` be a compact set and consider pairs `(f, a) : (π β π) Γ A` where `f` is
continuous on `s`, maps zero itself, and `quasispectrum π a β s` and `a` satisfies the predicate
`p a` for the continuous functional calculus.
Then `cfcβ` is jointly continuous in both variables (i.e., continuous in its uncurried form) on this
set of pairs when the function space is equipped with the topology of uniform convergence on `s`. -/
theorem continuousOn_cfcβ_setProd {s : Set π} (hs : IsCompact s) :
ContinuousOn (fun fa : (π βα΅€[{s}] π) Γ A β¦ cfcβ (toFun {s} fa.1) fa.2)
({f | ContinuousOn (toFun {s} f) s β§ f 0 = 0} ΓΛ’ {a | p a β§ quasispectrum π a β s}) :=
continuousOn_prod_of_continuousOn_lipschitzOnWith _ 1
(fun f hf β¦ continuousOn_cfcβ A hs ((toFun {s}) f) hf.1 hf.2)
(fun a β¨_, ha'β© β¦ lipschitzOnWith_cfcβ_fun_of_subset a ha')
/-- If `f : π β π` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` tends to
`aβ : A` along a filter `l` (such that eventually `a x` satisfies the predicate `p` associated to
`π` and has quasispectrum contained in `s`, as does `aβ`), then `fun x β¦ cfcβ f (a x)` tends to
`cfcβ f aβ`. -/
protected theorem Filter.Tendsto.cfcβ {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} {aβ : A} {l : Filter X} (ha_tendsto : Tendsto a l (π aβ))
(ha : βαΆ x in l, quasispectrum π (a x) β s) (ha' : βαΆ x in l, p (a x))
(haβ : quasispectrum π aβ β s) (haβ' : p aβ) (hf : ContinuousOn f s := by cfc_cont_tac)
(hf0 : f 0 = 0 := by cfc_zero_tac) :
Tendsto (fun x β¦ cfcβ f (a x)) l (π (cfcβ f aβ)) := by
apply continuousOn_cfcβ A hs f |>.continuousWithinAt β¨haβ', haββ© |>.tendsto.comp
rw [tendsto_nhdsWithin_iff]
exact β¨ha_tendsto, ha'.and haβ©
/-- If `f : π β π` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is continuous
at `xβ`, and eventually `a x` satisfies the predicate `p` associated to `π` and has quasispectrum
contained in `s`), then `fun x β¦ cfcβ f (a x)` is continuous at `xβ`. -/
protected theorem ContinuousAt.cfcβ [TopologicalSpace X] {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} {xβ : X} (ha_cont : ContinuousAt a xβ)
(ha : βαΆ x in π xβ, quasispectrum π (a x) β s) (ha' : βαΆ x in π xβ, p (a x))
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousAt (fun x β¦ cfcβ f (a x)) xβ :=
ha_cont.tendsto.cfcβ hs f ha ha' ha.self_of_nhds ha'.self_of_nhds
/-- If `f : π β π` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is continuous
at `xβ` within a set `t : Set X`, and eventually `a x` satisfies the predicate `p` associated to `π`
and has quasispectrum contained in `s`), then `fun x β¦ cfcβ f (a x)` is continuous at `xβ`
within `t`. -/
protected theorem ContinuousWithinAt.cfcβ [TopologicalSpace X] {s : Set π} (hs : IsCompact s)
(f : π β π) {a : X β A} {xβ : X} {t : Set X} (hxβ : xβ β t)
(ha_cont : ContinuousWithinAt a t xβ) (ha : βαΆ x in π[t] xβ, quasispectrum π (a x) β s)
(ha' : βαΆ x in π[t] xβ, p (a x)) (hf : ContinuousOn f s := by cfc_cont_tac)
(hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousWithinAt (fun x β¦ cfcβ f (a x)) t xβ :=
ha_cont.tendsto.cfcβ hs f ha ha' (ha.self_of_nhdsWithin hxβ) (ha'.self_of_nhdsWithin hxβ)
/-- If `f : π β π` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is continuous
on `t : Set X`, and `a x` satisfies the predicate `p` associated to `π` and has quasispectrum
contained in `s` for all `x β t`, then `fun x β¦ cfcβ f (a x)` is continuous on `t`. -/
protected theorem ContinuousOn.cfcβ [TopologicalSpace X] {s : Set π} (hs : IsCompact s)
(f : π β π) {a : X β A} {t : Set X} (ha_cont : ContinuousOn a t)
(ha : β x β t, quasispectrum π (a x) β s) (ha' : β x β t, p (a x))
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousOn (fun x β¦ cfcβ f (a x)) t := by
rw [ContinuousOn] at ha_cont β’
refine fun x hx β¦ (ha_cont x hx).cfcβ hs f hx ?_ ?_ hf
all_goals filter_upwards [self_mem_nhdsWithin] with x hx
exacts [ha x hx, ha' x hx]
/-- `cfcβ` is continuous in the variable `a : A` when `s : Set π` is compact and `a` varies over
elements whose quasispectrum is contained in `s`, all of which satisfy the predicate `p`, and the
function `f` is continuous `s` and `f 0 = 0`. -/
protected theorem Continuous.cfcβ [TopologicalSpace X] {s : Set π} (hs : IsCompact s) (f : π β π)
{a : X β A} (ha_cont : Continuous a) (ha : β x, quasispectrum π (a x) β s)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac)
(ha' : β x, p (a x) := by cfc_tac) :
Continuous (fun x β¦ cfcβ f (a x)) := by
rw [β continuousOn_univ] at ha_cont β’
exact ha_cont.cfcβ hs f (fun x _ β¦ ha x) (fun x _ β¦ ha' x)
/-- `cfcβ` is continuous in the variable `a : A` when `s : Set π` is compact and `a` varies over
elements whose spectrum is contained in `s`, all of which satisfy the predicate `p`, and the
function `f` is continuous on the spectrum of `a` and maps zero to itself. -/
theorem continuous_cfcβ [TopologicalSpace X] {s : Set π} (hs : IsCompact s) (hs0 : 0 β s)
(f : π β π) (a : X β A) (ha_cont : Continuous a) (ha : β x, quasispectrum π (a x) β s)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac)
(ha' : β x, p (a x) := by cfc_tac) :
Continuous (fun x β¦ cfcβ f (a x)) := by
convert continuous_cfcβHomSuperset_left hs (hs0 := β¨hs0β©) β¨β¨_, hf.restrictβ©, hf0β© ha_cont ha
rw [cfcβHomSuperset_apply, cfcβ_apply (hf := hf.mono (ha _))]
congr!
end RCLike
section NNReal
variable {X A : Type*} [NonUnitalNormedRing A] [StarRing A]
[NormedSpace β A] [IsScalarTower β A A] [SMulCommClass β A A] [ContinuousStar A]
[NonUnitalIsometricContinuousFunctionalCalculus β A IsSelfAdjoint]
[PartialOrder A] [StarOrderedRing A] [NonnegSpectrumClass β A]
[T2Space A] [IsTopologicalRing A]
variable (A) in
/-- A version of `continuousOn_cfcβ` over `ββ₯0` instead of `RCLike π`. -/
theorem continuousOn_cfcβ_nnreal {s : Set ββ₯0} (hs : IsCompact s) (f : ββ₯0 β ββ₯0)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousOn (cfcβ f Β· : A β A) {a : A | 0 β€ a β§ quasispectrum ββ₯0 a β s} := by
have : {a : A | 0 β€ a β§ quasispectrum ββ₯0 a β s}.EqOn (cfcβ f)
(cfcβ (fun x : β β¦ f x.toNNReal)) :=
fun a ha β¦ cfcβ_nnreal_eq_real _ ha.1
refine ContinuousOn.congr ?_ this
replace hf : ContinuousOn (fun x β¦ f x.toNNReal : β β β) (NNReal.toReal '' s) := by
apply hf.ofReal_map_toNNReal
rw [Set.mapsTo_image_iff]
intro x hx
simpa
refine continuousOn_cfcβ A (hs.image NNReal.continuous_coe) _ hf |>.mono fun a ha β¦ ?_
simp only [Set.mem_setOf_eq, nonneg_iff_isSelfAdjoint_and_quasispectrumRestricts] at ha β’
refine β¨ha.1.1, ?_β©
rw [β ha.1.2.algebraMap_image]
exact Set.image_mono ha.2
open UniformOnFun in
/-- Let `s : Set ββ₯0` be a compact set and consider pairs `(f, a) : (ββ₯0 β ββ₯0) Γ A` where `f` is
continuous on `s`, maps zero to itself, `spectrum ββ₯0 a β s` and `0 β€ a`.
Then `cfcβ` is jointly continuous in both variables (i.e., continuous in its uncurried form) on this
set of pairs when the function space is equipped with the topology of uniform convergence on `s`. -/
theorem continuousOn_cfcβ_nnreal_setProd {s : Set ββ₯0} (hs : IsCompact s) :
ContinuousOn (fun fa : (ββ₯0 βα΅€[{s}] ββ₯0) Γ A β¦ cfcβ (toFun {s} fa.1) fa.2)
({f | ContinuousOn (toFun {s} f) s β§ f 0 = 0} ΓΛ’ {a | 0 β€ a β§ quasispectrum ββ₯0 a β s}) :=
continuousOn_prod_of_continuousOn_lipschitzOnWith _ 1
(fun f hf β¦ continuousOn_cfcβ_nnreal A hs ((toFun {s}) f) hf.1 hf.2)
(fun a β¨_, ha'β© β¦ lipschitzOnWith_cfcβ_fun_of_subset a ha')
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` tends to
`aβ : A` along a filter `l` (such that eventually `a x` satisfies the predicate `p` associated to
`ββ₯0` and has quasispectrum contained in `s`, as does `aβ`), then `fun x β¦ cfcβ f (a x)` tends to
`cfcβ f aβ`. -/
theorem Filter.Tendsto.cfcβ_nnreal {s : Set ββ₯0} (hs : IsCompact s) (f : ββ₯0 β ββ₯0)
{a : X β A} {aβ : A} {l : Filter X} (ha_tendsto : Tendsto a l (π aβ))
(ha : βαΆ x in l, quasispectrum ββ₯0 (a x) β s) (ha' : βαΆ x in l, 0 β€ a x)
(haβ : quasispectrum ββ₯0 aβ β s) (haβ' : 0 β€ aβ) (hf : ContinuousOn f s := by cfc_cont_tac)
(hf0 : f 0 = 0 := by cfc_zero_tac) :
Tendsto (fun x β¦ cfcβ f (a x)) l (π (cfcβ f aβ)) := by
apply continuousOn_cfcβ_nnreal A hs f |>.continuousWithinAt β¨haβ', haββ© |>.tendsto.comp
rw [tendsto_nhdsWithin_iff]
exact β¨ha_tendsto, ha'.and haβ©
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is
continuous at `xβ`, and eventually `a x` satisfies the predicate `p` associated to `ββ₯0` and has
quasispectrum contained in `s`), then `fun x β¦ cfcβ f (a x)` is continuous at `xβ`. -/
theorem ContinuousAt.cfcβ_nnreal [TopologicalSpace X] {s : Set ββ₯0}
(hs : IsCompact s) (f : ββ₯0 β ββ₯0) {a : X β A} {xβ : X} (ha_cont : ContinuousAt a xβ)
(ha : βαΆ x in π xβ, quasispectrum ββ₯0 (a x) β s) (ha' : βαΆ x in π xβ, 0 β€ a x)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousAt (fun x β¦ cfcβ f (a x)) xβ :=
ha_cont.tendsto.cfcβ_nnreal hs f ha ha' ha.self_of_nhds ha'.self_of_nhds
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is
continuous at `xβ` within a set `t : Set X`, and eventually `a x` satisfies the predicate `p`
associated to `ββ₯0` and has quasispectrum contained in `s`), then `fun x β¦ cfcβ f (a x)` is
continuous at `xβ` within `t`. -/
theorem ContinuousWithinAt.cfcβ_nnreal [TopologicalSpace X] {s : Set ββ₯0}
(hs : IsCompact s) (f : ββ₯0 β ββ₯0) {a : X β A} {xβ : X} {t : Set X} (hxβ : xβ β t)
(ha_cont : ContinuousWithinAt a t xβ) (ha : βαΆ x in π[t] xβ, quasispectrum ββ₯0 (a x) β s)
(ha' : βαΆ x in π[t] xβ, 0 β€ a x) (hf : ContinuousOn f s := by cfc_cont_tac)
(hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousWithinAt (fun x β¦ cfcβ f (a x)) t xβ :=
ha_cont.tendsto.cfcβ_nnreal hs f ha ha' (ha.self_of_nhdsWithin hxβ) (ha'.self_of_nhdsWithin hxβ)
/-- If `f : ββ₯0 β ββ₯0` is continuous on a compact set `s` and `f 0 = 0` and `a : X β A` is
continuous on `t : Set X`, and `a x` satisfies the predicate `p` associated to `ββ₯0` and has
quasispectrum contained in `s` for all `x β t`, then `fun x β¦ cfcβ f (a x)` is continuous
on `t`. -/
theorem ContinuousOn.cfcβ_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} {t : Set X} (ha_cont : ContinuousOn a t)
(ha : β x β t, quasispectrum ββ₯0 (a x) β s) (ha' : β x β t, 0 β€ a x)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac) :
ContinuousOn (fun x β¦ cfcβ f (a x)) t := by
rw [ContinuousOn] at ha_cont β’
refine fun x hx β¦ (ha_cont x hx).cfcβ_nnreal hs f hx ?_ ?_ hf
all_goals filter_upwards [self_mem_nhdsWithin] with x hx
exacts [ha x hx, ha' x hx]
/-- `cfcβ` is continuous in the variable `a : A` when `s : Set ββ₯0` is compact and `a` varies over
elements whose quasispectrum is contained in `s`, all of which satisfy the predicate `p`, and the
function `f` is continuous `s` and `f 0 = 0`. -/
theorem Continuous.cfcβ_nnreal [TopologicalSpace X] {s : Set ββ₯0} (hs : IsCompact s)
(f : ββ₯0 β ββ₯0) {a : X β A} (ha_cont : Continuous a) (ha : β x, quasispectrum ββ₯0 (a x) β s)
(hf : ContinuousOn f s := by cfc_cont_tac) (hf0 : f 0 = 0 := by cfc_zero_tac)
(ha' : β x, 0 β€ a x := by cfc_tac) :
Continuous (fun x β¦ cfcβ f (a x)) := by
rw [β continuousOn_univ] at ha_cont β’
exact ha_cont.cfcβ_nnreal hs f (fun x _ β¦ ha x) (fun x _ β¦ ha' x)
end NNReal
end Right
end NonUnital
|
action.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnotations eqtype.
From mathcomp Require Import ssrnat div seq prime fintype bigop finset.
From mathcomp Require Import fingroup morphism perm automorphism quotient.
(******************************************************************************)
(* Group action: orbits, stabilisers, transitivity. *)
(* is_action D to == the function to : T -> aT -> T defines an action *)
(* of D : {set aT} on T. *)
(* action D T == structure for a function defining an action of D. *)
(* act_dom to == the domain D of to : action D rT. *)
(* {action: aT &-> T} == structure for a total action. *)
(* := action [set: aT] T *)
(* TotalAction to1 toM == the constructor for total actions; to1 and toM *)
(* are the proofs of the action identities for 1 and *)
(* a * b, respectively. *)
(* is_groupAction R to == to is a group action on range R: for all a in D, *)
(* the permutation induced by to a is in Aut R. Thus *)
(* the action of D must be trivial outside R. *)
(* groupAction D R == the structure for group actions of D on R. This *)
(* is a telescope on action D rT. *)
(* gact_range to == the range R of to : groupAction D R. *)
(* GroupAction toAut == constructs a groupAction for action to from *)
(* toAut : actm to @* D \subset Aut R (actm to is *)
(* the morphism to {perm rT} associated to 'to'). *)
(* orbit to A x == the orbit of x under the action of A via to. *)
(* orbit_transversal to A S == a transversal of the partition orbit to A @: S *)
(* of S, provided A acts on S via to. *)
(* amove to A x y == the set of a in A whose action sends x to y. *)
(* 'C_A[x | to] == the stabiliser of x : rT in A :&: D. *)
(* 'C_A(S | to) == the pointwise stabiliser of S : {set rT} in D :&: A. *)
(* 'N_A(S | to) == the global stabiliser of S : {set rT} in D :&: A. *)
(* 'Fix_(S | to)[a] == the set of fixpoints of a in S. *)
(* 'Fix_(S | to)(A) == the set of fixpoints of A in S. *)
(* In the first three _A can be omitted and defaults to the domain D of to; *)
(* in the last two S can be omitted and defaults to [set: T], so 'Fix_to[a] *)
(* is the set of all fixpoints of a. *)
(* The domain restriction ensures that stabilisers have a canonical group *)
(* structure, but note that 'Fix sets are generally not groups. Indeed, we *)
(* provide alternative definitions when to is a group action on R: *)
(* 'C_(G | to)(A) == the centraliser in R :&: G of the group action of *)
(* D :&: A via to *)
(* 'C_(G | to)[a] == the centraliser in R :&: G of a \in D, via to. *)
(* These sets are groups when G is; G can be omitted: 'C(|to)(A) is the *)
(* centraliser in R of the action of D :&: A via to. *)
(* [acts A, on S | to] == A \subset D acts on the set S via to. *)
(* {acts A, on S | to} == A acts on the set S (Prop statement). *)
(* {acts A, on group G | to} == [acts A, on S | to] /\ G \subset R, i.e., *)
(* A \subset D acts on G \subset R, via *)
(* to : groupAction D R. *)
(* [transitive A, on S | to] == A acts transitively on S. *)
(* [faithful A, on S | to] == A acts faithfully on S. *)
(* acts_irreducibly to A G == A acts irreducibly via the groupAction to *)
(* on the nontrivial group G, i.e., A does *)
(* not act on any nontrivial subgroup of G. *)
(* Important caveat: the definitions of orbit, amove, 'Fix_(S | to)(A), *)
(* transitive and faithful assume that A is a subset of the domain D. As most *)
(* of the permutation actions we consider are total this is usually harmless. *)
(* (Note that the theory of partial actions is only partially developed.) *)
(* In all of the above, to is expected to be the actual action structure, *)
(* not merely the function. There is a special scope %act for actions, and *)
(* constructions and notations for many classical actions: *)
(* 'P == natural action of a permutation group via aperm. *)
(* 'J == internal group action (conjugation) via conjg (_ ^ _). *)
(* 'R == regular group action (right translation) via mulg (_ * _). *)
(* (However, to limit ambiguity, _ * _ is NOT a canonical action.) *)
(* to^* == the action induced by to on {set rT} via to^* (== setact to). *)
(* 'Js == the internal action on subsets via _ :^ _, equivalent to 'J^*. *)
(* 'Rs == the regular action on subsets via rcoset, equivalent to 'R^*. *)
(* 'JG == the conjugation action on {group rT} via (_ :^ _)%G. *)
(* to / H == the action induced by to on coset_of H via qact to H, and *)
(* restricted to (qact_dom to H) == 'N(rcosets H 'N(H) | to^* ). *)
(* 'Q == the action induced to cosets by conjugation; the domain is *)
(* qact_dom 'J H, which is provably equal to 'N(H). *)
(* to %% A == the action of coset_of A via modact to A, with domain D / A *)
(* and support restricted to 'C(D :&: A | to). *)
(* to \ sAD == the action of A via ract to sAD == to, if sAD : A \subset D. *)
(* [Aut G] == the permutation action restricted to Aut G, via autact G. *)
(* <[nRA]> == the action of A on R via actby nRA == to in A and on R, and *)
(* the trivial action elsewhere; here nRA : [acts A, on R | to] *)
(* or nRA : {acts A, on group R | to}. *)
(* to^? == the action induced by to on sT : @subType rT P, via subact to *)
(* with domain subact_dom P to == 'N([set x | P x] | to). *)
(* <<phi>> == the action of phi : D >-> {perm rT}, via mact phi. *)
(* to \o f == the composite action (with domain f @*^-1 D) of the action to *)
(* with f : {morphism G >-> aT}, via comp_act to f. Here f must *)
(* be the actual morphism object (e.g., coset_morphism H), not *)
(* the underlying function (e.g., coset H). *)
(* The explicit application of an action to is usually written (to%act x a), *)
(* but %act can be omitted if to is an abstract action or a set action to^*. *)
(* Note that this form will simplify and expose the acting function. *)
(* There is a %gact scope for group actions; the notations above are *)
(* recognised in %gact when they denote canonical group actions. *)
(* Actions can be used to define morphisms: *)
(* actperm to == the morphism D >-> {perm rT} induced by to. *)
(* actm to a == if a \in D the function on D induced by the action to, else *)
(* the identity function. If to is a group action with range R *)
(* then actm to a is canonically a morphism on R. *)
(* We also define here the restriction operation on permutations (the domain *)
(* of this operations is a stabiliser), and local automorphism groups: *)
(* restr_perm S p == if p acts on S, the permutation with support in S that *)
(* coincides with p on S; else the identity. Note that *)
(* restr_perm is a permutation group morphism that maps *)
(* Aut G to Aut S when S is a subgroup of G. *)
(* Aut_in A G == the local permutation group 'N_A(G | 'P) / 'C_A(G | 'P) *)
(* Usually A is an automorphism group, and then Aut_in A G *)
(* is isomorphic to a subgroup of Aut G, specifically *)
(* restr_perm @* A. *)
(* Finally, gproduct.v will provide a semi-direct group construction that *)
(* maps an external group action to an internal one; the theory of morphisms *)
(* between such products makes use of the following definition: *)
(* morph_act to to' f fA <=> the action of to' on the images of f and fA is *)
(* the image of the action of to, i.e., for all x and a we *)
(* have f (to x a) = to' (f x) (fA a). Note that there is *)
(* no mention of the domains of to and to'; if needed, this *)
(* predicate should be restricted via the {in ...} notation *)
(* and domain conditions should be added. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope action_scope.
Declare Scope groupAction_scope.
Import GroupScope.
Section ActionDef.
Variables (aT : finGroupType) (D : {set aT}) (rT : Type).
Implicit Types a b : aT.
Implicit Type x : rT.
Definition act_morph to x := forall a b, to x (a * b) = to (to x a) b.
Definition is_action to :=
left_injective to /\ forall x, {in D &, act_morph to x}.
Record action := Action {act :> rT -> aT -> rT; _ : is_action act}.
Definition clone_action to :=
let: Action _ toP := to return {type of Action for to} -> action in
fun k => k toP.
End ActionDef.
(* Need to close the Section here to avoid re-declaring all Argument Scopes *)
Delimit Scope action_scope with act.
Bind Scope action_scope with action.
Arguments act_morph {aT rT%_type} to x%_g.
Arguments is_action {aT} D%_g {rT} to.
Arguments act {aT D%_g rT%_type} to%_act x%_g a%_g : rename.
Arguments clone_action [aT D%_g rT%_type to%_act] _.
Notation "{ 'action' aT &-> T }" := (action [set: aT] T)
(format "{ 'action' aT &-> T }") : type_scope.
Notation "[ 'action' 'of' to ]" := (clone_action (@Action _ _ _ to))
(format "[ 'action' 'of' to ]") : form_scope.
Definition act_dom aT D rT of @action aT D rT := D.
Section TotalAction.
Variables (aT : finGroupType) (rT : Type) (to : rT -> aT -> rT).
Hypotheses (to1 : to^~ 1 =1 id) (toM : forall x, act_morph to x).
Lemma is_total_action : is_action setT to.
Proof.
split=> [a | x a b _ _] /=; last by rewrite toM.
by apply: can_inj (to^~ a^-1) _ => x; rewrite -toM ?mulgV.
Qed.
Definition TotalAction := Action is_total_action.
End TotalAction.
Section ActionDefs.
Variables (aT aT' : finGroupType) (D : {set aT}) (D' : {set aT'}).
Definition morph_act rT rT' (to : action D rT) (to' : action D' rT') f fA :=
forall x a, f (to x a) = to' (f x) (fA a).
Variable rT : finType. (* Most definitions require a finType structure on rT *)
Implicit Type to : action D rT.
Implicit Type A : {set aT}.
Implicit Type S : {set rT}.
Definition actm to a := if a \in D then to^~ a else id.
Definition setact to S a := [set to x a | x in S].
Definition orbit to A x := to x @: A.
Definition amove to A x y := [set a in A | to x a == y].
Definition afix to A := [set x | A \subset [set a | to x a == x]].
Definition astab S to := D :&: [set a | S \subset [set x | to x a == x]].
Definition astabs S to := D :&: [set a | S \subset to^~ a @^-1: S].
Definition acts_on A S to := {in A, forall a x, (to x a \in S) = (x \in S)}.
Definition atrans A S to := S \in orbit to A @: S.
Definition faithful A S to := A :&: astab S to \subset [1].
End ActionDefs.
Arguments setact {aT D%_g rT} to%_act S%_g a%_g.
Arguments orbit {aT D%_g rT} to%_act A%_g x%_g.
Arguments amove {aT D%_g rT} to%_act A%_g x%_g y%_g.
Arguments afix {aT D%_g rT} to%_act A%_g.
Arguments astab {aT D%_g rT} S%_g to%_act.
Arguments astabs {aT D%_g rT} S%_g to%_act.
Arguments acts_on {aT D%_g rT} A%_g S%_g to%_act.
Arguments atrans {aT D%_g rT} A%_g S%_g to%_act.
Arguments faithful {aT D%_g rT} A%_g S%_g to%_act.
Notation "to ^*" := (setact to) : function_scope.
Prenex Implicits orbit amove.
Notation "''Fix_' to ( A )" := (afix to A)
(to at level 2, format "''Fix_' to ( A )") : group_scope.
(* camlp4 grammar factoring *)
Notation "''Fix_' ( to ) ( A )" := 'Fix_to(A) (only parsing) : group_scope.
Notation "''Fix_' ( S | to ) ( A )" := (S :&: 'Fix_to(A))
(format "''Fix_' ( S | to ) ( A )") : group_scope.
Notation "''Fix_' to [ a ]" := ('Fix_to([set a]))
(to at level 2, format "''Fix_' to [ a ]") : group_scope.
Notation "''Fix_' ( S | to ) [ a ]" := (S :&: 'Fix_to[a])
(format "''Fix_' ( S | to ) [ a ]") : group_scope.
Notation "''C' ( S | to )" := (astab S to) : group_scope.
Notation "''C_' A ( S | to )" := (A :&: 'C(S | to)) : group_scope.
Notation "''C_' ( A ) ( S | to )" := 'C_A(S | to) (only parsing) : group_scope.
Notation "''C' [ x | to ]" := ('C([set x] | to)) : group_scope.
Notation "''C_' A [ x | to ]" := (A :&: 'C[x | to]) : group_scope.
Notation "''C_' ( A ) [ x | to ]" := 'C_A[x | to] (only parsing) : group_scope.
Notation "''N' ( S | to )" := (astabs S to)
(format "''N' ( S | to )") : group_scope.
Notation "''N_' A ( S | to )" := (A :&: 'N(S | to))
(A at level 2, format "''N_' A ( S | to )") : group_scope.
Notation "[ 'acts' A , 'on' S | to ]" := (A \subset pred_of_set 'N(S | to))
(format "[ 'acts' A , 'on' S | to ]") : form_scope.
Notation "{ 'acts' A , 'on' S | to }" := (acts_on A S to)
(format "{ 'acts' A , 'on' S | to }") : type_scope.
Notation "[ 'transitive' A , 'on' S | to ]" := (atrans A S to)
(format "[ 'transitive' A , 'on' S | to ]") : form_scope.
Notation "[ 'faithful' A , 'on' S | to ]" := (faithful A S to)
(format "[ 'faithful' A , 'on' S | to ]") : form_scope.
Section RawAction.
(* Lemmas that do not require the group structure on the action domain. *)
(* Some lemmas like actMin would be actually be valid for arbitrary rT, *)
(* e.g., for actions on a function type, but would be difficult to use *)
(* as a view due to the confusion between parameters and assumptions. *)
Variables (aT : finGroupType) (D : {set aT}) (rT : finType) (to : action D rT).
Implicit Types (a : aT) (x y : rT) (A B : {set aT}) (S T : {set rT}).
Lemma act_inj : left_injective to. Proof. by case: to => ? []. Qed.
Arguments act_inj : clear implicits.
Lemma actMin x : {in D &, act_morph to x}.
Proof. by case: to => ? []. Qed.
Lemma actmEfun a : a \in D -> actm to a = to^~ a.
Proof. by rewrite /actm => ->. Qed.
Lemma actmE a : a \in D -> actm to a =1 to^~ a.
Proof. by move=> Da; rewrite actmEfun. Qed.
Lemma setactE S a : to^* S a = [set to x a | x in S].
Proof. by []. Qed.
Lemma mem_setact S a x : x \in S -> to x a \in to^* S a.
Proof. exact: imset_f. Qed.
Lemma card_setact S a : #|to^* S a| = #|S|.
Proof. by apply: card_imset; apply: act_inj. Qed.
Lemma setact_is_action : is_action D to^*.
Proof.
split=> [a R S eqRS | a b Da Db S]; last first.
by rewrite /setact /= -imset_comp; apply: eq_imset => x; apply: actMin.
apply/setP=> x; apply/idP/idP=> /(mem_setact a).
by rewrite eqRS => /imsetP[y Sy /act_inj->].
by rewrite -eqRS => /imsetP[y Sy /act_inj->].
Qed.
Canonical set_action := Action setact_is_action.
Lemma orbitE A x : orbit to A x = to x @: A. Proof. by []. Qed.
Lemma orbitP A x y :
reflect (exists2 a, a \in A & to x a = y) (y \in orbit to A x).
Proof. by apply: (iffP imsetP) => [] [a]; exists a. Qed.
Lemma mem_orbit A x a : a \in A -> to x a \in orbit to A x.
Proof. exact: imset_f. Qed.
Lemma afixP A x : reflect (forall a, a \in A -> to x a = x) (x \in 'Fix_to(A)).
Proof.
rewrite inE; apply: (iffP subsetP) => [xfix a /xfix | xfix a Aa].
by rewrite inE => /eqP.
by rewrite inE xfix.
Qed.
Lemma afixS A B : A \subset B -> 'Fix_to(B) \subset 'Fix_to(A).
Proof. by move=> sAB; apply/subsetP=> u /[!inE]; apply: subset_trans. Qed.
Lemma afixU A B : 'Fix_to(A :|: B) = 'Fix_to(A) :&: 'Fix_to(B).
Proof. by apply/setP=> x; rewrite !inE subUset. Qed.
Lemma afix1P a x : reflect (to x a = x) (x \in 'Fix_to[a]).
Proof. by rewrite inE sub1set inE; apply: eqP. Qed.
Lemma astabIdom S : 'C_D(S | to) = 'C(S | to).
Proof. by rewrite setIA setIid. Qed.
Lemma astab_dom S : {subset 'C(S | to) <= D}.
Proof. by move=> a /setIP[]. Qed.
Lemma astab_act S a x : a \in 'C(S | to) -> x \in S -> to x a = x.
Proof.
rewrite 2!inE => /andP[_ cSa] Sx; apply/eqP.
by have /[1!inE] := subsetP cSa x Sx.
Qed.
Lemma astabS S1 S2 : S1 \subset S2 -> 'C(S2 | to) \subset 'C(S1 | to).
Proof.
by move=> sS12; apply/subsetP=> x /[!inE] /andP[->]; apply: subset_trans.
Qed.
Lemma astabsIdom S : 'N_D(S | to) = 'N(S | to).
Proof. by rewrite setIA setIid. Qed.
Lemma astabs_dom S : {subset 'N(S | to) <= D}.
Proof. by move=> a /setIdP[]. Qed.
Lemma astabs_act S a x : a \in 'N(S | to) -> (to x a \in S) = (x \in S).
Proof.
rewrite 2!inE subEproper properEcard => /andP[_].
rewrite (card_preimset _ (act_inj _)) ltnn andbF orbF => /eqP{2}->.
by rewrite inE.
Qed.
Lemma astab_sub S : 'C(S | to) \subset 'N(S | to).
Proof.
apply/subsetP=> a cSa; rewrite !inE (astab_dom cSa).
by apply/subsetP=> x Sx; rewrite inE (astab_act cSa).
Qed.
Lemma astabsC S : 'N(~: S | to) = 'N(S | to).
Proof.
apply/setP=> a; apply/idP/idP=> nSa; rewrite !inE (astabs_dom nSa).
by rewrite -setCS -preimsetC; apply/subsetP=> x; rewrite inE astabs_act.
by rewrite preimsetC setCS; apply/subsetP=> x; rewrite inE astabs_act.
Qed.
Lemma astabsI S T : 'N(S | to) :&: 'N(T | to) \subset 'N(S :&: T | to).
Proof.
apply/subsetP=> a; rewrite !inE -!andbA preimsetI => /and4P[-> nSa _ nTa] /=.
by rewrite setISS.
Qed.
Lemma astabs_setact S a : a \in 'N(S | to) -> to^* S a = S.
Proof.
move=> nSa; apply/eqP; rewrite eqEcard card_setact leqnn andbT.
by apply/subsetP=> _ /imsetP[x Sx ->]; rewrite astabs_act.
Qed.
Lemma astab1_set S : 'C[S | set_action] = 'N(S | to).
Proof.
apply/setP=> a; apply/idP/idP=> nSa.
case/setIdP: nSa => Da; rewrite !inE Da sub1set inE => /eqP defS.
by apply/subsetP=> x Sx; rewrite inE -defS mem_setact.
by rewrite !inE (astabs_dom nSa) sub1set inE /= astabs_setact.
Qed.
Lemma astabs_set1 x : 'N([set x] | to) = 'C[x | to].
Proof.
apply/eqP; rewrite eqEsubset astab_sub andbC setIS //.
by apply/subsetP=> a; rewrite ?(inE,sub1set).
Qed.
Lemma acts_dom A S : [acts A, on S | to] -> A \subset D.
Proof. by move=> nSA; rewrite (subset_trans nSA) ?subsetIl. Qed.
Lemma acts_act A S : [acts A, on S | to] -> {acts A, on S | to}.
Proof. by move=> nAS a Aa x; rewrite astabs_act ?(subsetP nAS). Qed.
Lemma astabCin A S :
A \subset D -> (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)).
Proof.
move=> sAD; apply/subsetP/subsetP=> [sAC x xS | sSF a aA].
by apply/afixP=> a aA; apply: astab_act (sAC _ aA) xS.
rewrite !inE (subsetP sAD _ aA); apply/subsetP=> x xS.
by move/afixP/(_ _ aA): (sSF _ xS) => /[1!inE] ->.
Qed.
Section ActsSetop.
Variables (A : {set aT}) (S T : {set rT}).
Hypotheses (AactS : [acts A, on S | to]) (AactT : [acts A, on T | to]).
Lemma astabU : 'C(S :|: T | to) = 'C(S | to) :&: 'C(T | to).
Proof. by apply/setP=> a; rewrite !inE subUset; case: (a \in D). Qed.
Lemma astabsU : 'N(S | to) :&: 'N(T | to) \subset 'N(S :|: T | to).
Proof.
by rewrite -(astabsC S) -(astabsC T) -(astabsC (S :|: T)) setCU astabsI.
Qed.
Lemma astabsD : 'N(S | to) :&: 'N(T | to) \subset 'N(S :\: T| to).
Proof. by rewrite setDE -(astabsC T) astabsI. Qed.
Lemma actsI : [acts A, on S :&: T | to].
Proof. by apply: subset_trans (astabsI S T); rewrite subsetI AactS. Qed.
Lemma actsU : [acts A, on S :|: T | to].
Proof. by apply: subset_trans astabsU; rewrite subsetI AactS. Qed.
Lemma actsD : [acts A, on S :\: T | to].
Proof. by apply: subset_trans astabsD; rewrite subsetI AactS. Qed.
End ActsSetop.
Lemma acts_in_orbit A S x y :
[acts A, on S | to] -> y \in orbit to A x -> x \in S -> y \in S.
Proof.
by move=> nSA/imsetP[a Aa ->{y}] Sx; rewrite (astabs_act _ (subsetP nSA a Aa)).
Qed.
Lemma subset_faithful A B S :
B \subset A -> [faithful A, on S | to] -> [faithful B, on S | to].
Proof. by move=> sAB; apply: subset_trans; apply: setSI. Qed.
Section Reindex.
Variables (vT : Type) (idx : vT) (op : Monoid.com_law idx) (S : {set rT}).
Lemma reindex_astabs a F : a \in 'N(S | to) ->
\big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a).
Proof.
move=> nSa; rewrite (reindex_inj (act_inj a)); apply: eq_bigl => x.
exact: astabs_act.
Qed.
Lemma reindex_acts A a F : [acts A, on S | to] -> a \in A ->
\big[op/idx]_(i in S) F i = \big[op/idx]_(i in S) F (to i a).
Proof. by move=> nSA /(subsetP nSA); apply: reindex_astabs. Qed.
End Reindex.
End RawAction.
Arguments act_inj {aT D rT} to a [x1 x2] : rename.
Notation "to ^*" := (set_action to) : action_scope.
Arguments orbitP {aT D rT to A x y}.
Arguments afixP {aT D rT to A x}.
Arguments afix1P {aT D rT to a x}.
Arguments reindex_astabs [aT D rT] to [vT idx op S] a [F].
Arguments reindex_acts [aT D rT] to [vT idx op S A a F].
Section PartialAction.
(* Lemmas that require a (partial) group domain. *)
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Implicit Types a : aT.
Implicit Types x y : rT.
Implicit Types A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Types S : {set rT}.
Lemma act1 x : to x 1 = x.
Proof. by apply: (act_inj to 1); rewrite -actMin ?mulg1. Qed.
Lemma actKin : {in D, right_loop invg to}.
Proof. by move=> a Da /= x; rewrite -actMin ?groupV // mulgV act1. Qed.
Lemma actKVin : {in D, rev_right_loop invg to}.
Proof. by move=> a Da /= x; rewrite -{2}(invgK a) actKin ?groupV. Qed.
Lemma setactVin S a : a \in D -> to^* S a^-1 = to^~ a @^-1: S.
Proof.
by move=> Da; apply: can2_imset_pre; [apply: actKVin | apply: actKin].
Qed.
Lemma actXin x a i : a \in D -> to x (a ^+ i) = iter i (to^~ a) x.
Proof.
move=> Da; elim: i => /= [|i <-]; first by rewrite act1.
by rewrite expgSr actMin ?groupX.
Qed.
Lemma afix1 : 'Fix_to(1) = setT.
Proof. by apply/setP=> x; rewrite !inE sub1set inE act1 eqxx. Qed.
Lemma afixD1 G : 'Fix_to(G^#) = 'Fix_to(G).
Proof. by rewrite -{2}(setD1K (group1 G)) afixU afix1 setTI. Qed.
Lemma orbit_refl G x : x \in orbit to G x.
Proof. by rewrite -{1}[x]act1 mem_orbit. Qed.
Local Notation orbit_rel A := (fun x y => x \in orbit to A y).
Lemma contra_orbit G x y : x \notin orbit to G y -> x != y.
Proof. by apply: contraNneq => ->; apply: orbit_refl. Qed.
Lemma orbit_in_sym G : G \subset D -> symmetric (orbit_rel G).
Proof.
move=> sGD; apply: symmetric_from_pre => x y /imsetP[a Ga].
by move/(canLR (actKin (subsetP sGD a Ga))) <-; rewrite mem_orbit ?groupV.
Qed.
Lemma orbit_in_trans G : G \subset D -> transitive (orbit_rel G).
Proof.
move=> sGD _ _ z /imsetP[a Ga ->] /imsetP[b Gb ->].
by rewrite -actMin ?mem_orbit ?groupM // (subsetP sGD).
Qed.
Lemma orbit_in_eqP G x y :
G \subset D -> reflect (orbit to G x = orbit to G y) (x \in orbit to G y).
Proof.
move=> sGD; apply: (iffP idP) => [yGx|<-]; last exact: orbit_refl.
by apply/setP=> z; apply/idP/idP=> /orbit_in_trans-> //; rewrite orbit_in_sym.
Qed.
Lemma orbit_in_transl G x y z :
G \subset D -> y \in orbit to G x ->
(y \in orbit to G z) = (x \in orbit to G z).
Proof.
by move=> sGD Gxy; rewrite !(orbit_in_sym sGD _ z) (orbit_in_eqP y x sGD Gxy).
Qed.
Lemma orbit_act_in x a G :
G \subset D -> a \in G -> orbit to G (to x a) = orbit to G x.
Proof. by move=> sGD /mem_orbit/orbit_in_eqP->. Qed.
Lemma orbit_actr_in x a G y :
G \subset D -> a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x).
Proof. by move=> sGD /mem_orbit/orbit_in_transl->. Qed.
Lemma orbit_inv_in A x y :
A \subset D -> (y \in orbit to A^-1 x) = (x \in orbit to A y).
Proof.
move/subsetP=> sAD; apply/imsetP/imsetP=> [] [a Aa ->].
by exists a^-1; rewrite -?mem_invg ?actKin // -groupV sAD -?mem_invg.
by exists a^-1; rewrite ?memV_invg ?actKin // sAD.
Qed.
Lemma orbit_lcoset_in A a x :
A \subset D -> a \in D ->
orbit to (a *: A) x = orbit to A (to x a).
Proof.
move/subsetP=> sAD Da; apply/setP=> y; apply/imsetP/imsetP=> [] [b Ab ->{y}].
by exists (a^-1 * b); rewrite -?actMin ?mulKVg // ?sAD -?mem_lcoset.
by exists (a * b); rewrite ?mem_mulg ?set11 ?actMin // sAD.
Qed.
Lemma orbit_rcoset_in A a x y :
A \subset D -> a \in D ->
(to y a \in orbit to (A :* a) x) = (y \in orbit to A x).
Proof.
move=> sAD Da; rewrite -orbit_inv_in ?mul_subG ?sub1set // invMg.
by rewrite invg_set1 orbit_lcoset_in ?inv_subG ?groupV ?actKin ?orbit_inv_in.
Qed.
Lemma orbit_conjsg_in A a x y :
A \subset D -> a \in D ->
(to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x).
Proof.
move=> sAD Da; rewrite conjsgE.
by rewrite orbit_lcoset_in ?groupV ?mul_subG ?sub1set ?actKin ?orbit_rcoset_in.
Qed.
Lemma orbit1P G x : reflect (orbit to G x = [set x]) (x \in 'Fix_to(G)).
Proof.
apply: (iffP afixP) => [xfix | xfix a Ga].
apply/eqP; rewrite eq_sym eqEsubset sub1set -{1}[x]act1 imset_f //=.
by apply/subsetP=> y; case/imsetP=> a Ga ->; rewrite inE xfix.
by apply/set1P; rewrite -xfix imset_f.
Qed.
Lemma card_orbit1 G x : #|orbit to G x| = 1%N -> orbit to G x = [set x].
Proof.
move=> orb1; apply/eqP; rewrite eq_sym eqEcard {}orb1 cards1.
by rewrite sub1set orbit_refl.
Qed.
Lemma orbit_partition G S :
[acts G, on S | to] -> partition (orbit to G @: S) S.
Proof.
move=> actsGS; have sGD := acts_dom actsGS.
have eqiG: {in S & &, equivalence_rel [rel x y | y \in orbit to G x]}.
by move=> x y z * /=; rewrite orbit_refl; split=> // /orbit_in_eqP->.
congr (partition _ _): (equivalence_partitionP eqiG).
apply: eq_in_imset => x Sx; apply/setP=> y.
by rewrite inE /= andb_idl // => /acts_in_orbit->.
Qed.
Definition orbit_transversal A S := transversal (orbit to A @: S) S.
Lemma orbit_transversalP G S (P := orbit to G @: S)
(X := orbit_transversal G S) :
[acts G, on S | to] ->
[/\ is_transversal X P S, X \subset S,
{in X &, forall x y, (y \in orbit to G x) = (x == y)}
& forall x, x \in S -> exists2 a, a \in G & to x a \in X].
Proof.
move/orbit_partition; rewrite -/P => partP.
have [/eqP defS tiP _] := and3P partP.
have trXP: is_transversal X P S := transversalP partP.
have sXS: X \subset S := transversal_sub trXP.
split=> // [x y Xx Xy /= | x Sx].
have Sx := subsetP sXS x Xx.
rewrite -(inj_in_eq (pblock_inj trXP)) // eq_pblock ?defS //.
by rewrite (def_pblock tiP (imset_f _ Sx)) ?orbit_refl.
have /imsetP[y Xy defxG]: orbit to G x \in pblock P @: X.
by rewrite (pblock_transversal trXP) ?imset_f.
suffices /orbitP[a Ga def_y]: y \in orbit to G x by exists a; rewrite ?def_y.
by rewrite defxG mem_pblock defS (subsetP sXS).
Qed.
Lemma group_set_astab S : group_set 'C(S | to).
Proof.
apply/group_setP; split=> [|a b cSa cSb].
by rewrite !inE group1; apply/subsetP=> x _; rewrite inE act1.
rewrite !inE groupM ?(@astab_dom _ _ _ to S) //; apply/subsetP=> x Sx.
by rewrite inE actMin ?(@astab_dom _ _ _ to S) ?(astab_act _ Sx).
Qed.
Canonical astab_group S := group (group_set_astab S).
Lemma afix_gen_in A : A \subset D -> 'Fix_to(<<A>>) = 'Fix_to(A).
Proof.
move=> sAD; apply/eqP; rewrite eqEsubset afixS ?sub_gen //=.
by rewrite -astabCin gen_subG ?astabCin.
Qed.
Lemma afix_cycle_in a : a \in D -> 'Fix_to(<[a]>) = 'Fix_to[a].
Proof. by move=> Da; rewrite afix_gen_in ?sub1set. Qed.
Lemma afixYin A B :
A \subset D -> B \subset D -> 'Fix_to(A <*> B) = 'Fix_to(A) :&: 'Fix_to(B).
Proof. by move=> sAD sBD; rewrite afix_gen_in ?afixU // subUset sAD. Qed.
Lemma afixMin G H :
G \subset D -> H \subset D -> 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H).
Proof.
by move=> sGD sHD; rewrite -afix_gen_in ?mul_subG // genM_join afixYin.
Qed.
Lemma sub_astab1_in A x :
A \subset D -> (A \subset 'C[x | to]) = (x \in 'Fix_to(A)).
Proof. by move=> sAD; rewrite astabCin ?sub1set. Qed.
Lemma group_set_astabs S : group_set 'N(S | to).
Proof.
apply/group_setP; split=> [|a b cSa cSb].
by rewrite !inE group1; apply/subsetP=> x Sx; rewrite inE act1.
rewrite !inE groupM ?(@astabs_dom _ _ _ to S) //; apply/subsetP=> x Sx.
by rewrite inE actMin ?(@astabs_dom _ _ _ to S) ?astabs_act.
Qed.
Canonical astabs_group S := group (group_set_astabs S).
Lemma astab_norm S : 'N(S | to) \subset 'N('C(S | to)).
Proof.
apply/subsetP=> a nSa; rewrite inE sub_conjg; apply/subsetP=> b cSb.
have [Da Db] := (astabs_dom nSa, astab_dom cSb).
rewrite mem_conjgV !inE groupJ //; apply/subsetP=> x Sx.
rewrite inE !actMin ?groupM ?groupV //.
by rewrite (astab_act cSb) ?actKVin ?astabs_act ?groupV.
Qed.
Lemma astab_normal S : 'C(S | to) <| 'N(S | to).
Proof. by rewrite /normal astab_sub astab_norm. Qed.
Lemma acts_sub_orbit G S x :
[acts G, on S | to] -> (orbit to G x \subset S) = (x \in S).
Proof.
move/acts_act=> GactS.
apply/subsetP/idP=> [| Sx y]; first by apply; apply: orbit_refl.
by case/orbitP=> a Ga <-{y}; rewrite GactS.
Qed.
Lemma acts_orbit G x : G \subset D -> [acts G, on orbit to G x | to].
Proof.
move/subsetP=> sGD; apply/subsetP=> a Ga; rewrite !inE sGD //.
apply/subsetP=> _ /imsetP[b Gb ->].
by rewrite inE -actMin ?sGD // imset_f ?groupM.
Qed.
Lemma acts_subnorm_fix A : [acts 'N_D(A), on 'Fix_to(D :&: A) | to].
Proof.
apply/subsetP=> a nAa; have [Da _] := setIP nAa; rewrite !inE Da.
apply/subsetP=> x Cx /[1!inE]; apply/afixP=> b DAb.
have [Db _]:= setIP DAb; rewrite -actMin // conjgCV actMin ?groupJ ?groupV //.
by rewrite /= (afixP Cx) // memJ_norm // groupV (subsetP (normsGI _ _) _ nAa).
Qed.
Lemma atrans_orbit G x : [transitive G, on orbit to G x | to].
Proof. by apply: imset_f; apply: orbit_refl. Qed.
Section OrbitStabilizer.
Variables (G : {group aT}) (x : rT).
Hypothesis sGD : G \subset D.
Let ssGD := subsetP sGD.
Lemma amove_act a : a \in G -> amove to G x (to x a) = 'C_G[x | to] :* a.
Proof.
move=> Ga; apply/setP=> b; have Da := ssGD Ga.
rewrite mem_rcoset !(inE, sub1set) !groupMr ?groupV //.
by case Gb: (b \in G); rewrite //= actMin ?groupV ?ssGD ?(canF_eq (actKVin Da)).
Qed.
Lemma amove_orbit : amove to G x @: orbit to G x = rcosets 'C_G[x | to] G.
Proof.
apply/setP => Ha; apply/imsetP/rcosetsP=> [[y] | [a Ga ->]].
by case/imsetP=> b Gb -> ->{Ha y}; exists b => //; rewrite amove_act.
by rewrite -amove_act //; exists (to x a); first apply: mem_orbit.
Qed.
Lemma amoveK :
{in orbit to G x, cancel (amove to G x) (fun Ca => to x (repr Ca))}.
Proof.
move=> _ /orbitP[a Ga <-]; rewrite amove_act //= -[G :&: _]/(gval _).
case: repr_rcosetP => b; rewrite !(inE, sub1set)=> /and3P[Gb _ xbx].
by rewrite actMin ?ssGD ?(eqP xbx).
Qed.
Lemma orbit_stabilizer :
orbit to G x = [set to x (repr Ca) | Ca in rcosets 'C_G[x | to] G].
Proof.
rewrite -amove_orbit -imset_comp /=; apply/setP=> z.
by apply/idP/imsetP=> [xGz | [y xGy ->]]; first exists z; rewrite /= ?amoveK.
Qed.
Lemma act_reprK :
{in rcosets 'C_G[x | to] G, cancel (to x \o repr) (amove to G x)}.
Proof.
move=> _ /rcosetsP[a Ga ->] /=; rewrite amove_act ?rcoset_repr //.
rewrite -[G :&: _]/(gval _); case: repr_rcosetP => b /setIP[Gb _].
exact: groupM.
Qed.
End OrbitStabilizer.
Lemma card_orbit_in G x : G \subset D -> #|orbit to G x| = #|G : 'C_G[x | to]|.
Proof.
move=> sGD; rewrite orbit_stabilizer 1?card_in_imset //.
exact: can_in_inj (act_reprK _).
Qed.
Lemma card_orbit_in_stab G x :
G \subset D -> (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|.
Proof. by move=> sGD; rewrite mulnC card_orbit_in ?Lagrange ?subsetIl. Qed.
Lemma acts_sum_card_orbit G S :
[acts G, on S | to] -> \sum_(T in orbit to G @: S) #|T| = #|S|.
Proof. by move/orbit_partition/card_partition. Qed.
Lemma astab_setact_in S a : a \in D -> 'C(to^* S a | to) = 'C(S | to) :^ a.
Proof.
move=> Da; apply/setP=> b; rewrite mem_conjg !inE -mem_conjg conjGid //.
apply: andb_id2l => Db; rewrite sub_imset_pre; apply: eq_subset_r => x.
by rewrite !inE !actMin ?groupM ?groupV // invgK (canF_eq (actKVin Da)).
Qed.
Lemma astab1_act_in x a : a \in D -> 'C[to x a | to] = 'C[x | to] :^ a.
Proof. by move=> Da; rewrite -astab_setact_in // /setact imset_set1. Qed.
Theorem Frobenius_Cauchy G S : [acts G, on S | to] ->
\sum_(a in G) #|'Fix_(S | to)[a]| = (#|orbit to G @: S| * #|G|)%N.
Proof.
move=> GactS; have sGD := acts_dom GactS.
transitivity (\sum_(a in G) \sum_(x in 'Fix_(S | to)[a]) 1%N).
by apply: eq_bigr => a _; rewrite -sum1_card.
rewrite (exchange_big_dep [in S]) /= => [|a x _]; last by case/setIP.
rewrite (set_partition_big _ (orbit_partition GactS)) -sum_nat_const /=.
apply: eq_bigr => _ /imsetP[x Sx ->].
rewrite -(card_orbit_in_stab x sGD) -sum_nat_const.
apply: eq_bigr => y; rewrite orbit_in_sym // => /imsetP[a Ga defx].
rewrite defx astab1_act_in ?(subsetP sGD) //.
rewrite -{2}(conjGid Ga) -conjIg cardJg -sum1_card setIA (setIidPl sGD).
by apply: eq_bigl => b; rewrite !(sub1set, inE) -(acts_act GactS Ga) -defx Sx.
Qed.
Lemma atrans_dvd_index_in G S :
G \subset D -> [transitive G, on S | to] -> #|S| %| #|G : 'C_G(S | to)|.
Proof.
move=> sGD /imsetP[x Sx {1}->]; rewrite card_orbit_in //.
by rewrite indexgS // setIS // astabS // sub1set.
Qed.
Lemma atrans_dvd_in G S :
G \subset D -> [transitive G, on S | to] -> #|S| %| #|G|.
Proof.
move=> sGD transG; apply: dvdn_trans (atrans_dvd_index_in sGD transG) _.
exact: dvdn_indexg.
Qed.
Lemma atransPin G S :
G \subset D -> [transitive G, on S | to] ->
forall x, x \in S -> orbit to G x = S.
Proof. by move=> sGD /imsetP[y _ ->] x; apply/orbit_in_eqP. Qed.
Lemma atransP2in G S :
G \subset D -> [transitive G, on S | to] ->
{in S &, forall x y, exists2 a, a \in G & y = to x a}.
Proof. by move=> sGD transG x y /(atransPin sGD transG) <- /imsetP. Qed.
Lemma atrans_acts_in G S :
G \subset D -> [transitive G, on S | to] -> [acts G, on S | to].
Proof.
move=> sGD transG; apply/subsetP=> a Ga; rewrite !inE (subsetP sGD) //.
by apply/subsetP=> x /(atransPin sGD transG) <-; rewrite inE imset_f.
Qed.
Lemma subgroup_transitivePin G H S x :
x \in S -> H \subset G -> G \subset D -> [transitive G, on S | to] ->
reflect ('C_G[x | to] * H = G) [transitive H, on S | to].
Proof.
move=> Sx sHG sGD trG; have sHD := subset_trans sHG sGD.
apply: (iffP idP) => [trH | defG].
rewrite group_modr //; apply/setIidPl/subsetP=> a Ga.
have Sxa: to x a \in S by rewrite (acts_act (atrans_acts_in sGD trG)).
have [b Hb xab]:= atransP2in sHD trH Sxa Sx.
have Da := subsetP sGD a Ga; have Db := subsetP sHD b Hb.
rewrite -(mulgK b a) mem_mulg ?groupV // !inE groupM //= sub1set inE.
by rewrite actMin -?xab.
apply/imsetP; exists x => //; apply/setP=> y; rewrite -(atransPin sGD trG Sx).
apply/imsetP/imsetP=> [] [a]; last by exists a; first apply: (subsetP sHG).
rewrite -defG => /imset2P[c b /setIP[_ cxc] Hb ->] ->.
exists b; rewrite ?actMin ?(astab_dom cxc) ?(subsetP sHD) //.
by rewrite (astab_act cxc) ?inE.
Qed.
End PartialAction.
Arguments orbit_transversal {aT D%_g rT} to%_act A%_g S%_g.
Arguments orbit_in_eqP {aT D rT to G x y}.
Arguments orbit1P {aT D rT to G x}.
Arguments contra_orbit [aT D rT] to G [x y].
Notation "''C' ( S | to )" := (astab_group to S) : Group_scope.
Notation "''C_' A ( S | to )" := (setI_group A 'C(S | to)) : Group_scope.
Notation "''C_' ( A ) ( S | to )" := (setI_group A 'C(S | to))
(only parsing) : Group_scope.
Notation "''C' [ x | to ]" := (astab_group to [set x%g]) : Group_scope.
Notation "''C_' A [ x | to ]" := (setI_group A 'C[x | to]) : Group_scope.
Notation "''C_' ( A ) [ x | to ]" := (setI_group A 'C[x | to])
(only parsing) : Group_scope.
Notation "''N' ( S | to )" := (astabs_group to S) : Group_scope.
Notation "''N_' A ( S | to )" := (setI_group A 'N(S | to)) : Group_scope.
Section TotalActions.
(* These lemmas are only established for total actions (domain = [set: rT]) *)
Variable (aT : finGroupType) (rT : finType).
Variable to : {action aT &-> rT}.
Implicit Types (a b : aT) (x y z : rT) (A B : {set aT}) (G H : {group aT}).
Implicit Type S : {set rT}.
Lemma actM x a b : to x (a * b) = to (to x a) b.
Proof. by rewrite actMin ?inE. Qed.
Lemma actK : right_loop invg to.
Proof. by move=> a; apply: actKin; rewrite inE. Qed.
Lemma actKV : rev_right_loop invg to.
Proof. by move=> a; apply: actKVin; rewrite inE. Qed.
Lemma actX x a n : to x (a ^+ n) = iter n (to^~ a) x.
Proof. by elim: n => [|n /= <-]; rewrite ?act1 // -actM expgSr. Qed.
Lemma actCJ a b x : to (to x a) b = to (to x b) (a ^ b).
Proof. by rewrite !actM actK. Qed.
Lemma actCJV a b x : to (to x a) b = to (to x (b ^ a^-1)) a.
Proof. by rewrite (actCJ _ a) conjgKV. Qed.
Lemma orbit_sym G x y : (x \in orbit to G y) = (y \in orbit to G x).
Proof. exact/orbit_in_sym/subsetT. Qed.
Lemma orbit_trans G x y z :
x \in orbit to G y -> y \in orbit to G z -> x \in orbit to G z.
Proof. exact/orbit_in_trans/subsetT. Qed.
Lemma orbit_eqP G x y :
reflect (orbit to G x = orbit to G y) (x \in orbit to G y).
Proof. exact/orbit_in_eqP/subsetT. Qed.
Lemma orbit_transl G x y z :
y \in orbit to G x -> (y \in orbit to G z) = (x \in orbit to G z).
Proof. exact/orbit_in_transl/subsetT. Qed.
Lemma orbit_act G a x: a \in G -> orbit to G (to x a) = orbit to G x.
Proof. exact/orbit_act_in/subsetT. Qed.
Lemma orbit_actr G a x y :
a \in G -> (to y a \in orbit to G x) = (y \in orbit to G x).
Proof. by move/mem_orbit/orbit_transl; apply. Qed.
Lemma orbit_eq_mem G x y :
(orbit to G x == orbit to G y) = (x \in orbit to G y).
Proof. exact: sameP eqP (orbit_eqP G x y). Qed.
Lemma orbit_inv A x y : (y \in orbit to A^-1 x) = (x \in orbit to A y).
Proof. by rewrite orbit_inv_in ?subsetT. Qed.
Lemma orbit_lcoset A a x : orbit to (a *: A) x = orbit to A (to x a).
Proof. by rewrite orbit_lcoset_in ?subsetT ?inE. Qed.
Lemma orbit_rcoset A a x y :
(to y a \in orbit to (A :* a) x) = (y \in orbit to A x).
Proof. by rewrite orbit_rcoset_in ?subsetT ?inE. Qed.
Lemma orbit_conjsg A a x y :
(to y a \in orbit to (A :^ a) (to x a)) = (y \in orbit to A x).
Proof. by rewrite orbit_conjsg_in ?subsetT ?inE. Qed.
Lemma astabP S a : reflect (forall x, x \in S -> to x a = x) (a \in 'C(S | to)).
Proof.
apply: (iffP idP) => [cSa x|cSa]; first exact: astab_act.
by rewrite !inE; apply/subsetP=> x Sx; rewrite inE cSa.
Qed.
Lemma astab1P x a : reflect (to x a = x) (a \in 'C[x | to]).
Proof. by rewrite !inE sub1set inE; apply: eqP. Qed.
Lemma sub_astab1 A x : (A \subset 'C[x | to]) = (x \in 'Fix_to(A)).
Proof. by rewrite sub_astab1_in ?subsetT. Qed.
Lemma astabC A S : (A \subset 'C(S | to)) = (S \subset 'Fix_to(A)).
Proof. by rewrite astabCin ?subsetT. Qed.
Lemma afix_cycle a : 'Fix_to(<[a]>) = 'Fix_to[a].
Proof. by rewrite afix_cycle_in ?inE. Qed.
Lemma afix_gen A : 'Fix_to(<<A>>) = 'Fix_to(A).
Proof. by rewrite afix_gen_in ?subsetT. Qed.
Lemma afixM G H : 'Fix_to(G * H) = 'Fix_to(G) :&: 'Fix_to(H).
Proof. by rewrite afixMin ?subsetT. Qed.
Lemma astabsP S a :
reflect (forall x, (to x a \in S) = (x \in S)) (a \in 'N(S | to)).
Proof.
apply: (iffP idP) => [nSa x|nSa]; first exact: astabs_act.
by rewrite !inE; apply/subsetP=> x; rewrite inE nSa.
Qed.
Lemma card_orbit G x : #|orbit to G x| = #|G : 'C_G[x | to]|.
Proof. by rewrite card_orbit_in ?subsetT. Qed.
Lemma dvdn_orbit G x : #|orbit to G x| %| #|G|.
Proof. by rewrite card_orbit dvdn_indexg. Qed.
Lemma card_orbit_stab G x : (#|orbit to G x| * #|'C_G[x | to]|)%N = #|G|.
Proof. by rewrite mulnC card_orbit Lagrange ?subsetIl. Qed.
Lemma actsP A S : reflect {acts A, on S | to} [acts A, on S | to].
Proof.
apply: (iffP idP) => [nSA x|nSA]; first exact: acts_act.
by apply/subsetP=> a Aa /[!inE]; apply/subsetP=> x; rewrite inE nSA.
Qed.
Arguments actsP {A S}.
Lemma setact_orbit A x b : to^* (orbit to A x) b = orbit to (A :^ b) (to x b).
Proof.
apply/setP=> y; apply/idP/idP=> /imsetP[_ /imsetP[a Aa ->] ->{y}].
by rewrite actCJ mem_orbit ?memJ_conjg.
by rewrite -actCJ mem_setact ?mem_orbit.
Qed.
Lemma astab_setact S a : 'C(to^* S a | to) = 'C(S | to) :^ a.
Proof.
apply/setP=> b; rewrite mem_conjg.
apply/astabP/astabP=> stab x => [Sx|].
by rewrite conjgE invgK !actM stab ?actK //; apply/imsetP; exists x.
by case/imsetP=> y Sy ->{x}; rewrite -actM conjgCV actM stab.
Qed.
Lemma astab1_act x a : 'C[to x a | to] = 'C[x | to] :^ a.
Proof. by rewrite -astab_setact /setact imset_set1. Qed.
Lemma atransP G S : [transitive G, on S | to] ->
forall x, x \in S -> orbit to G x = S.
Proof. by case/imsetP=> x _ -> y; apply/orbit_eqP. Qed.
Lemma atransP2 G S : [transitive G, on S | to] ->
{in S &, forall x y, exists2 a, a \in G & y = to x a}.
Proof. by move=> GtrS x y /(atransP GtrS) <- /imsetP. Qed.
Lemma atrans_acts G S : [transitive G, on S | to] -> [acts G, on S | to].
Proof.
move=> GtrS; apply/subsetP=> a Ga; rewrite !inE.
by apply/subsetP=> x /(atransP GtrS) <-; rewrite inE imset_f.
Qed.
Lemma atrans_supgroup G H S :
G \subset H -> [transitive G, on S | to] ->
[transitive H, on S | to] = [acts H, on S | to].
Proof.
move=> sGH trG; apply/idP/idP=> [|actH]; first exact: atrans_acts.
case/imsetP: trG => x Sx defS; apply/imsetP; exists x => //.
by apply/eqP; rewrite eqEsubset acts_sub_orbit ?Sx // defS imsetS.
Qed.
Lemma atrans_acts_card G S :
[transitive G, on S | to] =
[acts G, on S | to] && (#|orbit to G @: S| == 1%N).
Proof.
apply/idP/andP=> [GtrS | [nSG]].
split; first exact: atrans_acts.
rewrite ((_ @: S =P [set S]) _) ?cards1 // eqEsubset sub1set.
apply/andP; split=> //; apply/subsetP=> _ /imsetP[x Sx ->].
by rewrite inE (atransP GtrS).
rewrite eqn_leq andbC lt0n => /andP[/existsP[X /imsetP[x Sx X_Gx]]].
rewrite (cardD1 X) {X}X_Gx imset_f // ltnS leqn0 => /eqP GtrS.
apply/imsetP; exists x => //; apply/eqP.
rewrite eqEsubset acts_sub_orbit // Sx andbT.
apply/subsetP=> y Sy; have:= card0_eq GtrS (orbit to G y).
by rewrite !inE /= imset_f // andbT => /eqP <-; apply: orbit_refl.
Qed.
Lemma atrans_dvd G S : [transitive G, on S | to] -> #|S| %| #|G|.
Proof. by case/imsetP=> x _ ->; apply: dvdn_orbit. Qed.
(* This is Aschbacher (5.2) *)
Lemma acts_fix_norm A B : A \subset 'N(B) -> [acts A, on 'Fix_to(B) | to].
Proof.
move=> nAB; have:= acts_subnorm_fix to B; rewrite !setTI.
exact: subset_trans.
Qed.
Lemma faithfulP A S :
reflect (forall a, a \in A -> {in S, to^~ a =1 id} -> a = 1)
[faithful A, on S | to].
Proof.
apply: (iffP subsetP) => [Cto1 a Aa Ca | Cto1 a].
by apply/set1P; rewrite Cto1 // inE Aa; apply/astabP.
by case/setIP=> Aa /astabP Ca; apply/set1P; apply: Cto1.
Qed.
(* This is the first part of Aschbacher (5.7) *)
Lemma astab_trans_gcore G S u :
[transitive G, on S | to] -> u \in S -> 'C(S | to) = gcore 'C[u | to] G.
Proof.
move=> transG Su; apply/eqP; rewrite eqEsubset.
rewrite gcore_max ?astabS ?sub1set //=; last first.
exact: subset_trans (atrans_acts transG) (astab_norm _ _).
apply/subsetP=> x cSx; apply/astabP=> uy.
case/(atransP2 transG Su) => y Gy ->{uy}.
by apply/astab1P; rewrite astab1_act (bigcapP cSx).
Qed.
(* This is Aschbacher (5.20) *)
Theorem subgroup_transitiveP G H S x :
x \in S -> H \subset G -> [transitive G, on S | to] ->
reflect ('C_G[x | to] * H = G) [transitive H, on S | to].
Proof. by move=> Sx sHG; apply: subgroup_transitivePin (subsetT G). Qed.
(* This is Aschbacher (5.21) *)
Lemma trans_subnorm_fixP x G H S :
let C := 'C_G[x | to] in let T := 'Fix_(S | to)(H) in
[transitive G, on S | to] -> x \in S -> H \subset C ->
reflect ((H :^: G) ::&: C = H :^: C) [transitive 'N_G(H), on T | to].
Proof.
move=> C T trGS Sx sHC; have actGS := acts_act (atrans_acts trGS).
have:= sHC; rewrite subsetI sub_astab1 => /andP[sHG cHx].
have Tx: x \in T by rewrite inE Sx.
apply: (iffP idP) => [trN | trC].
apply/setP=> Ha; apply/setIdP/imsetP=> [[]|[a Ca ->{Ha}]]; last first.
by rewrite conj_subG //; case/setIP: Ca => Ga _; rewrite imset_f.
case/imsetP=> a Ga ->{Ha}; rewrite subsetI !sub_conjg => /andP[_ sHCa].
have Txa: to x a^-1 \in T.
by rewrite inE -sub_astab1 astab1_act actGS ?Sx ?groupV.
have [b] := atransP2 trN Tx Txa; case/setIP=> Gb nHb cxba.
exists (b * a); last by rewrite conjsgM (normP nHb).
by rewrite inE groupM //; apply/astab1P; rewrite actM -cxba actKV.
apply/imsetP; exists x => //; apply/setP=> y; apply/idP/idP=> [Ty|].
have [Sy cHy]:= setIP Ty; have [a Ga defy] := atransP2 trGS Sx Sy.
have: H :^ a^-1 \in H :^: C.
rewrite -trC inE subsetI imset_f 1?conj_subG ?groupV // sub_conjgV.
by rewrite -astab1_act -defy sub_astab1.
case/imsetP=> b /setIP[Gb /astab1P cxb] defHb.
rewrite defy -{1}cxb -actM mem_orbit // inE groupM //.
by apply/normP; rewrite conjsgM -defHb conjsgKV.
case/imsetP=> a /setIP[Ga nHa] ->{y}.
by rewrite inE actGS // Sx (acts_act (acts_fix_norm _) nHa).
Qed.
End TotalActions.
Arguments astabP {aT rT to S a}.
Arguments orbit_eqP {aT rT to G x y}.
Arguments astab1P {aT rT to x a}.
Arguments astabsP {aT rT to S a}.
Arguments atransP {aT rT to G S}.
Arguments actsP {aT rT to A S}.
Arguments faithfulP {aT rT to A S}.
Section Restrict.
Variables (aT : finGroupType) (D : {set aT}) (rT : Type).
Variables (to : action D rT) (A : {set aT}).
Definition ract of A \subset D := act to.
Variable sAD : A \subset D.
Lemma ract_is_action : is_action A (ract sAD).
Proof.
rewrite /ract; case: to => f [injf fM].
by split=> // x; apply: (sub_in2 (subsetP sAD)).
Qed.
Canonical raction := Action ract_is_action.
Lemma ractE : raction =1 to. Proof. by []. Qed.
(* Other properties of raction need rT : finType; we defer them *)
(* until after the definition of actperm. *)
End Restrict.
Notation "to \ sAD" := (raction to sAD) (at level 50) : action_scope.
Section ActBy.
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Definition actby_cond (A : {set aT}) R (to : action D rT) : Prop :=
[acts A, on R | to].
Definition actby A R to of actby_cond A R to :=
fun x a => if (x \in R) && (a \in A) then to x a else x.
Variables (A : {group aT}) (R : {set rT}) (to : action D rT).
Hypothesis nRA : actby_cond A R to.
Lemma actby_is_action : is_action A (actby nRA).
Proof.
rewrite /actby; split=> [a x y | x a b Aa Ab /=]; last first.
rewrite Aa Ab groupM // !andbT actMin ?(subsetP (acts_dom nRA)) //.
by case Rx: (x \in R); rewrite ?(acts_act nRA) ?Rx.
case Aa: (a \in A); rewrite ?andbF ?andbT //.
case Rx: (x \in R); case Ry: (y \in R) => // eqxy; first exact: act_inj eqxy.
by rewrite -eqxy (acts_act nRA Aa) Rx in Ry.
by rewrite eqxy (acts_act nRA Aa) Ry in Rx.
Qed.
Canonical action_by := Action actby_is_action.
Local Notation "<[nRA]>" := action_by : action_scope.
Lemma actbyE x a : x \in R -> a \in A -> <[nRA]>%act x a = to x a.
Proof. by rewrite /= /actby => -> ->. Qed.
Lemma afix_actby B : 'Fix_<[nRA]>(B) = ~: R :|: 'Fix_to(A :&: B).
Proof.
apply/setP=> x; rewrite !inE /= /actby.
case: (x \in R); last by apply/subsetP=> a _ /[!inE].
apply/subsetP/subsetP=> [cBx a | cABx a Ba] /[!inE].
by case/andP=> Aa /cBx; rewrite inE Aa.
by case: ifP => //= Aa; have:= cABx a; rewrite !inE Aa => ->.
Qed.
Lemma astab_actby S : 'C(S | <[nRA]>) = 'C_A(R :&: S | to).
Proof.
apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE.
case Aa: (a \in A) => //=; apply/subsetP/subsetP=> cRSa x => [|Sx].
by case/setIP=> Rx /cRSa; rewrite !inE actbyE.
by have:= cRSa x; rewrite !inE /= /actby Aa Sx; case: (x \in R) => //; apply.
Qed.
Lemma astabs_actby S : 'N(S | <[nRA]>) = 'N_A(R :&: S | to).
Proof.
apply/setP=> a; rewrite setIA (setIidPl (acts_dom nRA)) !inE.
case Aa: (a \in A) => //=; apply/subsetP/subsetP=> nRSa x => [|Sx].
by case/setIP=> Rx /nRSa; rewrite !inE actbyE ?(acts_act nRA) ?Rx.
have:= nRSa x; rewrite !inE /= /actby Aa Sx ?(acts_act nRA) //.
by case: (x \in R) => //; apply.
Qed.
Lemma acts_actby (B : {set aT}) S :
[acts B, on S | <[nRA]>] = (B \subset A) && [acts B, on R :&: S | to].
Proof. by rewrite astabs_actby subsetI. Qed.
End ActBy.
Notation "<[ nRA ] >" := (action_by nRA) : action_scope.
Section SubAction.
Variables (aT : finGroupType) (D : {group aT}).
Variables (rT : finType) (sP : pred rT) (sT : subFinType sP) (to : action D rT).
Implicit Type A : {set aT}.
Implicit Type u : sT.
Implicit Type S : {set sT}.
Definition subact_dom := 'N([set x | sP x] | to).
Canonical subact_dom_group := [group of subact_dom].
Implicit Type Na : {a | a \in subact_dom}.
Lemma sub_act_proof u Na : sP (to (val u) (val Na)).
Proof. by case: Na => a /= /(astabs_act (val u)); rewrite !inE valP. Qed.
Definition subact u a :=
if insub a is Some Na then Sub _ (sub_act_proof u Na) else u.
Lemma val_subact u a :
val (subact u a) = if a \in subact_dom then to (val u) a else val u.
Proof.
by rewrite /subact -if_neg; case: insubP => [Na|] -> //=; rewrite SubK => ->.
Qed.
Lemma subact_is_action : is_action subact_dom subact.
Proof.
split=> [a u v eq_uv | u a b Na Nb]; apply: val_inj.
move/(congr1 val): eq_uv; rewrite !val_subact.
by case: (a \in _); first move/act_inj.
have Da := astabs_dom Na; have Db := astabs_dom Nb.
by rewrite !val_subact Na Nb groupM ?actMin.
Qed.
Canonical subaction := Action subact_is_action.
Lemma astab_subact S : 'C(S | subaction) = subact_dom :&: 'C(val @: S | to).
Proof.
apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa.
have [Da _] := setIP sDa; rewrite !inE Da.
apply/subsetP/subsetP=> [cSa _ /imsetP[x Sx ->] | cSa x Sx] /[!inE].
by have:= cSa x Sx; rewrite inE -val_eqE val_subact sDa.
by have:= cSa _ (imset_f val Sx); rewrite inE -val_eqE val_subact sDa.
Qed.
Lemma astabs_subact S : 'N(S | subaction) = subact_dom :&: 'N(val @: S | to).
Proof.
apply/setP=> a; rewrite inE in_setI; apply: andb_id2l => sDa.
have [Da _] := setIP sDa; rewrite !inE Da.
apply/subsetP/subsetP=> [nSa _ /imsetP[x Sx ->] | nSa x Sx] /[!inE].
by have /[1!inE]/(imset_f val) := nSa x Sx; rewrite val_subact sDa.
have /[1!inE]/imsetP[y Sy def_y] := nSa _ (imset_f val Sx).
by rewrite ((_ a =P y) _) // -val_eqE val_subact sDa def_y.
Qed.
Lemma afix_subact A :
A \subset subact_dom -> 'Fix_subaction(A) = val @^-1: 'Fix_to(A).
Proof.
move/subsetP=> sAD; apply/setP=> u.
rewrite !inE !(sameP setIidPl eqP); congr (_ == A).
apply/setP=> a /[!inE]; apply: andb_id2l => Aa.
by rewrite -val_eqE val_subact sAD.
Qed.
End SubAction.
Notation "to ^?" := (subaction _ to) (format "to ^?") : action_scope.
Section QuotientAction.
Variables (aT : finGroupType) (D : {group aT}) (rT : finGroupType).
Variables (to : action D rT) (H : {group rT}).
Definition qact_dom := 'N(rcosets H 'N(H) | to^*).
Canonical qact_dom_group := [group of qact_dom].
Local Notation subdom := (subact_dom (coset_range H) to^*).
Fact qact_subdomE : subdom = qact_dom.
Proof. by congr 'N(_|_); apply/setP=> Hx; rewrite !inE genGid. Qed.
Lemma qact_proof : qact_dom \subset subdom.
Proof. by rewrite qact_subdomE. Qed.
Definition qact : coset_of H -> aT -> coset_of H := act (to^*^? \ qact_proof).
Canonical quotient_action := [action of qact].
Lemma acts_qact_dom : [acts qact_dom, on 'N(H) | to].
Proof.
apply/subsetP=> a nNa; rewrite !inE (astabs_dom nNa); apply/subsetP=> x Nx.
have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f.
rewrite inE -(astabs_act _ nNa) => /rcosetsP[y Ny defHy].
have: to x a \in H :* y by rewrite -defHy (imset_f (to^~a)) ?rcoset_refl.
by apply: subsetP; rewrite mul_subG ?sub1set ?normG.
Qed.
Lemma qactEcond x a :
x \in 'N(H) ->
quotient_action (coset H x) a
= coset H (if a \in qact_dom then to x a else x).
Proof.
move=> Nx; apply: val_inj; rewrite val_subact //= qact_subdomE.
have: H :* x \in rcosets H 'N(H) by rewrite -rcosetE imset_f.
case nNa: (a \in _); rewrite // -(astabs_act _ nNa).
rewrite !val_coset ?(acts_act acts_qact_dom nNa) //=.
case/rcosetsP=> y Ny defHy; rewrite defHy; apply: rcoset_eqP.
by rewrite rcoset_sym -defHy (imset_f (_^~_)) ?rcoset_refl.
Qed.
Lemma qactE x a :
x \in 'N(H) -> a \in qact_dom ->
quotient_action (coset H x) a = coset H (to x a).
Proof. by move=> Nx nNa; rewrite qactEcond ?nNa. Qed.
Lemma acts_quotient (A : {set aT}) (B : {set rT}) :
A \subset 'N_qact_dom(B | to) -> [acts A, on B / H | quotient_action].
Proof.
move=> nBA; apply: subset_trans {A}nBA _; apply/subsetP=> a /setIP[dHa nBa].
rewrite inE dHa inE; apply/subsetP=> _ /morphimP[x nHx Bx ->].
rewrite inE /= qactE //.
by rewrite mem_morphim ?(acts_act acts_qact_dom) ?(astabs_act _ nBa).
Qed.
Lemma astabs_quotient (G : {group rT}) :
H <| G -> 'N(G / H | quotient_action) = 'N_qact_dom(G | to).
Proof.
move=> nsHG; have [_ nHG] := andP nsHG.
apply/eqP; rewrite eqEsubset acts_quotient // andbT.
apply/subsetP=> a nGa; have dHa := astabs_dom nGa; have [Da _]:= setIdP dHa.
rewrite inE dHa 2!inE Da; apply/subsetP=> x Gx; have nHx := subsetP nHG x Gx.
rewrite -(quotientGK nsHG) 2!inE (acts_act acts_qact_dom) ?nHx //= inE.
by rewrite -qactE // (astabs_act _ nGa) mem_morphim.
Qed.
End QuotientAction.
Notation "to / H" := (quotient_action to H) : action_scope.
Section ModAction.
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Implicit Types (G : {group aT}) (S : {set rT}).
Section GenericMod.
Variable H : {group aT}.
Local Notation dom := 'N_D(H).
Local Notation range := 'Fix_to(D :&: H).
Let acts_dom : {acts dom, on range | to} := acts_act (acts_subnorm_fix to H).
Definition modact x (Ha : coset_of H) :=
if x \in range then to x (repr (D :&: Ha)) else x.
Lemma modactEcond x a :
a \in dom -> modact x (coset H a) = (if x \in range then to x a else x).
Proof.
case/setIP=> Da Na; case: ifP => Cx; rewrite /modact Cx //.
rewrite val_coset // -group_modr ?sub1set //.
case: (repr _) / (repr_rcosetP (D :&: H) a) => a' Ha'.
by rewrite actMin ?(afixP Cx _ Ha') //; case/setIP: Ha'.
Qed.
Lemma modactE x a :
a \in D -> a \in 'N(H) -> x \in range -> modact x (coset H a) = to x a.
Proof. by move=> Da Na Rx; rewrite modactEcond ?Rx // inE Da. Qed.
Lemma modact_is_action : is_action (D / H) modact.
Proof.
split=> [Ha x y | x Ha Hb]; last first.
case/morphimP=> a Na Da ->{Ha}; case/morphimP=> b Nb Db ->{Hb}.
rewrite -morphM //= !modactEcond // ?groupM ?(introT setIP _) //.
by case: ifP => Cx; rewrite ?(acts_dom, Cx, actMin, introT setIP _).
case: (set_0Vmem (D :&: Ha)) => [Da0 | [a /setIP[Da NHa]]].
by rewrite /modact Da0 repr_set0 !act1 !if_same.
have Na := subsetP (coset_norm _) _ NHa.
have NDa: a \in 'N_D(H) by rewrite inE Da.
rewrite -(coset_mem NHa) !modactEcond //.
do 2![case: ifP]=> Cy Cx // eqxy; first exact: act_inj eqxy.
by rewrite -eqxy acts_dom ?Cx in Cy.
by rewrite eqxy acts_dom ?Cy in Cx.
Qed.
Canonical mod_action := Action modact_is_action.
Section Stabilizers.
Variable S : {set rT}.
Hypothesis cSH : H \subset 'C(S | to).
Let fixSH : S \subset 'Fix_to(D :&: H).
Proof. by rewrite -astabCin ?subsetIl // subIset ?cSH ?orbT. Qed.
Lemma astabs_mod : 'N(S | mod_action) = 'N(S | to) / H.
Proof.
apply/setP=> Ha; apply/idP/morphimP=> [nSa | [a nHa nSa ->]].
case/morphimP: (astabs_dom nSa) => a nHa Da defHa.
exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE.
by have:= Sx; rewrite -(astabs_act x nSa) defHa /= modactE ?(subsetP fixSH).
have Da := astabs_dom nSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx.
by rewrite !inE /= modactE ?(astabs_act x nSa) ?(subsetP fixSH).
Qed.
Lemma astab_mod : 'C(S | mod_action) = 'C(S | to) / H.
Proof.
apply/setP=> Ha; apply/idP/morphimP=> [cSa | [a nHa cSa ->]].
case/morphimP: (astab_dom cSa) => a nHa Da defHa.
exists a => //; rewrite !inE Da; apply/subsetP=> x Sx; rewrite !inE.
by rewrite -{2}[x](astab_act cSa) // defHa /= modactE ?(subsetP fixSH).
have Da := astab_dom cSa; rewrite !inE mem_quotient //; apply/subsetP=> x Sx.
by rewrite !inE /= modactE ?(astab_act cSa) ?(subsetP fixSH).
Qed.
End Stabilizers.
Lemma afix_mod G S :
H \subset 'C(S | to) -> G \subset 'N_D(H) ->
'Fix_(S | mod_action)(G / H) = 'Fix_(S | to)(G).
Proof.
move=> cSH /subsetIP[sGD nHG].
apply/eqP; rewrite eqEsubset !subsetI !subsetIl /= -!astabCin ?quotientS //.
have cfixH F: H \subset 'C(S :&: F | to).
by rewrite (subset_trans cSH) // astabS ?subsetIl.
rewrite andbC astab_mod ?quotientS //=; last by rewrite astabCin ?subsetIr.
by rewrite -(quotientSGK nHG) //= -astab_mod // astabCin ?quotientS ?subsetIr.
Qed.
End GenericMod.
Lemma modact_faithful G S :
[faithful G / 'C_G(S | to), on S | mod_action 'C_G(S | to)].
Proof.
rewrite /faithful astab_mod ?subsetIr //=.
by rewrite -quotientIG ?subsetIr ?trivg_quotient.
Qed.
End ModAction.
Notation "to %% H" := (mod_action to H) : action_scope.
Section ActPerm.
(* Morphism to permutations induced by an action. *)
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Variable to : action D rT.
Definition actperm a := perm (act_inj to a).
Lemma actpermM : {in D &, {morph actperm : a b / a * b}}.
Proof. by move=> a b Da Db; apply/permP=> x; rewrite permM !permE actMin. Qed.
Canonical actperm_morphism := Morphism actpermM.
Lemma actpermE a x : actperm a x = to x a.
Proof. by rewrite permE. Qed.
Lemma actpermK x a : aperm x (actperm a) = to x a.
Proof. exact: actpermE. Qed.
Lemma ker_actperm : 'ker actperm = 'C(setT | to).
Proof.
congr (_ :&: _); apply/setP=> a /[!inE]/=.
apply/eqP/subsetP=> [a1 x _ | a1]; first by rewrite inE -actpermE a1 perm1.
by apply/permP=> x; apply/eqP; have:= a1 x; rewrite !inE actpermE perm1 => ->.
Qed.
End ActPerm.
Section RestrictActionTheory.
Variables (aT : finGroupType) (D : {set aT}) (rT : finType).
Variables (to : action D rT).
Lemma faithful_isom (A : {group aT}) S (nSA : actby_cond A S to) :
[faithful A, on S | to] -> isom A (actperm <[nSA]> @* A) (actperm <[nSA]>).
Proof.
by move=> ffulAS; apply/isomP; rewrite ker_actperm astab_actby setIT.
Qed.
Variables (A : {set aT}) (sAD : A \subset D).
Lemma ractpermE : actperm (to \ sAD) =1 actperm to.
Proof. by move=> a; apply/permP=> x; rewrite !permE. Qed.
Lemma afix_ract B : 'Fix_(to \ sAD)(B) = 'Fix_to(B). Proof. by []. Qed.
Lemma astab_ract S : 'C(S | to \ sAD) = 'C_A(S | to).
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma astabs_ract S : 'N(S | to \ sAD) = 'N_A(S | to).
Proof. by rewrite setIA (setIidPl sAD). Qed.
Lemma acts_ract (B : {set aT}) S :
[acts B, on S | to \ sAD] = (B \subset A) && [acts B, on S | to].
Proof. by rewrite astabs_ract subsetI. Qed.
End RestrictActionTheory.
Section MorphAct.
(* Action induced by a morphism to permutations. *)
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable phi : {morphism D >-> {perm rT}}.
Definition mact x a := phi a x.
Lemma mact_is_action : is_action D mact.
Proof.
split=> [a x y | x a b Da Db]; first exact: perm_inj.
by rewrite /mact morphM //= permM.
Qed.
Canonical morph_action := Action mact_is_action.
Lemma mactE x a : morph_action x a = phi a x. Proof. by []. Qed.
Lemma injm_faithful : 'injm phi -> [faithful D, on setT | morph_action].
Proof.
move/injmP=> phi_inj; apply/subsetP=> a /setIP[Da /astab_act a1].
apply/set1P/phi_inj => //; apply/permP=> x.
by rewrite morph1 perm1 -mactE a1 ?inE.
Qed.
Lemma perm_mact a : actperm morph_action a = phi a.
Proof. by apply/permP=> x; rewrite permE. Qed.
End MorphAct.
Notation "<< phi >>" := (morph_action phi) : action_scope.
Section CompAct.
Variables (gT aT : finGroupType) (rT : finType).
Variables (D : {set aT}) (to : action D rT).
Variables (B : {set gT}) (f : {morphism B >-> aT}).
Definition comp_act x e := to x (f e).
Lemma comp_is_action : is_action (f @*^-1 D) comp_act.
Proof.
split=> [e | x e1 e2]; first exact: act_inj.
move=> /morphpreP[Be1 Dfe1] /morphpreP[Be2 Dfe2].
by rewrite /comp_act morphM ?actMin.
Qed.
Canonical comp_action := Action comp_is_action.
Lemma comp_actE x e : comp_action x e = to x (f e). Proof. by []. Qed.
Lemma afix_comp (A : {set gT}) :
A \subset B -> 'Fix_comp_action(A) = 'Fix_to(f @* A).
Proof.
move=> sAB; apply/setP=> x; rewrite !inE /morphim (setIidPr sAB).
apply/subsetP/subsetP; first by move=> + _ /imsetP[a + ->] => /[apply]/[!inE].
by move=> + a Aa => /(_ (f a)); rewrite !inE imset_f// => ->.
Qed.
Lemma astab_comp S : 'C(S | comp_action) = f @*^-1 'C(S | to).
Proof. by apply/setP=> x; rewrite !inE -andbA. Qed.
Lemma astabs_comp S : 'N(S | comp_action) = f @*^-1 'N(S | to).
Proof. by apply/setP=> x; rewrite !inE -andbA. Qed.
End CompAct.
Notation "to \o f" := (comp_action to f) : action_scope.
Section PermAction.
(* Natural action of permutation groups. *)
Variable rT : finType.
Local Notation gT := {perm rT}.
Implicit Types a b c : gT.
Lemma aperm_is_action : is_action setT (@aperm rT).
Proof.
by apply: is_total_action => [x|x a b]; rewrite apermE (perm1, permM).
Qed.
Canonical perm_action := Action aperm_is_action.
Lemma porbitE a : porbit a = orbit perm_action <[a]>%g.
Proof. by rewrite unlock. Qed.
Lemma perm_act1P a : reflect (forall x, aperm x a = x) (a == 1).
Proof.
apply: (iffP eqP) => [-> x | a1]; first exact: act1.
by apply/permP=> x; rewrite -apermE a1 perm1.
Qed.
Lemma perm_faithful A : [faithful A, on setT | perm_action].
Proof.
apply/subsetP=> a /setIP[Da crTa].
by apply/set1P; apply/permP=> x; rewrite -apermE perm1 (astabP crTa) ?inE.
Qed.
Lemma actperm_id p : actperm perm_action p = p.
Proof. by apply/permP=> x; rewrite permE. Qed.
End PermAction.
Arguments perm_act1P {rT a}.
Notation "'P" := (perm_action _) : action_scope.
Section ActpermOrbits.
Variables (aT : finGroupType) (D : {group aT}) (rT : finType).
Variable to : action D rT.
Lemma orbit_morphim_actperm (A : {set aT}) :
A \subset D -> orbit 'P (actperm to @* A) =1 orbit to A.
Proof.
move=> sAD x; rewrite morphimEsub // /orbit -imset_comp.
by apply: eq_imset => a //=; rewrite actpermK.
Qed.
Lemma porbit_actperm (a : aT) :
a \in D -> porbit (actperm to a) =1 orbit to <[a]>.
Proof.
move=> Da x.
by rewrite porbitE -orbit_morphim_actperm ?cycle_subG ?morphim_cycle.
Qed.
End ActpermOrbits.
Section RestrictPerm.
Variables (T : finType) (S : {set T}).
Definition restr_perm := actperm (<[subxx 'N(S | 'P)]>).
Canonical restr_perm_morphism := [morphism of restr_perm].
Lemma restr_perm_on p : perm_on S (restr_perm p).
Proof.
apply/subsetP=> x; apply: contraR => notSx.
by rewrite permE /= /actby (negPf notSx).
Qed.
Lemma triv_restr_perm p : p \notin 'N(S | 'P) -> restr_perm p = 1.
Proof.
move=> not_nSp; apply/permP=> x.
by rewrite !permE /= /actby (negPf not_nSp) andbF.
Qed.
Lemma restr_permE : {in 'N(S | 'P) & S, forall p, restr_perm p =1 p}.
Proof. by move=> y x nSp Sx; rewrite /= actpermE actbyE. Qed.
Lemma ker_restr_perm : 'ker restr_perm = 'C(S | 'P).
Proof. by rewrite ker_actperm astab_actby setIT (setIidPr (astab_sub _ _)). Qed.
Lemma im_restr_perm p : restr_perm p @: S = S.
Proof. exact: im_perm_on (restr_perm_on p). Qed.
Lemma restr_perm_commute s : commute (restr_perm s) s.
Proof.
have [sC|/triv_restr_perm->] := boolP (s \in 'N(S | 'P)); last first.
exact: (commute_sym (commute1 _)).
apply/permP => x; have /= xsS := astabsP sC x; rewrite !permM.
have [xS|xNS] := boolP (x \in S); first by rewrite ?(restr_permE) ?xsS.
by rewrite !(out_perm (restr_perm_on _)) ?xsS.
Qed.
End RestrictPerm.
Section Symmetry.
Variables (T : finType) (S : {set T}).
Lemma SymE : Sym S = 'C(~: S | 'P).
Proof.
apply/setP => s; rewrite inE; apply/idP/astabP => [sS x|/= S_id].
by rewrite inE /= apermE => /out_perm->.
by apply/subsetP => x; move=> /(contra_neqN (S_id _)); rewrite inE negbK.
Qed.
End Symmetry.
Section AutIn.
Variable gT : finGroupType.
Definition Aut_in A (B : {set gT}) := 'N_A(B | 'P) / 'C_A(B | 'P).
Variables G H : {group gT}.
Hypothesis sHG: H \subset G.
Lemma Aut_restr_perm a : a \in Aut G -> restr_perm H a \in Aut H.
Proof.
move=> AutGa.
case nHa: (a \in 'N(H | 'P)); last by rewrite triv_restr_perm ?nHa ?group1.
rewrite inE restr_perm_on; apply/morphicP=> x y Hx Hy /=.
by rewrite !restr_permE ?groupM // -(autmE AutGa) morphM ?(subsetP sHG).
Qed.
Lemma restr_perm_Aut : restr_perm H @* Aut G \subset Aut H.
Proof.
by apply/subsetP=> a'; case/morphimP=> a _ AutGa ->{a'}; apply: Aut_restr_perm.
Qed.
Lemma Aut_in_isog : Aut_in (Aut G) H \isog restr_perm H @* Aut G.
Proof.
rewrite /Aut_in -ker_restr_perm kerE -morphpreIdom -morphimIdom -kerE /=.
by rewrite setIA (setIC _ (Aut G)) first_isog_loc ?subsetIr.
Qed.
Lemma Aut_sub_fullP :
reflect (forall h : {morphism H >-> gT}, 'injm h -> h @* H = H ->
exists g : {morphism G >-> gT},
[/\ 'injm g, g @* G = G & {in H, g =1 h}])
(Aut_in (Aut G) H \isog Aut H).
Proof.
rewrite (isog_transl _ Aut_in_isog) /=; set rG := _ @* _.
apply: (iffP idP) => [iso_rG h injh hH| AutHinG].
have: aut injh hH \in rG; last case/morphimP=> g nHg AutGg def_g.
suffices ->: rG = Aut H by apply: Aut_aut.
by apply/eqP; rewrite eqEcard restr_perm_Aut /= (card_isog iso_rG).
exists (autm_morphism AutGg); rewrite injm_autm im_autm; split=> // x Hx.
by rewrite -(autE injh hH Hx) def_g actpermE actbyE.
suffices ->: rG = Aut H by apply: isog_refl.
apply/eqP; rewrite eqEsubset restr_perm_Aut /=.
apply/subsetP=> h AutHh; have hH := im_autm AutHh.
have [g [injg gG eq_gh]] := AutHinG _ (injm_autm AutHh) hH.
have [Ng AutGg]: aut injg gG \in 'N(H | 'P) /\ aut injg gG \in Aut G.
rewrite Aut_aut !inE; split=> //; apply/subsetP=> x Hx.
by rewrite inE /= /aperm autE ?(subsetP sHG) // -hH eq_gh ?mem_morphim.
apply/morphimP; exists (aut injg gG) => //; apply: (eq_Aut AutHh) => [|x Hx].
by rewrite (subsetP restr_perm_Aut) // mem_morphim.
by rewrite restr_permE //= /aperm autE ?eq_gh ?(subsetP sHG).
Qed.
End AutIn.
Arguments Aut_in {gT} A%_g B%_g.
Section InjmAutIn.
Variables (gT rT : finGroupType) (D G H : {group gT}) (f : {morphism D >-> rT}).
Hypotheses (injf : 'injm f) (sGD : G \subset D) (sHG : H \subset G).
Let sHD := subset_trans sHG sGD.
Local Notation fGisom := (Aut_isom injf sGD).
Local Notation fHisom := (Aut_isom injf sHD).
Local Notation inH := (restr_perm H).
Local Notation infH := (restr_perm (f @* H)).
Lemma astabs_Aut_isom a :
a \in Aut G -> (fGisom a \in 'N(f @* H | 'P)) = (a \in 'N(H | 'P)).
Proof.
move=> AutGa; rewrite !inE sub_morphim_pre // subsetI sHD /= /aperm.
rewrite !(sameP setIidPl eqP) !eqEsubset !subsetIl; apply: eq_subset_r => x.
rewrite !inE; apply: andb_id2l => Hx; have Gx: x \in G := subsetP sHG x Hx.
have Dax: a x \in D by rewrite (subsetP sGD) // Aut_closed.
by rewrite Aut_isomE // -!sub1set -morphim_set1 // injmSK ?sub1set.
Qed.
Lemma isom_restr_perm a : a \in Aut G -> fHisom (inH a) = infH (fGisom a).
Proof.
move=> AutGa; case nHa: (a \in 'N(H | 'P)); last first.
by rewrite !triv_restr_perm ?astabs_Aut_isom ?nHa ?morph1.
apply: (eq_Aut (Aut_Aut_isom injf sHD _)) => [|fx Hfx /=].
by rewrite (Aut_restr_perm (morphimS f sHG)) ?Aut_Aut_isom.
have [x Dx Hx def_fx] := morphimP Hfx; have Gx := subsetP sHG x Hx.
rewrite {1}def_fx Aut_isomE ?(Aut_restr_perm sHG) //.
by rewrite !restr_permE ?astabs_Aut_isom // def_fx Aut_isomE.
Qed.
Lemma restr_perm_isom : isom (inH @* Aut G) (infH @* Aut (f @* G)) fHisom.
Proof.
apply: sub_isom; rewrite ?restr_perm_Aut ?injm_Aut_isom //=.
rewrite -(im_Aut_isom injf sGD) -!morphim_comp.
apply: eq_in_morphim; last exact: isom_restr_perm.
(* TODO: investigate why rewrite does not match in the same order *)
apply/setP=> a; rewrite in_setI [in RHS]in_setI; apply: andb_id2r => AutGa.
(* the middle rewrite was rewrite 2!in_setI *)
rewrite /= inE andbC inE (Aut_restr_perm sHG) //=.
by symmetry; rewrite inE AutGa inE astabs_Aut_isom.
Qed.
Lemma injm_Aut_sub : Aut_in (Aut (f @* G)) (f @* H) \isog Aut_in (Aut G) H.
Proof.
do 2!rewrite isog_sym (isog_transl _ (Aut_in_isog _ _)).
by rewrite isog_sym (isom_isog _ _ restr_perm_isom) // restr_perm_Aut.
Qed.
Lemma injm_Aut_full :
(Aut_in (Aut (f @* G)) (f @* H) \isog Aut (f @* H))
= (Aut_in (Aut G) H \isog Aut H).
Proof.
by rewrite (isog_transl _ injm_Aut_sub) (isog_transr _ (injm_Aut injf sHD)).
Qed.
End InjmAutIn.
Section GroupAction.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Local Notation actT := (action D rT).
Definition is_groupAction (to : actT) :=
{in D, forall a, actperm to a \in Aut R}.
Structure groupAction := GroupAction {gact :> actT; _ : is_groupAction gact}.
Definition clone_groupAction to :=
let: GroupAction _ toA := to return {type of GroupAction for to} -> _ in
fun k => k toA : groupAction.
End GroupAction.
Delimit Scope groupAction_scope with gact.
Bind Scope groupAction_scope with groupAction.
Arguments is_groupAction {aT rT D%_g} R%_g to%_act.
Arguments groupAction {aT rT} D%_g R%_g.
Arguments gact {aT rT D%_g R%_g} to%_gact : rename.
Notation "[ 'groupAction' 'of' to ]" :=
(clone_groupAction (@GroupAction _ _ _ _ to))
(format "[ 'groupAction' 'of' to ]") : form_scope.
Section GroupActionDefs.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Implicit Type A : {set aT}.
Implicit Type S : {set rT}.
Implicit Type to : groupAction D R.
Definition gact_range of groupAction D R := R.
Definition gacent to A := 'Fix_(R | to)(D :&: A).
Definition acts_on_group A S to := [acts A, on S | to] /\ S \subset R.
Coercion actby_cond_group A S to : acts_on_group A S to -> actby_cond A S to :=
@proj1 _ _.
Definition acts_irreducibly A S to :=
[min S of G | G :!=: 1 & [acts A, on G | to]].
End GroupActionDefs.
Arguments gacent {aT rT D%_g R%_g} to%_gact A%_g.
Arguments acts_on_group {aT rT D%_g R%_g} A%_g S%_g to%_gact.
Arguments acts_irreducibly {aT rT D%_g R%_g} A%_g S%_g to%_gact.
Notation "''C_' ( | to ) ( A )" := (gacent to A) : group_scope.
Notation "''C_' ( G | to ) ( A )" := (G :&: 'C_(|to)(A)) : group_scope.
Notation "''C_' ( | to ) [ a ]" := 'C_(|to)([set a]) : group_scope.
Notation "''C_' ( G | to ) [ a ]" := 'C_(G | to)([set a]) : group_scope.
Notation "{ 'acts' A , 'on' 'group' G | to }" := (acts_on_group A G to)
(format "{ 'acts' A , 'on' 'group' G | to }") : type_scope.
Section RawGroupAction.
Variables (aT rT : finGroupType) (D : {set aT}) (R : {set rT}).
Variable to : groupAction D R.
Lemma actperm_Aut : is_groupAction R to. Proof. by case: to. Qed.
Lemma im_actperm_Aut : actperm to @* D \subset Aut R.
Proof. by apply/subsetP=> _ /morphimP[a _ Da ->]; apply: actperm_Aut. Qed.
Lemma gact_out x a : a \in D -> x \notin R -> to x a = x.
Proof. by move=> Da Rx; rewrite -actpermE (out_Aut _ Rx) ?actperm_Aut. Qed.
Lemma gactM : {in D, forall a, {in R &, {morph to^~ a : x y / x * y}}}.
Proof.
move=> a Da /= x y; rewrite -!(actpermE to); apply: morphicP x y.
by rewrite Aut_morphic ?actperm_Aut.
Qed.
Lemma actmM a : {in R &, {morph actm to a : x y / x * y}}.
Proof. by rewrite /actm; case: ifP => //; apply: gactM. Qed.
Canonical act_morphism a := Morphism (actmM a).
Lemma morphim_actm :
{in D, forall a (S : {set rT}), S \subset R -> actm to a @* S = to^* S a}.
Proof. by move=> a Da /= S sSR; rewrite /morphim /= actmEfun ?(setIidPr _). Qed.
Variables (a : aT) (A B : {set aT}) (S : {set rT}).
Lemma gacentIdom : 'C_(|to)(D :&: A) = 'C_(|to)(A).
Proof. by rewrite /gacent setIA setIid. Qed.
Lemma gacentIim : 'C_(R | to)(A) = 'C_(|to)(A).
Proof. by rewrite setIA setIid. Qed.
Lemma gacentS : A \subset B -> 'C_(|to)(B) \subset 'C_(|to)(A).
Proof. by move=> sAB; rewrite !(setIS, afixS). Qed.
Lemma gacentU : 'C_(|to)(A :|: B) = 'C_(|to)(A) :&: 'C_(|to)(B).
Proof. by rewrite -setIIr -afixU -setIUr. Qed.
Hypotheses (Da : a \in D) (sAD : A \subset D) (sSR : S \subset R).
Lemma gacentE : 'C_(|to)(A) = 'Fix_(R | to)(A).
Proof. by rewrite -{2}(setIidPr sAD). Qed.
Lemma gacent1E : 'C_(|to)[a] = 'Fix_(R | to)[a].
Proof. by rewrite /gacent [D :&: _](setIidPr _) ?sub1set. Qed.
Lemma subgacentE : 'C_(S | to)(A) = 'Fix_(S | to)(A).
Proof. by rewrite gacentE setIA (setIidPl sSR). Qed.
Lemma subgacent1E : 'C_(S | to)[a] = 'Fix_(S | to)[a].
Proof. by rewrite gacent1E setIA (setIidPl sSR). Qed.
End RawGroupAction.
Section GroupActionTheory.
Variables aT rT : finGroupType.
Variables (D : {group aT}) (R : {group rT}) (to : groupAction D R).
Implicit Type A B : {set aT}.
Implicit Types G H : {group aT}.
Implicit Type S : {set rT}.
Implicit Types M N : {group rT}.
Lemma gact1 : {in D, forall a, to 1 a = 1}.
Proof. by move=> a Da; rewrite /= -actmE ?morph1. Qed.
Lemma gactV : {in D, forall a, {in R, {morph to^~ a : x / x^-1}}}.
Proof. by move=> a Da /= x Rx; move; rewrite -!actmE ?morphV. Qed.
Lemma gactX : {in D, forall a n, {in R, {morph to^~ a : x / x ^+ n}}}.
Proof. by move=> a Da /= n x Rx; rewrite -!actmE // morphX. Qed.
Lemma gactJ : {in D, forall a, {in R &, {morph to^~ a : x y / x ^ y}}}.
Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphJ. Qed.
Lemma gactR : {in D, forall a, {in R &, {morph to^~ a : x y / [~ x, y]}}}.
Proof. by move=> a Da /= x Rx y Ry; rewrite -!actmE // morphR. Qed.
Lemma gact_stable : {acts D, on R | to}.
Proof.
apply: acts_act; apply/subsetP=> a Da; rewrite !inE Da.
apply/subsetP=> x; rewrite inE; apply: contraLR => R'xa.
by rewrite -(actKin to Da x) gact_out ?groupV.
Qed.
Lemma group_set_gacent A : group_set 'C_(|to)(A).
Proof.
apply/group_setP; split=> [|x y].
by rewrite !inE group1; apply/subsetP=> a /setIP[Da _]; rewrite inE gact1.
case/setIP=> Rx /afixP cAx /setIP[Ry /afixP cAy].
rewrite inE groupM //; apply/afixP=> a Aa.
by rewrite gactM ?cAx ?cAy //; case/setIP: Aa.
Qed.
Canonical gacent_group A := Group (group_set_gacent A).
Lemma gacent1 : 'C_(|to)(1) = R.
Proof. by rewrite /gacent (setIidPr (sub1G _)) afix1 setIT. Qed.
Lemma gacent_gen A : A \subset D -> 'C_(|to)(<<A>>) = 'C_(|to)(A).
Proof.
by move=> sAD; rewrite /gacent  ?gen_subG ?afix_gen_in.
Qed.
Lemma gacentD1 A : 'C_(|to)(A^#) = 'C_(|to)(A).
Proof.
rewrite -gacentIdom -gacent_gen ?subsetIl // setIDA genD1 ?group1 //.
by rewrite gacent_gen ?subsetIl // gacentIdom.
Qed.
Lemma gacent_cycle a : a \in D -> 'C_(|to)(<[a]>) = 'C_(|to)[a].
Proof. by move=> Da; rewrite gacent_gen ?sub1set. Qed.
Lemma gacentY A B :
A \subset D -> B \subset D -> 'C_(|to)(A <*> B) = 'C_(|to)(A) :&: 'C_(|to)(B).
Proof. by move=> sAD sBD; rewrite gacent_gen ?gacentU // subUset sAD. Qed.
Lemma gacentM G H :
G \subset D -> H \subset D -> 'C_(|to)(G * H) = 'C_(|to)(G) :&: 'C_(|to)(H).
Proof.
by move=> sGD sHB; rewrite -gacent_gen ?mul_subG // genM_join gacentY.
Qed.
Lemma astab1 : 'C(1 | to) = D.
Proof.
by apply/setP=> x; rewrite ?(inE, sub1set) andb_idr //; move/gact1=> ->.
Qed.
Lemma astab_range : 'C(R | to) = 'C(setT | to).
Proof.
apply/eqP; rewrite eqEsubset andbC astabS ?subsetT //=.
apply/subsetP=> a cRa; have Da := astab_dom cRa; rewrite !inE Da.
apply/subsetP=> x; rewrite -(setUCr R) !inE.
by case/orP=> ?; [rewrite (astab_act cRa) | rewrite gact_out].
Qed.
Lemma gacentC A S :
A \subset D -> S \subset R ->
(S \subset 'C_(|to)(A)) = (A \subset 'C(S | to)).
Proof. by move=> sAD sSR; rewrite subsetI sSR astabCin // (setIidPr sAD). Qed.
Lemma astab_gen S : S \subset R -> 'C(<<S>> | to) = 'C(S | to).
Proof.
move=> sSR; apply/setP=> a; case Da: (a \in D); last by rewrite !inE Da.
by rewrite -!sub1set -!gacentC ?sub1set ?gen_subG.
Qed.
Lemma astabM M N :
M \subset R -> N \subset R -> 'C(M * N | to) = 'C(M | to) :&: 'C(N | to).
Proof.
move=> sMR sNR; rewrite -astabU -astab_gen ?mul_subG // genM_join.
by rewrite astab_gen // subUset sMR.
Qed.
Lemma astabs1 : 'N(1 | to) = D.
Proof. by rewrite astabs_set1 astab1. Qed.
Lemma astabs_range : 'N(R | to) = D.
Proof.
apply/setIidPl; apply/subsetP=> a Da; rewrite inE.
by apply/subsetP=> x Rx; rewrite inE gact_stable.
Qed.
Lemma astabsD1 S : 'N(S^# | to) = 'N(S | to).
Proof.
case S1: (1 \in S); last first.
by rewrite (setDidPl _) // disjoint_sym disjoints_subset sub1set inE S1.
apply/eqP; rewrite eqEsubset andbC -{1}astabsIdom -{1}astabs1 setIC astabsD /=.
by rewrite -{2}(setD1K S1) -astabsIdom -{1}astabs1 astabsU.
Qed.
Lemma gacts_range A : A \subset D -> {acts A, on group R | to}.
Proof. by move=> sAD; split; rewrite ?astabs_range. Qed.
Lemma acts_subnorm_gacent A : A \subset D ->
[acts 'N_D(A), on 'C_(| to)(A) | to].
Proof.
move=> sAD; rewrite gacentE // actsI ?astabs_range ?subsetIl //.
by rewrite -{2}(setIidPr sAD) acts_subnorm_fix.
Qed.
Lemma acts_subnorm_subgacent A B S :
A \subset D -> [acts B, on S | to] -> [acts 'N_B(A), on 'C_(S | to)(A) | to].
Proof.
move=> sAD actsB; rewrite actsI //; first by rewrite subIset ?actsB.
by rewrite (subset_trans _ (acts_subnorm_gacent sAD)) ?setSI ?(acts_dom actsB).
Qed.
Lemma acts_gen A S :
S \subset R -> [acts A, on S | to] -> [acts A, on <<S>> | to].
Proof.
move=> sSR actsA; apply: {A}subset_trans actsA _.
apply/subsetP=> a nSa; have Da := astabs_dom nSa; rewrite !inE Da.
apply: subset_trans (_ : <<S>> \subset actm to a @*^-1 <<S>>) _.
rewrite gen_subG subsetI sSR; apply/subsetP=> x Sx.
by rewrite inE /= actmE ?mem_gen // astabs_act.
by apply/subsetP=> x /[!inE]; case/andP=> Rx; rewrite /= actmE.
Qed.
Lemma acts_joing A M N :
M \subset R -> N \subset R -> [acts A, on M | to] -> [acts A, on N | to] ->
[acts A, on M <*> N | to].
Proof. by move=> sMR sNR nMA nNA; rewrite acts_gen ?actsU // subUset sMR. Qed.
Lemma injm_actm a : 'injm (actm to a).
Proof.
apply/injmP=> x y Rx Ry; rewrite /= /actm; case: ifP => Da //.
exact: act_inj.
Qed.
Lemma im_actm a : actm to a @* R = R.
Proof.
apply/eqP; rewrite eqEcard (card_injm (injm_actm a)) // leqnn andbT.
apply/subsetP=> _ /morphimP[x Rx _ ->] /=.
by rewrite /actm; case: ifP => // Da; rewrite gact_stable.
Qed.
Lemma acts_char G M : G \subset D -> M \char R -> [acts G, on M | to].
Proof.
move=> sGD /charP[sMR charM].
apply/subsetP=> a Ga; have Da := subsetP sGD a Ga; rewrite !inE Da.
apply/subsetP=> x Mx; have Rx := subsetP sMR x Mx.
by rewrite inE -(charM _ (injm_actm a) (im_actm a)) -actmE // mem_morphim.
Qed.
Lemma gacts_char G M :
G \subset D -> M \char R -> {acts G, on group M | to}.
(* TODO: investigate why rewrite does not match in the same order *)
Proof. by move=> sGD charM; split; rewrite ?acts_char// char_sub. Qed.
(* was ending with rewrite (acts_char, char_sub)// *)
Section Restrict.
Variables (A : {group aT}) (sAD : A \subset D).
Lemma ract_is_groupAction : is_groupAction R (to \ sAD).
Proof. by move=> a Aa /=; rewrite ractpermE actperm_Aut ?(subsetP sAD). Qed.
Canonical ract_groupAction := GroupAction ract_is_groupAction.
Lemma gacent_ract B : 'C_(|ract_groupAction)(B) = 'C_(|to)(A :&: B).
Proof. by rewrite /gacent afix_ract setIA (setIidPr sAD). Qed.
End Restrict.
Section ActBy.
Variables (A : {group aT}) (G : {group rT}) (nGAg : {acts A, on group G | to}).
Lemma actby_is_groupAction : is_groupAction G <[nGAg]>.
Proof.
move=> a Aa; rewrite /= inE; apply/andP; split.
apply/subsetP=> x; apply: contraR => Gx.
by rewrite actpermE /= /actby (negbTE Gx).
apply/morphicP=> x y Gx Gy; rewrite !actpermE /= /actby Aa groupM ?Gx ?Gy //=.
by case nGAg; move/acts_dom; do 2!move/subsetP=> ?; rewrite gactM; auto.
Qed.
Canonical actby_groupAction := GroupAction actby_is_groupAction.
Lemma gacent_actby B :
'C_(|actby_groupAction)(B) = 'C_(G | to)(A :&: B).
Proof.
rewrite /gacent afix_actby !setIA setIid setIUr setICr set0U.
by have [nAG sGR] := nGAg; rewrite (setIidPr (acts_dom nAG)) (setIidPl sGR).
Qed.
End ActBy.
Section Quotient.
Variable H : {group rT}.
Lemma acts_qact_dom_norm : {acts qact_dom to H, on 'N(H) | to}.
Proof.
move=> a HDa /= x; rewrite {2}(('N(H) =P to^~ a @^-1: 'N(H)) _) ?inE {x}//.
rewrite eqEcard (card_preimset _ (act_inj _ _)) leqnn andbT.
apply/subsetP=> x Nx; rewrite inE; move/(astabs_act (H :* x)): HDa.
rewrite mem_rcosets mulSGid ?normG // Nx => /rcosetsP[y Ny defHy].
suffices: to x a \in H :* y by apply: subsetP; rewrite mul_subG ?sub1set ?normG.
by rewrite -defHy; apply: imset_f; apply: rcoset_refl.
Qed.
Lemma qact_is_groupAction : is_groupAction (R / H) (to / H).
Proof.
move=> a HDa /=; have Da := astabs_dom HDa.
rewrite inE; apply/andP; split.
apply/subsetP=> Hx /=; case: (cosetP Hx) => x Nx ->{Hx}.
apply: contraR => R'Hx; rewrite actpermE qactE // gact_out //.
by apply: contra R'Hx; apply: mem_morphim.
apply/morphicP=> Hx Hy; rewrite !actpermE.
case/morphimP=> x Nx Gx ->{Hx}; case/morphimP=> y Ny Gy ->{Hy}.
by rewrite -morphM ?qactE ?groupM ?gactM // morphM ?acts_qact_dom_norm.
Qed.
Canonical quotient_groupAction := GroupAction qact_is_groupAction.
Lemma qact_domE : H \subset R -> qact_dom to H = 'N(H | to).
Proof.
move=> sHR; apply/setP=> a; apply/idP/idP=> nHa; have Da := astabs_dom nHa.
rewrite !inE Da; apply/subsetP=> x Hx; rewrite inE -(rcoset1 H).
have /rcosetsP[y Ny defHy]: to^~ a @: H \in rcosets H 'N(H).
by rewrite (astabs_act _ nHa); apply/rcosetsP; exists 1; rewrite ?mulg1.
by rewrite (rcoset_eqP (_ : 1 \in H :* y)) -defHy -1?(gact1 Da) mem_setact.
rewrite !inE Da; apply/subsetP=> Hx /[1!inE] /rcosetsP[x Nx ->{Hx}].
apply/imsetP; exists (to x a).
case Rx: (x \in R); last by rewrite gact_out ?Rx.
rewrite inE; apply/subsetP=> _ /imsetP[y Hy ->].
rewrite -(actKVin to Da y) -gactJ // ?(subsetP sHR, astabs_act, groupV) //.
by rewrite memJ_norm // astabs_act ?groupV.
apply/eqP; rewrite rcosetE eqEcard.
rewrite (card_imset _ (act_inj _ _)) !card_rcoset leqnn andbT.
apply/subsetP=> _ /imsetP[y Hxy ->]; rewrite !mem_rcoset in Hxy *.
have Rxy := subsetP sHR _ Hxy; rewrite -(mulgKV x y).
case Rx: (x \in R); last by rewrite !gact_out ?mulgK // 1?groupMl ?Rx.
by rewrite -gactV // -gactM 1?groupMr ?groupV // mulgK astabs_act.
Qed.
End Quotient.
Section Mod.
Variable H : {group aT}.
Lemma modact_is_groupAction : is_groupAction 'C_(|to)(H) (to %% H).
Proof.
move=> Ha /morphimP[a Na Da ->]; have NDa: a \in 'N_D(H) by apply/setIP.
rewrite inE; apply/andP; split.
apply/subsetP=> x; rewrite 2!inE andbC actpermE /= modactEcond //.
by apply: contraR; case: ifP => // E Rx; rewrite gact_out.
apply/morphicP=> x y /setIP[Rx cHx] /setIP[Ry cHy].
rewrite /= !actpermE /= !modactE ?gactM //.
suffices: x * y \in 'C_(|to)(H) by case/setIP.
by rewrite groupM //; apply/setIP.
Qed.
Canonical mod_groupAction := GroupAction modact_is_groupAction.
Lemma modgactE x a :
H \subset 'C(R | to) -> a \in 'N_D(H) -> (to %% H)%act x (coset H a) = to x a.
Proof.
move=> cRH NDa /=; have [Da Na] := setIP NDa.
have [Rx | notRx] := boolP (x \in R).
by rewrite modactE //; apply/afixP=> b /setIP[_ /(subsetP cRH)/astab_act->].
rewrite gact_out //= /modact; case: ifP => // _; rewrite gact_out //.
suffices: a \in D :&: coset H a by case/mem_repr/setIP.
by rewrite inE Da val_coset // rcoset_refl.
Qed.
Lemma gacent_mod G M :
H \subset 'C(M | to) -> G \subset 'N(H) ->
'C_(M | mod_groupAction)(G / H) = 'C_(M | to)(G).
Proof.
move=> cMH nHG; rewrite -gacentIdom gacentE ?subsetIl // setICA.
have sHD: H \subset D by rewrite (subset_trans cMH) ?subsetIl.
rewrite -quotientGI // afix_mod ?setIS // setICA -gacentIim (setIC R) -setIA.
rewrite -gacentE ?subsetIl // gacentIdom setICA (setIidPr _) //.
by rewrite gacentC // ?(subset_trans cMH) ?astabS ?subsetIl // setICA subsetIl.
Qed.
Lemma acts_irr_mod G M :
H \subset 'C(M | to) -> G \subset 'N(H) -> acts_irreducibly G M to ->
acts_irreducibly (G / H) M mod_groupAction.
Proof.
move=> cMH nHG /mingroupP[/andP[ntM nMG] minM].
apply/mingroupP; rewrite ntM astabs_mod ?quotientS //; split=> // L modL ntL.
have cLH: H \subset 'C(L | to) by rewrite (subset_trans cMH) ?astabS //.
apply: minM => //; case/andP: modL => ->; rewrite astabs_mod ?quotientSGK //.
by rewrite (subset_trans cLH) ?astab_sub.
Qed.
End Mod.
Lemma modact_coset_astab x a :
a \in D -> (to %% 'C(R | to))%act x (coset _ a) = to x a.
Proof.
move=> Da; apply: modgactE => {x}//.
rewrite !inE Da; apply/subsetP=> _ /imsetP[c Cc ->].
have Dc := astab_dom Cc; rewrite !inE groupJ //.
apply/subsetP=> x Rx; rewrite inE conjgE !actMin ?groupM ?groupV //.
by rewrite (astab_act Cc) ?actKVin // gact_stable ?groupV.
Qed.
Lemma acts_irr_mod_astab G M :
acts_irreducibly G M to ->
acts_irreducibly (G / 'C_G(M | to)) M (mod_groupAction _).
Proof.
move=> irrG; have /andP[_ nMG] := mingroupp irrG.
apply: acts_irr_mod irrG; first exact: subsetIr.
by rewrite normsI ?normG // (subset_trans nMG) // astab_norm.
Qed.
Section CompAct.
Variables (gT : finGroupType) (G : {group gT}) (f : {morphism G >-> aT}).
Lemma comp_is_groupAction : is_groupAction R (comp_action to f).
Proof.
move=> a /morphpreP[Ba Dfa]; apply: etrans (actperm_Aut to Dfa).
by congr (_ \in Aut R); apply/permP=> x; rewrite !actpermE.
Qed.
Canonical comp_groupAction := GroupAction comp_is_groupAction.
Lemma gacent_comp U : 'C_(|comp_groupAction)(U) = 'C_(|to)(f @* U).
Proof.
rewrite /gacent afix_comp ?subIset ?subxx //.
by rewrite -(setIC U) (setIC D) morphim_setIpre.
Qed.
End CompAct.
End GroupActionTheory.
Notation "''C_' ( | to ) ( A )" := (gacent_group to A) : Group_scope.
Notation "''C_' ( G | to ) ( A )" :=
(setI_group G 'C_(|to)(A)) : Group_scope.
Notation "''C_' ( | to ) [ a ]" := (gacent_group to [set a%g]) : Group_scope.
Notation "''C_' ( G | to ) [ a ]" :=
(setI_group G 'C_(|to)[a]) : Group_scope.
Notation "to \ sAD" := (ract_groupAction to sAD) : groupAction_scope.
Notation "<[ nGA ] >" := (actby_groupAction nGA) : groupAction_scope.
Notation "to / H" := (quotient_groupAction to H) : groupAction_scope.
Notation "to %% H" := (mod_groupAction to H) : groupAction_scope.
Notation "to \o f" := (comp_groupAction to f) : groupAction_scope.
(* Operator group isomorphism. *)
Section MorphAction.
Variables (aT1 aT2 : finGroupType) (rT1 rT2 : finType).
Variables (D1 : {group aT1}) (D2 : {group aT2}).
Variables (to1 : action D1 rT1) (to2 : action D2 rT2).
Variables (A : {set aT1}) (R S : {set rT1}).
Variables (h : rT1 -> rT2) (f : {morphism D1 >-> aT2}).
Hypotheses (actsDR : {acts D1, on R | to1}) (injh : {in R &, injective h}).
Hypothesis defD2 : f @* D1 = D2.
Hypotheses (sSR : S \subset R) (sAD1 : A \subset D1).
Hypothesis hfJ : {in S & D1, morph_act to1 to2 h f}.
Lemma morph_astabs : f @* 'N(S | to1) = 'N(h @: S | to2).
Proof.
apply/setP=> fx; apply/morphimP/idP=> [[x D1x nSx ->] | nSx].
rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->].
by rewrite inE -hfJ ?imset_f // (astabs_act _ nSx).
have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1).
by rewrite defD2 (astabs_dom nSx).
exists x => //; rewrite !inE D1x; apply/subsetP=> u Su.
have /imsetP[u' Su' /injh def_u']: h (to1 u x) \in h @: S.
by rewrite hfJ // -def_fx (astabs_act _ nSx) imset_f.
by rewrite inE def_u' ?actsDR ?(subsetP sSR).
Qed.
Lemma morph_astab : f @* 'C(S | to1) = 'C(h @: S | to2).
Proof.
apply/setP=> fx; apply/morphimP/idP=> [[x D1x cSx ->] | cSx].
rewrite 2!inE -{1}defD2 mem_morphim //=; apply/subsetP=> _ /imsetP[u Su ->].
by rewrite inE -hfJ // (astab_act cSx).
have [|x D1x _ def_fx] := morphimP (_ : fx \in f @* D1).
by rewrite defD2 (astab_dom cSx).
exists x => //; rewrite !inE D1x; apply/subsetP=> u Su.
rewrite inE -(inj_in_eq injh) ?actsDR ?(subsetP sSR) ?hfJ //.
by rewrite -def_fx (astab_act cSx) ?imset_f.
Qed.
Lemma morph_afix : h @: 'Fix_(S | to1)(A) = 'Fix_(h @: S | to2)(f @* A).
Proof.
apply/setP=> hu; apply/imsetP/setIP=> [[u /setIP[Su cAu] ->]|].
split; first by rewrite imset_f.
by apply/afixP=> _ /morphimP[x D1x Ax ->]; rewrite -hfJ ?(afixP cAu).
case=> /imsetP[u Su ->] /afixP c_hu_fA; exists u; rewrite // inE Su.
apply/afixP=> x Ax; have Dx := subsetP sAD1 x Ax.
by apply: injh; rewrite ?actsDR ?(subsetP sSR) ?hfJ // c_hu_fA ?mem_morphim.
Qed.
End MorphAction.
Section MorphGroupAction.
Variables (aT1 aT2 rT1 rT2 : finGroupType).
Variables (D1 : {group aT1}) (D2 : {group aT2}).
Variables (R1 : {group rT1}) (R2 : {group rT2}).
Variables (to1 : groupAction D1 R1) (to2 : groupAction D2 R2).
Variables (h : {morphism R1 >-> rT2}) (f : {morphism D1 >-> aT2}).
Hypotheses (iso_h : isom R1 R2 h) (iso_f : isom D1 D2 f).
Hypothesis hfJ : {in R1 & D1, morph_act to1 to2 h f}.
Implicit Types (A : {set aT1}) (S : {set rT1}) (M : {group rT1}).
Lemma morph_gastabs S : S \subset R1 -> f @* 'N(S | to1) = 'N(h @* S | to2).
Proof.
have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h).
move=> sSR1; rewrite (morphimEsub _ sSR1).
apply: (morph_astabs (gact_stable to1) (injmP injh)) => // u x.
by move/(subsetP sSR1); apply: hfJ.
Qed.
Lemma morph_gastab S : S \subset R1 -> f @* 'C(S | to1) = 'C(h @* S | to2).
Proof.
have [[_ defD2] [injh _]] := (isomP iso_f, isomP iso_h).
move=> sSR1; rewrite (morphimEsub _ sSR1).
apply: (morph_astab (gact_stable to1) (injmP injh)) => // u x.
by move/(subsetP sSR1); apply: hfJ.
Qed.
Lemma morph_gacent A : A \subset D1 -> h @* 'C_(|to1)(A) = 'C_(|to2)(f @* A).
Proof.
have [[_ defD2] [injh defR2]] := (isomP iso_f, isomP iso_h).
move=> sAD1; rewrite !gacentE //; last by rewrite -defD2 morphimS.
rewrite morphimEsub ?subsetIl // -{1}defR2 morphimEdom.
exact: (morph_afix (gact_stable to1) (injmP injh)).
Qed.
Lemma morph_gact_irr A M :
A \subset D1 -> M \subset R1 ->
acts_irreducibly (f @* A) (h @* M) to2 = acts_irreducibly A M to1.
Proof.
move=> sAD1 sMR1.
have [[injf defD2] [injh defR2]] := (isomP iso_f, isomP iso_h).
have h_eq1 := morphim_injm_eq1 injh.
apply/mingroupP/mingroupP=> [] [/andP[ntM actAM] minM].
split=> [|U]; first by rewrite -h_eq1 // ntM -(injmSK injf) ?morph_gastabs.
case/andP=> ntU acts_fAU sUM; have sUR1 := subset_trans sUM sMR1.
apply: (injm_morphim_inj injh) => //; apply: minM; last exact: morphimS.
by rewrite h_eq1 // ntU -morph_gastabs ?morphimS.
split=> [|U]; first by rewrite h_eq1 // ntM -morph_gastabs ?morphimS.
case/andP=> ntU acts_fAU sUhM.
have sUhR1 := subset_trans sUhM (morphimS h sMR1).
have sU'M: h @*^-1 U \subset M by rewrite sub_morphpre_injm.
rewrite /= -(minM _ _ sU'M) ?morphpreK // -h_eq1 ?subsetIl // -(injmSK injf) //.
by rewrite morph_gastabs ?(subset_trans sU'M) // morphpreK ?ntU.
Qed.
End MorphGroupAction.
(* Conjugation and right translation actions. *)
Section InternalActionDefs.
Variable gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Type G : {group gT}.
(* This is not a Canonical action because it is seldom used, and it would *)
(* cause too many spurious matches (any group product would be viewed as an *)
(* action!). *)
Definition mulgr_action := TotalAction (@mulg1 gT) (@mulgA gT).
Canonical conjg_action := TotalAction (@conjg1 gT) (@conjgM gT).
Lemma conjg_is_groupAction : is_groupAction setT conjg_action.
Proof.
move=> a _; rewrite inE; apply/andP; split; first by apply/subsetP=> x /[1!inE].
by apply/morphicP=> x y _ _; rewrite !actpermE /= conjMg.
Qed.
Canonical conjg_groupAction := GroupAction conjg_is_groupAction.
Lemma rcoset_is_action : is_action setT (@rcoset gT).
Proof.
by apply: is_total_action => [A|A x y]; rewrite !rcosetE (mulg1, rcosetM).
Qed.
Canonical rcoset_action := Action rcoset_is_action.
Canonical conjsg_action := TotalAction (@conjsg1 gT) (@conjsgM gT).
Lemma conjG_is_action : is_action setT (@conjG_group gT).
Proof.
apply: is_total_action => [G | G x y]; apply: val_inj; rewrite /= ?act1 //.
exact: actM.
Qed.
Definition conjG_action := Action conjG_is_action.
End InternalActionDefs.
Notation "'R" := (@mulgr_action _) : action_scope.
Notation "'Rs" := (@rcoset_action _) : action_scope.
Notation "'J" := (@conjg_action _) : action_scope.
Notation "'J" := (@conjg_groupAction _) : groupAction_scope.
Notation "'Js" := (@conjsg_action _) : action_scope.
Notation "'JG" := (@conjG_action _) : action_scope.
Notation "'Q" := ('J / _)%act : action_scope.
Notation "'Q" := ('J / _)%gact : groupAction_scope.
Section InternalGroupAction.
Variable gT : finGroupType.
Implicit Types A B : {set gT}.
Implicit Types G H : {group gT}.
Implicit Type x : gT.
(* Various identities for actions on groups. *)
Lemma orbitR G x : orbit 'R G x = x *: G.
Proof. by rewrite -lcosetE. Qed.
Lemma astab1R x : 'C[x | 'R] = 1.
Proof.
apply/trivgP/subsetP=> y cxy.
by rewrite -(mulKg x y) [x * y](astab1P cxy) mulVg set11.
Qed.
Lemma astabR G : 'C(G | 'R) = 1.
Proof.
apply/trivgP/subsetP=> x cGx.
by rewrite -(mul1g x) [1 * x](astabP cGx) group1.
Qed.
Lemma astabsR G : 'N(G | 'R) = G.
Proof.
apply/setP=> x; rewrite !inE -setactVin ?inE //=.
by rewrite -groupV -{1 3}(mulg1 G) rcoset_sym -sub1set -mulGS -!rcosetE.
Qed.
Lemma atransR G : [transitive G, on G | 'R].
Proof. by rewrite /atrans -{1}(mul1g G) -orbitR imset_f. Qed.
Lemma faithfulR G : [faithful G, on G | 'R].
Proof. by rewrite /faithful astabR subsetIr. Qed.
Definition Cayley_repr G := actperm <[atrans_acts (atransR G)]>.
Theorem Cayley_isom G : isom G (Cayley_repr G @* G) (Cayley_repr G).
Proof. exact: faithful_isom (faithfulR G). Qed.
Theorem Cayley_isog G : G \isog Cayley_repr G @* G.
Proof. exact: isom_isog (Cayley_isom G). Qed.
Lemma orbitJ G x : orbit 'J G x = x ^: G. Proof. by []. Qed.
Lemma afixJ A : 'Fix_('J)(A) = 'C(A).
Proof.
apply/setP=> x; apply/afixP/centP=> cAx y Ay /=.
by rewrite /commute conjgC cAx.
by rewrite conjgE cAx ?mulKg.
Qed.
Lemma astabJ A : 'C(A |'J) = 'C(A).
Proof.
apply/setP=> x; apply/astabP/centP=> cAx y Ay /=.
by apply: esym; rewrite conjgC cAx.
by rewrite conjgE -cAx ?mulKg.
Qed.
Lemma astab1J x : 'C[x |'J] = 'C[x].
Proof. by rewrite astabJ cent_set1. Qed.
Lemma astabsJ A : 'N(A | 'J) = 'N(A).
Proof. by apply/setP=> x; rewrite -2!groupV !inE -conjg_preim -sub_conjg. Qed.
Lemma setactJ A x : 'J^*%act A x = A :^ x. Proof. by []. Qed.
Lemma gacentJ A : 'C_(|'J)(A) = 'C(A).
Proof. by rewrite gacentE ?setTI ?subsetT ?afixJ. Qed.
Lemma orbitRs G A : orbit 'Rs G A = rcosets A G. Proof. by []. Qed.
Lemma sub_afixRs_norms G x A : (G :* x \in 'Fix_('Rs)(A)) = (A \subset G :^ x).
Proof.
rewrite inE /=; apply: eq_subset_r => a.
rewrite inE rcosetE -(can2_eq (rcosetKV x) (rcosetK x)) -!rcosetM.
rewrite eqEcard card_rcoset leqnn andbT mulgA (conjgCV x) mulgK.
by rewrite -{2 3}(mulGid G) mulGS sub1set -mem_conjg.
Qed.
Lemma sub_afixRs_norm G x : (G :* x \in 'Fix_('Rs)(G)) = (x \in 'N(G)).
Proof. by rewrite sub_afixRs_norms -groupV inE sub_conjgV. Qed.
Lemma afixRs_rcosets A G : 'Fix_(rcosets G A | 'Rs)(G) = rcosets G 'N_A(G).
Proof.
apply/setP=> Gx; apply/setIP/rcosetsP=> [[/rcosetsP[x Ax ->]]|[x]].
by rewrite sub_afixRs_norm => Nx; exists x; rewrite // inE Ax.
by case/setIP=> Ax Nx ->; rewrite -{1}rcosetE imset_f // sub_afixRs_norm.
Qed.
Lemma astab1Rs G : 'C[G : {set gT} | 'Rs] = G.
Proof.
apply/setP=> x.
by apply/astab1P/idP=> /= [<- | Gx]; rewrite rcosetE ?rcoset_refl ?rcoset_id.
Qed.
Lemma actsRs_rcosets H G : [acts G, on rcosets H G | 'Rs].
Proof. by rewrite -orbitRs acts_orbit ?subsetT. Qed.
Lemma transRs_rcosets H G : [transitive G, on rcosets H G | 'Rs].
Proof. by rewrite -orbitRs atrans_orbit. Qed.
(* This is the second part of Aschbacher (5.7) *)
Lemma astabRs_rcosets H G : 'C(rcosets H G | 'Rs) = gcore H G.
Proof.
have transGH := transRs_rcosets H G.
by rewrite (astab_trans_gcore transGH (orbit_refl _ G _)) astab1Rs.
Qed.
Lemma orbitJs G A : orbit 'Js G A = A :^: G. Proof. by []. Qed.
Lemma astab1Js A : 'C[A | 'Js] = 'N(A).
Proof. by apply/setP=> x; apply/astab1P/normP. Qed.
Lemma card_conjugates A G : #|A :^: G| = #|G : 'N_G(A)|.
Proof. by rewrite card_orbit astab1Js. Qed.
Lemma afixJG G A : (G \in 'Fix_('JG)(A)) = (A \subset 'N(G)).
Proof. by apply/afixP/normsP=> nG x Ax; apply/eqP; move/eqP: (nG x Ax). Qed.
Lemma astab1JG G : 'C[G | 'JG] = 'N(G).
Proof.
by apply/setP=> x; apply/astab1P/normP=> [/congr_group | /group_inj].
Qed.
Lemma dom_qactJ H : qact_dom 'J H = 'N(H).
Proof. by rewrite qact_domE ?subsetT ?astabsJ. Qed.
Lemma qactJ H (Hy : coset_of H) x :
'Q%act Hy x = if x \in 'N(H) then Hy ^ coset H x else Hy.
Proof.
case: (cosetP Hy) => y Ny ->{Hy}.
by rewrite qactEcond // dom_qactJ; case Nx: (x \in 'N(H)); rewrite ?morphJ.
Qed.
Lemma actsQ A B H :
A \subset 'N(H) -> A \subset 'N(B) -> [acts A, on B / H | 'Q].
Proof.
by move=> nHA nBA; rewrite acts_quotient // subsetI dom_qactJ nHA astabsJ.
Qed.
Lemma astabsQ G H : H <| G -> 'N(G / H | 'Q) = 'N(H) :&: 'N(G).
Proof. by move=> nsHG; rewrite astabs_quotient // dom_qactJ astabsJ. Qed.
Lemma astabQ H Abar : 'C(Abar |'Q) = coset H @*^-1 'C(Abar).
Proof.
apply/setP=> x; rewrite inE /= dom_qactJ morphpreE in_setI /=.
apply: andb_id2l => Nx; rewrite !inE -sub1set centsC cent_set1.
apply: eq_subset_r => {Abar} Hy; rewrite inE qactJ Nx (sameP eqP conjg_fixP).
by rewrite (sameP cent1P eqP) (sameP commgP eqP).
Qed.
Lemma sub_astabQ A H Bbar :
(A \subset 'C(Bbar | 'Q)) = (A \subset 'N(H)) && (A / H \subset 'C(Bbar)).
Proof.
rewrite astabQ -morphpreIdom subsetI; apply: andb_id2l => nHA.
by rewrite -sub_quotient_pre.
Qed.
Lemma sub_astabQR A B H :
A \subset 'N(H) -> B \subset 'N(H) ->
(A \subset 'C(B / H | 'Q)) = ([~: A, B] \subset H).
Proof.
move=> nHA nHB; rewrite sub_astabQ nHA /= (sameP commG1P eqP).
by rewrite eqEsubset sub1G andbT -quotientR // quotient_sub1 // comm_subG.
Qed.
Lemma astabQR A H : A \subset 'N(H) ->
'C(A / H | 'Q) = [set x in 'N(H) | [~: [set x], A] \subset H].
Proof.
move=> nHA; apply/setP=> x; rewrite astabQ -morphpreIdom 2!inE -astabQ.
by case nHx: (x \in _); rewrite //= -sub1set sub_astabQR ?sub1set.
Qed.
Lemma quotient_astabQ H Abar : 'C(Abar | 'Q) / H = 'C(Abar).
Proof. by rewrite astabQ cosetpreK. Qed.
Lemma conj_astabQ A H x :
x \in 'N(H) -> 'C(A / H | 'Q) :^ x = 'C(A :^ x / H | 'Q).
Proof.
move=> nHx; apply/setP=> y; rewrite !astabQ mem_conjg !in_setI -mem_conjg.
rewrite -normJ (normP nHx) quotientJ //; apply/andb_id2l => nHy.
by rewrite !inE centJ morphJ ?groupV ?morphV // -mem_conjg.
Qed.
Section CardClass.
Variable G : {group gT}.
Lemma index_cent1 x : #|G : 'C_G[x]| = #|x ^: G|.
Proof. by rewrite -astab1J -card_orbit. Qed.
Lemma classes_partition : partition (classes G) G.
Proof. by apply: orbit_partition; apply/actsP=> x Gx y; apply: groupJr. Qed.
Lemma sum_card_class : \sum_(C in classes G) #|C| = #|G|.
Proof. by apply: acts_sum_card_orbit; apply/actsP=> x Gx y; apply: groupJr. Qed.
Lemma class_formula : \sum_(C in classes G) #|G : 'C_G[repr C]| = #|G|.
Proof.
rewrite -sum_card_class; apply: eq_bigr => _ /imsetP[x Gx ->].
have: x \in x ^: G by rewrite -{1}(conjg1 x) imset_f.
by case/mem_repr/imsetP=> y Gy ->; rewrite index_cent1 classGidl.
Qed.
Lemma abelian_classP : reflect {in G, forall x, x ^: G = [set x]} (abelian G).
Proof.
rewrite /abelian -astabJ astabC.
by apply: (iffP subsetP) => cGG x Gx; apply/orbit1P; apply: cGG.
Qed.
Lemma card_classes_abelian : abelian G = (#|classes G| == #|G|).
Proof.
have cGgt0 C: C \in classes G -> 1 <= #|C| ?= iff (#|C| == 1)%N.
by case/imsetP=> x _ ->; rewrite eq_sym -index_cent1.
rewrite -sum_card_class -sum1_card (leqif_sum cGgt0).
apply/abelian_classP/forall_inP=> [cGG _ /imsetP[x Gx ->]| cGG x Gx].
by rewrite cGG ?cards1.
apply/esym/eqP; rewrite eqEcard sub1set cards1 class_refl leq_eqVlt cGG //.
exact: imset_f.
Qed.
End CardClass.
End InternalGroupAction.
Lemma gacentQ (gT : finGroupType) (H : {group gT}) (A : {set gT}) :
'C_(|'Q)(A) = 'C(A / H).
Proof.
apply/setP=> Hx; case: (cosetP Hx) => x Nx ->{Hx}.
rewrite -sub_cent1 -astab1J astabC sub1set -(quotientInorm H A).
have defD: qact_dom 'J H = 'N(H) by rewrite qact_domE ?subsetT ?astabsJ.
rewrite !(inE, mem_quotient) //= defD setIC.
apply/subsetP/subsetP=> [cAx _ /morphimP[a Na Aa ->] | cAx a Aa].
by move/cAx: Aa; rewrite !inE qactE ?defD ?morphJ.
have [_ Na] := setIP Aa; move/implyP: (cAx (coset H a)); rewrite mem_morphim //.
by rewrite !inE qactE ?defD ?morphJ.
Qed.
Section AutAct.
Variable (gT : finGroupType) (G : {set gT}).
Definition autact := act ('P \ subsetT (Aut G)).
Canonical aut_action := [action of autact].
Lemma autactK a : actperm aut_action a = a.
Proof. by apply/permP=> x; rewrite permE. Qed.
Lemma autact_is_groupAction : is_groupAction G aut_action.
Proof. by move=> a Aa /=; rewrite autactK. Qed.
Canonical aut_groupAction := GroupAction autact_is_groupAction.
Section perm_prime_orbit.
Variable (T : finType) (c : {perm T}).
Hypothesis Tp : prime #|T|.
Hypothesis cc : #[c]%g = #|T|.
Let cp : prime #[c]%g. Proof. by rewrite cc. Qed.
Lemma perm_prime_atrans : [transitive <[c]>, on setT | 'P].
Proof.
apply/imsetP; suff /existsP[x] : [exists x, ~~ (#|orbit 'P <[c]> x| < #[c])].
move=> oxT; suff /eqP orbit_x : orbit 'P <[c]> x == setT by exists x.
by rewrite eqEcard subsetT cardsT -cc leqNgt.
apply/forallP => olT; have o1 x : #|orbit 'P <[c]> x| == 1%N.
by case/primeP: cp => _ /(_ _ (dvdn_orbit 'P _ x))/orP[]//; rewrite ltn_eqF.
suff c1 : c = 1%g by rewrite c1 ?order1 in (cp).
apply/permP => x; rewrite perm1; apply/set1P.
by rewrite -(card_orbit1 (eqP (o1 _))) (mem_orbit 'P) ?cycle_id.
Qed.
Lemma perm_prime_orbit x : orbit 'P <[c]> x = [set: T].
Proof. by apply: atransP => //; apply: perm_prime_atrans. Qed.
Lemma perm_prime_astab x : 'C_<[c]>[x | 'P]%g = 1%g.
Proof.
by apply/card1_trivg/eqP; rewrite -(@eqn_pmul2l #|orbit 'P <[c]> x|)
?card_orbit_stab ?perm_prime_orbit ?cardsT ?muln1 ?prime_gt0// -cc.
Qed.
End perm_prime_orbit.
End AutAct.
Arguments autact {gT} G%_g.
Arguments aut_action {gT} G%_g.
Arguments aut_groupAction {gT} G%_g.
Notation "[ 'Aut' G ]" := (aut_action G) : action_scope.
Notation "[ 'Aut' G ]" := (aut_groupAction G) : groupAction_scope.
|
Basic.lean
|
/-
Copyright (c) 2022 Jakob von Raumer. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jakob von Raumer, Kevin Klinge, Andrew Yang
-/
import Mathlib.GroupTheory.OreLocalization.OreSet
import Mathlib.Tactic.Common
import Mathlib.Algebra.Group.Submonoid.MulAction
import Mathlib.Algebra.Group.Units.Defs
import Mathlib.Algebra.Group.Basic
/-!
# Localization over left Ore sets.
This file defines the localization of a monoid over a left Ore set and proves its universal
mapping property.
## Notations
Introduces the notation `R[Sβ»ΒΉ]` for the Ore localization of a monoid `R` at a right Ore
subset `S`. Also defines a new heterogeneous division notation `r /β s` for a numerator `r : R` and
a denominator `s : S`.
## References
* <https://ncatlab.org/nlab/show/Ore+localization>
* [Zoran Ε koda, *Noncommutative localization in noncommutative geometry*][skoda2006]
## Tags
localization, Ore, non-commutative
-/
assert_not_exists RelIso MonoidWithZero
universe u
open OreLocalization
namespace OreLocalization
variable {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S] (X) [MulAction R X]
/-- The setoid on `R Γ S` used for the Ore localization. -/
@[to_additive AddOreLocalization.oreEqv /-- The setoid on `R Γ S` used for the Ore localization. -/]
def oreEqv : Setoid (X Γ S) where
r rs rs' := β (u : S) (v : R), u β’ rs'.1 = v β’ rs.1 β§ u * rs'.2 = v * rs.2
iseqv := by
refine β¨fun _ => β¨1, 1, by simpβ©, ?_, ?_β©
Β· rintro β¨r, sβ© β¨r', s'β© β¨u, v, hru, hsuβ©; dsimp only at *
rcases oreCondition (s : R) s' with β¨rβ, sβ, hββ©
rcases oreCondition rβ u with β¨rβ, sβ, hββ©
have : rβ * v * s = sβ * sβ * s := by
-- Porting note: the proof used `assoc_rw`
rw [mul_assoc _ (sβ : R), hβ, β mul_assoc, hβ, mul_assoc, β hsu, β mul_assoc]
rcases ore_right_cancel (rβ * v) (sβ * sβ) s this with β¨w, hwβ©
refine β¨w * (sβ * sβ), w * (rβ * u), ?_, ?_β© <;>
simp only [Submonoid.coe_mul, Submonoid.smul_def, β hw]
Β· simp only [mul_smul, hru, β Submonoid.smul_def]
Β· simp only [mul_assoc, hsu]
Β· rintro β¨rβ, sββ© β¨rβ, sββ© β¨rβ, sββ© β¨u, v, hurβ, hsβuβ© β¨u', v', hurβ, hsβuβ©
rcases oreCondition v' u with β¨r', s', hβ©; dsimp only at *
refine β¨s' * u', r' * v, ?_, ?_β© <;>
simp only [Submonoid.smul_def, Submonoid.coe_mul, mul_smul, mul_assoc] at *
Β· rw [hurβ, smul_smul, h, mul_smul, hurβ]
Β· rw [hsβu, β mul_assoc, h, mul_assoc, hsβu]
end OreLocalization
/-- The Ore localization of a monoid and a submonoid fulfilling the Ore condition. -/
@[to_additive AddOreLocalization /-- The Ore localization of an additive monoid and a submonoid
fulfilling the Ore condition. -/]
def OreLocalization {R : Type*} [Monoid R] (S : Submonoid R) [OreSet S]
(X : Type*) [MulAction R X] :=
Quotient (OreLocalization.oreEqv S X)
namespace OreLocalization
section Monoid
variable (R : Type*) [Monoid R] (S : Submonoid R) [OreSet S]
@[inherit_doc OreLocalization]
scoped syntax:1075 term noWs atomic("[" term "β»ΒΉ" noWs "]") : term
macro_rules | `($R[$Sβ»ΒΉ]) => ``(OreLocalization $S $R)
attribute [local instance] oreEqv
variable {R S}
variable {X} [MulAction R X]
/-- The division in the Ore localization `X[Sβ»ΒΉ]`, as a fraction of an element of `X` and `S`. -/
@[to_additive /-- The subtraction in the Ore localization,
as a difference of an element of `X` and `S`. -/]
def oreDiv (r : X) (s : S) : X[Sβ»ΒΉ] :=
Quotient.mk' (r, s)
@[inherit_doc]
infixl:70 " /β " => oreDiv
@[inherit_doc]
infixl:65 " -β " => _root_.AddOreLocalization.oreSub
@[to_additive (attr := elab_as_elim, cases_eliminator, induction_eliminator)]
protected theorem ind {Ξ² : X[Sβ»ΒΉ] β Prop}
(c : β (r : X) (s : S), Ξ² (r /β s)) : β q, Ξ² q := by
apply Quotient.ind
rintro β¨r, sβ©
exact c r s
@[to_additive]
theorem oreDiv_eq_iff {rβ rβ : X} {sβ sβ : S} :
rβ /β sβ = rβ /β sβ β β (u : S) (v : R), u β’ rβ = v β’ rβ β§ u * sβ = v * sβ :=
Quotient.eq''
/-- A fraction `r /β s` is equal to its expansion by an arbitrary factor `t` if `t * s β S`. -/
@[to_additive /-- A difference `r -β s` is equal to its expansion by an
arbitrary translation `t` if `t + s β S`. -/]
protected theorem expand (r : X) (s : S) (t : R) (hst : t * (s : R) β S) :
r /β s = t β’ r /β β¨t * s, hstβ© := by
apply Quotient.sound
exact β¨s, s * t, by rw [mul_smul, Submonoid.smul_def], by rw [β mul_assoc]β©
/-- A fraction is equal to its expansion by a factor from `S`. -/
@[to_additive /-- A difference is equal to its expansion by a summand from `S`. -/]
protected theorem expand' (r : X) (s s' : S) : r /β s = s' β’ r /β (s' * s) :=
OreLocalization.expand r s s' (by norm_cast; apply SetLike.coe_mem)
/-- Fractions which differ by a factor of the numerator can be proven equal if
those factors expand to equal elements of `R`. -/
@[to_additive /-- Differences whose minuends differ by a common summand can be proven equal if
those summands expand to equal elements of `R`. -/]
protected theorem eq_of_num_factor_eq {r r' rβ rβ : R} {s t : S} (h : t * r = t * r') :
rβ * r * rβ /β s = rβ * r' * rβ /β s := by
rcases oreCondition rβ t with β¨rβ', t', hrββ©
rw [OreLocalization.expand' _ s t', OreLocalization.expand' _ s t']
congr 1
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO: use `assoc_rw`?
calc (t' : R) * (rβ * r * rβ)
= t' * rβ * r * rβ := by simp [β mul_assoc]
_ = rβ' * t * r * rβ := by rw [hrβ]
_ = rβ' * (t * r) * rβ := by simp [β mul_assoc]
_ = rβ' * (t * r') * rβ := by rw [h]
_ = rβ' * t * r' * rβ := by simp [β mul_assoc]
_ = t' * rβ * r' * rβ := by rw [hrβ]
_ = t' * (rβ * r' * rβ) := by simp [β mul_assoc]
/-- A function or predicate over `X` and `S` can be lifted to `X[Sβ»ΒΉ]` if it is invariant
under expansion on the left. -/
@[to_additive /-- A function or predicate over `X` and `S` can be lifted to the localizaton if it is
invariant under expansion on the left. -/]
def liftExpand {C : Sort*} (P : X β S β C)
(hP : β (r : X) (t : R) (s : S) (ht : t * s β S), P r s = P (t β’ r) β¨t * s, htβ©) :
X[Sβ»ΒΉ] β C :=
Quotient.lift (fun p : X Γ S => P p.1 p.2) fun (rβ, sβ) (rβ, sβ) β¨u, v, hrβ, hsββ© => by
dsimp at *
have sβvS : v * sβ β S := by
rw [β hsβ, β S.coe_mul]
exact SetLike.coe_mem (u * sβ)
replace hsβ : u * sβ = β¨_, sβvSβ© := by ext; simp [hsβ]
rw [hP rβ v sβ sβvS, hP rβ u sβ (by norm_cast; rwa [hsβ]), β hrβ]
simp only [β hsβ]; rfl
@[to_additive (attr := simp)]
theorem liftExpand_of {C : Sort*} {P : X β S β C}
{hP : β (r : X) (t : R) (s : S) (ht : t * s β S), P r s = P (t β’ r) β¨t * s, htβ©} (r : X)
(s : S) : liftExpand P hP (r /β s) = P r s :=
rfl
/-- A version of `liftExpand` used to simultaneously lift functions with two arguments
in `X[Sβ»ΒΉ]`. -/
@[to_additive
/-- A version of `liftExpand` used to simultaneously lift functions with two arguments. -/]
def liftβExpand {C : Sort*} (P : X β S β X β S β C)
(hP :
β (rβ : X) (tβ : R) (sβ : S) (htβ : tβ * sβ β S) (rβ : X) (tβ : R) (sβ : S)
(htβ : tβ * sβ β S),
P rβ sβ rβ sβ = P (tβ β’ rβ) β¨tβ * sβ, htββ© (tβ β’ rβ) β¨tβ * sβ, htββ©) :
X[Sβ»ΒΉ] β X[Sβ»ΒΉ] β C :=
liftExpand
(fun rβ sβ => liftExpand (P rβ sβ) fun rβ tβ sβ htβ => by
have := hP rβ 1 sβ (by simp) rβ tβ sβ htβ
simp [this])
fun rβ tβ sβ htβ => by
ext x; cases x with | _ rβ sβ
dsimp only
rw [liftExpand_of, liftExpand_of, hP rβ tβ sβ htβ rβ 1 sβ (by simp)]; simp
@[to_additive (attr := simp)]
theorem liftβExpand_of {C : Sort*} {P : X β S β X β S β C}
{hP :
β (rβ : X) (tβ : R) (sβ : S) (htβ : tβ * sβ β S) (rβ : X) (tβ : R) (sβ : S)
(htβ : tβ * sβ β S),
P rβ sβ rβ sβ = P (tβ β’ rβ) β¨tβ * sβ, htββ© (tβ β’ rβ) β¨tβ * sβ, htββ©}
(rβ : X) (sβ : S) (rβ : X) (sβ : S) : liftβExpand P hP (rβ /β sβ) (rβ /β sβ) = P rβ sβ rβ sβ :=
rfl
@[to_additive]
private def smul' (rβ : R) (sβ : S) (rβ : X) (sβ : S) : X[Sβ»ΒΉ] :=
oreNum rβ sβ β’ rβ /β (oreDenom rβ sβ * sβ)
@[to_additive]
private theorem smul'_char (rβ : R) (rβ : X) (sβ sβ : S) (u : S) (v : R) (huv : u * rβ = v * sβ) :
OreLocalization.smul' rβ sβ rβ sβ = v β’ rβ /β (u * sβ) := by
-- Porting note: `assoc_rw` was not ported yet
simp only [smul']
have hβ := ore_eq rβ sβ; set vβ := oreNum rβ sβ; set uβ := oreDenom rβ sβ
rcases oreCondition (uβ : R) u with β¨rβ, sβ, hββ©
have :=
calc
rβ * v * sβ = rβ * (u * rβ) := by rw [mul_assoc, β huv]
_ = sβ * (uβ * rβ) := by rw [β mul_assoc, β mul_assoc, hβ]
_ = sβ * vβ * sβ := by rw [mul_assoc, hβ]
rcases ore_right_cancel _ _ _ this with β¨sβ, hsββ©
symm; rw [oreDiv_eq_iff]
use sβ * sβ
use sβ * rβ
simp only [Submonoid.coe_mul, Submonoid.smul_def]
constructor
Β· rw [smul_smul, mul_assoc (c := vβ), β hsβ]
simp only [smul_smul, mul_assoc]
Β· rw [β mul_assoc (b := (uβ : R)), mul_assoc (c := (uβ : R)), hβ]
simp only [mul_assoc]
/-- The multiplication on the Ore localization of monoids. -/
@[to_additive]
private def smul'' (r : R) (s : S) : X[Sβ»ΒΉ] β X[Sβ»ΒΉ] :=
liftExpand (smul' r s) fun rβ rβ s' hs => by
rcases oreCondition r s' with β¨rβ', sβ', hββ©
rw [smul'_char _ _ _ _ _ _ hβ]
rcases oreCondition r β¨_, hsβ© with β¨rβ', sβ', hββ©
rw [smul'_char _ _ _ _ _ _ hβ]
rcases oreCondition (sβ' : R) (sβ') with β¨rβ', sβ', hββ©
have : sβ' * rβ' * s' = (rβ' * rβ' * rβ) * s' := by
rw [mul_assoc, β hβ, β mul_assoc, hβ, mul_assoc, hβ]
simp [mul_assoc]
rcases ore_right_cancel _ _ _ this with β¨sβ', hββ©
have : (sβ' * rβ') * (sβ' * s) β S := by
rw [mul_assoc, β mul_assoc rβ', β hβ]
exact (sβ' * (sβ' * sβ' * s)).2
rw [OreLocalization.expand' _ _ (sβ' * sβ'), OreLocalization.expand _ (sβ' * s) _ this]
simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, hβ]
congr 1
ext; simp only [Submonoid.coe_mul, β mul_assoc]
rw [mul_assoc (sβ' : R), hβ, β mul_assoc]
/-- The scalar multiplication on the Ore localization of monoids. -/
@[to_additive (attr := irreducible)
/-- the vector addition on the Ore localization of additive monoids. -/]
protected def smul : R[Sβ»ΒΉ] β X[Sβ»ΒΉ] β X[Sβ»ΒΉ] :=
liftExpand smul'' fun rβ rβ s hs => by
ext x
cases x with | _ x sβ
change OreLocalization.smul' rβ s x sβ = OreLocalization.smul' (rβ * rβ) β¨_, hsβ© x sβ
rcases oreCondition rβ sβ with β¨rβ', sβ', hββ©
rw [smul'_char _ _ _ _ _ _ hβ]
rcases oreCondition (rβ * rβ) sβ with β¨rβ', sβ', hββ©
rw [smul'_char _ _ _ _ _ _ hβ]
rcases oreCondition (sβ' * rβ) (sβ') with β¨rβ', sβ', hββ©
have : sβ' * rβ' * sβ = rβ' * rβ' * sβ := by
rw [mul_assoc, β hβ, β mul_assoc _ rβ, β mul_assoc, hβ, mul_assoc, hβ, mul_assoc]
rcases ore_right_cancel _ _ _ this with β¨sβ', hββ©
have : (sβ' * rβ') * (sβ' * s) β S := by
rw [β mul_assoc, mul_assoc _ rβ', β hβ, β mul_assoc, β mul_assoc, mul_assoc]
exact mul_mem (sβ' * sβ' * sβ').2 hs
rw [OreLocalization.expand' (rβ' β’ x) _ (sβ' * sβ'), OreLocalization.expand _ _ _ this]
simp only [Submonoid.smul_def, Submonoid.coe_mul, smul_smul, mul_assoc, hβ]
congr 1
ext; simp only [Submonoid.coe_mul, β mul_assoc]
rw [mul_assoc _ rβ', β hβ, β mul_assoc, β mul_assoc]
@[to_additive]
instance : SMul R[Sβ»ΒΉ] X[Sβ»ΒΉ] :=
β¨OreLocalization.smulβ©
@[to_additive]
instance : Mul R[Sβ»ΒΉ] :=
β¨OreLocalization.smulβ©
@[to_additive]
theorem oreDiv_smul_oreDiv {rβ : R} {rβ : X} {sβ sβ : S} :
(rβ /β sβ) β’ (rβ /β sβ) = oreNum rβ sβ β’ rβ /β (oreDenom rβ sβ * sβ) := by
with_unfolding_all rfl
@[to_additive]
theorem oreDiv_mul_oreDiv {rβ : R} {rβ : R} {sβ sβ : S} :
(rβ /β sβ) * (rβ /β sβ) = oreNum rβ sβ * rβ /β (oreDenom rβ sβ * sβ) := by
with_unfolding_all rfl
/-- A characterization lemma for the scalar multiplication on the Ore localization,
allowing for a choice of Ore numerator and Ore denominator. -/
@[to_additive /-- A characterization lemma for the vector addition on the Ore localization,
allowing for a choice of Ore minuend and Ore subtrahend. -/]
theorem oreDiv_smul_char (rβ : R) (rβ : X) (sβ sβ : S) (r' : R) (s' : S) (huv : s' * rβ = r' * sβ) :
(rβ /β sβ) β’ (rβ /β sβ) = r' β’ rβ /β (s' * sβ) := by
with_unfolding_all exact smul'_char rβ rβ sβ sβ s' r' huv
/-- A characterization lemma for the multiplication on the Ore localization, allowing for a choice
of Ore numerator and Ore denominator. -/
@[to_additive /-- A characterization lemma for the addition on the Ore localization,
allowing for a choice of Ore minuend and Ore subtrahend. -/]
theorem oreDiv_mul_char (rβ rβ : R) (sβ sβ : S) (r' : R) (s' : S) (huv : s' * rβ = r' * sβ) :
rβ /β sβ * (rβ /β sβ) = r' * rβ /β (s' * sβ) := by
with_unfolding_all exact smul'_char rβ rβ sβ sβ s' r' huv
/-- Another characterization lemma for the scalar multiplication on the Ore localizaion delivering
Ore witnesses and conditions bundled in a sigma type. -/
@[to_additive /-- Another characterization lemma for the vector addition on the
Ore localizaion delivering Ore witnesses and conditions bundled in a sigma type. -/]
def oreDivSMulChar' (rβ : R) (rβ : X) (sβ sβ : S) :
Ξ£' r' : R, Ξ£' s' : S, s' * rβ = r' * sβ β§ (rβ /β sβ) β’ (rβ /β sβ) = r' β’ rβ /β (s' * sβ) :=
β¨oreNum rβ sβ, oreDenom rβ sβ, ore_eq rβ sβ, oreDiv_smul_oreDivβ©
/-- Another characterization lemma for the multiplication on the Ore localizaion delivering
Ore witnesses and conditions bundled in a sigma type. -/
@[to_additive /-- Another characterization lemma for the addition on the Ore localizaion delivering
Ore witnesses and conditions bundled in a sigma type. -/]
def oreDivMulChar' (rβ rβ : R) (sβ sβ : S) :
Ξ£' r' : R, Ξ£' s' : S, s' * rβ = r' * sβ β§ rβ /β sβ * (rβ /β sβ) = r' * rβ /β (s' * sβ) :=
β¨oreNum rβ sβ, oreDenom rβ sβ, ore_eq rβ sβ, oreDiv_mul_oreDivβ©
/-- `1` in the localization, defined as `1 /β 1`. -/
@[to_additive (attr := irreducible) /-- `0` in the additive localization, defined as `0 -β 0`. -/]
protected def one : R[Sβ»ΒΉ] := 1 /β 1
@[to_additive]
instance : One R[Sβ»ΒΉ] :=
β¨OreLocalization.oneβ©
@[to_additive]
protected theorem one_def : (1 : R[Sβ»ΒΉ]) = 1 /β 1 := by
with_unfolding_all rfl
@[to_additive]
instance : Inhabited R[Sβ»ΒΉ] :=
β¨1β©
@[to_additive (attr := simp)]
protected theorem div_eq_one' {r : R} (hr : r β S) : r /β β¨r, hrβ© = 1 := by
rw [OreLocalization.one_def, oreDiv_eq_iff]
exact β¨β¨r, hrβ©, 1, by simp, by simpβ©
@[to_additive (attr := simp)]
protected theorem div_eq_one {s : S} : (s : R) /β s = 1 :=
OreLocalization.div_eq_one' _
@[to_additive]
protected theorem one_smul (x : X[Sβ»ΒΉ]) : (1 : R[Sβ»ΒΉ]) β’ x = x := by
cases x with | _ r s
simp [OreLocalization.one_def, oreDiv_smul_char 1 r 1 s 1 s (by simp)]
@[to_additive]
protected theorem one_mul (x : R[Sβ»ΒΉ]) : 1 * x = x :=
OreLocalization.one_smul x
@[to_additive]
protected theorem mul_one (x : R[Sβ»ΒΉ]) : x * 1 = x := by
cases x with | _ r s
simp [OreLocalization.one_def, oreDiv_mul_char r (1 : R) s (1 : S) r 1 (by simp)]
@[to_additive]
protected theorem mul_smul (x y : R[Sβ»ΒΉ]) (z : X[Sβ»ΒΉ]) : (x * y) β’ z = x β’ y β’ z := by
-- Porting note: `assoc_rw` was not ported yet
cases x with | _ rβ sβ
cases y with | _ rβ sβ
cases z with | _ rβ sβ
rcases oreDivMulChar' rβ rβ sβ sβ with β¨ra, sa, ha, ha'β©; rw [ha']; clear ha'
rcases oreDivSMulChar' rβ rβ sβ sβ with β¨rb, sb, hb, hb'β©; rw [hb']; clear hb'
rcases oreCondition ra sb with β¨rc, sc, hcβ©
rw [oreDiv_smul_char (ra * rβ) rβ (sa * sβ) sβ (rc * rb) sc]; swap
Β· rw [β mul_assoc _ ra, hc, mul_assoc, hb, β mul_assoc]
rw [β mul_assoc, mul_smul]
symm; apply oreDiv_smul_char
rw [Submonoid.coe_mul, Submonoid.coe_mul, β mul_assoc, β hc, mul_assoc _ ra, β ha, mul_assoc]
@[to_additive]
protected theorem mul_assoc (x y z : R[Sβ»ΒΉ]) : x * y * z = x * (y * z) :=
OreLocalization.mul_smul x y z
/-- `npow` of `OreLocalization` -/
@[to_additive (attr := irreducible) /-- `nsmul` of `AddOreLocalization` -/]
protected def npow : β β R[Sβ»ΒΉ] β R[Sβ»ΒΉ] := npowRec
unseal OreLocalization.npow in
@[to_additive]
instance : Monoid R[Sβ»ΒΉ] where
one_mul := OreLocalization.one_mul
mul_one := OreLocalization.mul_one
mul_assoc := OreLocalization.mul_assoc
npow := OreLocalization.npow
@[to_additive]
instance instMulActionOreLocalization : MulAction R[Sβ»ΒΉ] X[Sβ»ΒΉ] where
one_smul := OreLocalization.one_smul
mul_smul := OreLocalization.mul_smul
@[to_additive]
protected theorem mul_inv (s s' : S) : ((s : R) /β s') * ((s' : R) /β s) = 1 := by
simp [oreDiv_mul_char (s : R) s' s' s 1 1 (by simp)]
@[to_additive (attr := simp)]
protected theorem one_div_smul {r : X} {s t : S} : ((1 : R) /β t) β’ (r /β s) = r /β (s * t) := by
simp [oreDiv_smul_char 1 r t s 1 s (by simp)]
@[to_additive (attr := simp)]
protected theorem one_div_mul {r : R} {s t : S} : (1 /β t) * (r /β s) = r /β (s * t) := by
simp [oreDiv_mul_char 1 r t s 1 s (by simp)]
@[to_additive (attr := simp)]
protected theorem smul_cancel {r : X} {s t : S} : ((s : R) /β t) β’ (r /β s) = r /β t := by
simp [oreDiv_smul_char s.1 r t s 1 1 (by simp)]
@[to_additive (attr := simp)]
protected theorem mul_cancel {r : R} {s t : S} : ((s : R) /β t) * (r /β s) = r /β t := by
simp [oreDiv_mul_char s.1 r t s 1 1 (by simp)]
@[to_additive (attr := simp)]
protected theorem smul_cancel' {rβ : R} {rβ : X} {s t : S} :
((rβ * s) /β t) β’ (rβ /β s) = (rβ β’ rβ) /β t := by
simp [oreDiv_smul_char (rβ * s) rβ t s rβ 1 (by simp)]
@[to_additive (attr := simp)]
protected theorem mul_cancel' {rβ rβ : R} {s t : S} :
((rβ * s) /β t) * (rβ /β s) = (rβ * rβ) /β t := by
simp [oreDiv_mul_char (rβ * s) rβ t s rβ 1 (by simp)]
@[to_additive (attr := simp)]
theorem smul_div_one {p : R} {r : X} {s : S} : (p /β s) β’ (r /β 1) = (p β’ r) /β s := by
simp [oreDiv_smul_char p r s 1 p 1 (by simp)]
@[to_additive (attr := simp)]
theorem mul_div_one {p r : R} {s : S} : (p /β s) * (r /β 1) = (p * r) /β s := by
--TODO use coercion r β¦ r /β 1
simp [oreDiv_mul_char p r s 1 p 1 (by simp)]
/-- The fraction `s /β 1` as a unit in `R[Sβ»ΒΉ]`, where `s : S`. -/
@[to_additive /-- The difference `s -β 0` as a an additive unit. -/]
def numeratorUnit (s : S) : Units R[Sβ»ΒΉ] where
val := (s : R) /β 1
inv := (1 : R) /β s
val_inv := OreLocalization.mul_inv s 1
inv_val := OreLocalization.mul_inv 1 s
/-- The multiplicative homomorphism from `R` to `R[Sβ»ΒΉ]`, mapping `r : R` to the
fraction `r /β 1`. -/
@[to_additive /-- The additive homomorphism from `R` to `AddOreLocalization R S`,
mapping `r : R` to the difference `r -β 0`. -/]
def numeratorHom : R β* R[Sβ»ΒΉ] where
toFun r := r /β 1
map_one' := by with_unfolding_all rfl
map_mul' _ _ := mul_div_one.symm
@[to_additive]
theorem numeratorHom_apply {r : R} : numeratorHom r = r /β (1 : S) :=
rfl
@[to_additive]
theorem numerator_isUnit (s : S) : IsUnit (numeratorHom (s : R) : R[Sβ»ΒΉ]) :=
β¨numeratorUnit s, rflβ©
section UMP
variable {T : Type*} [Monoid T]
variable (f : R β* T) (fS : S β* Units T)
/-- The universal lift from a morphism `R β* T`, which maps elements of `S` to units of `T`,
to a morphism `R[Sβ»ΒΉ] β* T`. -/
@[to_additive /-- The universal lift from a morphism `R β+ T`, which maps elements of `S` to
additive-units of `T`, to a morphism `AddOreLocalization R S β+ T`. -/]
def universalMulHom (hf : β s : S, f s = fS s) : R[Sβ»ΒΉ] β* T where
toFun x :=
x.liftExpand (fun r s => ((fS s)β»ΒΉ : Units T) * f r) fun r t s ht => by
simp only [smul_eq_mul]
have : (fS β¨t * s, htβ© : T) = f t * fS s := by
simp only [β hf, MonoidHom.map_mul]
conv_rhs =>
rw [MonoidHom.map_mul, β one_mul (f r), β Units.val_one, β mul_inv_cancel (fS s)]
rw [Units.val_mul, mul_assoc, β mul_assoc _ (fS s : T), β this, β mul_assoc]
simp only [one_mul, Units.inv_mul]
map_one' := by beta_reduce; rw [OreLocalization.one_def, liftExpand_of]; simp
map_mul' x y := by
cases x with | _ rβ sβ
cases y with | _ rβ sβ
rcases oreDivMulChar' rβ rβ sβ sβ with β¨ra, sa, ha, ha'β©; rw [ha']; clear ha'
rw [liftExpand_of, liftExpand_of, liftExpand_of, Units.inv_mul_eq_iff_eq_mul, map_mul, map_mul,
Units.val_mul, mul_assoc, β mul_assoc (fS sβ : T), β mul_assoc (fS sβ : T), Units.mul_inv,
one_mul, β hf, β mul_assoc, β map_mul _ _ rβ, ha, map_mul, hf sβ, mul_assoc,
β mul_assoc (fS sβ : T), (fS sβ).mul_inv, one_mul]
variable (hf : β s : S, f s = fS s)
@[to_additive]
theorem universalMulHom_apply {r : R} {s : S} :
universalMulHom f fS hf (r /β s) = ((fS s)β»ΒΉ : Units T) * f r :=
rfl
@[to_additive]
theorem universalMulHom_commutes {r : R} : universalMulHom f fS hf (numeratorHom r) = f r := by
simp [numeratorHom_apply, universalMulHom_apply]
/-- The universal morphism `universalMulHom` is unique. -/
@[to_additive /-- The universal morphism `universalAddHom` is unique. -/]
theorem universalMulHom_unique (Ο : R[Sβ»ΒΉ] β* T) (huniv : β r : R, Ο (numeratorHom r) = f r) :
Ο = universalMulHom f fS hf := by
ext x; cases x with | _ r s
rw [universalMulHom_apply, β huniv r, numeratorHom_apply, β one_mul (Ο (r /β s)), β
Units.val_one, β inv_mul_cancel (fS s), Units.val_mul, mul_assoc, β hf, β huniv, β Ο.map_mul,
numeratorHom_apply, OreLocalization.mul_cancel]
end UMP
end Monoid
section SMul
variable {R R' M X : Type*} [Monoid M] {S : Submonoid M} [OreSet S] [MulAction M X]
variable [SMul R X] [SMul R M] [IsScalarTower R M M] [IsScalarTower R M X]
variable [SMul R' X] [SMul R' M] [IsScalarTower R' M M] [IsScalarTower R' M X]
variable [SMul R R'] [IsScalarTower R R' M]
/-- Scalar multiplication in a monoid localization. -/
@[to_additive (attr := irreducible) /-- Vector addition in an additive monoid localization. -/]
protected def hsmul (c : R) :
X[Sβ»ΒΉ] β X[Sβ»ΒΉ] :=
liftExpand (fun m s β¦ oreNum (c β’ 1) s β’ m /β oreDenom (c β’ 1) s) (fun r t s ht β¦ by
dsimp only
rw [β mul_one (oreDenom (c β’ 1) s), β oreDiv_smul_oreDiv, β mul_one (oreDenom (c β’ 1) _),
β oreDiv_smul_oreDiv, β OreLocalization.expand])
/- Warning: This gives an diamond on `SMul R[Sβ»ΒΉ] M[Sβ»ΒΉ][Sβ»ΒΉ]`, but we will almost never localize
at the same monoid twice. -/
/- Although the definition does not require `IsScalarTower R M X`,
it does not make sense without it. -/
@[to_additive (attr := nolint unusedArguments)]
instance [SMul R X] [SMul R M] [IsScalarTower R M X] [IsScalarTower R M M] : SMul R (X[Sβ»ΒΉ]) where
smul := OreLocalization.hsmul
@[to_additive]
theorem smul_oreDiv (r : R) (x : X) (s : S) :
r β’ (x /β s) = oreNum (r β’ 1) s β’ x /β oreDenom (r β’ 1) s := by with_unfolding_all rfl
@[to_additive (attr := simp)]
theorem oreDiv_one_smul (r : M) (x : X[Sβ»ΒΉ]) : (r /β (1 : S)) β’ x = r β’ x := by
cases x
rw [smul_oreDiv, oreDiv_smul_oreDiv, mul_one, smul_eq_mul, mul_one]
@[to_additive]
theorem smul_one_smul (r : R) (x : X[Sβ»ΒΉ]) : (r β’ 1 : M) β’ x = r β’ x := by
cases x
simp only [smul_oreDiv, smul_eq_mul, mul_one]
@[to_additive]
theorem smul_one_oreDiv_one_smul (r : R) (x : X[Sβ»ΒΉ]) :
((r β’ 1 : M) /β (1 : S)) β’ x = r β’ x := by
rw [oreDiv_one_smul, smul_one_smul]
@[to_additive]
instance : IsScalarTower R R' X[Sβ»ΒΉ] where
smul_assoc r m x := by
rw [β smul_one_oreDiv_one_smul, β smul_one_oreDiv_one_smul, β smul_one_oreDiv_one_smul,
β mul_smul, mul_div_one]
simp only [smul_mul_assoc, smul_assoc, one_mul]
@[to_additive]
instance [SMulCommClass R R' M] : SMulCommClass R R' X[Sβ»ΒΉ] where
smul_comm r m x := by
rw [β smul_one_smul m, β smul_assoc, smul_comm, smul_assoc, smul_one_smul]
@[to_additive]
instance : IsScalarTower R M[Sβ»ΒΉ] X[Sβ»ΒΉ] where
smul_assoc r m x := by
rw [β smul_one_oreDiv_one_smul, β smul_one_oreDiv_one_smul, β mul_smul, smul_eq_mul]
@[to_additive]
instance [SMulCommClass R M M] : SMulCommClass R M[Sβ»ΒΉ] X[Sβ»ΒΉ] where
smul_comm r x y := by
cases x with | _ rβ sβ
cases y with | _ rβ sβ
rw [β smul_one_oreDiv_one_smul, β smul_one_oreDiv_one_smul, smul_smul, smul_smul,
mul_div_one, oreDiv_mul_char _ _ _ _ (r β’ 1) sβ (by simp), mul_one]
simp
@[to_additive]
instance [SMul Rα΅α΅α΅ M] [SMul Rα΅α΅α΅ X] [IsScalarTower Rα΅α΅α΅ M M] [IsScalarTower Rα΅α΅α΅ M X]
[IsCentralScalar R M] : IsCentralScalar R X[Sβ»ΒΉ] where
op_smul_eq_smul r x := by
rw [β smul_one_oreDiv_one_smul, β smul_one_oreDiv_one_smul, op_smul_eq_smul]
@[to_additive]
instance {R} [Monoid R] [MulAction R M] [IsScalarTower R M M]
[MulAction R X] [IsScalarTower R M X] : MulAction R X[Sβ»ΒΉ] where
one_smul := OreLocalization.ind fun x s β¦ by
rw [β smul_one_oreDiv_one_smul, one_smul, β OreLocalization.one_def, one_smul]
mul_smul sβ sβ x := by rw [β smul_eq_mul, smul_assoc]
@[to_additive]
theorem smul_oreDiv_one (r : R) (x : X) : r β’ (x /β (1 : S)) = (r β’ x) /β (1 : S) := by
rw [β smul_one_oreDiv_one_smul, smul_div_one, smul_assoc, one_smul]
end SMul
section CommMonoid
variable {R : Type*} [CommMonoid R] {S : Submonoid R} [OreSet S]
@[to_additive]
theorem oreDiv_mul_oreDiv_comm {rβ rβ : R} {sβ sβ : S} :
rβ /β sβ * (rβ /β sβ) = rβ * rβ /β (sβ * sβ) := by
rw [oreDiv_mul_char rβ rβ sβ sβ rβ sβ (by simp [mul_comm]), mul_comm sβ]
@[to_additive]
instance : CommMonoid R[Sβ»ΒΉ] where
mul_comm := fun x y => by
cases x with | _ rβ sβ
cases y with | _ rβ sβ
rw [oreDiv_mul_oreDiv_comm, oreDiv_mul_oreDiv_comm, mul_comm rβ, mul_comm sβ]
end CommMonoid
section Zero
variable {R : Type*} [Monoid R] {S : Submonoid R} [OreSet S] {X : Type*} [Zero X]
variable [MulAction R X]
/-- `0` in the localization, defined as `0 /β 1`. -/
@[irreducible]
protected def zero : X[Sβ»ΒΉ] := 0 /β 1
instance : Zero X[Sβ»ΒΉ] :=
β¨OreLocalization.zeroβ©
protected theorem zero_def : (0 : X[Sβ»ΒΉ]) = 0 /β 1 := by
with_unfolding_all rfl
end Zero
end OreLocalization
|
Pointwise.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison
-/
import Mathlib.Algebra.Group.Finsupp
import Mathlib.Algebra.Module.Defs
import Mathlib.Algebra.Ring.InjSurj
import Mathlib.Algebra.Ring.Pi
/-!
# The pointwise product on `Finsupp`.
For the convolution product on `Finsupp` when the domain has a binary operation,
see the type synonyms `AddMonoidAlgebra`
(which is in turn used to define `Polynomial` and `MvPolynomial`)
and `MonoidAlgebra`.
-/
noncomputable section
open Finset
universe uβ uβ uβ uβ uβ
variable {Ξ± : Type uβ} {Ξ² : Type uβ} {Ξ³ : Type uβ} {Ξ΄ : Type uβ} {ΞΉ : Type uβ
}
namespace Finsupp
/-! ### Declarations about the pointwise product on `Finsupp`s -/
section
variable [MulZeroClass Ξ²]
/-- The product of `f g : Ξ± ββ Ξ²` is the finitely supported function
whose value at `a` is `f a * g a`. -/
instance : Mul (Ξ± ββ Ξ²) :=
β¨zipWith (Β· * Β·) (mul_zero 0)β©
theorem coe_mul (gβ gβ : Ξ± ββ Ξ²) : β(gβ * gβ) = gβ * gβ :=
rfl
@[simp]
theorem mul_apply {gβ gβ : Ξ± ββ Ξ²} {a : Ξ±} : (gβ * gβ) a = gβ a * gβ a :=
rfl
@[simp]
theorem single_mul (a : Ξ±) (bβ bβ : Ξ²) : single a (bβ * bβ) = single a bβ * single a bβ :=
(zipWith_single_single _ _ _ _ _).symm
lemma support_mul_subset_left {gβ gβ : Ξ± ββ Ξ²} :
(gβ * gβ).support β gβ.support := fun x hx => by
aesop
lemma support_mul_subset_right {gβ gβ : Ξ± ββ Ξ²} :
(gβ * gβ).support β gβ.support := fun x hx => by
aesop
theorem support_mul [DecidableEq Ξ±] {gβ gβ : Ξ± ββ Ξ²} :
(gβ * gβ).support β gβ.support β© gβ.support :=
subset_inter support_mul_subset_left support_mul_subset_right
instance : MulZeroClass (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.mulZeroClass _ coe_zero coe_mul
end
instance [SemigroupWithZero Ξ²] : SemigroupWithZero (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.semigroupWithZero _ coe_zero coe_mul
instance [NonUnitalNonAssocSemiring Ξ²] : NonUnitalNonAssocSemiring (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalNonAssocSemiring _ coe_zero coe_add coe_mul fun _ _ β¦ rfl
instance [NonUnitalSemiring Ξ²] : NonUnitalSemiring (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalSemiring _ coe_zero coe_add coe_mul fun _ _ β¦ rfl
instance [NonUnitalCommSemiring Ξ²] : NonUnitalCommSemiring (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalCommSemiring _ coe_zero coe_add coe_mul fun _ _ β¦ rfl
instance [NonUnitalNonAssocRing Ξ²] : NonUnitalNonAssocRing (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalNonAssocRing _ coe_zero coe_add coe_mul coe_neg coe_sub
(fun _ _ β¦ rfl) fun _ _ β¦ rfl
instance [NonUnitalRing Ξ²] : NonUnitalRing (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalRing _ coe_zero coe_add coe_mul coe_neg coe_sub (fun _ _ β¦ rfl)
fun _ _ β¦ rfl
instance [NonUnitalCommRing Ξ²] : NonUnitalCommRing (Ξ± ββ Ξ²) :=
DFunLike.coe_injective.nonUnitalCommRing _ coe_zero coe_add coe_mul coe_neg coe_sub
(fun _ _ β¦ rfl) fun _ _ β¦ rfl
-- TODO can this be generalized in the direction of `Pi.smul'`
-- (i.e. dependent functions and finsupps)
-- TODO in theory this could be generalised, we only really need `smul_zero` for the definition
instance pointwiseScalar [Semiring Ξ²] : SMul (Ξ± β Ξ²) (Ξ± ββ Ξ²) where
smul f g :=
Finsupp.ofSupportFinite (fun a β¦ f a β’ g a) (by
apply Set.Finite.subset g.finite_support
simp only [Function.support_subset_iff, Finsupp.mem_support_iff, Ne,
Finsupp.fun_support_eq, Finset.mem_coe]
intro x hx h
apply hx
rw [h, smul_zero])
@[simp]
theorem coe_pointwise_smul [Semiring Ξ²] (f : Ξ± β Ξ²) (g : Ξ± ββ Ξ²) : β(f β’ g) = f β’ βg :=
rfl
/-- The pointwise multiplicative action of functions on finitely supported functions -/
instance pointwiseModule [Semiring Ξ²] : Module (Ξ± β Ξ²) (Ξ± ββ Ξ²) :=
Function.Injective.module _ coeFnAddHom DFunLike.coe_injective coe_pointwise_smul
end Finsupp
|
Qq.lean
|
/-
Copyright (c) 2023 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kim Morrison, Alex J. Best, YaΓ«l Dillies
-/
import Mathlib.Init
import Qq
/-!
# Extra `Qq` helpers
This file contains some additional functions for using the quote4 library more conveniently.
-/
open Lean Elab Tactic Meta
namespace Qq
/-- Variant of `inferTypeQ` that yields a type in `Type u` rather than `Sort u`.
Throws an error if the type is a `Prop` or if it's otherwise not possible to represent
the universe as `Type u` (for example due to universe level metavariables). -/
-- See https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Using.20.60QQ.60.20when.20you.20only.20have.20an.20.60Expr.60/near/303349037
def inferTypeQ' (e : Expr) : MetaM ((u : Level) Γ (Ξ± : Q(Type $u)) Γ Q($Ξ±)) := do
let Ξ± β inferType e
let .sort u β whnf (β inferType Ξ±) | throwError "not a type{indentExpr Ξ±}"
let some v := (β instantiateLevelMVars u).dec | throwError "not a Type{indentExpr e}"
pure β¨v, Ξ±, eβ©
theorem QuotedDefEq.rfl {u : Level} {Ξ± : Q(Sort u)} {a : Q($Ξ±)} : @QuotedDefEq u Ξ± a a := β¨β©
/-- Return a local declaration whose type is definitionally equal to `sort`.
This is a Qq version of `Lean.Meta.findLocalDeclWithType?` -/
def findLocalDeclWithTypeQ? {u : Level} (sort : Q(Sort u)) : MetaM (Option Q($sort)) := do
let some fvarId β findLocalDeclWithType? q($sort) | return none
return some <| .fvar fvarId
/-- Returns a proof of `p : Prop` using `decide p`.
This is a Qq version of `Lean.Meta.mkDecideProof`. -/
def mkDecideProofQ (p : Q(Prop)) : MetaM Q($p) := mkDecideProof p
/-- Join a list of elements of type `Ξ±` into a container `Ξ²`.
Usually `Ξ²` is `q(Multiset Ξ±)` or `q(Finset Ξ±)` or `q(Set Ξ±)`.
As an example
```lean
mkSetLiteralQ q(Finset β) (List.range 4 |>.map fun n : β β¦ q($nβ’Ο))
```
produces the expression `{0 β’ Ο, 1 β’ Ο, 2 β’ Ο, 3 β’ Ο} : Finset β`.
-/
def mkSetLiteralQ {u v : Level} {Ξ± : Q(Type u)} (Ξ² : Q(Type v))
(elems : List Q($Ξ±))
(_ : Q(EmptyCollection $Ξ²) := by exact q(inferInstance))
(_ : Q(Singleton $Ξ± $Ξ²) := by exact q(inferInstance))
(_ : Q(Insert $Ξ± $Ξ²) := by exact q(inferInstance)) :
Q($Ξ²) :=
match elems with
| [] => q(β
)
| [x] => q({$x})
| x :: xs => q(Insert.insert $x $(mkSetLiteralQ Ξ² xs))
end Qq
|
algC.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun ssrnat eqtype seq choice.
From mathcomp Require Import div fintype path bigop finset prime order ssralg.
From mathcomp Require Import poly polydiv mxpoly generic_quotient countalg.
From mathcomp Require Import ssrnum closed_field ssrint archimedean rat intdiv.
From mathcomp Require Import algebraics_fundamentals.
(******************************************************************************)
(* This file provides an axiomatic construction of the algebraic numbers. *)
(* The construction only assumes the existence of an algebraically closed *)
(* filed with an automorphism of order 2; this amounts to the purely *)
(* algebraic contents of the Fundamenta Theorem of Algebra. *)
(* algC == the closed, countable field of algebraic numbers. *)
(* algCeq, algCnzRing, ..., algCnumField == structures for algC. *)
(* The ssrnum interfaces are implemented for algC as follows: *)
(* x <= y <=> (y - x) is a nonnegative real *)
(* x < y <=> (y - x) is a (strictly) positive real *)
(* `|z| == the complex norm of z, i.e., sqrtC (z * z^* ). *)
(* Creal == the subset of real numbers (:= Num.real for algC). *)
(* 'i == the imaginary number (:= sqrtC (-1)). *)
(* 'Re z == the real component of z. *)
(* 'Im z == the imaginary component of z. *)
(* z^* == the complex conjugate of z (:= conjC z). *)
(* sqrtC z == a nonnegative square root of z, i.e., 0 <= sqrt x if 0 <= x. *)
(* n.-root z == more generally, for n > 0, an nth root of z, chosen with a *)
(* minimal non-negative argument for n > 1 (i.e., with a *)
(* maximal real part subject to a nonnegative imaginary part). *)
(* Note that n.-root (-1) is a primitive 2nth root of unity, *)
(* an thus not equal to -1 for n odd > 1 (this will be shown in *)
(* file cyclotomic.v). *)
(* In addition, we provide: *)
(* Crat == the subset of rational numbers. *)
(* getCrat z == some a : rat such that ratr a = z, provided z \in Crat. *)
(* minCpoly z == the minimal (monic) polynomial over Crat with root z. *)
(* algC_invaut nu == an inverse of nu : {rmorphism algC -> algC}. *)
(* (x %| y)%C <=> y is an integer (Num.int) multiple of x; if x or y *)
(* (x %| y)%Cx are of type nat or int they are coerced to algC. *)
(* The (x %| y)%Cx display form is a workaround for *)
(* design limitations of the Coq Notation facilities. *)
(* (x == y %[mod z])%C <=> x and y differ by an integer (Num.int) multiple of *)
(* z; as above, arguments of type nat or int are cast to algC. *)
(* (x != y %[mod z])%C <=> x and y do not differ by an integer multiple of z. *)
(* algR == the subset of real algebraic numbers. *)
(* algR_norm x == the norm of (x : algR). *)
(* algR_pfactor x == the minimal (monic) polynomial over algR with root x. *)
(* algC_pfactor x == the minimal (monic) polynomial over algR with root x, *)
(* with coefficients in algC. *)
(* Note that in file algnum we give an alternative definition of divisibility *)
(* based on algebraic integers, overloading the notation in the %A scope. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope C_scope.
Declare Scope C_core_scope.
Declare Scope C_expanded_scope.
Import Order.TTheory GRing.Theory Num.Theory.
Local Open Scope ring_scope.
HB.factory Record isComplex L of GRing.ClosedField L := {
conj : {rmorphism L -> L};
conjK : involutive conj;
conj_nt : ~ conj =1 id
}.
HB.builders Context L of isComplex L.
Lemma nz2: 2 != 0 :> L.
Proof.
apply/eqP=> pchar2; apply: conj_nt => e; apply/eqP/idPn=> eJ.
have opp_id x: - x = x :> L.
by apply/esym/eqP; rewrite -addr_eq0 -mulr2n -mulr_natl pchar2 mul0r.
have{} pchar2: 2%N \in [pchar L] by apply/eqP.
without loss{eJ} eJ: e / conj e = e + 1.
move/(_ (e / (e + conj e))); apply.
rewrite fmorph_div rmorphD /= conjK -{1}[conj e](addNKr e) mulrDl.
by rewrite opp_id (addrC e) divff // addr_eq0 opp_id.
pose a := e * conj e; have aJ: conj a = a by rewrite rmorphM /= conjK mulrC.
have [w Dw] := @solve_monicpoly _ 2%N (nth 0 [:: e * a; - 1]) isT.
have{} Dw: w ^+ 2 + w = e * a.
by rewrite Dw !big_ord_recl big_ord0 /= mulr1 mulN1r addr0 subrK.
pose b := w + conj w; have bJ: conj b = b by rewrite rmorphD /= conjK addrC.
have Db2: b ^+ 2 + b = a.
rewrite -pFrobenius_autE // rmorphD addrACA Dw /= pFrobenius_autE -rmorphXn.
by rewrite -rmorphD Dw rmorphM /= aJ eJ -mulrDl -{1}[e]opp_id addKr mul1r.
have /eqP[] := oner_eq0 L; apply: (addrI b); rewrite addr0 -{2}bJ.
have: (b + e) * (b + conj e) == 0.
(* FIX ME : had to add pattern selection *)
rewrite mulrDl 2![_ * (b + _)]mulrDr -/a.
rewrite addrA addr_eq0 opp_id (mulrC e) -addrA.
by rewrite -mulrDr eJ addrAC -{2}[e]opp_id subrr add0r mulr1 Db2.
rewrite mulf_eq0 !addr_eq0 !opp_id => /pred2P[] -> //.
by rewrite {2}eJ rmorphD rmorph1.
Qed.
Lemma mul2I: injective (fun z : L => z *+ 2).
Proof.
have nz2 := nz2.
by move=> x y; rewrite /= -mulr_natl -(mulr_natl y) => /mulfI->.
Qed.
Definition sqrt x : L :=
sval (sig_eqW (@solve_monicpoly _ 2%N (nth 0 [:: x]) isT)).
Lemma sqrtK x: sqrt x ^+ 2 = x.
Proof.
rewrite /sqrt; case: sig_eqW => /= y ->.
by rewrite !big_ord_recl big_ord0 /= mulr1 mul0r !addr0.
Qed.
Lemma sqrtE x y: y ^+ 2 = x -> {b : bool | y = (-1) ^+ b * sqrt x}.
Proof.
move=> Dx; exists (y != sqrt x); apply/eqP; rewrite mulr_sign if_neg.
by case: ifPn => //; apply/implyP; rewrite implyNb -eqf_sqr Dx sqrtK.
Qed.
Definition i := sqrt (- 1).
Lemma sqrMi x: (i * x) ^+ 2 = - x ^+ 2.
Proof. by rewrite exprMn sqrtK mulN1r. Qed.
Lemma iJ : conj i = - i.
Proof.
have nz2 := nz2.
have /sqrtE[b]: conj i ^+ 2 = - 1 by rewrite -rmorphXn /= sqrtK rmorphN1.
rewrite mulr_sign -/i; case: b => // Ri.
case: conj_nt => z; wlog zJ: z / conj z = - z.
move/(_ (z - conj z)); rewrite !rmorphB conjK opprB => zJ.
by apply/mul2I/(canRL (subrK _)); rewrite -addrA zJ // addrC subrK.
have [-> | nz_z] := eqVneq z 0; first exact: rmorph0.
have [u Ru [v Rv Dz]]:
exists2 u, conj u = u & exists2 v, conj v = v & (u + z * v) ^+ 2 = z.
- pose y := sqrt z; exists ((y + conj y) / 2).
by rewrite fmorph_div rmorphD /= conjK addrC rmorph_nat.
exists ((y - conj y) / (z *+ 2)).
rewrite fmorph_div rmorphMn /= zJ mulNrn invrN mulrN -mulNr rmorphB opprB.
by rewrite conjK.
rewrite -(mulr_natl z) invfM (mulrC z) !mulrA divfK // -mulrDl addrACA.
(* FIX ME : had to add the explicit pattern *)
by rewrite subrr addr0 -mulr2n -[_ *+ 2]mulr_natr mulfK ?Neq0 ?sqrtK.
suff u0: u = 0 by rewrite -Dz u0 add0r rmorphXn rmorphM /= Rv zJ mulNr sqrrN.
suff [b Du]: exists b : bool, u = (-1) ^+ b * i * z * v.
apply: mul2I; rewrite mul0rn mulr2n -{2}Ru.
by rewrite Du !rmorphM /= rmorph_sign Rv Ri zJ !mulrN mulNr subrr.
have/eqP:= zJ; rewrite -addr_eq0 -{1 2}Dz rmorphXn rmorphD rmorphM /= Ru Rv zJ.
rewrite mulNr sqrrB sqrrD addrACA (addrACA (u ^+ 2)) addNr addr0 -!mulr2n.
rewrite -mulrnDl -(mul0rn _ 2) (inj_eq mul2I) /= -[rhs in _ + rhs]opprK.
rewrite -sqrMi subr_eq0 eqf_sqr -mulNr !mulrA.
by case/pred2P=> ->; [exists false | exists true]; rewrite mulr_sign.
Qed.
Definition norm x := sqrt x * conj (sqrt x).
Lemma normK x : norm x ^+ 2 = x * conj x.
Proof. by rewrite exprMn -rmorphXn sqrtK. Qed.
Lemma normE x y : y ^+ 2 = x -> norm x = y * conj y.
Proof.
rewrite /norm => /sqrtE[b /(canLR (signrMK b)) <-].
by rewrite !rmorphM /= rmorph_sign mulrACA -mulrA signrMK.
Qed.
Lemma norm_eq0 x : norm x = 0 -> x = 0.
Proof.
by move/eqP; rewrite mulf_eq0 fmorph_eq0 -mulf_eq0 -expr2 sqrtK => /eqP.
Qed.
Lemma normM x y : norm (x * y) = norm x * norm y.
Proof.
by rewrite mulrACA -rmorphM; apply: normE; rewrite exprMn !sqrtK.
Qed.
Lemma normN x : norm (- x) = norm x.
Proof.
by rewrite -mulN1r normM {1}/norm iJ mulrN -expr2 sqrtK opprK mul1r.
Qed.
Definition le x y := norm (y - x) == y - x.
Definition lt x y := (y != x) && le x y.
Lemma posE x: le 0 x = (norm x == x).
Proof. by rewrite /le subr0. Qed.
Lemma leB x y: le x y = le 0 (y - x).
Proof. by rewrite posE. Qed.
Lemma posP x : reflect (exists y, x = y * conj y) (le 0 x).
Proof.
rewrite posE; apply: (iffP eqP) => [Dx | [y {x}->]]; first by exists (sqrt x).
by rewrite (normE (normK y)) rmorphM /= conjK (mulrC (conj _)) -expr2 normK.
Qed.
Lemma posJ x : le 0 x -> conj x = x.
Proof.
by case/posP=> {x}u ->; rewrite rmorphM /= conjK mulrC.
Qed.
Lemma pos_linear x y : le 0 x -> le 0 y -> le x y || le y x.
Proof.
move=> pos_x pos_y; rewrite leB -opprB orbC leB !posE normN -eqf_sqr.
by rewrite normK rmorphB !posJ ?subrr.
Qed.
Lemma sposDl x y : lt 0 x -> le 0 y -> lt 0 (x + y).
Proof.
have sqrtJ z : le 0 z -> conj (sqrt z) = sqrt z.
rewrite posE -{2}[z]sqrtK -subr_eq0 -mulrBr mulf_eq0 subr_eq0.
by case/pred2P=> ->; rewrite ?rmorph0.
case/andP=> nz_x /sqrtJ uJ /sqrtJ vJ.
set u := sqrt x in uJ; set v := sqrt y in vJ; pose w := u + i * v.
have ->: x + y = w * conj w.
rewrite rmorphD rmorphM /= iJ uJ vJ mulNr mulrC -subr_sqr sqrMi opprK.
by rewrite !sqrtK.
apply/andP; split; last by apply/posP; exists w.
rewrite -normK expf_eq0 //=; apply: contraNneq nz_x => /norm_eq0 w0.
rewrite -[x]sqrtK expf_eq0 /= -/u -(inj_eq mul2I) !mulr2n -{2}(rmorph0 conj).
by rewrite -w0 rmorphD rmorphM /= iJ uJ vJ mulNr addrACA subrr addr0.
Qed.
Lemma sposD x y : lt 0 x -> lt 0 y -> lt 0 (x + y).
Proof.
by move=> x_gt0 /andP[_]; apply: sposDl.
Qed.
Lemma normD x y : le (norm (x + y)) (norm x + norm y).
Proof.
have sposM u v: lt 0 u -> le 0 (u * v) -> le 0 v.
by rewrite /lt !posE normM andbC => /andP[/eqP-> /mulfI/inj_eq->].
have posD u v: le 0 u -> le 0 v -> le 0 (u + v).
have [-> | nz_u u_ge0 v_ge0] := eqVneq u 0; first by rewrite add0r.
by have /andP[]: lt 0 (u + v) by rewrite sposDl // /lt nz_u.
have le_sqr u v: conj u = u -> le 0 v -> le (u ^+ 2) (v ^+ 2) -> le u v.
case: (eqVneq u 0) => [-> //|nz_u Ru v_ge0].
have [u_gt0 | u_le0 _] := boolP (lt 0 u).
by rewrite leB (leB u) subr_sqr mulrC addrC; apply: sposM; apply: sposDl.
rewrite leB posD // posE normN -addr_eq0; apply/eqP.
rewrite /lt nz_u posE -subr_eq0 in u_le0; apply: (mulfI u_le0).
by rewrite mulr0 -subr_sqr normK Ru subrr.
have pos_norm z: le 0 (norm z) by apply/posP; exists (sqrt z).
rewrite le_sqr ?posJ ?posD // sqrrD !normK -normM rmorphD mulrDl !mulrDr.
rewrite addrA addrC !addrA -(addrC (y * conj y)) !addrA.
move: (y * _ + _) => u; rewrite -!addrA leB opprD addrACA {u}subrr add0r -leB.
rewrite {}le_sqr ?posD //.
by rewrite rmorphD !rmorphM /= !conjK addrC (mulrC x) (mulrC y).
rewrite -mulr2n -mulr_natr exprMn normK -natrX mulr_natr sqrrD mulrACA.
rewrite -rmorphM (mulrC y x) addrAC leB mulrnA mulr2n opprD addrACA.
rewrite subrr addr0 {2}(mulrC x) rmorphM mulrACA -opprB addrAC -sqrrB -sqrMi.
apply/posP; exists (i * (x * conj y - y * conj x)); congr (_ * _).
rewrite !(rmorphM, rmorphB) iJ !conjK mulNr -[in RHS]mulrN opprB.
by rewrite (mulrC x) (mulrC y).
Qed.
HB.instance Definition _ :=
Num.IntegralDomain_isNumRing.Build L normD sposD norm_eq0
pos_linear normM (fun x y => erefl (le x y))
(fun x y => erefl (lt x y)).
HB.instance Definition _ :=
Num.NumField_isImaginary.Build L (sqrtK _) normK.
HB.end.
Module Algebraics.
Module Type Specification.
Parameter type : Type.
Parameter conjMixin : Num.ClosedField type.
Parameter isCountable : Countable type.
(* Note that this cannot be included in conjMixin since a few proofs
depend from nat_num being definitionally equal to (truncn x)%:R == x *)
Axiom archimedean : Num.archimedean_axiom (Num.ClosedField.Pack conjMixin).
Axiom algebraic : integralRange (@ratr (Num.ClosedField.Pack conjMixin)).
End Specification.
Module Implementation : Specification.
Definition L := tag Fundamental_Theorem_of_Algebraics.
Definition conjL : {rmorphism L -> L} :=
s2val (tagged Fundamental_Theorem_of_Algebraics).
Fact conjL_K : involutive conjL.
Proof. exact: s2valP (tagged Fundamental_Theorem_of_Algebraics). Qed.
Fact conjL_nt : ~ conjL =1 id.
Proof. exact: s2valP' (tagged Fundamental_Theorem_of_Algebraics). Qed.
Definition L' : Type := eta L.
HB.instance Definition _ := GRing.ClosedField.on L'.
HB.instance Definition _ := isComplex.Build L' conjL_K conjL_nt.
Notation cfType := (L' : closedFieldType).
Definition QtoL : {rmorphism _ -> _} := @ratr cfType.
Notation pQtoL := (map_poly QtoL).
Definition rootQtoL p_j :=
if p_j.1 == 0 then 0 else
(sval (closed_field_poly_normal (pQtoL p_j.1)))`_p_j.2.
Definition eq_root p_j q_k := rootQtoL p_j == rootQtoL q_k.
Fact eq_root_is_equiv : equiv_class_of eq_root.
Proof. by rewrite /eq_root; split=> [ ? | ? ? | ? ? ? ] // /eqP->. Qed.
Canonical eq_root_equiv := EquivRelPack eq_root_is_equiv.
Definition type : Type := {eq_quot eq_root}%qT.
HB.instance Definition _ : EqQuotient _ eq_root type := EqQuotient.on type.
HB.instance Definition _ := Choice.on type.
HB.instance Definition _ := isCountable.Build type
(pcan_pickleK (can_pcan reprK)).
Definition CtoL (u : type) := rootQtoL (repr u).
Fact CtoL_inj : injective CtoL.
Proof. by move=> u v /eqP eq_uv; rewrite -[u]reprK -[v]reprK; apply/eqmodP. Qed.
Fact CtoL_P u : integralOver QtoL (CtoL u).
Proof.
rewrite /CtoL /rootQtoL; case: (repr u) => p j /=.
case: (closed_field_poly_normal _) => r Dp /=.
case: ifPn => [_ | nz_p]; first exact: integral0.
have [/(nth_default 0)-> | lt_j_r] := leqP (size r) j; first exact: integral0.
apply/integral_algebraic; exists p; rewrite // Dp -mul_polyC rootM orbC.
by rewrite root_prod_XsubC mem_nth.
Qed.
Fact LtoC_subproof z : integralOver QtoL z -> {u | CtoL u = z}.
Proof.
case/sig2_eqW=> p mon_p pz0; rewrite /CtoL.
pose j := index z (sval (closed_field_poly_normal (pQtoL p))).
pose u := \pi_type%qT (p, j); exists u; have /eqmodP/eqP-> := reprK u.
rewrite /rootQtoL -if_neg monic_neq0 //; apply: nth_index => /=.
case: (closed_field_poly_normal _) => r /= Dp.
by rewrite Dp (monicP _) ?(monic_map QtoL) // scale1r root_prod_XsubC in pz0.
Qed.
Definition LtoC z Az := sval (@LtoC_subproof z Az).
Fact LtoC_K z Az : CtoL (@LtoC z Az) = z.
Proof. exact: (svalP (LtoC_subproof Az)). Qed.
Fact CtoL_K u : LtoC (CtoL_P u) = u.
Proof. by apply: CtoL_inj; rewrite LtoC_K. Qed.
Definition zero := LtoC (integral0 _).
Definition add u v := LtoC (integral_add (CtoL_P u) (CtoL_P v)).
Definition opp u := LtoC (integral_opp (CtoL_P u)).
Fact addA : associative add.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K addrA. Qed.
Fact addC : commutative add.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K addrC. Qed.
Fact add0 : left_id zero add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K add0r. Qed.
Fact addN : left_inverse zero opp add.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build type addA addC add0 addN.
Fact CtoL_is_zmod_morphism : zmod_morphism CtoL.
Proof. by move=> u v; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition CtoL_is_additive := CtoL_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build type L' CtoL
CtoL_is_zmod_morphism.
Definition one := LtoC (integral1 _).
Definition mul u v := LtoC (integral_mul (CtoL_P u) (CtoL_P v)).
Definition inv u := LtoC (integral_inv (CtoL_P u)).
Fact mulA : associative mul.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrA. Qed.
Fact mulC : commutative mul.
Proof. by move=> u v; apply: CtoL_inj; rewrite !LtoC_K mulrC. Qed.
Fact mul1 : left_id one mul.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K mul1r. Qed.
Fact mulD : left_distributive mul +%R.
Proof. by move=> u v w; apply: CtoL_inj; rewrite !LtoC_K mulrDl. Qed.
Fact one_nz : one != 0 :> type.
Proof. by rewrite -(inj_eq CtoL_inj) !LtoC_K oner_eq0. Qed.
HB.instance Definition _ :=
GRing.Zmodule_isComNzRing.Build type mulA mulC mul1 mulD one_nz.
Fact CtoL_is_monoid_morphism : monoid_morphism CtoL.
Proof. by split=> [|u v]; rewrite !LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_is_monoid_morphism` instead")]
Definition CtoL_is_multiplicative :=
(fun g => (g.2,g.1)) CtoL_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build type L' CtoL
CtoL_is_monoid_morphism.
Fact mulVf u : u != 0 -> inv u * u = 1.
Proof.
rewrite -(inj_eq CtoL_inj) rmorph0 => nz_u.
by apply: CtoL_inj; rewrite !LtoC_K mulVf.
Qed.
Fact inv0 : inv 0 = 0. Proof. by apply: CtoL_inj; rewrite !LtoC_K invr0. Qed.
HB.instance Definition _ := GRing.ComNzRing_isField.Build type mulVf inv0.
Fact closedFieldAxiom : GRing.closed_field_axiom type.
Proof.
move=> n a n_gt0; pose p := 'X^n - \poly_(i < n) CtoL (a i).
have Ap : {in p : seq L, integralRange QtoL}.
move=> _ /(nthP 0)[j _ <-]; rewrite coefB coefXn coef_poly.
apply: integral_sub; first exact: integral_nat.
by case: ifP => _; [apply: CtoL_P | apply: integral0].
have sz_p : size p = n.+1.
by rewrite size_polyDl size_polyXn // size_polyN ltnS size_poly.
have [z pz0] : exists z, root p z by apply/closed_rootP; rewrite sz_p eqSS -lt0n.
have Az: integralOver ratr z.
by apply: integral_root Ap; rewrite // -size_poly_gt0 sz_p.
exists (LtoC Az); apply/CtoL_inj; rewrite -[CtoL _]subr0 -(rootP pz0).
rewrite rmorphXn /= LtoC_K hornerD hornerXn hornerN opprD addNKr opprK.
rewrite horner_poly rmorph_sum; apply: eq_bigr => k _.
by rewrite rmorphM rmorphXn /= LtoC_K.
Qed.
HB.instance Definition _ := Field_isAlgClosed.Build type closedFieldAxiom.
Fact conj_subproof u : integralOver QtoL (conjL (CtoL u)).
Proof.
have [p mon_p pu0] := CtoL_P u; exists p => //.
rewrite -(fmorph_root conjL) conjL_K map_poly_id // => _ /(nthP 0)[j _ <-].
by rewrite coef_map fmorph_rat.
Qed.
Fact conj_is_nmod_morphism : nmod_morphism (fun u => LtoC (conj_subproof u)).
Proof.
by split=> [|u v]; apply: CtoL_inj; rewrite LtoC_K ?raddf0// !rmorphD/= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_nmod_morphism` instead")]
Definition conj_is_semi_additive := conj_is_nmod_morphism.
Fact conj_is_zmod_morphism : {morph (fun u => LtoC (conj_subproof u)) : x / - x}.
Proof. by move=> u; apply: CtoL_inj; rewrite LtoC_K !raddfN /= LtoC_K. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `CtoL_inj_is_zmod_morphism` instead")]
Definition conj_is_additive := conj_is_zmod_morphism.
Fact conj_is_monoid_morphism : monoid_morphism (fun u => LtoC (conj_subproof u)).
Proof.
split=> [|u v]; apply: CtoL_inj; first by rewrite !LtoC_K rmorph1.
by rewrite LtoC_K 3!{1}rmorphM /= !LtoC_K.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `conj_is_monoid_morphism` instead")]
Definition conj_is_multiplicative :=
(fun g => (g.2,g.1)) conj_is_monoid_morphism.
Definition conj : {rmorphism type -> type} :=
GRing.RMorphism.Pack
(GRing.RMorphism.Class
(GRing.isNmodMorphism.Build _ _ _ conj_is_nmod_morphism)
(GRing.isMonoidMorphism.Build _ _ _ conj_is_monoid_morphism)).
Lemma conjK : involutive conj.
Proof. by move=> u; apply: CtoL_inj; rewrite !LtoC_K conjL_K. Qed.
Fact conj_nt : ~ conj =1 id.
Proof.
have [i i2]: exists i : type, i ^+ 2 = -1.
have [i] := @solve_monicpoly _ 2%N (nth 0 [:: -1 : type]) isT.
by rewrite !big_ord_recl big_ord0 /= mul0r mulr1 !addr0; exists i.
move/(_ i)/(congr1 CtoL); rewrite LtoC_K => iL_J.
have/lt_geF/idP[] := @ltr01 cfType.
rewrite -oppr_ge0 -(rmorphN1 CtoL).
by rewrite -i2 rmorphXn /= expr2 -{2}iL_J -normCK exprn_ge0.
Qed.
HB.instance Definition _ := isComplex.Build type conjK conj_nt.
Definition conjMixin := Num.ClosedField.on type.
Lemma algebraic : integralRange (@ratr type).
Proof.
move=> u; have [p mon_p pu0] := CtoL_P u; exists p => {mon_p}//.
rewrite -(fmorph_root CtoL) -map_poly_comp; congr (root _ _):pu0.
by apply/esym/eq_map_poly; apply: fmorph_eq_rat.
Qed.
Fact archimedean : Num.archimedean_axiom type.
Proof. exact: rat_algebraic_archimedean algebraic. Qed.
Definition isCountable := Countable.on type.
End Implementation.
Definition divisor := Implementation.type.
#[export] HB.instance Definition _ := Implementation.conjMixin.
#[export] HB.instance Definition _ :=
Num.NumDomain_bounded_isArchimedean.Build Implementation.type
Implementation.archimedean.
#[export] HB.instance Definition _ := Implementation.isCountable.
Module Internals.
Import Implementation.
Local Notation algC := type.
Local Notation QtoC := (ratr : rat -> algC).
Local Notation pQtoC := (map_poly QtoC : {poly rat} -> {poly algC}).
Fact algCi_subproof : {i : algC | i ^+ 2 = -1}.
Proof. exact: GRing.imaginary_exists. Qed.
Variant getCrat_spec : Type := GetCrat_spec CtoQ of cancel QtoC CtoQ.
Fact getCrat_subproof : getCrat_spec.
Proof.
have isQ := rat_algebraic_decidable algebraic.
exists (fun z => if isQ z is left Qz then sval (sig_eqW Qz) else 0) => a.
case: (isQ _) => [Qa | []]; last by exists a.
by case: (sig_eqW _) => b /= /fmorph_inj.
Qed.
Fact minCpoly_subproof (x : algC) :
{p : {poly rat} | p \is monic & forall q, root (pQtoC q) x = (p %| q)%R}.
Proof.
have isQ := rat_algebraic_decidable algebraic.
have [p [mon_p px0 irr_p]] := minPoly_decidable_closure isQ (algebraic x).
exists p => // q; apply/idP/idP=> [qx0 | /dvdpP[r ->]]; last first.
by rewrite rmorphM rootM px0 orbT.
suffices /eqp_dvdl <-: gcdp p q %= p by apply: dvdp_gcdr.
rewrite irr_p ?dvdp_gcdl ?gtn_eqF // -(size_map_poly QtoC) gcdp_map /=.
rewrite (@root_size_gt1 _ x) ?root_gcd ?px0 //.
by rewrite gcdp_eq0 negb_and map_poly_eq0 monic_neq0.
Qed.
Definition algC_divisor (x : algC) := x : divisor.
Definition int_divisor m := m%:~R : divisor.
Definition nat_divisor n := n%:R : divisor.
End Internals.
Module Import Exports.
Import Implementation Internals.
Notation algC := type.
Delimit Scope C_scope with C.
Delimit Scope C_core_scope with Cc.
Delimit Scope C_expanded_scope with Cx.
Open Scope C_core_scope.
Notation algCeq := (type : eqType).
Notation algCzmod := (type : zmodType).
Notation algCnzRing := (type : nzRingType).
#[deprecated(since="mathcomp 2.4.0",
note="Use algCnzRing instead.")]
Notation algCring := (type : nzRingType).
Notation algCuring := (type : unitRingType).
Notation algCnum := (type : numDomainType).
Notation algCfield := (type : fieldType).
Notation algCnumField := (type : numFieldType).
Notation algCnumClosedField := (type : numClosedFieldType).
Notation Creal := (@Num.Def.Rreal algCnum).
Definition getCrat := let: GetCrat_spec CtoQ _ := getCrat_subproof in CtoQ.
Definition Crat : {pred algC} := fun x => ratr (getCrat x) == x.
Definition minCpoly x : {poly algC} :=
let: exist2 p _ _ := minCpoly_subproof x in map_poly ratr p.
Coercion nat_divisor : nat >-> divisor.
Coercion int_divisor : int >-> divisor.
Coercion algC_divisor : algC >-> divisor.
Lemma nCdivE (p : nat) : p = p%:R :> divisor. Proof. by []. Qed.
Lemma zCdivE (p : int) : p = p%:~R :> divisor. Proof. by []. Qed.
Definition CdivE := (nCdivE, zCdivE).
Definition dvdC (x : divisor) : {pred algC} :=
fun y => if x == 0 then y == 0 else y / x \in Num.int.
Notation "x %| y" := (y \in dvdC x) : C_expanded_scope.
Notation "x %| y" := (@in_mem divisor y (mem (dvdC x))) : C_scope.
Definition eqCmod (e x y : divisor) := (e %| x - y)%C.
Notation "x == y %[mod e ]" := (eqCmod e x y) : C_scope.
Notation "x != y %[mod e ]" := (~~ (x == y %[mod e])%C) : C_scope.
End Exports.
Module HBExports. HB.reexport. End HBExports.
End Algebraics.
Export Algebraics.Exports.
Export Algebraics.HBExports.
Section AlgebraicsTheory.
Implicit Types (x y z : algC) (n : nat) (m : int) (b : bool).
Import Algebraics.Internals.
Local Notation ZtoQ := (intr : int -> rat).
Local Notation ZtoC := (intr : int -> algC).
Local Notation QtoC := (ratr : rat -> algC).
Local Notation CtoQ := getCrat.
Local Notation intrp := (map_poly intr).
Local Notation pZtoQ := (map_poly ZtoQ).
Local Notation pZtoC := (map_poly ZtoC).
Local Notation pQtoC := (map_poly ratr).
Let intr_inj_ZtoC := (intr_inj : injective ZtoC).
#[local] Hint Resolve intr_inj_ZtoC : core.
(* Specialization of a few basic ssrnum order lemmas. *)
Definition eqC_nat n p : (n%:R == p%:R :> algC) = (n == p) := eqr_nat _ n p.
Definition leC_nat n p : (n%:R <= p%:R :> algC) = (n <= p)%N := ler_nat _ n p.
Definition ltC_nat n p : (n%:R < p%:R :> algC) = (n < p)%N := ltr_nat _ n p.
Definition Cpchar : [pchar algC] =i pred0 := @pchar_num _.
(* This can be used in the converse direction to evaluate assertions over *)
(* manifest rationals, such as 3^-1 + 7%:%^-1 < 2%:%^-1 :> algC. *)
(* Missing norm and integer exponent, due to gaps in ssrint and rat. *)
Definition CratrE :=
let CnF : numClosedFieldType := algC in
let QtoCm : {rmorphism _ -> _} := @ratr CnF in
((rmorph0 QtoCm, rmorph1 QtoCm, rmorphMn QtoCm, rmorphN QtoCm, rmorphD QtoCm),
(rmorphM QtoCm, rmorphXn QtoCm, fmorphV QtoCm),
(rmorphMz QtoCm, rmorphXz QtoCm, @ratr_norm CnF, @ratr_sg CnF),
=^~ (@ler_rat CnF, @ltr_rat CnF, (inj_eq (fmorph_inj QtoCm)))).
Definition CintrE :=
let CnF : numClosedFieldType := algC in
let ZtoCm : {rmorphism _ -> _} := *~%R (1 : CnF) in
((rmorph0 ZtoCm, rmorph1 ZtoCm, rmorphMn ZtoCm, rmorphN ZtoCm, rmorphD ZtoCm),
(rmorphM ZtoCm, rmorphXn ZtoCm),
(rmorphMz ZtoCm, @intr_norm CnF, @intr_sg CnF),
=^~ (@ler_int CnF, @ltr_int CnF, (inj_eq (@intr_inj CnF)))).
Let nz2 : 2 != 0 :> algC.
Proof. by rewrite pnatr_eq0. Qed.
(* Conjugation and norm. *)
Definition algC_algebraic x := Algebraics.Implementation.algebraic x.
(* Real number subset. *)
Lemma algCrect x : x = 'Re x + 'i * 'Im x.
Proof. by rewrite [LHS]Crect. Qed.
Lemma algCreal_Re x : 'Re x \is Creal.
Proof. by rewrite Creal_Re. Qed.
Lemma algCreal_Im x : 'Im x \is Creal.
Proof. by rewrite Creal_Im. Qed.
Hint Resolve algCreal_Re algCreal_Im : core.
(* Integer divisibility. *)
Lemma dvdCP x y : reflect (exists2 z, z \in Num.int & y = z * x) (x %| y)%C.
Proof.
rewrite unfold_in; have [-> | nz_x] := eqVneq.
by apply: (iffP eqP) => [-> | [z _ ->]]; first exists 0; rewrite ?mulr0.
apply: (iffP idP) => [Zyx | [z Zz ->]]; last by rewrite mulfK.
by exists (y / x); rewrite ?divfK.
Qed.
Lemma dvdCP_nat x y : 0 <= x -> 0 <= y -> (x %| y)%C -> {n | y = n%:R * x}.
Proof.
move=> x_ge0 y_ge0 x_dv_y; apply: sig_eqW.
case/dvdCP: x_dv_y => z Zz -> in y_ge0 *; move: x_ge0 y_ge0 Zz.
rewrite le_eqVlt => /predU1P[<- | ]; first by exists 22%N; rewrite !mulr0.
by move=> /pmulr_lge0-> /intrEge0-> /natrP[n ->]; exists n.
Qed.
Lemma dvdC0 x : (x %| 0)%C.
Proof. by apply/dvdCP; exists 0; rewrite ?mul0r. Qed.
Lemma dvd0C x : (0 %| x)%C = (x == 0).
Proof. by rewrite unfold_in eqxx. Qed.
Lemma dvdC_mull x y z : y \in Num.int -> (x %| z)%C -> (x %| y * z)%C.
Proof.
move=> Zy /dvdCP[m Zm ->]; apply/dvdCP.
by exists (y * m); rewrite ?mulrA ?rpredM.
Qed.
Lemma dvdC_mulr x y z : y \in Num.int -> (x %| z)%C -> (x %| z * y)%C.
Proof. by rewrite mulrC; apply: dvdC_mull. Qed.
Lemma dvdC_mul2r x y z : y != 0 -> (x * y %| z * y)%C = (x %| z)%C.
Proof.
move=> nz_y; rewrite !unfold_in !(mulIr_eq0 _ (mulIf nz_y)).
by rewrite mulrAC invfM mulrA divfK.
Qed.
Lemma dvdC_mul2l x y z : y != 0 -> (y * x %| y * z)%C = (x %| z)%C.
Proof. by rewrite !(mulrC y); apply: dvdC_mul2r. Qed.
Lemma dvdC_trans x y z : (x %| y)%C -> (y %| z)%C -> (x %| z)%C.
Proof. by move=> x_dv_y /dvdCP[m Zm ->]; apply: dvdC_mull. Qed.
Lemma dvdC_refl x : (x %| x)%C.
Proof. by apply/dvdCP; exists 1; rewrite ?mul1r. Qed.
Hint Resolve dvdC_refl : core.
Lemma dvdC_zmod x : zmod_closed (dvdC x).
Proof.
split=> [| _ _ /dvdCP[y Zy ->] /dvdCP[z Zz ->]]; first exact: dvdC0.
by rewrite -mulrBl dvdC_mull ?rpredB.
Qed.
HB.instance Definition _ x := GRing.isZmodClosed.Build _ (dvdC x) (dvdC_zmod x).
Lemma dvdC_nat (p n : nat) : (p %| n)%C = (p %| n)%N.
Proof.
rewrite unfold_in intrEge0 ?divr_ge0 ?invr_ge0 ?ler0n // !pnatr_eq0.
have [-> | nz_p] := eqVneq; first by rewrite dvd0n.
apply/natrP/dvdnP=> [[q def_q] | [q ->]]; exists q.
by apply/eqP; rewrite -eqC_nat natrM -def_q divfK ?pnatr_eq0.
by rewrite [num in num / _]natrM mulfK ?pnatr_eq0.
Qed.
Lemma dvdC_int (p : nat) x :
x \in Num.int -> (p %| x)%C = (p %| `|Num.floor x|)%N.
Proof.
move=> Zx; rewrite -{1}(floorK Zx) {1}[Num.floor x]intEsign.
by rewrite rmorphMsign rpredMsign dvdC_nat.
Qed.
(* Elementary modular arithmetic. *)
Lemma eqCmod_refl e x : (x == x %[mod e])%C.
Proof. by rewrite /eqCmod subrr rpred0. Qed.
Lemma eqCmodm0 e : (e == 0 %[mod e])%C. Proof. by rewrite /eqCmod subr0. Qed.
Hint Resolve eqCmod_refl eqCmodm0 : core.
Lemma eqCmod0 e x : (x == 0 %[mod e])%C = (e %| x)%C.
Proof. by rewrite /eqCmod subr0. Qed.
Lemma eqCmod_sym e x y : ((x == y %[mod e]) = (y == x %[mod e]))%C.
Proof. by rewrite /eqCmod -opprB rpredN. Qed.
Lemma eqCmod_trans e y x z :
(x == y %[mod e] -> y == z %[mod e] -> x == z %[mod e])%C.
Proof.
by move=> Exy Eyz; rewrite /eqCmod -[x](subrK y) -[_ - z]addrA rpredD.
Qed.
Lemma eqCmod_transl e x y z :
(x == y %[mod e])%C -> (x == z %[mod e])%C = (y == z %[mod e])%C.
Proof. by move/(sym_left_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmod_transr e x y z :
(x == y %[mod e])%C -> (z == x %[mod e])%C = (z == y %[mod e])%C.
Proof. by move/(sym_right_transitive (eqCmod_sym e) (@eqCmod_trans e)). Qed.
Lemma eqCmodN e x y : (- x == y %[mod e])%C = (x == - y %[mod e])%C.
Proof. by rewrite eqCmod_sym /eqCmod !opprK addrC. Qed.
Lemma eqCmodDr e x y z : (y + x == z + x %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite /eqCmod addrAC opprD !addrA subrK. Qed.
Lemma eqCmodDl e x y z : (x + y == x + z %[mod e])%C = (y == z %[mod e])%C.
Proof. by rewrite !(addrC x) eqCmodDr. Qed.
Lemma eqCmodD e x1 x2 y1 y2 :
(x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 + y1 == x2 + y2 %[mod e])%C.
Proof.
by rewrite -(eqCmodDl e x2 y1) -(eqCmodDr e y1); apply: eqCmod_trans.
Qed.
Lemma eqCmod_nat (e m n : nat) : (m == n %[mod e])%C = (m == n %[mod e]).
Proof.
without loss lenm: m n / (n <= m)%N.
by move=> IH; case/orP: (leq_total m n) => /IH //; rewrite eqCmod_sym eq_sym.
by rewrite /eqCmod -natrB // dvdC_nat eqn_mod_dvd.
Qed.
Lemma eqCmod0_nat (e m : nat) : (m == 0 %[mod e])%C = (e %| m)%N.
Proof. by rewrite eqCmod0 dvdC_nat. Qed.
Lemma eqCmodMr e :
{in Num.int, forall z x y, x == y %[mod e] -> x * z == y * z %[mod e]}%C.
Proof. by move=> z Zz x y; rewrite /eqCmod -mulrBl => /dvdC_mulr->. Qed.
Lemma eqCmodMl e :
{in Num.int, forall z x y, x == y %[mod e] -> z * x == z * y %[mod e]}%C.
Proof. by move=> z Zz x y Exy; rewrite !(mulrC z) eqCmodMr. Qed.
Lemma eqCmodMl0 e : {in Num.int, forall x, x * e == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite -(mulr0 x) eqCmodMl. Qed.
Lemma eqCmodMr0 e : {in Num.int, forall x, e * x == 0 %[mod e]}%C.
Proof. by move=> x Zx; rewrite /= mulrC eqCmodMl0. Qed.
Lemma eqCmod_addl_mul e : {in Num.int, forall x y, x * e + y == y %[mod e]}%C.
Proof. by move=> x Zx y; rewrite -{2}[y]add0r eqCmodDr eqCmodMl0. Qed.
Lemma eqCmodM e : {in Num.int & Num.int, forall x1 y2 x2 y1,
x1 == x2 %[mod e] -> y1 == y2 %[mod e] -> x1 * y1 == x2 * y2 %[mod e]}%C.
Proof.
move=> x1 y2 Zx1 Zy2 x2 y1 eq_x /(eqCmodMl Zx1)/eqCmod_trans-> //.
exact: eqCmodMr.
Qed.
(* Rational number subset. *)
Lemma ratCK : cancel QtoC CtoQ.
Proof. by rewrite /getCrat; case: getCrat_subproof. Qed.
Lemma getCratK : {in Crat, cancel CtoQ QtoC}.
Proof. by move=> x /eqP. Qed.
Lemma Crat_rat (a : rat) : QtoC a \in Crat.
Proof. by rewrite unfold_in ratCK. Qed.
Lemma CratP x : reflect (exists a, x = QtoC a) (x \in Crat).
Proof.
by apply: (iffP eqP) => [<- | [a ->]]; [exists (CtoQ x) | rewrite ratCK].
Qed.
Lemma Crat0 : 0 \in Crat. Proof. by apply/CratP; exists 0; rewrite rmorph0. Qed.
Lemma Crat1 : 1 \in Crat. Proof. by apply/CratP; exists 1; rewrite rmorph1. Qed.
#[local] Hint Resolve Crat0 Crat1 : core.
Fact Crat_divring_closed : divring_closed Crat.
Proof.
split=> // _ _ /CratP[x ->] /CratP[y ->].
by rewrite -rmorphB Crat_rat.
by rewrite -fmorph_div Crat_rat.
Qed.
HB.instance Definition _ := GRing.isDivringClosed.Build _ Crat
Crat_divring_closed.
Lemma rpred_Crat (S : divringClosed algC) : {subset Crat <= S}.
Proof. by move=> _ /CratP[a ->]; apply: rpred_rat. Qed.
Lemma conj_Crat z : z \in Crat -> z^* = z.
Proof. by move/getCratK <-; rewrite fmorph_div !rmorph_int. Qed.
Lemma Creal_Crat : {subset Crat <= Creal}.
Proof. by move=> x /conj_Crat/CrealP. Qed.
Lemma Cint_rat a : (QtoC a \in Num.int) = (a \in Num.int).
Proof.
apply/idP/idP=> [Za | /numqK <-]; last by rewrite rmorph_int.
apply/intrP; exists (Num.floor (QtoC a)); apply: (can_inj ratCK).
by rewrite rmorph_int floorK.
Qed.
Lemma minCpolyP x :
{p : {poly rat} | minCpoly x = pQtoC p /\ p \is monic
& forall q, root (pQtoC q) x = (p %| q)%R}.
Proof. by rewrite /minCpoly; case: (minCpoly_subproof x) => p; exists p. Qed.
Lemma minCpoly_monic x : minCpoly x \is monic.
Proof. by have [p [-> mon_p] _] := minCpolyP x; rewrite map_monic. Qed.
Lemma minCpoly_eq0 x : (minCpoly x == 0) = false.
Proof. exact/negbTE/monic_neq0/minCpoly_monic. Qed.
Lemma root_minCpoly x : root (minCpoly x) x.
Proof. by have [p [-> _] ->] := minCpolyP x. Qed.
Lemma size_minCpoly x : (1 < size (minCpoly x))%N.
Proof. by apply: root_size_gt1 (root_minCpoly x); rewrite ?minCpoly_eq0. Qed.
(* Basic properties of automorphisms. *)
Section AutC.
Implicit Type nu : {rmorphism algC -> algC}.
Lemma aut_Crat nu : {in Crat, nu =1 id}.
Proof. by move=> _ /CratP[a ->]; apply: fmorph_rat. Qed.
Lemma Crat_aut nu x : (nu x \in Crat) = (x \in Crat).
Proof.
apply/idP/idP=> /CratP[a] => [|->]; last by rewrite fmorph_rat Crat_rat.
by rewrite -(fmorph_rat nu) => /fmorph_inj->; apply: Crat_rat.
Qed.
Lemma algC_invaut_subproof nu x : {y | nu y = x}.
Proof.
have [r Dp] := closed_field_poly_normal (minCpoly x).
suffices /mapP/sig2_eqW[y _ ->]: x \in map nu r by exists y.
rewrite -root_prod_XsubC; congr (root _ x): (root_minCpoly x).
have [q [Dq _] _] := minCpolyP x; rewrite Dq -(eq_map_poly (fmorph_rat nu)).
rewrite (map_poly_comp nu) -{q}Dq Dp (monicP (minCpoly_monic x)) scale1r.
rewrite rmorph_prod big_map /=; apply: eq_bigr => z _.
by rewrite rmorphB /= map_polyX map_polyC.
Qed.
Definition algC_invaut nu x := sval (algC_invaut_subproof nu x).
Lemma algC_invautK nu : cancel (algC_invaut nu) nu.
Proof. by move=> x; rewrite /algC_invaut; case: algC_invaut_subproof. Qed.
Lemma algC_autK nu : cancel nu (algC_invaut nu).
Proof. exact: inj_can_sym (algC_invautK nu) (fmorph_inj nu). Qed.
Fact algC_invaut_is_zmod_morphism nu : zmod_morphism (algC_invaut nu).
Proof. exact: can2_zmod_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_zmod_morphism` instead")]
Definition algC_invaut_is_additive := algC_invaut_is_zmod_morphism.
Fact algC_invaut_is_monoid_morphism nu : monoid_morphism (algC_invaut nu).
Proof. exact: can2_monoid_morphism (algC_autK nu) (algC_invautK nu). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algC_invaut_is_monoid_morphism` instead")]
Definition algC_invaut_is_multiplicative nu :=
(fun g => (g.2,g.1)) (algC_invaut_is_monoid_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isZmodMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_zmod_morphism nu).
HB.instance Definition _ (nu : {rmorphism algC -> algC}) :=
GRing.isMonoidMorphism.Build algC algC (algC_invaut nu)
(algC_invaut_is_monoid_morphism nu).
Lemma minCpoly_aut nu x : minCpoly (nu x) = minCpoly x.
Proof.
wlog suffices dvd_nu: nu x / (minCpoly x %| minCpoly (nu x))%R.
apply/eqP; rewrite -eqp_monic ?minCpoly_monic //; apply/andP; split=> //.
by rewrite -{2}(algC_autK nu x) dvd_nu.
have [[q [Dq _] min_q] [q1 [Dq1 _] _]] := (minCpolyP x, minCpolyP (nu x)).
rewrite Dq Dq1 dvdp_map -min_q -(fmorph_root nu) -map_poly_comp.
by rewrite (eq_map_poly (fmorph_rat nu)) -Dq1 root_minCpoly.
Qed.
End AutC.
End AlgebraicsTheory.
#[deprecated(since="mathcomp 2.4.0", note="Use Cpchar instead.")]
Notation Cchar := (Cpchar) (only parsing).
#[global] Hint Resolve Crat0 Crat1 dvdC0 dvdC_refl eqCmod_refl eqCmodm0 : core.
Local Notation "p ^^ f" := (map_poly f p)
(at level 30, f at level 30, format "p ^^ f").
Record algR := in_algR {algRval :> algC; algRvalP : algRval \is Creal}.
HB.instance Definition _ := [isSub for algRval].
HB.instance Definition _ := [Countable of algR by <:].
HB.instance Definition _ := [SubChoice_isSubIntegralDomain of algR by <:].
HB.instance Definition _ := [SubIntegralDomain_isSubField of algR by <:].
HB.instance Definition _ : Order.isPOrder ring_display algR :=
Order.CancelPartial.Pcan _ valK.
Lemma total_algR : total (<=%O : rel (algR : porderType _)).
Proof. by move=> x y; apply/real_leVge/valP/valP. Qed.
HB.instance Definition _ := Order.POrder_isTotal.Build _ algR total_algR.
Lemma algRval_is_zmod_morphism : zmod_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_zmod_morphism` instead")]
Definition algRval_is_additive := algRval_is_zmod_morphism.
Lemma algRval_is_monoid_morphism : monoid_morphism algRval. Proof. by []. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `algRval_is_monoid_morphism` instead")]
Definition algRval_is_multiplicative :=
(fun g => (g.2,g.1)) algRval_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build algR algC algRval
algRval_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build algR algC algRval
algRval_is_monoid_morphism.
Definition algR_norm (x : algR) : algR := in_algR (normr_real (val x)).
Lemma algR_ler_normD x y : algR_norm (x + y) <= (algR_norm x + algR_norm y).
Proof. exact: ler_normD. Qed.
Lemma algR_normr0_eq0 x : algR_norm x = 0 -> x = 0.
Proof. by move=> /(congr1 val)/normr0_eq0 ?; apply/val_inj. Qed.
Lemma algR_normrMn x n : algR_norm (x *+ n) = algR_norm x *+ n.
Proof. by apply/val_inj; rewrite /= !rmorphMn/= normrMn. Qed.
Lemma algR_normrN x : algR_norm (- x) = algR_norm x.
Proof. by apply/val_inj; apply: normrN. Qed.
Section Num.
Section withz.
Let z : algR := 0.
Lemma algR_addr_gt0 (x y : algR) : z < x -> z < y -> z < x + y.
Proof. exact: addr_gt0. Qed.
Lemma algR_ger_leVge (x y : algR) : z <= x -> z <= y -> (x <= y) || (y <= x).
Proof. exact: ger_leVge. Qed.
Lemma algR_normrM : {morph algR_norm : x y / x * y}.
Proof. by move=> *; apply/val_inj; apply: normrM. Qed.
Lemma algR_ler_def (x y : algR) : (x <= y) = (algR_norm (y - x) == y - x).
Proof. by apply: ler_def. Qed.
End withz.
HB.instance Definition _ := Num.Zmodule_isNormed.Build _ algR
algR_ler_normD algR_normr0_eq0 algR_normrMn algR_normrN.
HB.instance Definition _ := Num.isNumRing.Build algR
algR_addr_gt0 algR_ger_leVge algR_normrM algR_ler_def.
End Num.
Definition algR_archiFieldMixin : Num.archimedean_axiom algR.
Proof.
move=> /= x; have := real_floorD1_gt (valP `|x|).
set n := Num.floor _ + 1 => x_lt.
exists (`|(n + 1)%R|%N); apply: (lt_le_trans x_lt _).
by rewrite /= rmorphMn/= pmulrn ler_int (le_trans _ (lez_abs _))// lerDl.
Qed.
HB.instance Definition _ := Num.NumDomain_bounded_isArchimedean.Build algR
algR_archiFieldMixin.
Definition algR_pfactor (x : algC) : {poly algR} :=
if x \is Creal =P true is ReflectT xR then 'X - (in_algR xR)%:P else
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Notation algC_pfactor x := (algR_pfactor x ^^ algRval).
Lemma algR_pfactorRE (x : algC) (xR : x \is Creal) :
algR_pfactor x = 'X - (in_algR xR)%:P.
Proof.
rewrite /algR_pfactor; case: eqP xR => //= p1 p2.
by rewrite (bool_irrelevance p1 p2).
Qed.
Lemma algC_pfactorRE (x : algC) : x \is Creal ->
algC_pfactor x = 'X - x%:P.
Proof. by move=> xR; rewrite algR_pfactorRE map_polyXsubC. Qed.
Lemma algR_pfactorCE (x : algC) : x \isn't Creal ->
algR_pfactor x =
'X^2 - (in_algR (Creal_Re x) *+ 2) *: 'X + ((in_algR (normr_real x))^+2)%:P.
Proof. by rewrite /algR_pfactor; case: eqP => // p; rewrite p. Qed.
Lemma algC_pfactorCE (x : algC) : x \isn't Creal ->
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P).
Proof.
move=> xNR; rewrite algR_pfactorCE//=.
rewrite rmorphD /= rmorphB/= !map_polyZ !map_polyXn/= map_polyX.
rewrite (map_polyC algRval)/=.
rewrite mulrBl !mulrBr -!addrA; congr (_ + _).
rewrite opprD addrA opprK -opprD -rmorphM/= -normCK; congr (- _ + _).
rewrite mulrC !mul_polyC -scalerDl.
rewrite [x in RHS]algCrect conjC_rect ?Creal_Re ?Creal_Im//.
by rewrite addrACA addNr addr0.
Qed.
Lemma algC_pfactorE x :
algC_pfactor x = ('X - x%:P) * ('X - x^*%:P) ^+ (x \isn't Creal).
Proof.
by have [/algC_pfactorRE|/algC_pfactorCE] := boolP (_ \is _); rewrite ?mulr1.
Qed.
Lemma size_algC_pfactor x : size (algC_pfactor x) = (x \isn't Creal).+2.
Proof.
have [xR|xNR] := boolP (_ \is _); first by rewrite algC_pfactorRE// size_XsubC.
by rewrite algC_pfactorCE// size_mul ?size_XsubC ?polyXsubC_eq0.
Qed.
Lemma size_algR_pfactor x : size (algR_pfactor x) = (x \isn't Creal).+2.
Proof. by have := size_algC_pfactor x; rewrite size_map_poly. Qed.
Lemma algC_pfactor_eq0 x : (algC_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algC_pfactor. Qed.
Lemma algR_pfactor_eq0 x : (algR_pfactor x == 0) = false.
Proof. by rewrite -size_poly_eq0 size_algR_pfactor. Qed.
Lemma algC_pfactorCgt0 x y : x \isn't Creal -> y \is Creal ->
(algC_pfactor x).[y] > 0.
Proof.
move=> xNR yR; rewrite algC_pfactorCE// hornerM !hornerXsubC.
rewrite [x]algCrect conjC_rect ?Creal_Re ?Creal_Im// !opprD !addrA opprK.
rewrite -subr_sqr exprMn sqrCi mulN1r opprK ltr_wpDl//.
- by rewrite real_exprn_even_ge0// ?rpredB// ?Creal_Re.
by rewrite real_exprn_even_gt0 ?Creal_Im ?orTb//=; apply/eqP/Creal_ImP.
Qed.
Lemma algR_pfactorR_mul_gt0 (x a b : algC) :
x \is Creal -> a \is Creal -> b \is Creal ->
a <= b ->
((algC_pfactor x).[a] * (algC_pfactor x).[b] <= 0) =
(a <= x <= b).
Proof.
move=> xR aR bR ab; rewrite !algC_pfactorRE// !hornerXsubC.
have [lt_xa|lt_ax|->]/= := real_ltgtP xR aR; last first.
- by rewrite subrr mul0r lexx ab.
- by rewrite nmulr_rle0 ?subr_lt0 ?subr_ge0.
rewrite pmulr_rle0 ?subr_gt0// subr_le0.
by apply: negbTE; rewrite -real_ltNge// (lt_le_trans lt_xa).
Qed.
Lemma monic_algC_pfactor x : algC_pfactor x \is monic.
Proof. by rewrite algC_pfactorE rpredM ?rpredX ?monicXsubC. Qed.
Lemma monic_algR_pfactor x : algR_pfactor x \is monic.
Proof. by have := monic_algC_pfactor x; rewrite map_monic. Qed.
Lemma poly_algR_pfactor (p : {poly algR}) :
{ r : seq algC |
p ^^ algRval = val (lead_coef p) *: \prod_(z <- r) algC_pfactor z }.
Proof.
wlog p_monic : p / p \is monic => [hwlog|].
have [->|pN0] := eqVneq p 0.
by exists [::]; rewrite lead_coef0/= rmorph0 scale0r.
have [|r] := hwlog ((lead_coef p)^-1 *: p).
by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0//.
rewrite !lead_coefZ mulVf ?lead_coef_eq0//= scale1r.
rewrite map_polyZ/= => /(canRL (scalerKV _))->; first by exists r.
by rewrite fmorph_eq0 lead_coef_eq0.
suff: {r : seq algC | p ^^ algRval = \prod_(z <- r) algC_pfactor z}.
by move=> [r rP]; exists r; rewrite rP (monicP _)// scale1r.
have [/= r pr] := closed_field_poly_normal (p ^^ algRval).
rewrite (monicP _) ?monic_map ?scale1r// {p_monic} in pr *.
have [n] := ubnP (size r).
elim: n r => // n IHn [|x r]/= in p pr *.
by exists [::]; rewrite pr !big_nil.
rewrite ltnS => r_lt.
have xJxr : x^* \in x :: r.
rewrite -root_prod_XsubC -pr.
have /eq_map_poly-> : algRval =1 Num.conj_op \o algRval.
by move=> a /=; rewrite (CrealP (algRvalP _)).
by rewrite map_poly_comp mapf_root pr root_prod_XsubC mem_head.
have xJr : (x \isn't Creal) ==> (x^* \in r) by rewrite implyNb CrealE.
have pxdvdC : algC_pfactor x %| p ^^ algRval.
rewrite pr algC_pfactorE big_cons/= dvdp_mul2l ?polyXsubC_eq0//.
by case: (_ \is _) xJr; rewrite ?dvd1p// dvdp_XsubCl root_prod_XsubC.
pose pr'x := p %/ algR_pfactor x.
have [||r'] := IHn (if x \is Creal then r else rem x^* r) pr'x; last 2 first.
- by case: (_ \is _) in xJr *; rewrite ?size_rem// (leq_ltn_trans (leq_pred _)).
- move=> /eqP; rewrite map_divp -dvdp_eq_mul ?algC_pfactor_eq0//= => /eqP->.
by exists (x :: r'); rewrite big_cons mulrC.
rewrite map_divp/= pr big_cons algC_pfactorE/=.
rewrite divp_pmul2l ?expf_neq0 ?polyXsubC_eq0//.
case: (_ \is _) => /= in xJr *; first by rewrite divp1//.
by rewrite (big_rem _ xJr)/= mulKp ?polyXsubC_eq0.
Qed.
Definition algR_rcfMixin : Num.real_closed_axiom algR.
Proof.
move=> p a b le_ab /andP[pa_le0 pb_ge0]/=.
case: ltgtP pa_le0 => //= pa0 _; last first.
by exists a; rewrite ?lexx// rootE pa0.
case: ltgtP pb_ge0 => //= pb0 _; last first.
by exists b; rewrite ?lexx ?andbT// rootE -pb0.
have p_neq0 : p != 0 by apply: contraTneq pa0 => ->; rewrite horner0 ltxx.
have {pa0 pb0} pab0 : p.[a] * p.[b] < 0 by rewrite pmulr_llt0.
wlog p_monic : p p_neq0 pab0 / p \is monic => [hwlog|].
have [|||x axb] := hwlog ((lead_coef p)^-1 *: p).
- by rewrite scaler_eq0 invr_eq0 lead_coef_eq0 (negPf p_neq0).
- rewrite !hornerE/= -mulrA mulrACA -expr2 pmulr_rlt0//.
by rewrite exprn_even_gt0//= invr_eq0 lead_coef_eq0.
- by rewrite monicE lead_coefZ mulVf ?lead_coef_eq0 ?eqxx.
by rewrite rootZ ?invr_eq0 ?lead_coef_eq0//; exists x.
have /= [rs prs] := poly_algR_pfactor p.
rewrite (monicP _) ?monic_map// scale1r {p_monic} in prs.
pose ab := [pred x | val a <= x <= val b].
have abR : {subset ab <= Creal}.
move=> x /andP[+ _].
by rewrite -subr_ge0 => /ger0_real; rewrite rpredBr// algRvalP.
wlog : p pab0 {p_neq0 prs} /
p ^^ algRval = \prod_(x <- rs | x \in ab) ('X - x%:P) => [hw|].
move: prs; rewrite -!rmorph_prod => /map_poly_inj.
rewrite (bigID ab)/=; set q := (X in X * _); set u := (X in _ * X) => pqu.
have [||] := hw q; last first.
- by move=> x; exists x => //; rewrite pqu rootM q0.
- by rewrite rmorph_prod/=; under eq_bigr do rewrite algC_pfactorRE ?abR//.
have := pab0; rewrite pqu !hornerM mulrACA [_ * _ * _ < 0]pmulr_llt0//.
rewrite !horner_prod -big_split/= prodr_gt0// => x.
have [xR|xNR] := boolP (x \is Creal); last first.
rewrite (_ : (0 < ?[a]) = (algRval 0 < algRval ?a))//=.
by rewrite -!horner_map/= mulr_gt0 ?algC_pfactorCgt0 ?algRvalP.
apply: contraNT; rewrite -leNgt.
rewrite (_ : (?[a] <= 0) = (algRval ?a <= algRval 0))//= -!horner_map/=.
by rewrite algR_pfactorR_mul_gt0 ?algRvalP.
rewrite -big_filter; have := filter_all ab rs.
set rsab := filter _ _.
have: all (mem Creal) rsab.
by apply/allP => x; rewrite mem_filter => /andP[/abR].
case: rsab => [_ _|x rsab]/=; rewrite (big_nil, big_cons).
move=> pval1; move: pab0.
have /map_poly_inj-> : p ^^ algRval = 1 ^^ algRval by rewrite rmorph1.
by rewrite !hornerE ltr10.
move=> /andP[xR rsabR] /andP[axb arsb] prsab.
exists (in_algR xR) => //=.
by rewrite -(mapf_root algRval)//= prsab rootM root_XsubC eqxx.
Qed.
HB.instance Definition _ := Num.RealField_isClosed.Build algR algR_rcfMixin.
|
NatFib.lean
|
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller, Mario Carneiro
-/
import Mathlib.Data.Nat.Fib.Basic
import Mathlib.Tactic.NormNum
/-! # `norm_num` extension for `Nat.fib`
This `norm_num` extension uses a strategy parallel to that of `Nat.fastFib`, but it instead
produces proofs of what `Nat.fib` evaluates to.
-/
namespace Mathlib.Meta.NormNum
open Qq Lean Elab.Tactic
open Nat
/-- Auxiliary definition for `proveFib` extension. -/
def IsFibAux (n a b : β) :=
fib n = a β§ fib (n + 1) = b
theorem isFibAux_zero : IsFibAux 0 0 1 :=
β¨fib_zero, fib_oneβ©
theorem isFibAux_one : IsFibAux 1 1 1 :=
β¨fib_one, fib_twoβ©
theorem isFibAux_two_mul {n a b n' a' b' : β} (H : IsFibAux n a b)
(hn : 2 * n = n') (h1 : a * (2 * b - a) = a') (h2 : a * a + b * b = b') :
IsFibAux n' a' b' :=
β¨by rw [β hn, fib_two_mul, H.1, H.2, β h1],
by rw [β hn, fib_two_mul_add_one, H.1, H.2, pow_two, pow_two, add_comm, h2]β©
theorem isFibAux_two_mul_add_one {n a b n' a' b' : β} (H : IsFibAux n a b)
(hn : 2 * n + 1 = n') (h1 : a * a + b * b = a') (h2 : b * (2 * a + b) = b') :
IsFibAux n' a' b' :=
β¨by rw [β hn, fib_two_mul_add_one, H.1, H.2, pow_two, pow_two, add_comm, h1],
by rw [β hn, fib_two_mul_add_two, H.1, H.2, h2]β©
partial def proveNatFibAux (en' : Q(β)) : (ea' eb' : Q(β)) Γ Q(IsFibAux $en' $ea' $eb') :=
match en'.natLit! with
| 0 =>
show (ea' eb' : Q(β)) Γ Q(IsFibAux 0 $ea' $eb') from
β¨mkRawNatLit 0, mkRawNatLit 1, q(isFibAux_zero)β©
| 1 =>
show (ea' eb' : Q(β)) Γ Q(IsFibAux 1 $ea' $eb') from
β¨mkRawNatLit 1, mkRawNatLit 1, q(isFibAux_one)β©
| n' =>
have en : Q(β) := mkRawNatLit <| n' / 2
let β¨ea, eb, Hβ© := proveNatFibAux en
let a := ea.natLit!
let b := eb.natLit!
if n' % 2 == 0 then
have hn : Q(2 * $en = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(β) := mkRawNatLit <| a * (2 * b - a)
have eb' : Q(β) := mkRawNatLit <| a * a + b * b
have h1 : Q($ea * (2 * $eb - $ea) = $ea') := (q(Eq.refl $ea') : Expr)
have h2 : Q($ea * $ea + $eb * $eb = $eb') := (q(Eq.refl $eb') : Expr)
β¨ea', eb', q(isFibAux_two_mul $H $hn $h1 $h2)β©
else
have hn : Q(2 * $en + 1 = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(β) := mkRawNatLit <| a * a + b * b
have eb' : Q(β) := mkRawNatLit <| b * (2 * a + b)
have h1 : Q($ea * $ea + $eb * $eb = $ea') := (q(Eq.refl $ea') : Expr)
have h2 : Q($eb * (2 * $ea + $eb) = $eb') := (q(Eq.refl $eb') : Expr)
β¨ea', eb', q(isFibAux_two_mul_add_one $H $hn $h1 $h2)β©
theorem isFibAux_two_mul_done {n a b n' a' : β} (H : IsFibAux n a b)
(hn : 2 * n = n') (h : a * (2 * b - a) = a') : fib n' = a' :=
(isFibAux_two_mul H hn h rfl).1
theorem isFibAux_two_mul_add_one_done {n a b n' a' : β} (H : IsFibAux n a b)
(hn : 2 * n + 1 = n') (h : a * a + b * b = a') : fib n' = a' :=
(isFibAux_two_mul_add_one H hn h rfl).1
/-- Given the natural number literal `ex`, returns `Nat.fib ex` as a natural number literal
and an equality proof. Panics if `ex` isn't a natural number literal. -/
def proveNatFib (en' : Q(β)) : (em : Q(β)) Γ Q(Nat.fib $en' = $em) :=
match en'.natLit! with
| 0 => show (em : Q(β)) Γ Q(Nat.fib 0 = $em) from β¨mkRawNatLit 0, q(Nat.fib_zero)β©
| 1 => show (em : Q(β)) Γ Q(Nat.fib 1 = $em) from β¨mkRawNatLit 1, q(Nat.fib_one)β©
| 2 => show (em : Q(β)) Γ Q(Nat.fib 2 = $em) from β¨mkRawNatLit 1, q(Nat.fib_two)β©
| n' =>
have en : Q(β) := mkRawNatLit <| n' / 2
let β¨ea, eb, Hβ© := proveNatFibAux en
let a := ea.natLit!
let b := eb.natLit!
if n' % 2 == 0 then
have hn : Q(2 * $en = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(β) := mkRawNatLit <| a * (2 * b - a)
have h1 : Q($ea * (2 * $eb - $ea) = $ea') := (q(Eq.refl $ea') : Expr)
β¨ea', q(isFibAux_two_mul_done $H $hn $h1)β©
else
have hn : Q(2 * $en + 1 = $en') := (q(Eq.refl $en') : Expr)
have ea' : Q(β) := mkRawNatLit <| a * a + b * b
have h1 : Q($ea * $ea + $eb * $eb = $ea') := (q(Eq.refl $ea') : Expr)
β¨ea', q(isFibAux_two_mul_add_one_done $H $hn $h1)β©
theorem isNat_fib : {x nx z : β} β IsNat x nx β Nat.fib nx = z β IsNat (Nat.fib x) z
| _, _, _, β¨rflβ©, rfl => β¨rflβ©
/-- Evaluates the `Nat.fib` function. -/
@[norm_num Nat.fib _]
def evalNatFib : NormNumExt where eval {_ _} e := do
let .app _ (x : Q(β)) β Meta.whnfR e | failure
let sβ : Q(AddMonoidWithOne β) := q(instAddMonoidWithOneNat)
let β¨ex, pβ© β deriveNat x sβ
let β¨ey, pfβ© := proveNatFib ex
let pf' : Q(IsNat (Nat.fib $x) $ey) := q(isNat_fib $p $pf)
return .isNat sβ ey pf'
end NormNum
end Meta
end Mathlib
|
ThickenedIndicator.lean
|
/-
Copyright (c) 2022 Kalle KytΓΆlΓ€. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kalle KytΓΆlΓ€
-/
import Mathlib.Data.ENNReal.Lemmas
import Mathlib.Topology.MetricSpace.Thickening
import Mathlib.Topology.ContinuousMap.Bounded.Basic
/-!
# Thickened indicators
This file is about thickened indicators of sets in (pseudo e)metric spaces. For a decreasing
sequence of thickening radii tending to 0, the thickened indicators of a closed set form a
decreasing pointwise converging approximation of the indicator function of the set, where the
members of the approximating sequence are nonnegative bounded continuous functions.
## Main definitions
* `thickenedIndicatorAux Ξ΄ E`: The `Ξ΄`-thickened indicator of a set `E` as an
unbundled `ββ₯0β`-valued function.
* `thickenedIndicator Ξ΄ E`: The `Ξ΄`-thickened indicator of a set `E` as a bundled
bounded continuous `ββ₯0`-valued function.
## Main results
* For a sequence of thickening radii tending to 0, the `Ξ΄`-thickened indicators of a set `E` tend
pointwise to the indicator of `closure E`.
- `thickenedIndicatorAux_tendsto_indicator_closure`: The version is for the
unbundled `ββ₯0β`-valued functions.
- `thickenedIndicator_tendsto_indicator_closure`: The version is for the bundled `ββ₯0`-valued
bounded continuous functions.
-/
open NNReal ENNReal Topology BoundedContinuousFunction Set Metric EMetric Filter
noncomputable section thickenedIndicator
variable {Ξ± : Type*} [PseudoEMetricSpace Ξ±]
/-- The `Ξ΄`-thickened indicator of a set `E` is the function that equals `1` on `E`
and `0` outside a `Ξ΄`-thickening of `E` and interpolates (continuously) between
these values using `infEdist _ E`.
`thickenedIndicatorAux` is the unbundled `ββ₯0β`-valued function. See `thickenedIndicator`
for the (bundled) bounded continuous function with `ββ₯0`-values. -/
def thickenedIndicatorAux (Ξ΄ : β) (E : Set Ξ±) : Ξ± β ββ₯0β :=
fun x : Ξ± => (1 : ββ₯0β) - infEdist x E / ENNReal.ofReal Ξ΄
theorem continuous_thickenedIndicatorAux {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) :
Continuous (thickenedIndicatorAux Ξ΄ E) := by
unfold thickenedIndicatorAux
let f := fun x : Ξ± => (β¨1, infEdist x E / ENNReal.ofReal Ξ΄β© : ββ₯0 Γ ββ₯0β)
let sub := fun p : ββ₯0 Γ ββ₯0β => (p.1 : ββ₯0β) - p.2
rw [show (fun x : Ξ± => (1 : ββ₯0β) - infEdist x E / ENNReal.ofReal Ξ΄) = sub β f by rfl]
apply (@ENNReal.continuous_nnreal_sub 1).comp
apply (ENNReal.continuous_div_const (ENNReal.ofReal Ξ΄) _).comp continuous_infEdist
norm_num [Ξ΄_pos]
theorem thickenedIndicatorAux_le_one (Ξ΄ : β) (E : Set Ξ±) (x : Ξ±) :
thickenedIndicatorAux Ξ΄ E x β€ 1 := by
apply tsub_le_self (Ξ± := ββ₯0β)
theorem thickenedIndicatorAux_lt_top {Ξ΄ : β} {E : Set Ξ±} {x : Ξ±} :
thickenedIndicatorAux Ξ΄ E x < β :=
lt_of_le_of_lt (thickenedIndicatorAux_le_one _ _ _) one_lt_top
theorem thickenedIndicatorAux_closure_eq (Ξ΄ : β) (E : Set Ξ±) :
thickenedIndicatorAux Ξ΄ (closure E) = thickenedIndicatorAux Ξ΄ E := by
simp +unfoldPartialApp only [thickenedIndicatorAux, infEdist_closure]
theorem thickenedIndicatorAux_one (Ξ΄ : β) (E : Set Ξ±) {x : Ξ±} (x_in_E : x β E) :
thickenedIndicatorAux Ξ΄ E x = 1 := by
simp [thickenedIndicatorAux, infEdist_zero_of_mem x_in_E, tsub_zero]
theorem thickenedIndicatorAux_one_of_mem_closure (Ξ΄ : β) (E : Set Ξ±) {x : Ξ±}
(x_mem : x β closure E) : thickenedIndicatorAux Ξ΄ E x = 1 := by
rw [β thickenedIndicatorAux_closure_eq, thickenedIndicatorAux_one Ξ΄ (closure E) x_mem]
theorem thickenedIndicatorAux_zero {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) {x : Ξ±}
(x_out : x β thickening Ξ΄ E) : thickenedIndicatorAux Ξ΄ E x = 0 := by
rw [thickening, mem_setOf_eq, not_lt] at x_out
unfold thickenedIndicatorAux
apply le_antisymm _ bot_le
have key := tsub_le_tsub
(@rfl _ (1 : ββ₯0β)).le (ENNReal.div_le_div x_out (@rfl _ (ENNReal.ofReal Ξ΄ : ββ₯0β)).le)
rw [ENNReal.div_self (ne_of_gt (ENNReal.ofReal_pos.mpr Ξ΄_pos)) ofReal_ne_top] at key
simpa [tsub_self] using key
theorem thickenedIndicatorAux_mono {Ξ΄β Ξ΄β : β} (hle : Ξ΄β β€ Ξ΄β) (E : Set Ξ±) :
thickenedIndicatorAux Ξ΄β E β€ thickenedIndicatorAux Ξ΄β E :=
fun _ => tsub_le_tsub (@rfl ββ₯0β 1).le (ENNReal.div_le_div rfl.le (ofReal_le_ofReal hle))
theorem indicator_le_thickenedIndicatorAux (Ξ΄ : β) (E : Set Ξ±) :
(E.indicator fun _ => (1 : ββ₯0β)) β€ thickenedIndicatorAux Ξ΄ E := by
intro a
by_cases h : a β E
Β· simp only [h, indicator_of_mem, thickenedIndicatorAux_one Ξ΄ E h, le_refl]
Β· simp only [h, indicator_of_notMem, not_false_iff, zero_le]
theorem thickenedIndicatorAux_subset (Ξ΄ : β) {Eβ Eβ : Set Ξ±} (subset : Eβ β Eβ) :
thickenedIndicatorAux Ξ΄ Eβ β€ thickenedIndicatorAux Ξ΄ Eβ :=
fun _ => tsub_le_tsub (@rfl ββ₯0β 1).le (ENNReal.div_le_div (infEdist_anti subset) rfl.le)
/-- As the thickening radius Ξ΄ tends to 0, the Ξ΄-thickened indicator of a set E (in Ξ±) tends
pointwise (i.e., w.r.t. the product topology on `Ξ± β ββ₯0β`) to the indicator function of the
closure of E.
This statement is for the unbundled `ββ₯0β`-valued functions `thickenedIndicatorAux Ξ΄ E`, see
`thickenedIndicator_tendsto_indicator_closure` for the version for bundled `ββ₯0`-valued
bounded continuous functions. -/
theorem thickenedIndicatorAux_tendsto_indicator_closure {Ξ΄seq : β β β}
(Ξ΄seq_lim : Tendsto Ξ΄seq atTop (π 0)) (E : Set Ξ±) :
Tendsto (fun n => thickenedIndicatorAux (Ξ΄seq n) E) atTop
(π (indicator (closure E) fun _ => (1 : ββ₯0β))) := by
rw [tendsto_pi_nhds]
intro x
by_cases x_mem_closure : x β closure E
Β· simp_rw [thickenedIndicatorAux_one_of_mem_closure _ E x_mem_closure]
rw [show (indicator (closure E) fun _ => (1 : ββ₯0β)) x = 1 by
simp only [x_mem_closure, indicator_of_mem]]
exact tendsto_const_nhds
Β· rw [show (closure E).indicator (fun _ => (1 : ββ₯0β)) x = 0 by
simp only [x_mem_closure, indicator_of_notMem, not_false_iff]]
rcases exists_real_pos_lt_infEdist_of_notMem_closure x_mem_closure with β¨Ξ΅, β¨Ξ΅_pos, Ξ΅_ltβ©β©
rw [Metric.tendsto_nhds] at Ξ΄seq_lim
specialize Ξ΄seq_lim Ξ΅ Ξ΅_pos
simp only [dist_zero_right, Real.norm_eq_abs, eventually_atTop] at Ξ΄seq_lim
rcases Ξ΄seq_lim with β¨N, hNβ©
apply tendsto_atTop_of_eventually_const (iβ := N)
intro n n_large
have key : x β thickening Ξ΅ E := by simpa only [thickening, mem_setOf_eq, not_lt] using Ξ΅_lt.le
refine le_antisymm ?_ bot_le
apply (thickenedIndicatorAux_mono (lt_of_abs_lt (hN n n_large)).le E x).trans
exact (thickenedIndicatorAux_zero Ξ΅_pos E key).le
/-- The `Ξ΄`-thickened indicator of a set `E` is the function that equals `1` on `E`
and `0` outside a `Ξ΄`-thickening of `E` and interpolates (continuously) between
these values using `infEdist _ E`.
`thickenedIndicator` is the (bundled) bounded continuous function with `ββ₯0`-values.
See `thickenedIndicatorAux` for the unbundled `ββ₯0β`-valued function. -/
@[simps]
def thickenedIndicator {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) : Ξ± βα΅ ββ₯0 where
toFun := fun x : Ξ± => (thickenedIndicatorAux Ξ΄ E x).toNNReal
continuous_toFun := by
apply ContinuousOn.comp_continuous continuousOn_toNNReal
(continuous_thickenedIndicatorAux Ξ΄_pos E)
intro x
exact (lt_of_le_of_lt (@thickenedIndicatorAux_le_one _ _ Ξ΄ E x) one_lt_top).ne
map_bounded' := by
use 2
intro x y
rw [NNReal.dist_eq]
apply (abs_sub _ _).trans
rw [NNReal.abs_eq, NNReal.abs_eq, β one_add_one_eq_two]
have key := @thickenedIndicatorAux_le_one _ _ Ξ΄ E
apply add_le_add <;>
Β· norm_cast
exact (toNNReal_le_toNNReal (lt_of_le_of_lt (key _) one_lt_top).ne one_ne_top).mpr (key _)
theorem thickenedIndicator.coeFn_eq_comp {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) :
β(thickenedIndicator Ξ΄_pos E) = ENNReal.toNNReal β thickenedIndicatorAux Ξ΄ E :=
rfl
theorem thickenedIndicator_le_one {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) (x : Ξ±) :
thickenedIndicator Ξ΄_pos E x β€ 1 := by
rw [thickenedIndicator.coeFn_eq_comp]
simpa using (toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.ne one_ne_top).mpr
(thickenedIndicatorAux_le_one Ξ΄ E x)
theorem thickenedIndicator_one_of_mem_closure {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) {x : Ξ±}
(x_mem : x β closure E) : thickenedIndicator Ξ΄_pos E x = 1 := by
rw [thickenedIndicator_apply, thickenedIndicatorAux_one_of_mem_closure Ξ΄ E x_mem, toNNReal_one]
lemma one_le_thickenedIndicator_apply' {X : Type _} [PseudoEMetricSpace X]
{Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) {F : Set X} {x : X} (hxF : x β closure F) :
1 β€ thickenedIndicator Ξ΄_pos F x := by
rw [thickenedIndicator_one_of_mem_closure Ξ΄_pos F hxF]
lemma one_le_thickenedIndicator_apply (X : Type _) [PseudoEMetricSpace X]
{Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) {F : Set X} {x : X} (hxF : x β F) :
1 β€ thickenedIndicator Ξ΄_pos F x :=
one_le_thickenedIndicator_apply' Ξ΄_pos (subset_closure hxF)
theorem thickenedIndicator_one {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) {x : Ξ±} (x_in_E : x β E) :
thickenedIndicator Ξ΄_pos E x = 1 :=
thickenedIndicator_one_of_mem_closure _ _ (subset_closure x_in_E)
theorem thickenedIndicator_zero {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) {x : Ξ±}
(x_out : x β thickening Ξ΄ E) : thickenedIndicator Ξ΄_pos E x = 0 := by
rw [thickenedIndicator_apply, thickenedIndicatorAux_zero Ξ΄_pos E x_out, toNNReal_zero]
theorem indicator_le_thickenedIndicator {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) (E : Set Ξ±) :
(E.indicator fun _ => (1 : ββ₯0)) β€ thickenedIndicator Ξ΄_pos E := by
intro a
by_cases h : a β E
Β· simp only [h, indicator_of_mem, thickenedIndicator_one Ξ΄_pos E h, le_refl]
Β· simp only [h, indicator_of_notMem, not_false_iff, zero_le]
theorem thickenedIndicator_mono {Ξ΄β Ξ΄β : β} (Ξ΄β_pos : 0 < Ξ΄β) (Ξ΄β_pos : 0 < Ξ΄β) (hle : Ξ΄β β€ Ξ΄β)
(E : Set Ξ±) : β(thickenedIndicator Ξ΄β_pos E) β€ thickenedIndicator Ξ΄β_pos E := by
intro x
apply (toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.ne thickenedIndicatorAux_lt_top.ne).mpr
apply thickenedIndicatorAux_mono hle
theorem thickenedIndicator_subset {Ξ΄ : β} (Ξ΄_pos : 0 < Ξ΄) {Eβ Eβ : Set Ξ±} (subset : Eβ β Eβ) :
β(thickenedIndicator Ξ΄_pos Eβ) β€ thickenedIndicator Ξ΄_pos Eβ := fun x =>
(toNNReal_le_toNNReal thickenedIndicatorAux_lt_top.ne thickenedIndicatorAux_lt_top.ne).mpr
(thickenedIndicatorAux_subset Ξ΄ subset x)
/-- As the thickening radius Ξ΄ tends to 0, the Ξ΄-thickened indicator of a set E (in Ξ±) tends
pointwise to the indicator function of the closure of E.
Note: This version is for the bundled bounded continuous functions, but the topology is not
the topology on `Ξ± βα΅ ββ₯0`. Coercions to functions `Ξ± β ββ₯0` are done first, so the topology
instance is the product topology (the topology of pointwise convergence). -/
theorem thickenedIndicator_tendsto_indicator_closure {Ξ΄seq : β β β} (Ξ΄seq_pos : β n, 0 < Ξ΄seq n)
(Ξ΄seq_lim : Tendsto Ξ΄seq atTop (π 0)) (E : Set Ξ±) :
Tendsto (fun n : β => ((β) : (Ξ± βα΅ ββ₯0) β Ξ± β ββ₯0) (thickenedIndicator (Ξ΄seq_pos n) E)) atTop
(π (indicator (closure E) fun _ => (1 : ββ₯0))) := by
have key := thickenedIndicatorAux_tendsto_indicator_closure Ξ΄seq_lim E
rw [tendsto_pi_nhds] at *
intro x
rw [show indicator (closure E) (fun _ => (1 : ββ₯0)) x =
(indicator (closure E) (fun _ => (1 : ββ₯0β)) x).toNNReal
by refine (congr_fun (comp_indicator_const 1 ENNReal.toNNReal toNNReal_zero) x).symm]
refine Tendsto.comp (tendsto_toNNReal ?_) (key x)
by_cases x_mem : x β closure E <;> simp [x_mem]
end thickenedIndicator
section indicator
variable {Ξ± : Type*} [PseudoEMetricSpace Ξ±] {Ξ² : Type*} [One Ξ²]
/-- Pointwise, the multiplicative indicators of Ξ΄-thickenings of a set eventually coincide
with the multiplicative indicator of the set as Ξ΄>0 tends to zero. -/
@[to_additive /-- Pointwise, the indicators of Ξ΄-thickenings of a set eventually coincide
with the indicator of the set as Ξ΄>0 tends to zero. -/]
lemma mulIndicator_thickening_eventually_eq_mulIndicator_closure (f : Ξ± β Ξ²) (E : Set Ξ±) (x : Ξ±) :
βαΆ Ξ΄ in π[>] (0 : β),
(Metric.thickening Ξ΄ E).mulIndicator f x = (closure E).mulIndicator f x := by
by_cases x_mem_closure : x β closure E
Β· filter_upwards [self_mem_nhdsWithin] with Ξ΄ Ξ΄_pos
simp only [closure_subset_thickening Ξ΄_pos E x_mem_closure, mulIndicator_of_mem, x_mem_closure]
Β· have obs := eventually_notMem_thickening_of_infEdist_pos x_mem_closure
filter_upwards [mem_nhdsWithin_of_mem_nhds obs, self_mem_nhdsWithin]
with Ξ΄ x_notin_thE _
simp only [x_notin_thE, not_false_eq_true, mulIndicator_of_notMem, x_mem_closure]
/-- Pointwise, the multiplicative indicators of closed Ξ΄-thickenings of a set eventually coincide
with the multiplicative indicator of the set as Ξ΄ tends to zero. -/
@[to_additive /-- Pointwise, the indicators of closed Ξ΄-thickenings of a set eventually coincide
with the indicator of the set as Ξ΄ tends to zero. -/]
lemma mulIndicator_cthickening_eventually_eq_mulIndicator_closure (f : Ξ± β Ξ²) (E : Set Ξ±) (x : Ξ±) :
βαΆ Ξ΄ in π (0 : β),
(Metric.cthickening Ξ΄ E).mulIndicator f x = (closure E).mulIndicator f x := by
by_cases x_mem_closure : x β closure E
Β· filter_upwards [univ_mem] with Ξ΄ _
have obs : x β cthickening Ξ΄ E := closure_subset_cthickening Ξ΄ E x_mem_closure
rw [mulIndicator_of_mem obs f, mulIndicator_of_mem x_mem_closure f]
Β· filter_upwards [eventually_notMem_cthickening_of_infEdist_pos x_mem_closure] with Ξ΄ hΞ΄
simp only [hΞ΄, not_false_eq_true, mulIndicator_of_notMem, x_mem_closure]
variable [TopologicalSpace Ξ²]
/-- The multiplicative indicators of Ξ΄-thickenings of a set tend pointwise to the multiplicative
indicator of the set, as Ξ΄>0 tends to zero. -/
@[to_additive /-- The indicators of Ξ΄-thickenings of a set tend pointwise to the indicator of the
set, as Ξ΄>0 tends to zero. -/]
lemma tendsto_mulIndicator_thickening_mulIndicator_closure (f : Ξ± β Ξ²) (E : Set Ξ±) :
Tendsto (fun Ξ΄ β¦ (Metric.thickening Ξ΄ E).mulIndicator f) (π[>] 0)
(π ((closure E).mulIndicator f)) := by
rw [tendsto_pi_nhds]
intro x
rw [tendsto_congr' (mulIndicator_thickening_eventually_eq_mulIndicator_closure f E x)]
apply tendsto_const_nhds
/-- The multiplicative indicators of closed Ξ΄-thickenings of a set tend pointwise to the
multiplicative indicator of the set, as Ξ΄ tends to zero. -/
@[to_additive /-- The indicators of closed Ξ΄-thickenings of a set tend pointwise to the indicator
of the set, as Ξ΄ tends to zero. -/]
lemma tendsto_mulIndicator_cthickening_mulIndicator_closure (f : Ξ± β Ξ²) (E : Set Ξ±) :
Tendsto (fun Ξ΄ β¦ (Metric.cthickening Ξ΄ E).mulIndicator f) (π 0)
(π ((closure E).mulIndicator f)) := by
rw [tendsto_pi_nhds]
intro x
rw [tendsto_congr' (mulIndicator_cthickening_eventually_eq_mulIndicator_closure f E x)]
apply tendsto_const_nhds
end indicator
|
ApplyCongr.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lucas Allen, Kim Morrison
-/
import Mathlib.Tactic.Conv
/-!
## Introduce the `apply_congr` conv mode tactic.
`apply_congr` will apply congruence lemmas inside `conv` mode.
It is particularly useful when the automatically generated congruence lemmas
are not of the optimal shape. An example, described in the doc-string is
rewriting inside the operand of a `Finset.sum`.
-/
open Lean Expr Parser.Tactic Elab Command Elab.Tactic Meta Conv
/--
Apply a congruence lemma inside `conv` mode.
When called without an argument `apply_congr` will try applying all lemmas marked with `@[congr]`.
Otherwise `apply_congr e` will apply the lemma `e`.
Recall that a goal that appears as `β£ X` in `conv` mode
represents a goal of `β’ X = ?m`,
i.e. an equation with a metavariable for the right hand side.
To successfully use `apply_congr e`, `e` will need to be an equation
(possibly after function arguments),
which can be unified with a goal of the form `X = ?m`.
The right hand side of `e` will then determine the metavariable,
and `conv` will subsequently replace `X` with that right hand side.
As usual, `apply_congr` can create new goals;
any of these which are _not_ equations with a metavariable on the right hand side
will be hard to deal with in `conv` mode.
Thus `apply_congr` automatically calls `intros` on any new goals,
and fails if they are not then equations.
In particular it is useful for rewriting inside the operand of a `Finset.sum`,
as it provides an extra hypothesis asserting we are inside the domain.
For example:
```lean
example (f g : β€ β β€) (S : Finset β€) (h : β m β S, f m = g m) :
Finset.sum S f = Finset.sum S g := by
conv_lhs =>
-- If we just call `congr` here, in the second goal we're helpless,
-- because we are only given the opportunity to rewrite `f`.
-- However `apply_congr` uses the appropriate `@[congr]` lemma,
-- so we get to rewrite `f x`, in the presence of the crucial `H : x β S` hypothesis.
apply_congr
Β· skip
Β· simp [*]
```
In the above example, when the `apply_congr` tactic is called it gives the hypothesis `H : x β S`
which is then used to rewrite the `f x` to `g x`.
-/
def Lean.Elab.Tactic.applyCongr (q : Option Expr) : TacticM Unit := do
let const lhsFun _ β (getAppFn β cleanupAnnotations) <$> instantiateMVars (β getLhs) |
throwError "Left-hand side must be an application of a constant."
let congrTheoremExprs β
match q with
-- If the user specified a lemma, use that one,
| some e =>
pure [e]
-- otherwise, look up everything tagged `@[congr]`
| none =>
let congrTheorems β
(fun congrTheoremMap => congrTheoremMap.get lhsFun) <$> getSimpCongrTheorems
congrTheorems.mapM (fun congrTheorem =>
liftM <| mkConstWithFreshMVarLevels congrTheorem.theoremName)
if congrTheoremExprs == [] then
throwError "No matching congr lemmas found"
-- For every lemma:
liftMetaTactic fun mainGoal => congrTheoremExprs.firstM (fun congrTheoremExpr => do
let newGoals β mainGoal.apply congrTheoremExpr { newGoals := .nonDependentOnly }
newGoals.mapM fun newGoal => Prod.snd <$> newGoal.intros)
syntax (name := Lean.Parser.Tactic.applyCongr) "apply_congr" (ppSpace colGt term)? : conv
-- TODO: add `apply_congr with h` to specify hypothesis name
-- https://github.com/leanprover-community/mathlib/issues/2882
elab_rules : conv
| `(conv| apply_congr$[ $t?]?) => do
let e? β t?.mapM (fun t => elabTerm t.raw none)
applyCongr e?
|
Analytic.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.Analytic.CPolynomial
import Mathlib.Analysis.Analytic.Inverse
import Mathlib.Analysis.Analytic.Within
import Mathlib.Analysis.Calculus.Deriv.Basic
import Mathlib.Analysis.Calculus.ContDiff.FTaylorSeries
import Mathlib.Analysis.Calculus.FDeriv.Add
import Mathlib.Analysis.Calculus.FDeriv.Prod
import Mathlib.Analysis.Normed.Module.Completion
/-!
# Frechet derivatives of analytic functions.
A function expressible as a power series at a point has a Frechet derivative there.
Also the special case in terms of `deriv` when the domain is 1-dimensional.
As an application, we show that continuous multilinear maps are smooth. We also compute their
iterated derivatives, in `ContinuousMultilinearMap.iteratedFDeriv_eq`.
## Main definitions and results
* `AnalyticAt.differentiableAt` : an analytic function at a point is differentiable there.
* `AnalyticOnNhd.fderiv` : in a complete space, if a function is analytic on a
neighborhood of a set `s`, so is its derivative.
* `AnalyticOnNhd.fderiv_of_isOpen` : if a function is analytic on a neighborhood of an
open set `s`, so is its derivative.
* `AnalyticOn.fderivWithin` : if a function is analytic on a set of unique differentiability,
so is its derivative within this set.
* `PartialHomeomorph.analyticAt_symm` : if a partial homeomorphism `f` is analytic at a
point `f.symm a`, with invertible derivative, then its inverse is analytic at `a`.
## Comments on completeness
Some theorems need a complete space, some don't, for the following reason.
(1) If a function is analytic at a point `x`, then it is differentiable there (with derivative given
by the first term in the power series). There is no issue of convergence here.
(2) If a function has a power series on a ball `B (x, r)`, there is no guarantee that the power
series for the derivative will converge at `y β x`, if the space is not complete. So, to deduce
that `f` is differentiable at `y`, one needs completeness in general.
(3) However, if a function `f` has a power series on a ball `B (x, r)`, and is a priori known to be
differentiable at some point `y β x`, then the power series for the derivative of `f` will
automatically converge at `y`, towards the given derivative: this follows from the facts that this
is true in the completion (thanks to the previous point) and that the map to the completion is
an embedding.
(4) Therefore, if one assumes `AnalyticOn π f s` where `s` is an open set, then `f` is analytic
therefore differentiable at every point of `s`, by (1), so by (3) the power series for its
derivative converges on whole balls. Therefore, the derivative of `f` is also analytic on `s`. The
same holds if `s` is merely a set with unique differentials.
(5) However, this does not work for `AnalyticOnNhd π f s`, as we don't get for free
differentiability at points in a neighborhood of `s`. Therefore, the theorem that deduces
`AnalyticOnNhd π (fderiv π f) s` from `AnalyticOnNhd π f s` requires completeness of the space.
-/
open Filter Asymptotics Set
open scoped ENNReal Topology
universe u v
variable {π : Type*} [NontriviallyNormedField π]
variable {E : Type u} [NormedAddCommGroup E] [NormedSpace π E]
variable {F : Type v} [NormedAddCommGroup F] [NormedSpace π F]
section fderiv
variable {p : FormalMultilinearSeries π E F} {r : ββ₯0β}
variable {f : E β F} {x : E} {s : Set E}
/-- A function which is analytic within a set is strictly differentiable there. Since we
don't have a predicate `HasStrictFDerivWithinAt`, we spell out what it would mean. -/
theorem HasFPowerSeriesWithinAt.hasStrictFDerivWithinAt (h : HasFPowerSeriesWithinAt f p s x) :
(fun y β¦ f y.1 - f y.2 - (continuousMultilinearCurryFin1 π E F (p 1)) (y.1 - y.2))
=o[π[insert x s ΓΛ’ insert x s] (x, x)] fun y β¦ y.1 - y.2 := by
refine h.isBigO_image_sub_norm_mul_norm_sub.trans_isLittleO (IsLittleO.of_norm_right ?_)
refine isLittleO_iff_exists_eq_mul.2 β¨fun y => βy - (x, x)β, ?_, EventuallyEq.rflβ©
apply Tendsto.mono_left _ nhdsWithin_le_nhds
refine (continuous_id.sub continuous_const).norm.tendsto' _ _ ?_
rw [_root_.id, sub_self, norm_zero]
theorem HasFPowerSeriesAt.hasStrictFDerivAt (h : HasFPowerSeriesAt f p x) :
HasStrictFDerivAt f (continuousMultilinearCurryFin1 π E F (p 1)) x := by
simpa only [hasStrictFDerivAt_iff_isLittleO, Set.insert_eq_of_mem, Set.mem_univ,
Set.univ_prod_univ, nhdsWithin_univ]
using (h.hasFPowerSeriesWithinAt (s := Set.univ)).hasStrictFDerivWithinAt
theorem HasFPowerSeriesWithinAt.hasFDerivWithinAt (h : HasFPowerSeriesWithinAt f p s x) :
HasFDerivWithinAt f (continuousMultilinearCurryFin1 π E F (p 1)) (insert x s) x := by
rw [HasFDerivWithinAt, hasFDerivAtFilter_iff_isLittleO, isLittleO_iff]
intro c hc
have : Tendsto (fun y β¦ (y, x)) (π[insert x s] x) (π[insert x s ΓΛ’ insert x s] (x, x)) := by
rw [nhdsWithin_prod_eq]
exact Tendsto.prodMk tendsto_id (tendsto_const_nhdsWithin (by simp))
exact this (isLittleO_iff.1 h.hasStrictFDerivWithinAt hc)
theorem HasFPowerSeriesAt.hasFDerivAt (h : HasFPowerSeriesAt f p x) :
HasFDerivAt f (continuousMultilinearCurryFin1 π E F (p 1)) x :=
h.hasStrictFDerivAt.hasFDerivAt
theorem HasFPowerSeriesWithinAt.differentiableWithinAt (h : HasFPowerSeriesWithinAt f p s x) :
DifferentiableWithinAt π f (insert x s) x :=
h.hasFDerivWithinAt.differentiableWithinAt
theorem HasFPowerSeriesAt.differentiableAt (h : HasFPowerSeriesAt f p x) : DifferentiableAt π f x :=
h.hasFDerivAt.differentiableAt
theorem AnalyticWithinAt.differentiableWithinAt (h : AnalyticWithinAt π f s x) :
DifferentiableWithinAt π f (insert x s) x := by
obtain β¨p, hpβ© := h
exact hp.differentiableWithinAt
@[fun_prop]
theorem AnalyticAt.differentiableAt : AnalyticAt π f x β DifferentiableAt π f x
| β¨_, hpβ© => hp.differentiableAt
theorem AnalyticAt.differentiableWithinAt (h : AnalyticAt π f x) : DifferentiableWithinAt π f s x :=
h.differentiableAt.differentiableWithinAt
theorem HasFPowerSeriesWithinAt.fderivWithin_eq
(h : HasFPowerSeriesWithinAt f p s x) (hu : UniqueDiffWithinAt π (insert x s) x) :
fderivWithin π f (insert x s) x = continuousMultilinearCurryFin1 π E F (p 1) :=
h.hasFDerivWithinAt.fderivWithin hu
theorem HasFPowerSeriesAt.fderiv_eq (h : HasFPowerSeriesAt f p x) :
fderiv π f x = continuousMultilinearCurryFin1 π E F (p 1) :=
h.hasFDerivAt.fderiv
theorem AnalyticAt.hasStrictFDerivAt (h : AnalyticAt π f x) :
HasStrictFDerivAt f (fderiv π f x) x := by
rcases h with β¨p, hpβ©
rw [hp.fderiv_eq]
exact hp.hasStrictFDerivAt
theorem HasFPowerSeriesWithinOnBall.differentiableOn [CompleteSpace F]
(h : HasFPowerSeriesWithinOnBall f p s x r) :
DifferentiableOn π f (insert x s β© EMetric.ball x r) := by
intro y hy
have Z := (h.analyticWithinAt_of_mem hy).differentiableWithinAt
rcases eq_or_ne y x with rfl | hy
Β· exact Z.mono inter_subset_left
Β· apply (Z.mono (subset_insert _ _)).mono_of_mem_nhdsWithin
suffices s β π[insert x s] y from nhdsWithin_mono _ inter_subset_left this
rw [nhdsWithin_insert_of_ne hy]
exact self_mem_nhdsWithin
theorem HasFPowerSeriesOnBall.differentiableOn [CompleteSpace F]
(h : HasFPowerSeriesOnBall f p x r) : DifferentiableOn π f (EMetric.ball x r) := fun _ hy =>
(h.analyticAt_of_mem hy).differentiableWithinAt
theorem HasFPowerSeriesAt.eventually_differentiableAt
[CompleteSpace F] (hp : HasFPowerSeriesAt f p x) :
βαΆ z in π x, DifferentiableAt π f z := by
obtain β¨r, hpβ© := hp
exact hp.differentiableOn.eventually_differentiableAt (EMetric.ball_mem_nhds _ hp.r_pos)
theorem AnalyticOn.differentiableOn (h : AnalyticOn π f s) : DifferentiableOn π f s :=
fun y hy β¦ (h y hy).differentiableWithinAt.mono (by simp)
theorem AnalyticOnNhd.differentiableOn (h : AnalyticOnNhd π f s) : DifferentiableOn π f s :=
fun y hy β¦ (h y hy).differentiableWithinAt
theorem HasFPowerSeriesWithinOnBall.hasFDerivWithinAt [CompleteSpace F]
(h : HasFPowerSeriesWithinOnBall f p s x r)
{y : E} (hy : (βyββ : ββ₯0β) < r) (h'y : x + y β insert x s) :
HasFDerivWithinAt f (continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1))
(insert x s) (x + y) := by
rcases eq_or_ne y 0 with rfl | h''y
Β· convert (h.changeOrigin hy h'y).hasFPowerSeriesWithinAt.hasFDerivWithinAt
simp
Β· have Z := (h.changeOrigin hy h'y).hasFPowerSeriesWithinAt.hasFDerivWithinAt
apply (Z.mono (subset_insert _ _)).mono_of_mem_nhdsWithin
rw [nhdsWithin_insert_of_ne]
Β· exact self_mem_nhdsWithin
Β· simpa using h''y
theorem HasFPowerSeriesOnBall.hasFDerivAt [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r)
{y : E} (hy : (βyββ : ββ₯0β) < r) :
HasFDerivAt f (continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1)) (x + y) :=
(h.changeOrigin hy).hasFPowerSeriesAt.hasFDerivAt
theorem HasFPowerSeriesWithinOnBall.fderivWithin_eq [CompleteSpace F]
(h : HasFPowerSeriesWithinOnBall f p s x r)
{y : E} (hy : (βyββ : ββ₯0β) < r) (h'y : x + y β insert x s) (hu : UniqueDiffOn π (insert x s)) :
fderivWithin π f (insert x s) (x + y) =
continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1) :=
(h.hasFDerivWithinAt hy h'y).fderivWithin (hu _ h'y)
theorem HasFPowerSeriesOnBall.fderiv_eq [CompleteSpace F] (h : HasFPowerSeriesOnBall f p x r)
{y : E} (hy : (βyββ : ββ₯0β) < r) :
fderiv π f (x + y) = continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1) :=
(h.hasFDerivAt hy).fderiv
/-- If a function has a power series on a ball, then so does its derivative. -/
protected theorem HasFPowerSeriesOnBall.fderiv [CompleteSpace F]
(h : HasFPowerSeriesOnBall f p x r) :
HasFPowerSeriesOnBall (fderiv π f) p.derivSeries x r := by
refine .congr (f := fun z β¦ continuousMultilinearCurryFin1 π E F (p.changeOrigin (z - x) 1)) ?_
fun z hz β¦ ?_
Β· refine continuousMultilinearCurryFin1 π E F
|>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesOnBall ?_
simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1
(h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x
dsimp only
rw [β h.fderiv_eq, add_sub_cancel]
simpa only [edist_eq_enorm_sub, EMetric.mem_ball] using hz
/-- If a function has a power series within a set on a ball, then so does its derivative. -/
protected theorem HasFPowerSeriesWithinOnBall.fderivWithin [CompleteSpace F]
(h : HasFPowerSeriesWithinOnBall f p s x r) (hu : UniqueDiffOn π (insert x s)) :
HasFPowerSeriesWithinOnBall (fderivWithin π f (insert x s)) p.derivSeries s x r := by
refine .congr' (f := fun z β¦ continuousMultilinearCurryFin1 π E F (p.changeOrigin (z - x) 1)) ?_
(fun z hz β¦ ?_)
Β· refine continuousMultilinearCurryFin1 π E F
|>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFPowerSeriesWithinOnBall ?_
apply HasFPowerSeriesOnBall.hasFPowerSeriesWithinOnBall
simpa using ((p.hasFPowerSeriesOnBall_changeOrigin 1
(h.r_pos.trans_le h.r_le)).mono h.r_pos h.r_le).comp_sub x
Β· dsimp only
rw [β h.fderivWithin_eq _ _ hu, add_sub_cancel]
Β· simpa only [edist_eq_enorm_sub, EMetric.mem_ball] using hz.2
Β· simpa using hz.1
/-- If a function has a power series within a set on a ball, then so does its derivative. For a
version without completeness, but assuming that the function is analytic on the set `s`, see
`HasFPowerSeriesWithinOnBall.fderivWithin_of_mem_of_analyticOn`. -/
protected theorem HasFPowerSeriesWithinOnBall.fderivWithin_of_mem [CompleteSpace F]
(h : HasFPowerSeriesWithinOnBall f p s x r) (hu : UniqueDiffOn π s) (hx : x β s) :
HasFPowerSeriesWithinOnBall (fderivWithin π f s) p.derivSeries s x r := by
have : insert x s = s := insert_eq_of_mem hx
rw [β this] at hu
convert h.fderivWithin hu
exact this.symm
/-- If a function is analytic on a set `s`, so is its FrΓ©chet derivative. -/
@[fun_prop]
protected theorem AnalyticAt.fderiv [CompleteSpace F] (h : AnalyticAt π f x) :
AnalyticAt π (fderiv π f) x := by
rcases h with β¨p, r, hpβ©
exact hp.fderiv.analyticAt
/-- If a function is analytic on a set `s`, so is its FrΓ©chet derivative. See also
`AnalyticOnNhd.fderiv_of_isOpen`, removing the completeness assumption but requiring the set
to be open. -/
protected theorem AnalyticOnNhd.fderiv [CompleteSpace F] (h : AnalyticOnNhd π f s) :
AnalyticOnNhd π (fderiv π f) s :=
fun y hy β¦ AnalyticAt.fderiv (h y hy)
/-- If a function is analytic on a set `s`, so are its successive FrΓ©chet derivative. See also
`AnalyticOnNhd.iteratedFDeriv_of_isOpen`, removing the completeness assumption but requiring the set
to be open. -/
protected theorem AnalyticOnNhd.iteratedFDeriv [CompleteSpace F] (h : AnalyticOnNhd π f s) (n : β) :
AnalyticOnNhd π (iteratedFDeriv π n f) s := by
induction n with
| zero =>
rw [iteratedFDeriv_zero_eq_comp]
exact ((continuousMultilinearCurryFin0 π E F).symm : F βL[π] E[Γ0]βL[π] F).comp_analyticOnNhd h
| succ n IH =>
rw [iteratedFDeriv_succ_eq_comp_left]
-- Porting note: for reasons that I do not understand at all, `?g` cannot be inlined.
convert ContinuousLinearMap.comp_analyticOnNhd ?g IH.fderiv
case g => exact β(continuousMultilinearCurryLeftEquiv π (fun _ : Fin (n + 1) β¦ E) F).symm
simp
/-- If a function is analytic on a neighborhood of a set `s`, then it has a Taylor series given
by the sequence of its derivatives. Note that, if the function were just analytic on `s`, then
one would have to use instead the sequence of derivatives inside the set, as in
`AnalyticOn.hasFTaylorSeriesUpToOn`. -/
lemma AnalyticOnNhd.hasFTaylorSeriesUpToOn [CompleteSpace F]
(n : WithTop ββ) (h : AnalyticOnNhd π f s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeries π f) s := by
refine β¨fun x _hx β¦ rfl, fun m _hm x hx β¦ ?_, fun m _hm x hx β¦ ?_β©
Β· apply HasFDerivAt.hasFDerivWithinAt
exact ((h.iteratedFDeriv m x hx).differentiableAt).hasFDerivAt
Β· apply (DifferentiableAt.continuousAt (π := π) ?_).continuousWithinAt
exact (h.iteratedFDeriv m x hx).differentiableAt
lemma AnalyticWithinAt.exists_hasFTaylorSeriesUpToOn [CompleteSpace F]
(n : WithTop ββ) (h : AnalyticWithinAt π f s x) :
β u β π[insert x s] x, β (p : E β FormalMultilinearSeries π E F),
HasFTaylorSeriesUpToOn n f p u β§ β i, AnalyticOn π (fun x β¦ p x i) u := by
rcases h.exists_analyticAt with β¨g, -, fg, hgβ©
rcases hg.exists_mem_nhds_analyticOnNhd with β¨v, vx, hvβ©
refine β¨insert x s β© v, inter_mem_nhdsWithin _ vx, ftaylorSeries π g, ?_, fun i β¦ ?_β©
Β· suffices HasFTaylorSeriesUpToOn n g (ftaylorSeries π g) (insert x s β© v) from
this.congr (fun y hy β¦ fg hy.1)
exact AnalyticOnNhd.hasFTaylorSeriesUpToOn _ (hv.mono Set.inter_subset_right)
Β· exact (hv.iteratedFDeriv i).analyticOn.mono Set.inter_subset_right
/-- If a function has a power series `p` within a set of unique differentiability, inside a ball,
and is differentiable at a point, then the derivative series of `p` is summable at a point, with
sum the given differential. Note that this theorem does not require completeness of the space. -/
theorem HasFPowerSeriesWithinOnBall.hasSum_derivSeries_of_hasFDerivWithinAt
(h : HasFPowerSeriesWithinOnBall f p s x r)
{f' : E βL[π] F}
{y : E} (hy : (βyββ : ββ₯0β) < r) (h'y : x + y β insert x s)
(hf' : HasFDerivWithinAt f f' (insert x s) (x + y))
(hu : UniqueDiffOn π (insert x s)) :
HasSum (fun n β¦ p.derivSeries n (fun _ β¦ y)) f' := by
/- In the completion of the space, the derivative series is summable, and its sum is a derivative
of the function. Therefore, by uniqueness of derivatives, its sum is the image of `f'` under
the canonical embedding. As this is an embedding, it means that there was also convergence in
the original space, to `f'`. -/
let F' := UniformSpace.Completion F
let a : F βL[π] F' := UniformSpace.Completion.toComplL
let b : (E βL[π] F) ββα΅’[π] (E βL[π] F') := UniformSpace.Completion.toComplβα΅’.postcomp
rw [β b.isEmbedding.hasSum_iff]
have : HasFPowerSeriesWithinOnBall (a β f) (a.compFormalMultilinearSeries p) s x r :=
a.comp_hasFPowerSeriesWithinOnBall h
have Z := (this.fderivWithin hu).hasSum h'y (by simpa [edist_zero_eq_enorm] using hy)
have : fderivWithin π (a β f) (insert x s) (x + y) = a βL f' := by
apply HasFDerivWithinAt.fderivWithin _ (hu _ h'y)
exact a.hasFDerivAt.comp_hasFDerivWithinAt (x + y) hf'
rw [this] at Z
convert Z with n
ext v
simp only [FormalMultilinearSeries.derivSeries, ContinuousLinearMap.coe_sum', Finset.sum_apply,
ContinuousLinearMap.compFormalMultilinearSeries_apply,
FormalMultilinearSeries.changeOriginSeries,
ContinuousLinearMap.compContinuousMultilinearMap_coe, ContinuousLinearEquiv.coe_coe,
LinearIsometryEquiv.coe_coe, Function.comp_apply, ContinuousMultilinearMap.sum_apply, map_sum]
rfl
/-- If a function has a power series within a set on a ball, then so does its derivative. Version
assuming that the function is analytic on `s`. For a version without this assumption but requiring
that `F` is complete, see `HasFPowerSeriesWithinOnBall.fderivWithin_of_mem`. -/
protected theorem HasFPowerSeriesWithinOnBall.fderivWithin_of_mem_of_analyticOn
(hr : HasFPowerSeriesWithinOnBall f p s x r)
(h : AnalyticOn π f s) (hs : UniqueDiffOn π s) (hx : x β s) :
HasFPowerSeriesWithinOnBall (fderivWithin π f s) p.derivSeries s x r := by
refine β¨hr.r_le.trans p.radius_le_radius_derivSeries, hr.r_pos, fun {y} hy h'y β¦ ?_β©
apply hr.hasSum_derivSeries_of_hasFDerivWithinAt (by simpa [edist_zero_eq_enorm] using h'y) hy
Β· rw [insert_eq_of_mem hx] at hy β’
apply DifferentiableWithinAt.hasFDerivWithinAt
exact h.differentiableOn _ hy
Β· rwa [insert_eq_of_mem hx]
/-- If a function is analytic within a set with unique differentials, then so is its derivative.
Note that this theorem does not require completeness of the space. -/
protected theorem AnalyticOn.fderivWithin (h : AnalyticOn π f s) (hu : UniqueDiffOn π s) :
AnalyticOn π (fderivWithin π f s) s := by
intro x hx
rcases h x hx with β¨p, r, hrβ©
refine β¨p.derivSeries, r, hr.fderivWithin_of_mem_of_analyticOn h hu hxβ©
/-- If a function is analytic on a set `s`, so are its successive FrΓ©chet derivative within this
set. Note that this theorem does not require completeness of the space. -/
protected theorem AnalyticOn.iteratedFDerivWithin (h : AnalyticOn π f s)
(hu : UniqueDiffOn π s) (n : β) :
AnalyticOn π (iteratedFDerivWithin π n f s) s := by
induction n with
| zero =>
rw [iteratedFDerivWithin_zero_eq_comp]
exact ((continuousMultilinearCurryFin0 π E F).symm : F βL[π] E[Γ0]βL[π] F)
|>.comp_analyticOn h
| succ n IH =>
rw [iteratedFDerivWithin_succ_eq_comp_left]
apply AnalyticOnNhd.comp_analyticOn _ (IH.fderivWithin hu) (mapsTo_univ _ _)
apply LinearIsometryEquiv.analyticOnNhd
protected lemma AnalyticOn.hasFTaylorSeriesUpToOn {n : WithTop ββ}
(h : AnalyticOn π f s) (hu : UniqueDiffOn π s) :
HasFTaylorSeriesUpToOn n f (ftaylorSeriesWithin π f s) s := by
refine β¨fun x _hx β¦ rfl, fun m _hm x hx β¦ ?_, fun m _hm x hx β¦ ?_β©
Β· have := (h.iteratedFDerivWithin hu m x hx).differentiableWithinAt.hasFDerivWithinAt
rwa [insert_eq_of_mem hx] at this
Β· exact (h.iteratedFDerivWithin hu m x hx).continuousWithinAt
lemma AnalyticOn.exists_hasFTaylorSeriesUpToOn
(h : AnalyticOn π f s) (hu : UniqueDiffOn π s) :
β p : E β FormalMultilinearSeries π E F,
HasFTaylorSeriesUpToOn β€ f p s β§ β i, AnalyticOn π (fun x β¦ p x i) s :=
β¨ftaylorSeriesWithin π f s, h.hasFTaylorSeriesUpToOn hu, h.iteratedFDerivWithin huβ©
theorem AnalyticOnNhd.fderiv_of_isOpen (h : AnalyticOnNhd π f s) (hs : IsOpen s) :
AnalyticOnNhd π (fderiv π f) s := by
rw [β hs.analyticOn_iff_analyticOnNhd] at h β’
exact (h.fderivWithin hs.uniqueDiffOn).congr (fun x hx β¦ (fderivWithin_of_isOpen hs hx).symm)
theorem AnalyticOnNhd.iteratedFDeriv_of_isOpen (h : AnalyticOnNhd π f s) (hs : IsOpen s) (n : β) :
AnalyticOnNhd π (iteratedFDeriv π n f) s := by
rw [β hs.analyticOn_iff_analyticOnNhd] at h β’
exact (h.iteratedFDerivWithin hs.uniqueDiffOn n).congr
(fun x hx β¦ (iteratedFDerivWithin_of_isOpen n hs hx).symm)
/-- If a partial homeomorphism `f` is analytic at a point `a`, with invertible derivative, then
its inverse is analytic at `f a`. -/
theorem PartialHomeomorph.analyticAt_symm' (f : PartialHomeomorph E F) {a : E}
{i : E βL[π] F} (h0 : a β f.source) (h : AnalyticAt π f a) (h' : fderiv π f a = i) :
AnalyticAt π f.symm (f a) := by
rcases h with β¨p, hpβ©
have : p 1 = (continuousMultilinearCurryFin1 π E F).symm i := by simp [β h', hp.fderiv_eq]
exact (f.hasFPowerSeriesAt_symm h0 hp this).analyticAt
/-- If a partial homeomorphism `f` is analytic at a point `f.symm a`, with invertible derivative,
then its inverse is analytic at `a`. -/
theorem PartialHomeomorph.analyticAt_symm (f : PartialHomeomorph E F) {a : F}
{i : E βL[π] F} (h0 : a β f.target) (h : AnalyticAt π f (f.symm a))
(h' : fderiv π f (f.symm a) = i) :
AnalyticAt π f.symm a := by
have : a = f (f.symm a) := by simp [h0]
rw [this]
exact f.analyticAt_symm' (by simp [h0]) h h'
end fderiv
section deriv
variable {p : FormalMultilinearSeries π π F} {r : ββ₯0β}
variable {f : π β F} {x : π} {s : Set π}
protected theorem HasFPowerSeriesAt.hasStrictDerivAt (h : HasFPowerSeriesAt f p x) :
HasStrictDerivAt f (p 1 fun _ => 1) x :=
h.hasStrictFDerivAt.hasStrictDerivAt
protected theorem HasFPowerSeriesAt.hasDerivAt (h : HasFPowerSeriesAt f p x) :
HasDerivAt f (p 1 fun _ => 1) x :=
h.hasStrictDerivAt.hasDerivAt
protected theorem HasFPowerSeriesAt.deriv (h : HasFPowerSeriesAt f p x) :
deriv f x = p 1 fun _ => 1 :=
h.hasDerivAt.deriv
/-- If a function is analytic on a set `s` in a complete space, so is its derivative. -/
protected theorem AnalyticOnNhd.deriv [CompleteSpace F] (h : AnalyticOnNhd π f s) :
AnalyticOnNhd π (deriv f) s :=
(ContinuousLinearMap.apply π F (1 : π)).comp_analyticOnNhd h.fderiv
/-- If a function is analytic on an open set `s`, so is its derivative. -/
theorem AnalyticOnNhd.deriv_of_isOpen (h : AnalyticOnNhd π f s) (hs : IsOpen s) :
AnalyticOnNhd π (deriv f) s :=
(ContinuousLinearMap.apply π F (1 : π)).comp_analyticOnNhd (h.fderiv_of_isOpen hs)
/-- If a function is analytic on a set `s`, so are its successive derivatives. -/
theorem AnalyticOnNhd.iterated_deriv [CompleteSpace F] (h : AnalyticOnNhd π f s) (n : β) :
AnalyticOnNhd π (deriv^[n] f) s := by
induction n with
| zero => exact h
| succ n IH => simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv
protected theorem AnalyticAt.deriv [CompleteSpace F] (h : AnalyticAt π f x) :
AnalyticAt π (deriv f) x := by
obtain β¨r, hr, hβ© := h.exists_ball_analyticOnNhd
exact h.deriv x (by simp [hr])
theorem AnalyticAt.iterated_deriv [CompleteSpace F] (h : AnalyticAt π f x) (n : β) :
AnalyticAt π (deriv^[n] f) x := by
induction n with
| zero => exact h
| succ n IH => simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv
end deriv
section fderiv
variable {p : FormalMultilinearSeries π E F} {r : ββ₯0β} {n : β}
variable {f : E β F} {x : E} {s : Set E}
/-! The case of continuously polynomial functions. We get the same differentiability
results as for analytic functions, but without the assumptions that `F` is complete. -/
theorem HasFiniteFPowerSeriesOnBall.differentiableOn
(h : HasFiniteFPowerSeriesOnBall f p x n r) : DifferentiableOn π f (EMetric.ball x r) :=
fun _ hy β¦ (h.cpolynomialAt_of_mem hy).analyticAt.differentiableWithinAt
theorem HasFiniteFPowerSeriesOnBall.hasFDerivAt (h : HasFiniteFPowerSeriesOnBall f p x n r)
{y : E} (hy : (βyββ : ββ₯0β) < r) :
HasFDerivAt f (continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1)) (x + y) :=
(h.changeOrigin hy).toHasFPowerSeriesOnBall.hasFPowerSeriesAt.hasFDerivAt
theorem HasFiniteFPowerSeriesOnBall.fderiv_eq (h : HasFiniteFPowerSeriesOnBall f p x n r)
{y : E} (hy : (βyββ : ββ₯0β) < r) :
fderiv π f (x + y) = continuousMultilinearCurryFin1 π E F (p.changeOrigin y 1) :=
(h.hasFDerivAt hy).fderiv
/-- If a function has a finite power series on a ball, then so does its derivative. -/
protected theorem HasFiniteFPowerSeriesOnBall.fderiv
(h : HasFiniteFPowerSeriesOnBall f p x (n + 1) r) :
HasFiniteFPowerSeriesOnBall (fderiv π f) p.derivSeries x n r := by
refine .congr (f := fun z β¦ continuousMultilinearCurryFin1 π E F (p.changeOrigin (z - x) 1)) ?_
fun z hz β¦ ?_
Β· refine continuousMultilinearCurryFin1 π E F
|>.toContinuousLinearEquiv.toContinuousLinearMap.comp_hasFiniteFPowerSeriesOnBall ?_
simpa using
((p.hasFiniteFPowerSeriesOnBall_changeOrigin 1 h.finite).mono h.r_pos le_top).comp_sub x
dsimp only
rw [β h.fderiv_eq, add_sub_cancel]
simpa only [edist_eq_enorm_sub, EMetric.mem_ball] using hz
/-- If a function has a finite power series on a ball, then so does its derivative.
This is a variant of `HasFiniteFPowerSeriesOnBall.fderiv` where the degree of `f` is `< n`
and not `< n + 1`. -/
theorem HasFiniteFPowerSeriesOnBall.fderiv' (h : HasFiniteFPowerSeriesOnBall f p x n r) :
HasFiniteFPowerSeriesOnBall (fderiv π f) p.derivSeries x (n - 1) r := by
obtain rfl | hn := eq_or_ne n 0
Β· rw [zero_tsub]
refine HasFiniteFPowerSeriesOnBall.bound_zero_of_eq_zero (fun y hy β¦ ?_) h.r_pos fun n β¦ ?_
Β· rw [Filter.EventuallyEq.fderiv_eq (f := fun _ β¦ 0)]
Β· simp
Β· exact Filter.eventuallyEq_iff_exists_mem.mpr β¨EMetric.ball x r,
EMetric.isOpen_ball.mem_nhds hy, fun z hz β¦ by rw [h.eq_zero_of_bound_zero z hz]β©
Β· apply ContinuousMultilinearMap.ext; intro a
change (continuousMultilinearCurryFin1 π E F) (p.changeOriginSeries 1 n a) = 0
rw [p.changeOriginSeries_finite_of_finite h.finite 1 (Nat.zero_le _)]
exact map_zero _
Β· rw [β Nat.succ_pred hn] at h
exact h.fderiv
/-- If a function is polynomial on a set `s`, so is its FrΓ©chet derivative. -/
theorem CPolynomialOn.fderiv (h : CPolynomialOn π f s) :
CPolynomialOn π (fderiv π f) s := by
intro y hy
rcases h y hy with β¨p, r, n, hpβ©
exact hp.fderiv'.cpolynomialAt
/-- If a function is polynomial on a set `s`, so are its successive FrΓ©chet derivative. -/
theorem CPolynomialOn.iteratedFDeriv (h : CPolynomialOn π f s) (n : β) :
CPolynomialOn π (iteratedFDeriv π n f) s := by
induction n with
| zero =>
rw [iteratedFDeriv_zero_eq_comp]
exact ((continuousMultilinearCurryFin0 π E F).symm : F βL[π] E[Γ0]βL[π] F).comp_cpolynomialOn h
| succ n IH =>
rw [iteratedFDeriv_succ_eq_comp_left]
convert ContinuousLinearMap.comp_cpolynomialOn ?g IH.fderiv
case g => exact β(continuousMultilinearCurryLeftEquiv π (fun _ : Fin (n + 1) β¦ E) F).symm
simp
end fderiv
section deriv
variable {p : FormalMultilinearSeries π π F} {r : ββ₯0β}
variable {f : π β F} {x : π} {s : Set π}
/-- If a function is polynomial on a set `s`, so is its derivative. -/
protected theorem CPolynomialOn.deriv (h : CPolynomialOn π f s) : CPolynomialOn π (deriv f) s :=
(ContinuousLinearMap.apply π F (1 : π)).comp_cpolynomialOn h.fderiv
/-- If a function is polynomial on a set `s`, so are its successive derivatives. -/
theorem CPolynomialOn.iterated_deriv (h : CPolynomialOn π f s) (n : β) :
CPolynomialOn π (deriv^[n] f) s := by
induction n with
| zero => exact h
| succ n IH => simpa only [Function.iterate_succ', Function.comp_apply] using IH.deriv
end deriv
namespace ContinuousMultilinearMap
variable {ΞΉ : Type*} {E : ΞΉ β Type*} [β i, NormedAddCommGroup (E i)] [β i, NormedSpace π (E i)]
[Fintype ΞΉ] (f : ContinuousMultilinearMap π E F)
open FormalMultilinearSeries
theorem changeOriginSeries_support {k l : β} (h : k + l β Fintype.card ΞΉ) :
f.toFormalMultilinearSeries.changeOriginSeries k l = 0 :=
Finset.sum_eq_zero fun _ _ β¦ by
simp_rw [FormalMultilinearSeries.changeOriginSeriesTerm,
toFormalMultilinearSeries, dif_neg h.symm, LinearIsometryEquiv.map_zero]
variable {n : WithTop ββ} (x : β i, E i)
open Finset in
theorem changeOrigin_toFormalMultilinearSeries [DecidableEq ΞΉ] :
continuousMultilinearCurryFin1 π (β i, E i) F (f.toFormalMultilinearSeries.changeOrigin x 1) =
f.linearDeriv x := by
ext y
rw [continuousMultilinearCurryFin1_apply, linearDeriv_apply,
changeOrigin, FormalMultilinearSeries.sum]
cases isEmpty_or_nonempty ΞΉ
Β· have (l : _) : 1 + l β Fintype.card ΞΉ := by
rw [add_comm, Fintype.card_eq_zero]; exact Nat.succ_ne_zero _
simp_rw [Fintype.sum_empty, changeOriginSeries_support _ (this _), zero_apply _, tsum_zero]; rfl
rw [tsum_eq_single (Fintype.card ΞΉ - 1), changeOriginSeries]; swap
Β· intro m hm
rw [Ne, eq_tsub_iff_add_eq_of_le (by exact Fintype.card_pos), add_comm] at hm
rw [f.changeOriginSeries_support hm, zero_apply]
rw [sum_apply, ContinuousMultilinearMap.sum_apply, Fin.snoc_zero]
simp_rw [changeOriginSeriesTerm_apply]
refine (Fintype.sum_bijective (?_ β Fintype.equivFinOfCardEq (Nat.add_sub_of_le
Fintype.card_pos).symm) (.comp ?_ <| Equiv.bijective _) _ _ fun i β¦ ?_).symm
Β· exact (β¨{Β·}αΆ, by
rw [card_compl, Fintype.card_fin, Finset.card_singleton, Nat.add_sub_cancel_left]β©)
Β· use fun _ _ β¦ (singleton_injective <| compl_injective <| Subtype.ext_iff.mp Β·)
intro β¨s, hsβ©
have h : #sαΆ = 1 := by rw [card_compl, hs, Fintype.card_fin, Nat.add_sub_cancel]
obtain β¨a, haβ© := card_eq_one.mp h
exact β¨a, Subtype.ext (compl_eq_comm.mp ha)β©
rw [Function.comp_apply, Subtype.coe_mk, compl_singleton, piecewise_erase_univ,
toFormalMultilinearSeries, dif_pos (Nat.add_sub_of_le Fintype.card_pos).symm]
simp_rw [domDomCongr_apply, compContinuousLinearMap_apply, ContinuousLinearMap.proj_apply,
Function.update_apply, (Equiv.injective _).eq_iff, ite_apply]
congr
grind [Function.update_self, Function.update_of_ne]
protected theorem hasFDerivAt [DecidableEq ΞΉ] : HasFDerivAt f (f.linearDeriv x) x := by
rw [β changeOrigin_toFormalMultilinearSeries]
convert f.hasFiniteFPowerSeriesOnBall.hasFDerivAt (y := x) ENNReal.coe_lt_top
rw [zero_add]
/-- Given `f` a multilinear map, then the derivative of `x β¦ f (gβ x, ..., gβ x)` at `x` applied
to a vector `v` is given by `β i, f (gβ x, ..., g'α΅’ v, ..., gβ x)`. Version inside a set. -/
theorem _root_.HasFDerivWithinAt.multilinear_comp
[DecidableEq ΞΉ] {G : Type*} [NormedAddCommGroup G] [NormedSpace π G]
{g : β i, G β E i} {g' : β i, G βL[π] E i} {s : Set G} {x : G}
(hg : β i, HasFDerivWithinAt (g i) (g' i) s x) :
HasFDerivWithinAt (fun x β¦ f (fun i β¦ g i x))
((β i : ΞΉ, (f.toContinuousLinearMap (fun j β¦ g j x) i) βL (g' i))) s x := by
convert (f.hasFDerivAt (fun j β¦ g j x)).comp_hasFDerivWithinAt x (hasFDerivWithinAt_pi.2 hg)
ext v
simp [linearDeriv]
/-- Given `f` a multilinear map, then the derivative of `x β¦ f (gβ x, ..., gβ x)` at `x` applied
to a vector `v` is given by `β i, f (gβ x, ..., g'α΅’ v, ..., gβ x)`. -/
theorem _root_.HasFDerivAt.multilinear_comp
[DecidableEq ΞΉ] {G : Type*} [NormedAddCommGroup G] [NormedSpace π G]
{g : β i, G β E i} {g' : β i, G βL[π] E i} {x : G}
(hg : β i, HasFDerivAt (g i) (g' i) x) :
HasFDerivAt (fun x β¦ f (fun i β¦ g i x))
((β i : ΞΉ, (f.toContinuousLinearMap (fun j β¦ g j x) i) βL (g' i))) x := by
convert (f.hasFDerivAt (fun j β¦ g j x)).comp x (hasFDerivAt_pi.2 hg)
ext v
simp [linearDeriv]
/-- Technical lemma used in the proof of `hasFTaylorSeriesUpTo_iteratedFDeriv`, to compare sums
over embedding of `Fin k` and `Fin (k + 1)`. -/
private lemma _root_.Equiv.succ_embeddingFinSucc_fst_symm_apply {ΞΉ : Type*} [DecidableEq ΞΉ]
{n : β} (e : Fin (n + 1) βͺ ΞΉ) {k : ΞΉ}
(h'k : k β Set.range (Equiv.embeddingFinSucc n ΞΉ e).1) (hk : k β Set.range e) :
Fin.succ ((Equiv.embeddingFinSucc n ΞΉ e).1.toEquivRange.symm β¨k, h'kβ©)
= e.toEquivRange.symm β¨k, hkβ© := by
rcases hk with β¨j, rflβ©
have hj : j β 0 := by
rintro rfl
simp at h'k
simp only [Function.Embedding.toEquivRange_symm_apply_self]
have : e j = (Equiv.embeddingFinSucc n ΞΉ e).1 (Fin.pred j hj) := by simp
simp_rw [this]
simp [-Equiv.embeddingFinSucc_fst]
/-- A continuous multilinear function `f` admits a Taylor series, whose successive terms are given
by `f.iteratedFDeriv n`. This is the point of the definition of `f.iteratedFDeriv`. -/
theorem hasFTaylorSeriesUpTo_iteratedFDeriv :
HasFTaylorSeriesUpTo β€ f (fun v n β¦ f.iteratedFDeriv n v) := by
classical
constructor
Β· simp [ContinuousMultilinearMap.iteratedFDeriv]
Β· rintro n - x
suffices H : curryLeft (f.iteratedFDeriv (Nat.succ n) x) = (β e : Fin n βͺ ΞΉ,
((iteratedFDerivComponent f e.toEquivRange).linearDeriv
(Pi.compRightL π _ Subtype.val x)) βL (Pi.compRightL π _ Subtype.val)) by
have A : HasFDerivAt (f.iteratedFDeriv n) (β e : Fin n βͺ ΞΉ,
((iteratedFDerivComponent f e.toEquivRange).linearDeriv (Pi.compRightL π _ Subtype.val x))
βL (Pi.compRightL π _ Subtype.val)) x := by
apply HasFDerivAt.fun_sum (fun s _hs β¦ ?_)
exact (ContinuousMultilinearMap.hasFDerivAt _ _).comp x (ContinuousLinearMap.hasFDerivAt _)
rwa [β H] at A
ext v m
simp only [ContinuousMultilinearMap.iteratedFDeriv, curryLeft_apply, sum_apply,
iteratedFDerivComponent_apply, Finset.univ_sigma_univ,
Pi.compRightL_apply, ContinuousLinearMap.coe_sum', ContinuousLinearMap.coe_comp',
Finset.sum_apply, Function.comp_apply, linearDeriv_apply, Finset.sum_sigma']
rw [β (Equiv.embeddingFinSucc n ΞΉ).sum_comp]
congr with e
congr with k
by_cases hke : k β Set.range e
Β· simp only [hke, βreduceDIte]
split_ifs with hkf
Β· simp only [β Equiv.succ_embeddingFinSucc_fst_symm_apply e hkf hke, Fin.cons_succ]
Β· obtain rfl : k = e 0 := by
rcases hke with β¨j, rflβ©
simpa using hkf
simp only [Function.Embedding.toEquivRange_symm_apply_self, Fin.cons_zero, Function.update,
Pi.compRightL_apply]
split_ifs with h
Β· congr!
Β· exfalso
apply h
simp_rw [β Equiv.embeddingFinSucc_snd e]
Β· have hkf : k β Set.range (Equiv.embeddingFinSucc n ΞΉ e).1 := by
contrapose! hke
rw [Equiv.embeddingFinSucc_fst] at hke
exact Set.range_comp_subset_range _ _ hke
simp only [hke, hkf, βreduceDIte, Pi.compRightL,
ContinuousLinearMap.coe_mk', LinearMap.coe_mk, AddHom.coe_mk]
rw [Function.update_of_ne]
contrapose! hke
rw [show k = _ from Subtype.ext_iff_val.1 hke, Equiv.embeddingFinSucc_snd e]
exact Set.mem_range_self _
Β· rintro n -
apply continuous_finset_sum _ (fun e _ β¦ ?_)
exact (ContinuousMultilinearMap.coe_continuous _).comp (ContinuousLinearMap.continuous _)
theorem iteratedFDeriv_eq (n : β) :
iteratedFDeriv π n f = f.iteratedFDeriv n :=
funext fun x β¦ (f.hasFTaylorSeriesUpTo_iteratedFDeriv.eq_iteratedFDeriv (m := n) le_top x).symm
theorem norm_iteratedFDeriv_le (n : β) (x : (i : ΞΉ) β E i) :
βiteratedFDeriv π n f xβ
β€ Nat.descFactorial (Fintype.card ΞΉ) n * βfβ * βxβ ^ (Fintype.card ΞΉ - n) := by
rw [f.iteratedFDeriv_eq]
exact f.norm_iteratedFDeriv_le' n x
@[deprecated (since := "2025-02-15")] alias cPolynomialAt := cpolynomialAt
@[deprecated (since := "2025-02-15")] alias cPolynomialOn := cpolynomialOn
end ContinuousMultilinearMap
namespace FormalMultilinearSeries
variable (p : FormalMultilinearSeries π E F)
open Fintype ContinuousLinearMap in
theorem derivSeries_apply_diag (n : β) (x : E) :
derivSeries p n (fun _ β¦ x) x = (n + 1) β’ p (n + 1) fun _ β¦ x := by
simp only [derivSeries, compFormalMultilinearSeries_apply, changeOriginSeries,
compContinuousMultilinearMap_coe, ContinuousLinearEquiv.coe_coe, LinearIsometryEquiv.coe_coe,
Function.comp_apply, ContinuousMultilinearMap.sum_apply, map_sum, coe_sum', Finset.sum_apply,
continuousMultilinearCurryFin1_apply, Matrix.zero_empty]
convert Finset.sum_const _
Β· rw [Fin.snoc_zero, changeOriginSeriesTerm_apply, Finset.piecewise_same, add_comm]
Β· rw [β card, card_subtype, β Finset.powerset_univ, β Finset.powersetCard_eq_filter,
Finset.card_powersetCard, β card, card_fin, eq_comm, add_comm, Nat.choose_succ_self_right]
@[simp]
lemma derivSeries_coeff_one (p : FormalMultilinearSeries π π F) (n : β) :
p.derivSeries.coeff n 1 = (n + 1) β’ p.coeff (n + 1) :=
p.derivSeries_apply_diag _ _
end FormalMultilinearSeries
namespace HasFPowerSeriesOnBall
open FormalMultilinearSeries ENNReal Nat
variable {p : FormalMultilinearSeries π E F} {f : E β F} {x : E} {r : ββ₯0β}
(h : HasFPowerSeriesOnBall f p x r) (y : E)
include h in
theorem iteratedFDeriv_zero_apply_diag : iteratedFDeriv π 0 f x = p 0 := by
ext
convert (h.hasSum <| EMetric.mem_ball_self h.r_pos).tsum_eq.symm
Β· rw [iteratedFDeriv_zero_apply, add_zero]
Β· rw [tsum_eq_single 0 fun n hn β¦ by haveI := NeZero.mk hn; exact (p n).map_zero]
exact congr(p 0 $(Subsingleton.elim _ _))
open ContinuousLinearMap
private theorem factorial_smul' {n : β} : β {F : Type max u v} [NormedAddCommGroup F]
[NormedSpace π F] [CompleteSpace F] {p : FormalMultilinearSeries π E F}
{f : E β F}, HasFPowerSeriesOnBall f p x r β
n ! β’ p n (fun _ β¦ y) = iteratedFDeriv π n f x (fun _ β¦ y) := by
induction n with | zero => _ | succ n ih => _ <;> intro F _ _ _ p f h
Β· rw [factorial_zero, one_smul, h.iteratedFDeriv_zero_apply_diag]
Β· rw [factorial_succ, mul_comm, mul_smul, β derivSeries_apply_diag,
β ContinuousLinearMap.smul_apply, ih h.fderiv, iteratedFDeriv_succ_apply_right]
rfl
variable [CompleteSpace F]
include h
/-- The iterated derivative of an analytic function, on vectors `(y, ..., y)`, is given by `n!`
times the `n`-th term in the power series. For a more general result giving the full iterated
derivative as a sum over the permutations of `Fin n`, see
`HasFPowerSeriesOnBall.iteratedFDeriv_eq_sum`. -/
theorem factorial_smul (n : β) :
n ! β’ p n (fun _ β¦ y) = iteratedFDeriv π n f x (fun _ β¦ y) := by
cases n
Β· rw [factorial_zero, one_smul, h.iteratedFDeriv_zero_apply_diag]
Β· rw [factorial_succ, mul_comm, mul_smul, β derivSeries_apply_diag,
β ContinuousLinearMap.smul_apply, factorial_smul' _ h.fderiv, iteratedFDeriv_succ_apply_right]
rfl
theorem hasSum_iteratedFDeriv [CharZero π] {y : E} (hy : y β EMetric.ball 0 r) :
HasSum (fun n β¦ (n ! : π)β»ΒΉ β’ iteratedFDeriv π n f x fun _ β¦ y) (f (x + y)) := by
convert h.hasSum hy with n
rw [β h.factorial_smul y n, smul_comm, β smul_assoc, nsmul_eq_mul,
mul_inv_cancelβ <| cast_ne_zero.mpr n.factorial_ne_zero, one_smul]
end HasFPowerSeriesOnBall
/-!
### Derivative of a linear map into multilinear maps
-/
namespace ContinuousLinearMap
variable {ΞΉ : Type*} {G : ΞΉ β Type*} [β i, NormedAddCommGroup (G i)] [β i, NormedSpace π (G i)]
[Fintype ΞΉ] {H : Type*} [NormedAddCommGroup H]
[NormedSpace π H]
theorem hasFDerivAt_uncurry_of_multilinear [DecidableEq ΞΉ]
(f : E βL[π] ContinuousMultilinearMap π G F) (v : E Γ Ξ i, G i) :
HasFDerivAt (fun (p : E Γ Ξ i, G i) β¦ f p.1 p.2)
((f.flipMultilinear v.2) βL (.fst _ _ _) +
β i : ΞΉ, ((f v.1).toContinuousLinearMap v.2 i) βL (.proj _) βL (.snd _ _ _)) v := by
convert HasFDerivAt.multilinear_comp (f.continuousMultilinearMapOption)
(g := fun (_ : Option ΞΉ) p β¦ p) (g' := fun _ β¦ ContinuousLinearMap.id _ _) (x := v)
(fun _ β¦ hasFDerivAt_id _)
have I : f.continuousMultilinearMapOption.toContinuousLinearMap (fun _ β¦ v) none =
(f.flipMultilinear v.2) βL (.fst _ _ _) := by
simp [ContinuousMultilinearMap.toContinuousLinearMap, continuousMultilinearMapOption]
apply ContinuousLinearMap.ext (fun w β¦ ?_)
simp
have J : β (i : ΞΉ), f.continuousMultilinearMapOption.toContinuousLinearMap (fun _ β¦ v) (some i)
= ((f v.1).toContinuousLinearMap v.2 i) βL (.proj _) βL (.snd _ _ _) := by
intro i
apply ContinuousLinearMap.ext (fun w β¦ ?_)
simp only [ContinuousMultilinearMap.toContinuousLinearMap, continuousMultilinearMapOption,
coe_mk', MultilinearMap.toLinearMap_apply, ContinuousMultilinearMap.coe_coe,
MultilinearMap.coe_mkContinuous, MultilinearMap.coe_mk, ne_eq, reduceCtorEq,
not_false_eq_true, Function.update_of_ne, coe_comp', coe_snd', Function.comp_apply,
proj_apply]
congr
ext j
rcases eq_or_ne j i with rfl | hij
Β· simp
Β· simp [hij]
simp [I, J]
/-- Given `f` a linear map into multilinear maps, then the derivative
of `x β¦ f (a x) (bβ x, ..., bβ x)` at `x` applied to a vector `v` is given by
`f (a' v) (bβ x, ...., bβ x) + β i, f a (bβ x, ..., b'α΅’ v, ..., bβ x)`. Version inside a set. -/
theorem _root_.HasFDerivWithinAt.linear_multilinear_comp
[DecidableEq ΞΉ] {a : H β E} {a' : H βL[π] E}
{b : β i, H β G i} {b' : β i, H βL[π] G i} {s : Set H} {x : H}
(ha : HasFDerivWithinAt a a' s x) (hb : β i, HasFDerivWithinAt (b i) (b' i) s x)
(f : E βL[π] ContinuousMultilinearMap π G F) :
HasFDerivWithinAt (fun y β¦ f (a y) (fun i β¦ b i y))
((f.flipMultilinear (fun i β¦ b i x)) βL a' +
β i, ((f (a x)).toContinuousLinearMap (fun j β¦ b j x) i) βL (b' i)) s x := by
convert (hasFDerivAt_uncurry_of_multilinear f (a x, fun i β¦ b i x)).comp_hasFDerivWithinAt x
(ha.prodMk (hasFDerivWithinAt_pi.mpr hb))
ext v
simp
/-- Given `f` a linear map into multilinear maps, then the derivative
of `x β¦ f (a x) (bβ x, ..., bβ x)` at `x` applied to a vector `v` is given by
`f (a' v) (bβ x, ...., bβ x) + β i, f a (bβ x, ..., b'α΅’ v, ..., bβ x)`. -/
theorem _root_.HasFDerivAt.linear_multilinear_comp [DecidableEq ΞΉ] {a : H β E} {a' : H βL[π] E}
{b : β i, H β G i} {b' : β i, H βL[π] G i} {x : H}
(ha : HasFDerivAt a a' x) (hb : β i, HasFDerivAt (b i) (b' i) x)
(f : E βL[π] ContinuousMultilinearMap π G F) :
HasFDerivAt (fun y β¦ f (a y) (fun i β¦ b i y))
((f.flipMultilinear (fun i β¦ b i x)) βL a' +
β i, ((f (a x)).toContinuousLinearMap (fun j β¦ b j x) i) βL (b' i)) x := by
simp_rw [β hasFDerivWithinAt_univ] at ha hb β’
exact HasFDerivWithinAt.linear_multilinear_comp ha hb f
end ContinuousLinearMap
|
HasIterationOfShape.lean
|
/-
Copyright (c) 2024 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.CategoryTheory.Limits.Comma
import Mathlib.CategoryTheory.Limits.FunctorCategory.Basic
import Mathlib.CategoryTheory.Limits.Shapes.Preorder.Basic
import Mathlib.Order.SuccPred.Limit
import Mathlib.Order.Interval.Set.InitialSeg
/-!
# An assumption for constructions by transfinite induction
In this file, we introduce the typeclass `HasIterationOfShape J C` which is
an assumption in order to do constructions by transfinite induction indexed by
a well-ordered type `J` in a category `C` (see `CategoryTheory.SmallObject`).
-/
universe w v v' u u'
namespace CategoryTheory.Limits
variable (J : Type w) [LinearOrder J] (C : Type u) [Category.{v} C]
(K : Type u') [Category.{v'} K]
/-- A category `C` has iterations of shape a linearly ordered type `J`
when certain specific shapes of colimits exists: colimits indexed by `J`,
and by `Set.Iio j` for `j : J`. -/
class HasIterationOfShape : Prop where
hasColimitsOfShape_of_isSuccLimit (j : J) (hj : Order.IsSuccLimit j) :
HasColimitsOfShape (Set.Iio j) C := by infer_instance
hasColimitsOfShape : HasColimitsOfShape J C := by infer_instance
attribute [instance] HasIterationOfShape.hasColimitsOfShape
instance [HasColimitsOfSize.{w, w} C] : HasIterationOfShape J C where
variable [HasIterationOfShape J C]
variable {J} in
lemma hasColimitsOfShape_of_isSuccLimit (j : J)
(hj : Order.IsSuccLimit j) :
HasColimitsOfShape (Set.Iio j) C :=
HasIterationOfShape.hasColimitsOfShape_of_isSuccLimit j hj
variable {J} in
lemma hasColimitsOfShape_of_isSuccLimit'
{Ξ± : Type*} [PartialOrder Ξ±] (h : Ξ± <i J) (hΞ± : Order.IsSuccLimit h.top) :
HasColimitsOfShape Ξ± C := by
have := hasColimitsOfShape_of_isSuccLimit C h.top hΞ±
exact hasColimitsOfShape_of_equivalence h.orderIsoIio.equivalence.symm
instance : HasIterationOfShape J (Arrow C) where
hasColimitsOfShape_of_isSuccLimit j hj := by
have := hasColimitsOfShape_of_isSuccLimit C j hj
infer_instance
instance : HasIterationOfShape J (K β₯€ C) where
hasColimitsOfShape_of_isSuccLimit j hj := by
have := hasColimitsOfShape_of_isSuccLimit C j hj
infer_instance
variable {J} [SuccOrder J] [WellFoundedLT J]
lemma hasColimitsOfShape_of_initialSeg
{Ξ± : Type*} [PartialOrder Ξ±] (f : Ξ± β€i J) [Nonempty Ξ±] :
HasColimitsOfShape Ξ± C := by
by_cases hf : Function.Surjective f
Β· exact hasColimitsOfShape_of_equivalence
(OrderIso.ofRelIsoLT (RelIso.ofSurjective f.toRelEmbedding hf)).equivalence.symm
Β· let s := f.toPrincipalSeg hf
obtain β¨i, hiββ© : β i, i = s.top := β¨_, rflβ©
induction i using SuccOrder.limitRecOn with
| isMin i hi =>
subst hiβ
exact (hi.not_lt (s.lt_top (Classical.arbitrary _))).elim
| succ i hi _ =>
obtain β¨a, rflβ© := (s.mem_range_iff_rel (b := i)).2 (by
simpa only [β hiβ] using Order.lt_succ_of_not_isMax hi)
have : OrderTop Ξ± :=
{ top := a
le_top b := by
rw [β s.le_iff_le]
exact Order.le_of_lt_succ (by simpa only [hiβ] using s.lt_top b) }
infer_instance
| isSuccLimit i hi =>
subst hiβ
exact hasColimitsOfShape_of_isSuccLimit' C s hi
lemma hasIterationOfShape_of_initialSeg {Ξ± : Type*} [LinearOrder Ξ±]
(h : Ξ± β€i J) [Nonempty Ξ±] :
HasIterationOfShape Ξ± C where
hasColimitsOfShape := hasColimitsOfShape_of_initialSeg C h
hasColimitsOfShape_of_isSuccLimit j hj := by
have : Nonempty (Set.Iio j) := by
obtain β¨a, haβ© := not_isMin_iff.1 hj.1
exact β¨β¨a, haβ©β©
exact hasColimitsOfShape_of_initialSeg _
(InitialSeg.trans (Set.principalSegIio j) h)
instance (j : J) : HasIterationOfShape (Set.Iic j) C :=
hasIterationOfShape_of_initialSeg C (Set.initialSegIic j)
end CategoryTheory.Limits
|
LowerUpperTopology.lean
|
/-
Copyright (c) 2023 Christopher Hoskin. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Christopher Hoskin
-/
import Mathlib.Order.Hom.CompleteLattice
import Mathlib.Topology.Homeomorph.Defs
import Mathlib.Topology.Order.Lattice
/-!
# Lower and Upper topology
This file introduces the lower topology on a preorder as the topology generated by the complements
of the left-closed right-infinite intervals.
For completeness we also introduce the dual upper topology, generated by the complements of the
right-closed left-infinite intervals.
## Main statements
- `IsLower.t0Space` - the lower topology on a partial order is Tβ
- `IsLower.isTopologicalBasis` - the complements of the upper closures of finite
subsets form a basis for the lower topology
- `IsLower.continuousInf` - the inf map is continuous with respect to the lower topology
## Implementation notes
A type synonym `WithLower` is introduced and for a preorder `Ξ±`, `WithLower Ξ±`
is made an instance of `TopologicalSpace` by the topology generated by the complements of the
closed intervals to infinity.
We define a mixin class `IsLower` for the class of types which are both a preorder and a
topology and where the topology is generated by the complements of the closed intervals to infinity.
It is shown that `WithLower Ξ±` is an instance of `IsLower`.
Similarly for the upper topology.
## Motivation
The lower topology is used with the `Scott` topology to define the Lawson topology. The restriction
of the lower topology to the spectrum of a complete lattice coincides with the hull-kernel topology.
## References
* [Gierz et al, *A Compendium of Continuous Lattices*][GierzEtAl1980]
## Tags
lower topology, upper topology, preorder
-/
open Set TopologicalSpace Topology
namespace Topology
/--
The lower topology is the topology generated by the complements of the left-closed right-infinite
intervals.
-/
def lower (Ξ± : Type*) [Preorder Ξ±] : TopologicalSpace Ξ± := generateFrom {s | β a, (Ici a)αΆ = s}
/--
The upper topology is the topology generated by the complements of the right-closed left-infinite
intervals.
-/
def upper (Ξ± : Type*) [Preorder Ξ±] : TopologicalSpace Ξ± := generateFrom {s | β a, (Iic a)αΆ = s}
/-- Type synonym for a preorder equipped with the lower set topology. -/
def WithLower (Ξ± : Type*) := Ξ±
variable {Ξ± Ξ² : Type*}
namespace WithLower
/-- `toLower` is the identity function to the `WithLower` of a type. -/
@[match_pattern] def toLower : Ξ± β WithLower Ξ± := Equiv.refl _
/-- `ofLower` is the identity function from the `WithLower` of a type. -/
@[match_pattern] def ofLower : WithLower Ξ± β Ξ± := Equiv.refl _
@[simp] lemma toLower_symm : (@toLower Ξ±).symm = ofLower := rfl
@[simp] lemma ofLower_symm : (@ofLower Ξ±).symm = toLower := rfl
@[simp] lemma toLower_ofLower (a : WithLower Ξ±) : toLower (ofLower a) = a := rfl
@[simp] lemma ofLower_toLower (a : Ξ±) : ofLower (toLower a) = a := rfl
lemma toLower_inj {a b : Ξ±} : toLower a = toLower b β a = b := Iff.rfl
theorem ofLower_inj {a b : WithLower Ξ±} : ofLower a = ofLower b β a = b :=
Iff.rfl
/-- A recursor for `WithLower`. Use as `induction x`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected def rec {Ξ² : WithLower Ξ± β Sort*} (h : β a, Ξ² (toLower a)) : β a, Ξ² a := fun a =>
h (ofLower a)
instance [Nonempty Ξ±] : Nonempty (WithLower Ξ±) := βΉNonempty Ξ±βΊ
instance [Inhabited Ξ±] : Inhabited (WithLower Ξ±) := βΉInhabited Ξ±βΊ
section Preorder
variable [Preorder Ξ±] {s : Set Ξ±}
instance : Preorder (WithLower Ξ±) := βΉPreorder Ξ±βΊ
instance : TopologicalSpace (WithLower Ξ±) := lower (WithLower Ξ±)
@[simp] lemma toLower_le_toLower {x y : Ξ±} : toLower x β€ toLower y β x β€ y := .rfl
@[simp] lemma toLower_lt_toLower {x y : Ξ±} : toLower x < toLower y β x < y := .rfl
@[simp] lemma ofLower_le_ofLower {x y : WithLower Ξ±} : ofLower x β€ ofLower y β x β€ y := .rfl
@[simp] lemma ofLower_lt_ofLower {x y : WithLower Ξ±} : ofLower x < ofLower y β x < y := .rfl
lemma isOpen_preimage_ofLower : IsOpen (ofLower β»ΒΉ' s) β IsOpen[lower Ξ±] s := Iff.rfl
lemma isOpen_def (T : Set (WithLower Ξ±)) : IsOpen T β IsOpen[lower Ξ±] (WithLower.toLower β»ΒΉ' T) :=
Iff.rfl
theorem continuous_toLower [TopologicalSpace Ξ±] [ClosedIciTopology Ξ±] :
Continuous (toLower : Ξ± β WithLower Ξ±) :=
continuous_generateFrom_iff.mpr <| by rintro _ β¨a, rflβ©; exact isClosed_Ici.isOpen_compl
end Preorder
instance [PartialOrder Ξ±] : PartialOrder (WithLower Ξ±) := βΉPartialOrder Ξ±βΊ
instance [LinearOrder Ξ±] : LinearOrder (WithLower Ξ±) := βΉLinearOrder Ξ±βΊ
end WithLower
/-- Type synonym for a preorder equipped with the upper topology. -/
def WithUpper (Ξ± : Type*) := Ξ±
namespace WithUpper
/-- `toUpper` is the identity function to the `WithUpper` of a type. -/
@[match_pattern] def toUpper : Ξ± β WithUpper Ξ± := Equiv.refl _
/-- `ofUpper` is the identity function from the `WithUpper` of a type. -/
@[match_pattern] def ofUpper : WithUpper Ξ± β Ξ± := Equiv.refl _
@[simp] lemma toUpper_symm {Ξ±} : (@toUpper Ξ±).symm = ofUpper := rfl
@[simp] lemma ofUpper_symm : (@ofUpper Ξ±).symm = toUpper := rfl
@[simp] lemma toUpper_ofUpper (a : WithUpper Ξ±) : toUpper (ofUpper a) = a := rfl
@[simp] lemma ofUpper_toUpper (a : Ξ±) : ofUpper (toUpper a) = a := rfl
lemma toUpper_inj {a b : Ξ±} : toUpper a = toUpper b β a = b := Iff.rfl
lemma ofUpper_inj {a b : WithUpper Ξ±} : ofUpper a = ofUpper b β a = b := Iff.rfl
/-- A recursor for `WithUpper`. Use as `induction x`. -/
@[elab_as_elim, cases_eliminator, induction_eliminator]
protected def rec {Ξ² : WithUpper Ξ± β Sort*} (h : β a, Ξ² (toUpper a)) : β a, Ξ² a := fun a =>
h (ofUpper a)
instance [Nonempty Ξ±] : Nonempty (WithUpper Ξ±) := βΉNonempty Ξ±βΊ
instance [Inhabited Ξ±] : Inhabited (WithUpper Ξ±) := βΉInhabited Ξ±βΊ
section Preorder
variable [Preorder Ξ±] {s : Set Ξ±}
instance : Preorder (WithUpper Ξ±) := βΉPreorder Ξ±βΊ
instance : TopologicalSpace (WithUpper Ξ±) := upper (WithUpper Ξ±)
@[simp] lemma toUpper_le_toUpper {x y : Ξ±} : toUpper x β€ toUpper y β x β€ y := .rfl
@[simp] lemma toUpper_lt_toUpper {x y : Ξ±} : toUpper x < toUpper y β x < y := .rfl
@[simp] lemma ofUpper_le_ofUpper {x y : WithUpper Ξ±} : ofUpper x β€ ofUpper y β x β€ y := .rfl
@[simp] lemma ofUpper_lt_ofUpper {x y : WithUpper Ξ±} : ofUpper x < ofUpper y β x < y := .rfl
lemma isOpen_preimage_ofUpper : IsOpen (ofUpper β»ΒΉ' s) β (upper Ξ±).IsOpen s := Iff.rfl
lemma isOpen_def {s : Set (WithUpper Ξ±)} : IsOpen s β (upper Ξ±).IsOpen (toUpper β»ΒΉ' s) := Iff.rfl
theorem continuous_toUpper [TopologicalSpace Ξ±] [ClosedIicTopology Ξ±] :
Continuous (toUpper : Ξ± β WithUpper Ξ±) :=
continuous_generateFrom_iff.mpr <| by rintro _ β¨a, rflβ©; exact isClosed_Iic.isOpen_compl
end Preorder
instance [PartialOrder Ξ±] : PartialOrder (WithUpper Ξ±) := βΉPartialOrder Ξ±βΊ
instance [LinearOrder Ξ±] : LinearOrder (WithUpper Ξ±) := βΉLinearOrder Ξ±βΊ
end WithUpper
/--
The lower topology is the topology generated by the complements of the left-closed right-infinite
intervals.
-/
class IsLower (Ξ± : Type*) [t : TopologicalSpace Ξ±] [Preorder Ξ±] : Prop where
topology_eq_lowerTopology : t = lower Ξ±
attribute [nolint docBlame] IsLower.topology_eq_lowerTopology
/--
The upper topology is the topology generated by the complements of the right-closed left-infinite
intervals.
-/
class IsUpper (Ξ± : Type*) [t : TopologicalSpace Ξ±] [Preorder Ξ±] : Prop where
topology_eq_upperTopology : t = upper Ξ±
attribute [nolint docBlame] IsUpper.topology_eq_upperTopology
instance [Preorder Ξ±] : IsLower (WithLower Ξ±) := β¨rflβ©
instance [Preorder Ξ±] : IsUpper (WithUpper Ξ±) := β¨rflβ©
/--
The lower topology is homeomorphic to the upper topology on the dual order
-/
def WithLower.toDualHomeomorph [Preorder Ξ±] : WithLower Ξ± ββ WithUpper Ξ±α΅α΅ where
toFun := OrderDual.toDual
invFun := OrderDual.ofDual
left_inv := OrderDual.toDual_ofDual
right_inv := OrderDual.ofDual_toDual
continuous_toFun := continuous_coinduced_rng
continuous_invFun := continuous_coinduced_rng
namespace IsLower
/-- The complements of the upper closures of finite sets are a collection of lower sets
which form a basis for the lower topology. -/
def lowerBasis (Ξ± : Type*) [Preorder Ξ±] :=
{ s : Set Ξ± | β t : Set Ξ±, t.Finite β§ (upperClosure t : Set Ξ±)αΆ = s }
section Preorder
variable (Ξ±)
variable [Preorder Ξ±] [TopologicalSpace Ξ±] [IsLower Ξ±] {s : Set Ξ±}
lemma topology_eq : βΉ_βΊ = lower Ξ± := topology_eq_lowerTopology
variable {Ξ±}
/-- If `Ξ±` is equipped with the lower topology, then it is homeomorphic to `WithLower Ξ±`.
-/
def withLowerHomeomorph : WithLower Ξ± ββ Ξ± :=
WithLower.ofLower.toHomeomorphOfIsInducing β¨topology_eq Ξ± βΈ induced_id.symmβ©
theorem isOpen_iff_generate_Ici_compl : IsOpen s β GenerateOpen { t | β a, (Ici a)αΆ = t } s := by
rw [topology_eq Ξ±]; rfl
instance _root_.OrderDual.instIsUpper [Preorder Ξ±] [TopologicalSpace Ξ±] [IsLower Ξ±] :
IsUpper Ξ±α΅α΅ where
topology_eq_upperTopology := topology_eq_lowerTopology (Ξ± := Ξ±)
/-- Left-closed right-infinite intervals [a, β) are closed in the lower topology. -/
instance : ClosedIciTopology Ξ± :=
β¨fun a β¦ isOpen_compl_iff.1 <| isOpen_iff_generate_Ici_compl.2 <| GenerateOpen.basic _ β¨a, rflβ©β©
/-- The upper closure of a finite set is closed in the lower topology. -/
theorem isClosed_upperClosure (h : s.Finite) : IsClosed (upperClosure s : Set Ξ±) := by
simp only [β UpperSet.iInf_Ici, UpperSet.coe_iInf]
exact h.isClosed_biUnion fun _ _ => isClosed_Ici
/-- Every set open in the lower topology is a lower set. -/
theorem isLowerSet_of_isOpen (h : IsOpen s) : IsLowerSet s := by
replace h := isOpen_iff_generate_Ici_compl.1 h
induction h with
| basic u h' => obtain β¨a, rflβ© := h'; exact (isUpperSet_Ici a).compl
| univ => exact isLowerSet_univ
| inter u v _ _ hu2 hv2 => exact hu2.inter hv2
| sUnion _ _ ih => exact isLowerSet_sUnion ih
theorem isUpperSet_of_isClosed (h : IsClosed s) : IsUpperSet s :=
isLowerSet_compl.1 <| isLowerSet_of_isOpen h.isOpen_compl
theorem tendsto_nhds_iff_not_le {Ξ² : Type*} {f : Ξ² β Ξ±} {l : Filter Ξ²} {x : Ξ±} :
Filter.Tendsto f l (π x) β β y, Β¬y β€ x β βαΆ z in l, Β¬y β€ f z := by
simp [topology_eq_lowerTopology, tendsto_nhds_generateFrom_iff, Filter.Eventually, Ici,
compl_setOf]
/--
The closure of a singleton `{a}` in the lower topology is the left-closed right-infinite interval
[a, β).
-/
@[simp]
theorem closure_singleton (a : Ξ±) : closure {a} = Ici a :=
Subset.antisymm ((closure_minimal fun _ h => h.ge) <| isClosed_Ici) <|
(isUpperSet_of_isClosed isClosed_closure).Ici_subset <| subset_closure rfl
protected theorem isTopologicalBasis : IsTopologicalBasis (lowerBasis Ξ±) := by
convert isTopologicalBasis_of_subbasis (topology_eq Ξ±)
simp_rw [lowerBasis, coe_upperClosure, compl_iUnion]
ext s
constructor
Β· rintro β¨F, hF, rflβ©
refine β¨(fun a => (Ici a)αΆ) '' F, β¨hF.image _, image_subset_iff.2 fun _ _ => β¨_, rflβ©β©, ?_β©
simp only [sInter_image]
Β· rintro β¨F, β¨hF, hsβ©, rflβ©
haveI := hF.to_subtype
rw [subset_def, Subtype.forall'] at hs
choose f hf using hs
exact β¨_, finite_range f, by simp_rw [biInter_range, hf, sInter_eq_iInter]β©
/-- A function `f : Ξ² β Ξ±` with lower topology in the codomain is continuous
if and only if the preimage of every interval `Set.Ici a` is a closed set.
-/
lemma continuous_iff_Ici [TopologicalSpace Ξ²] {f : Ξ² β Ξ±} :
Continuous f β β a, IsClosed (f β»ΒΉ' (Ici a)) := by
obtain rfl := IsLower.topology_eq Ξ±
simp [continuous_generateFrom_iff]
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [TopologicalSpace Ξ±] [IsLower Ξ±]
-- see Note [lower instance priority]
/-- The lower topology on a partial order is Tβ. -/
instance (priority := 90) t0Space : T0Space Ξ± :=
(t0Space_iff_inseparable Ξ±).2 fun x y h =>
Ici_injective <| by simpa only [inseparable_iff_closure_eq, closure_singleton] using h
end PartialOrder
section LinearOrder
variable [LinearOrder Ξ±] [TopologicalSpace Ξ±] [IsLower Ξ±]
lemma isTopologicalBasis_insert_univ_subbasis :
IsTopologicalBasis (insert univ {s : Set Ξ± | β a, (Ici a)αΆ = s}) :=
isTopologicalBasis_of_subbasis_of_inter (by rw [topology_eq Ξ±, lower]) (by
rintro _ β¨b, rflβ© _ β¨c, rflβ©
use b β c
rw [compl_Ici, compl_Ici, compl_Ici, Iio_inter_Iio])
theorem tendsto_nhds_iff_lt {Ξ² : Type*} {f : Ξ² β Ξ±} {l : Filter Ξ²} {x : Ξ±} :
Filter.Tendsto f l (π x) β β y, x < y β βαΆ z in l, f z < y := by
simp only [tendsto_nhds_iff_not_le, not_le]
end LinearOrder
section CompleteLinearOrder
variable [CompleteLinearOrder Ξ±] [t : TopologicalSpace Ξ±] [IsLower Ξ±]
lemma isTopologicalSpace_basis (U : Set Ξ±) : IsOpen U β U = univ β¨ β a, (Ici a)αΆ = U := by
by_cases hU : U = univ
Β· simp only [hU, isOpen_univ, compl_Ici, true_or]
refine β¨?_, isTopologicalBasis_insert_univ_subbasis.isOpenβ©
intro hO
apply Or.inr
convert IsTopologicalBasis.open_eq_sUnion isTopologicalBasis_insert_univ_subbasis hO
constructor
Β· intro β¨a, haβ©
use {U}
constructor
Β· apply subset_trans (singleton_subset_iff.mpr _) (subset_insert _ _)
use a
Β· rw [sUnion_singleton]
Β· intro β¨S, hS1, hS2β©
have hUS : univ β S := by
by_contra hUS'
apply hU
rw [hS2]
exact sUnion_eq_univ_iff.mpr (fun a => β¨univ, hUS', trivialβ©)
use sSup {a | (Ici a)αΆ β S}
rw [hS2, sUnion_eq_compl_sInter_compl, compl_inj_iff]
apply le_antisymm
Β· intro b hb
simp only [sInter_image, mem_iInter, mem_compl_iff]
intro s hs
obtain β¨a, haβ© := (subset_insert_iff_of_notMem hUS).mp hS1 hs
subst hS2 ha
simp_all only [compl_Ici, mem_Ici, sSup_le_iff, mem_setOf_eq, mem_Iio, not_lt]
Β· intro b hb
rw [mem_Ici, sSup_le_iff]
intro c hc
simp only [sInter_image, mem_iInter] at hb
rw [β not_lt, β mem_Iio, β compl_Ici]
exact hb _ hc
end CompleteLinearOrder
end IsLower
namespace IsUpper
/-- The complements of the lower closures of finite sets are a collection of upper sets
which form a basis for the upper topology. -/
def upperBasis (Ξ± : Type*) [Preorder Ξ±] :=
{ s : Set Ξ± | β t : Set Ξ±, t.Finite β§ (lowerClosure t : Set Ξ±)αΆ = s }
section Preorder
variable (Ξ±)
variable [Preorder Ξ±] [TopologicalSpace Ξ±] [IsUpper Ξ±] {s : Set Ξ±}
lemma topology_eq : βΉ_βΊ = upper Ξ± := topology_eq_upperTopology
variable {Ξ±}
/-- If `Ξ±` is equipped with the upper topology, then it is homeomorphic to `WithUpper Ξ±`.
-/
def withUpperHomeomorph : WithUpper Ξ± ββ Ξ± :=
WithUpper.ofUpper.toHomeomorphOfIsInducing β¨topology_eq Ξ± βΈ induced_id.symmβ©
theorem isOpen_iff_generate_Iic_compl : IsOpen s β GenerateOpen { t | β a, (Iic a)αΆ = t } s := by
rw [topology_eq Ξ±]; rfl
instance _root_.OrderDual.instIsLower [Preorder Ξ±] [TopologicalSpace Ξ±] [IsUpper Ξ±] :
IsLower Ξ±α΅α΅ where
topology_eq_lowerTopology := topology_eq_upperTopology (Ξ± := Ξ±)
/-- Left-infinite right-closed intervals (-β,a] are closed in the upper topology. -/
instance : ClosedIicTopology Ξ± :=
β¨fun a β¦ isOpen_compl_iff.1 <| isOpen_iff_generate_Iic_compl.2 <| GenerateOpen.basic _ β¨a, rflβ©β©
/-- The lower closure of a finite set is closed in the upper topology. -/
theorem isClosed_lowerClosure (h : s.Finite) : IsClosed (lowerClosure s : Set Ξ±) :=
IsLower.isClosed_upperClosure (Ξ± := Ξ±α΅α΅) h
/-- Every set open in the upper topology is a upper set. -/
theorem isUpperSet_of_isOpen (h : IsOpen s) : IsUpperSet s :=
IsLower.isLowerSet_of_isOpen (Ξ± := Ξ±α΅α΅) h
theorem isLowerSet_of_isClosed (h : IsClosed s) : IsLowerSet s :=
isUpperSet_compl.1 <| isUpperSet_of_isOpen h.isOpen_compl
theorem tendsto_nhds_iff_not_le {Ξ² : Type*} {f : Ξ² β Ξ±} {l : Filter Ξ²} {x : Ξ±} :
Filter.Tendsto f l (π x) β β y, Β¬x β€ y β βαΆ z in l, Β¬f z β€ y :=
IsLower.tendsto_nhds_iff_not_le (Ξ± := Ξ±α΅α΅)
/--
The closure of a singleton `{a}` in the upper topology is the left-infinite right-closed interval
(-β,a].
-/
@[simp]
theorem closure_singleton (a : Ξ±) : closure {a} = Iic a :=
IsLower.closure_singleton (Ξ± := Ξ±α΅α΅) _
protected theorem isTopologicalBasis : IsTopologicalBasis (upperBasis Ξ±) :=
IsLower.isTopologicalBasis (Ξ± := Ξ±α΅α΅)
/-- A function `f : Ξ² β Ξ±` with upper topology in the codomain is continuous
if and only if the preimage of every interval `Set.Iic a` is a closed set. -/
lemma continuous_iff_Iic [TopologicalSpace Ξ²] {f : Ξ² β Ξ±} :
Continuous f β β a, IsClosed (f β»ΒΉ' (Iic a)) :=
IsLower.continuous_iff_Ici (Ξ± := Ξ±α΅α΅)
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [TopologicalSpace Ξ±] [IsUpper Ξ±]
-- see Note [lower instance priority]
/-- The upper topology on a partial order is Tβ. -/
instance (priority := 90) t0Space : T0Space Ξ± :=
IsLower.t0Space (Ξ± := Ξ±α΅α΅)
end PartialOrder
section LinearOrder
variable [LinearOrder Ξ±] [TopologicalSpace Ξ±] [IsUpper Ξ±]
lemma isTopologicalBasis_insert_univ_subbasis :
IsTopologicalBasis (insert univ {s : Set Ξ± | β a, (Iic a)αΆ = s}) :=
IsLower.isTopologicalBasis_insert_univ_subbasis (Ξ± := Ξ±α΅α΅)
theorem tendsto_nhds_iff_lt {Ξ² : Type*} {f : Ξ² β Ξ±} {l : Filter Ξ²} {x : Ξ±} :
Filter.Tendsto f l (π x) β β y < x, βαΆ z in l, y < f z :=
IsLower.tendsto_nhds_iff_lt (Ξ± := Ξ±α΅α΅)
end LinearOrder
section CompleteLinearOrder
variable [CompleteLinearOrder Ξ±] [t : TopologicalSpace Ξ±] [IsUpper Ξ±]
lemma isTopologicalSpace_basis (U : Set Ξ±) : IsOpen U β U = univ β¨ β a, (Iic a)αΆ = U :=
IsLower.isTopologicalSpace_basis (Ξ± := Ξ±α΅α΅) U
end CompleteLinearOrder
end IsUpper
instance instIsLowerProd [Preorder Ξ±] [TopologicalSpace Ξ±] [IsLower Ξ±]
[OrderBot Ξ±] [Preorder Ξ²] [TopologicalSpace Ξ²] [IsLower Ξ²] [OrderBot Ξ²] :
IsLower (Ξ± Γ Ξ²) where
topology_eq_lowerTopology := by
refine le_antisymm (le_generateFrom ?_) ?_
Β· rintro _ β¨x, rflβ©
exact (isClosed_Ici.prod isClosed_Ici).isOpen_compl
rw [(IsLower.isTopologicalBasis.prod
IsLower.isTopologicalBasis).eq_generateFrom, le_generateFrom_iff_subset_isOpen,
image2_subset_iff]
rintro _ β¨s, hs, rflβ© _ β¨t, ht, rflβ©
dsimp
simp_rw [coe_upperClosure, compl_iUnion, prod_eq, preimage_iInter, preimage_compl]
-- without `let`, `refine` tries to use the product topology and fails
let _ : TopologicalSpace (Ξ± Γ Ξ²) := lower (Ξ± Γ Ξ²)
refine (hs.isOpen_biInter fun a _ => ?_).inter (ht.isOpen_biInter fun b _ => ?_)
Β· exact GenerateOpen.basic _ β¨(a, β₯), by simp [Ici_prod_eq, prod_univ]β©
Β· exact GenerateOpen.basic _ β¨(β₯, b), by simp [Ici_prod_eq, univ_prod]β©
instance instIsUpperProd [Preorder Ξ±] [TopologicalSpace Ξ±] [IsUpper Ξ±]
[OrderTop Ξ±] [Preorder Ξ²] [TopologicalSpace Ξ²] [IsUpper Ξ²] [OrderTop Ξ²] :
IsUpper (Ξ± Γ Ξ²) where
topology_eq_upperTopology := by
suffices IsLower (Ξ± Γ Ξ²)α΅α΅ from IsLower.topology_eq_lowerTopology (Ξ± := (Ξ± Γ Ξ²)α΅α΅)
exact instIsLowerProd (Ξ± := Ξ±α΅α΅) (Ξ² := Ξ²α΅α΅)
section CompleteLattice_IsLower
variable [CompleteLattice Ξ±] [CompleteLattice Ξ²] [TopologicalSpace Ξ±] [IsLower Ξ±]
[TopologicalSpace Ξ²] [IsLower Ξ²]
protected lemma _root_.sInfHom.continuous (f : sInfHom Ξ± Ξ²) : Continuous f := by
refine IsLower.continuous_iff_Ici.2 fun b => ?_
convert isClosed_Ici (a := sInf <| f β»ΒΉ' Ici b)
refine Subset.antisymm (fun a => sInf_le) fun a ha => le_trans ?_ <|
OrderHomClass.mono (f : Ξ± βo Ξ²) ha
refine LE.le.trans ?_ (map_sInf f _).ge
simp
-- see Note [lower instance priority]
instance (priority := 90) IsLower.toContinuousInf : ContinuousInf Ξ± :=
β¨(infsInfHom : sInfHom (Ξ± Γ Ξ±) Ξ±).continuousβ©
end CompleteLattice_IsLower
section CompleteLattice_IsUpper
variable [CompleteLattice Ξ±] [CompleteLattice Ξ²] [TopologicalSpace Ξ±] [IsUpper Ξ±]
[TopologicalSpace Ξ²] [IsUpper Ξ²]
protected lemma _root_.sSupHom.continuous (f : sSupHom Ξ± Ξ²) : Continuous f :=
sInfHom.continuous (Ξ± := Ξ±α΅α΅) (Ξ² := Ξ²α΅α΅) (sSupHom.dual.toFun f)
-- see Note [lower instance priority]
instance (priority := 90) IsUpper.toContinuousInf : ContinuousSup Ξ± :=
β¨(supsSupHom : sSupHom (Ξ± Γ Ξ±) Ξ±).continuousβ©
end CompleteLattice_IsUpper
lemma isUpper_orderDual [Preorder Ξ±] [TopologicalSpace Ξ±] : IsUpper Ξ±α΅α΅ β IsLower Ξ± := by
constructor
Β· apply OrderDual.instIsLower
Β· apply OrderDual.instIsUpper
lemma isLower_orderDual [Preorder Ξ±] [TopologicalSpace Ξ±] : IsLower Ξ±α΅α΅ β IsUpper Ξ± :=
isUpper_orderDual.symm
end Topology
/-- The SierpiΕski topology on `Prop` is the upper topology -/
instance : IsUpper Prop where
topology_eq_upperTopology := by
rw [Topology.upper, sierpinskiSpace, β generateFrom_insert_empty]
congr
exact le_antisymm
(fun h hs => by
simp only [compl_Iic, mem_setOf_eq]
rw [β Ioi_True, β Ioi_False] at hs
rcases hs with (rfl | rfl)
Β· use True
Β· use False)
(by rintro _ β¨a, rflβ©; by_cases a <;> aesop (add simp [Ioi, lt_iff_le_not_ge]))
|
Commutator.lean
|
/-
Copyright (c) 2022 Thomas Browning. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Thomas Browning
-/
import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Bracket
/-!
# The bracket on a group given by commutator.
-/
assert_not_exists MonoidWithZero DenselyOrdered
/-- The commutator of two elements `gβ` and `gβ`. -/
instance commutatorElement {G : Type*} [Group G] : Bracket G G :=
β¨fun gβ gβ β¦ gβ * gβ * gββ»ΒΉ * gββ»ΒΉβ©
theorem commutatorElement_def {G : Type*} [Group G] (gβ gβ : G) :
β
gβ, gββ = gβ * gβ * gββ»ΒΉ * gββ»ΒΉ :=
rfl
|
Change.lean
|
/-
Copyright (c) 2023 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa
-/
import Mathlib.Init
import Lean.Elab.Tactic.ElabTerm
import Lean.Meta.Tactic.TryThis
/-!
# Tactic `change? term`
This tactic is used to suggest a replacement of the goal by a definitionally equal term.
`term` is intended to contain holes which get unified with the main goal and filled in explicitly
in the suggestion.
`term` can also be omitted, in which case `change?` simply suggests `change` with the main goal.
This is helpful after tactics like `dsimp`, which can then be deleted.
-/
/-- `change? term` unifies `term` with the current goal, then suggests explicit `change` syntax
that uses the resulting unified term.
If `term` is not present, `change?` suggests the current goal itself. This is useful after tactics
which transform the goal while maintaining definitional equality, such as `dsimp`; those preceding
tactic calls can then be deleted.
```lean
example : (fun x : Nat => x) 0 = 1 := by
change? 0 = _ -- `Try this: change 0 = 1`
```
-/
syntax (name := change?) "change?" (ppSpace colGt term)? : tactic
open Lean Meta Elab.Tactic Meta.Tactic.TryThis in
elab_rules : tactic
| `(tactic|change?%$tk $[$sop:term]?) => withMainContext do
let stx β getRef
let expr β match sop with
| none => getMainTarget
| some sop => do
let tgt β getMainTarget
let ex β withRef sop <| elabTermEnsuringType sop (β inferType tgt)
if !(β isDefEq ex tgt) then throwErrorAt sop "\
The term{indentD ex}\n\
is not defeq to the goal:{indentD tgt}"
instantiateMVars ex
let dstx β delabToRefinableSyntax expr
addSuggestion tk (β `(tactic| change $dstx)) (origSpan? := stx)
|
finsupp_notation.lean
|
import Mathlib.Data.Finsupp.Notation
import Mathlib.Data.DFinsupp.Notation -- to ensure it does not interfere
import Mathlib.Data.Nat.Factorization.Basic
example : (funβ | 1 => 3) 1 = 3 := by
simp
example : (funβ | 1 | 2 | 3 => 3 | 3 => 4) 1 = 3 := by
simp
example : (funβ | 1 | 2 | 3 => 3 | 3 => 4) 2 = 3 := by
simp
example : (funβ | 1 | 2 | 3 => 3 | 3 => 4) 3 = 4 := by
simp
section repr
/-- info: funβ | 1 => 3 | 2 => 3 -/
#guard_msgs in
#eval (Finsupp.mk {1, 2} (fun | 1 | 2 => 3 | _ => 0) (fun x => by aesop))
/--
info: funβ
| ["there are five words here", "and five more words here"] => 5
| ["there are seven words but only here"] => 7
| ["just two"] => 2
-/
#guard_msgs in
#eval Finsupp.mk
{["there are five words here", "and five more words here"],
["there are seven words but only here"],
["just two"]}
(fun
| ["there are five words here", "and five more words here"] => 5
| ["there are seven words but only here"] => 7
| ["just two"] => 2
| _ => 0)
(fun x => by aesop)
end repr
section PrettyPrinter
/--
info: funβ
| ["there are five words here", "and five more words here"] => 5
| ["there are seven words but only here"] => 7
| ["just two"] => 2 : List String ββ β
-/
#guard_msgs in
#check funβ
| ["there are five words here", "and five more words here"] => 5
| ["there are seven words but only here"] => 7
| ["just two"] => 2
end PrettyPrinter
/-! ## (computable) number theory examples -/
/-- info: funβ | 2 => 2 | 7 => 1 -/
#guard_msgs in
#eval Nat.factorization 28
/-- info: funβ | 3 => 2 | 5 => 1 -/
#guard_msgs in
#eval (Nat.factorization 720).filter Odd
|
Char.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.Data.Nat.Basic
import Mathlib.Order.Defs.LinearOrder
/-!
# More `Char` instances
This file provides a `LinearOrder` instance on `Char`. `Char` is the type of Unicode scalar values.
Provides an additional definition to truncate a `Char` to `UInt8` and a theorem on conversion to
`Nat`.
-/
/--
Provides a `LinearOrder` instance on `Char`. `Char` is the type of Unicode scalar values.
-/
instance : LinearOrder Char where
le_refl := fun _ => @le_refl β _ _
le_trans := fun _ _ _ => @le_trans β _ _ _ _
le_antisymm := fun _ _ hβ hβ => Char.eq_of_val_eq <| UInt32.eq_of_toBitVec_eq <|
BitVec.le_antisymm hβ hβ
lt_iff_le_not_ge := fun _ _ => @lt_iff_le_not_ge β _ _ _
le_total := fun _ _ => @le_total β _ _ _
min := fun a b => if a β€ b then a else b
max := fun a b => if a β€ b then b else a
toDecidableLE := inferInstance
toDecidableEq := inferInstance
toDecidableLT := inferInstance
|
Continuous.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.Action.Basic
import Mathlib.Topology.Algebra.MulAction
import Mathlib.Topology.Category.TopCat.Basic
import Mathlib.Topology.Algebra.ContinuousMonoidHom
/-!
# Topological subcategories of `Action V G`
For a concrete category `V`, where the forgetful functor factors via `TopCat`,
and a monoid `G`, equipped with a topological space instance,
we define the full subcategory `ContAction V G` of all objects of `Action V G`
where the induced action is continuous.
We also define a category `DiscreteContAction V G` as the full subcategory of `ContAction V G`,
where the underlying topological space is discrete.
Finally we define inclusion functors into `Action V G` and `TopCat` in terms
of `HasForgetβ` instances.
-/
open CategoryTheory Limits
variable (V : Type*) [Category V] [HasForget V] [HasForgetβ V TopCat]
variable (G : Type*) [Monoid G] [TopologicalSpace G]
namespace Action
instance : HasForgetβ (Action V G) TopCat :=
HasForgetβ.trans (Action V G) V TopCat
instance (X : Action V G) : MulAction G ((CategoryTheory.forgetβ _ TopCat).obj X) where
smul g x := ((CategoryTheory.forgetβ _ TopCat).map (X.Ο g)) x
one_smul x := by
change ((CategoryTheory.forgetβ _ TopCat).map (X.Ο 1)) x = x
simp
mul_smul g h x := by
change (CategoryTheory.forgetβ _ TopCat).map (X.Ο (g * h)) x =
((CategoryTheory.forgetβ _ TopCat).map (X.Ο h) β«
(CategoryTheory.forgetβ _ TopCat).map (X.Ο g)) x
rw [β Functor.map_comp, map_mul]
rfl
variable {V G}
/-- For `HasForgetβ V TopCat` a predicate on an `X : Action V G` saying that the induced action on
the underlying topological space is continuous. -/
abbrev IsContinuous (X : Action V G) : Prop :=
ContinuousSMul G ((CategoryTheory.forgetβ _ TopCat).obj X)
lemma isContinuous_def (X : Action V G) :
X.IsContinuous β Continuous (fun p : G Γ (forgetβ _ TopCat).obj X β¦
(forgetβ _ TopCat).map (X.Ο p.1) p.2) :=
β¨fun h β¦ h.1, fun h β¦ β¨hβ©β©
end Action
open Action
/-- For `HasForgetβ V TopCat`, this is the full subcategory of `Action V G` where the induced
action is continuous. -/
def ContAction : Type _ := ObjectProperty.FullSubcategory (IsContinuous (V := V) (G := G))
namespace ContAction
instance : Category (ContAction V G) :=
ObjectProperty.FullSubcategory.category (IsContinuous (V := V) (G := G))
instance : HasForget (ContAction V G) :=
FullSubcategory.hasForget (IsContinuous (V := V) (G := G))
instance {FV : V β V β Type*} {CV : V β Type*} [β X Y, FunLike (FV X Y) (CV X) (CV Y)]
[ConcreteCategory V FV] :
ConcreteCategory (ContAction V G) (fun X Y => Action.HomSubtype V G X.1 Y.1) :=
FullSubcategory.concreteCategory (IsContinuous (V := V) (G := G))
instance : HasForgetβ (ContAction V G) (Action V G) :=
FullSubcategory.hasForgetβ (IsContinuous (V := V) (G := G))
instance : HasForgetβ (ContAction V G) V :=
HasForgetβ.trans (ContAction V G) (Action V G) V
instance : HasForgetβ (ContAction V G) TopCat :=
HasForgetβ.trans (ContAction V G) (Action V G) TopCat
instance : Coe (ContAction V G) (Action V G) where
coe X := X.obj
variable {V G}
/-- A predicate on an `X : ContAction V G` saying that the topology on the underlying type of `X`
is discrete. -/
abbrev IsDiscrete (X : ContAction V G) : Prop :=
DiscreteTopology ((CategoryTheory.forgetβ _ TopCat).obj X)
variable (V) {H : Type*} [Monoid H] [TopologicalSpace H]
/-- The "restriction" functor along a monoid homomorphism `f : G β* H`,
taking actions of `H` to actions of `G`. This is the analogue of
`Action.res` in the continuous setting. -/
@[simps! obj_obj map]
def res (f : G ββ* H) : ContAction V H β₯€ ContAction V G :=
ObjectProperty.lift _ (ObjectProperty.ΞΉ _ β Action.res _ f) fun X β¦ by
constructor
let v : G Γ (forgetβ _ TopCat).obj X β H Γ (forgetβ _ TopCat).obj X := fun p β¦ (f p.1, p.2)
have : Continuous v := by fun_prop
let u : H Γ (forgetβ _ TopCat).obj X β (forgetβ _ TopCat).obj X :=
fun p β¦ (forgetβ _ TopCat).map (X.obj.Ο p.1) p.2
have : Continuous u := X.2.1
change Continuous (u β v)
fun_prop
/-- Restricting scalars along a composition is naturally isomorphic to restricting scalars twice. -/
@[simps! hom inv]
def resComp {K : Type*} [Monoid K] [TopologicalSpace K]
(f : G ββ* H) (h : H ββ* K) :
ContAction.res V (h.comp f) β
ContAction.res V h β ContAction.res V f :=
NatIso.ofComponents (fun _ β¦ Iso.refl _)
/-- If `f = f'`, restriction of scalars along `f` and `f'` is the same. -/
@[simps! hom inv]
def resCongr (f f' : G ββ* H) (h : f = f') : ContAction.res V f β
ContAction.res V f' :=
NatIso.ofComponents (fun _ β¦ ObjectProperty.isoMk _ (Action.mkIso (Iso.refl _)
(by subst h; simp))) fun f β¦ by
apply Action.Hom.ext
rw [ObjectProperty.FullSubcategory.comp_def, ObjectProperty.FullSubcategory.comp_def]
simp
/-- Restriction of scalars along a topological monoid isomorphism induces an equivalence of
categories. -/
@[simps! functor inverse]
def resEquiv (f : G ββ* H) : ContAction V H β ContAction V G where
functor := res _ f
inverse := res _ f.symm
unitIso := resCongr V (ContinuousMonoidHom.id H) _ (by ext; simp) βͺβ«
ContAction.resComp _ _ _
counitIso := (ContAction.resComp _ _ _).symm βͺβ«
ContAction.resCongr V _ (ContinuousMonoidHom.id G) (by ext; simp)
functor_unitIso_comp X := (Action.resEquiv V f.toMulEquiv).functor_unitIso_comp X.obj
end ContAction
open ContAction
/-- The subcategory of `ContAction V G` where the topology is discrete. -/
def DiscreteContAction : Type _ := ObjectProperty.FullSubcategory (IsDiscrete (V := V) (G := G))
namespace DiscreteContAction
instance : Category (DiscreteContAction V G) :=
ObjectProperty.FullSubcategory.category (IsDiscrete (V := V) (G := G))
instance : HasForget (DiscreteContAction V G) :=
FullSubcategory.hasForget (IsDiscrete (V := V) (G := G))
instance {FV : V β V β Type*} {CV : V β Type*} [β X Y, FunLike (FV X Y) (CV X) (CV Y)]
[ConcreteCategory V FV] :
ConcreteCategory (DiscreteContAction V G) (fun X Y => Action.HomSubtype V G X.1 Y.1) :=
FullSubcategory.concreteCategory (IsDiscrete (V := V) (G := G))
instance : HasForgetβ (DiscreteContAction V G) (ContAction V G) :=
FullSubcategory.hasForgetβ (IsDiscrete (V := V) (G := G))
instance : HasForgetβ (DiscreteContAction V G) TopCat :=
HasForgetβ.trans (DiscreteContAction V G) (ContAction V G) TopCat
variable {V G}
instance (X : DiscreteContAction V G) :
DiscreteTopology ((CategoryTheory.forgetβ _ TopCat).obj X) :=
X.property
end DiscreteContAction
namespace CategoryTheory
variable {V W : Type*} [Category V] [HasForget V] [HasForgetβ V TopCat]
[Category W] [HasForget W] [HasForgetβ W TopCat]
(G : Type*) [Monoid G] [TopologicalSpace G]
namespace Functor
/-- Continuous version of `Functor.mapAction`. -/
@[simps! obj_obj map]
def mapContAction (F : V β₯€ W) (H : β X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous) :
ContAction V G β₯€ ContAction W G :=
ObjectProperty.lift _ (ObjectProperty.ΞΉ _ β F.mapAction G) H
/-- Continuous version of `Functor.mapActionComp`. -/
@[simps! hom inv]
def mapContActionComp {T : Type*} [Category T] [HasForget T] [HasForgetβ T TopCat]
(F : V β₯€ W) (H : β X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous)
(F' : W β₯€ T) (H' : β X : ContAction W G, ((F'.mapAction G).obj X.obj).IsContinuous) :
Functor.mapContAction G (F β F') (fun X β¦ H' ((F.mapContAction G H).obj X)) β
Functor.mapContAction G F H β Functor.mapContAction G F' H' :=
NatIso.ofComponents (fun _ β¦ Iso.refl _)
/-- Continuous version of `Functor.mapActionCongr`. -/
@[simps! hom inv]
def mapContActionCongr
{F : V β₯€ W} {F' : V β₯€ W} (e : F β
F')
(H : β X : ContAction V G, ((F.mapAction G).obj X.obj).IsContinuous)
(H' : β X : ContAction V G, ((F'.mapAction G).obj X.obj).IsContinuous) :
Functor.mapContAction G F H β
Functor.mapContAction G F' H' :=
NatIso.ofComponents (fun X β¦ ObjectProperty.isoMk _ (Action.mkIso (e.app X.obj.V) (by simp))) <|
(fun f β¦ (Functor.mapActionCongr G e).hom.naturality f)
end Functor
/-- Continuous version of `Equivalence.mapAction`. -/
@[simps functor inverse]
def Equivalence.mapContAction (E : V β W)
(Hβ : β X : ContAction V G, ((E.functor.mapAction G).obj X.obj).IsContinuous)
(Hβ : β X : ContAction W G, ((E.inverse.mapAction G).obj X.obj).IsContinuous) :
ContAction V G β ContAction W G where
functor := E.functor.mapContAction G Hβ
inverse := E.inverse.mapContAction G Hβ
unitIso := Functor.mapContActionCongr G E.unitIso
(fun X β¦ X.2) (fun X β¦ Hβ ((E.functor.mapContAction G Hβ).obj X)) βͺβ«
Functor.mapContActionComp G _ _ _ _
counitIso := (Functor.mapContActionComp G _ _ _ _).symm βͺβ«
Functor.mapContActionCongr G E.counitIso _ (fun X β¦ X.2)
functor_unitIso_comp X := (E.mapAction G).functor_unitIso_comp X.obj
end CategoryTheory
|
commutator.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat fintype.
From mathcomp Require Import bigop finset binomial fingroup morphism.
From mathcomp Require Import automorphism quotient gfunctor.
(******************************************************************************)
(* This files contains the proofs of several key properties of commutators, *)
(* including the Hall-Witt identity and the Three Subgroup Lemma. *)
(* The definition and notation for both pointwise and set wise commutators *)
(* ([~x, y, ...] and [~: A, B ,...], respectively) are given in fingroup.v *)
(* This file defines the derived group series: *)
(* G^`(0) == G *)
(* G^`(n.+1) == [~: G^`(n), G^`(n)] *)
(* as several classical results involve the (first) derived group G^`(1), *)
(* such as the equivalence H <| G /\ G / H abelian <-> G^`(1) \subset H. *)
(* The connection between the derived series and solvable groups will only be *)
(* established in nilpotent.v, however. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Definition derived_at n (gT : finGroupType) (A : {set gT}) :=
iter n (fun B => [~: B, B]) A.
Arguments derived_at n%_N {gT} A%_g : simpl never.
Notation "G ^` ( n )" := (derived_at n G) : group_scope.
Section DerivedBasics.
Variables gT : finGroupType.
Implicit Type A : {set gT}.
Implicit Types G : {group gT}.
Lemma derg0 A : A^`(0) = A. Proof. by []. Qed.
Lemma derg1 A : A^`(1) = [~: A, A]. Proof. by []. Qed.
Lemma dergSn n A : A^`(n.+1) = [~: A^`(n), A^`(n)]. Proof. by []. Qed.
Lemma der_group_set G n : group_set G^`(n).
Proof. by case: n => [|n]; apply: groupP. Qed.
Canonical derived_at_group G n := Group (der_group_set G n).
End DerivedBasics.
Notation "G ^` ( n )" := (derived_at_group G n) : Group_scope.
Section Basic_commutator_properties.
Variable gT : finGroupType.
Implicit Types x y z : gT.
Lemma conjg_mulR x y : x ^ y = x * [~ x, y].
Proof. by rewrite mulKVg. Qed.
Lemma conjg_Rmul x y : x ^ y = [~ y, x^-1] * x.
Proof. by rewrite commgEr invgK mulgKV. Qed.
Lemma commMgJ x y z : [~ x * y, z] = [~ x, z] ^ y * [~ y, z].
Proof. by rewrite !commgEr conjgM mulgA -conjMg mulgK. Qed.
Lemma commgMJ x y z : [~ x, y * z] = [~ x, z] * [~ x, y] ^ z.
Proof. by rewrite !commgEl conjgM -mulgA -conjMg mulKVg. Qed.
Lemma commMgR x y z : [~ x * y, z] = [~ x, z] * [~ x, z, y] * [~ y, z].
Proof. by rewrite commMgJ conjg_mulR. Qed.
Lemma commgMR x y z : [~ x, y * z] = [~ x, z] * [~ x, y] * [~ x, y, z].
Proof. by rewrite commgMJ conjg_mulR mulgA. Qed.
Lemma Hall_Witt_identity x y z :
[~ x, y^-1, z] ^ y * [~ y, z^-1, x] ^ z * [~ z, x^-1, y] ^ x = 1.
Proof. (* gsimpl *)
pose a x y z : gT := x * z * y ^ x.
suffices{x y z} hw_aux x y z: [~ x, y^-1, z] ^ y = (a x y z)^-1 * (a y z x).
by rewrite !hw_aux 2!mulgA !mulgK mulVg.
by rewrite commgEr conjMg -conjgM -conjg_Rmul 2!invMg conjgE !mulgA.
Qed.
(* the following properties are useful for studying p-groups of class 2 *)
Section LeftComm.
Variables (i : nat) (x y : gT).
Hypothesis cxz : commute x [~ x, y].
Lemma commVg : [~ x^-1, y] = [~ x, y]^-1.
Proof.
apply/eqP; rewrite commgEl eq_sym eq_invg_mul invgK mulgA -cxz.
by rewrite -conjg_mulR -conjMg mulgV conj1g.
Qed.
Lemma commXg : [~ x ^+ i, y] = [~ x, y] ^+ i.
Proof.
elim: i => [|i' IHi]; first exact: comm1g.
by rewrite !expgS commMgJ /conjg commuteX // mulKg IHi.
Qed.
End LeftComm.
Section RightComm.
Variables (i : nat) (x y : gT).
Hypothesis cyz : commute y [~ x, y].
Let cyz' := commuteV cyz.
Lemma commgV : [~ x, y^-1] = [~ x, y]^-1.
Proof. by rewrite -invg_comm commVg -(invg_comm x y) ?invgK. Qed.
Lemma commgX : [~ x, y ^+ i] = [~ x, y] ^+ i.
Proof. by rewrite -invg_comm commXg -(invg_comm x y) ?expgVn ?invgK. Qed.
End RightComm.
Section LeftRightComm.
Variables (i j : nat) (x y : gT).
Hypotheses (cxz : commute x [~ x, y]) (cyz : commute y [~ x, y]).
Lemma commXXg : [~ x ^+ i, y ^+ j] = [~ x, y] ^+ (i * j).
Proof. by rewrite expgM commgX commXg //; apply: commuteX. Qed.
Lemma expMg_Rmul : (y * x) ^+ i = y ^+ i * x ^+ i * [~ x, y] ^+ 'C(i, 2).
Proof.
rewrite -bin2_sum; symmetry.
elim: i => [|k IHk] /=; first by rewrite big_geq ?mulg1.
rewrite big_nat_recr //= addnC expgD !expgS -{}IHk !mulgA; congr (_ * _).
by rewrite -!mulgA commuteX2 // -commgX // [mulg y]lock 3!mulgA -commgC.
Qed.
End LeftRightComm.
End Basic_commutator_properties.
(***** Set theoretic commutators *****)
Section Commutator_properties.
Variable gT : finGroupType.
Implicit Type (rT : finGroupType) (A B C : {set gT}) (D G H K : {group gT}).
Lemma commG1 A : [~: A, 1] = 1.
Proof. by apply/commG1P; rewrite centsC sub1G. Qed.
Lemma comm1G A : [~: 1, A] = 1.
Proof. by rewrite commGC commG1. Qed.
Lemma commg_sub A B : [~: A, B] \subset A <*> B.
Proof. by rewrite comm_subG // (joing_subl, joing_subr). Qed.
Lemma commg_norml G A : G \subset 'N([~: G, A]).
Proof.
apply/subsetP=> x Gx; rewrite inE -genJ gen_subG.
apply/subsetP=> _ /imsetP[_ /imset2P[y z Gy Az ->] ->].
by rewrite -(mulgK [~ x, z] (_ ^ x)) -commMgJ !(mem_commg, groupMl, groupV).
Qed.
Lemma commg_normr G A : G \subset 'N([~: A, G]).
Proof. by rewrite commGC commg_norml. Qed.
Lemma commg_norm G H : G <*> H \subset 'N([~: G, H]).
Proof. by rewrite join_subG ?commg_norml ?commg_normr. Qed.
Lemma commg_normal G H : [~: G, H] <| G <*> H.
Proof. by rewrite /(_ <| _) commg_sub commg_norm. Qed.
Lemma normsRl A G B : A \subset G -> A \subset 'N([~: G, B]).
Proof. by move=> sAG; apply: subset_trans (commg_norml G B). Qed.
Lemma normsRr A G B : A \subset G -> A \subset 'N([~: B, G]).
Proof. by move=> sAG; apply: subset_trans (commg_normr G B). Qed.
Lemma commg_subr G H : ([~: G, H] \subset H) = (G \subset 'N(H)).
Proof.
rewrite gen_subG; apply/subsetP/subsetP=> [sRH x Gx | nGH xy].
rewrite inE; apply/subsetP=> _ /imsetP[y Ky ->].
by rewrite conjg_Rmul groupMr // sRH // imset2_f ?groupV.
case/imset2P=> x y Gx Hy ->{xy}.
by rewrite commgEr groupMr // memJ_norm (groupV, nGH).
Qed.
Lemma commg_subl G H : ([~: G, H] \subset G) = (H \subset 'N(G)).
Proof. by rewrite commGC commg_subr. Qed.
Lemma commg_subI A B G H :
A \subset 'N_G(H) -> B \subset 'N_H(G) -> [~: A, B] \subset G :&: H.
Proof.
rewrite !subsetI -(gen_subG _ 'N(G)) -(gen_subG _ 'N(H)).
rewrite -commg_subr -commg_subl; case/andP=> sAG sRH; case/andP=> sBH sRG.
by rewrite (subset_trans _ sRG) ?(subset_trans _ sRH) ?commgSS ?subset_gen.
Qed.
Lemma quotient_cents2 A B K :
A \subset 'N(K) -> B \subset 'N(K) ->
(A / K \subset 'C(B / K)) = ([~: A, B] \subset K).
Proof.
move=> nKA nKB.
by rewrite (sameP commG1P trivgP) /= -quotientR // quotient_sub1 // comm_subG.
Qed.
Lemma quotient_cents2r A B K :
[~: A, B] \subset K -> (A / K) \subset 'C(B / K).
Proof.
move=> sABK; rewrite -2![_ / _]morphimIdom -!quotientE.
by rewrite quotient_cents2 ?subsetIl ?(subset_trans _ sABK) ?commgSS ?subsetIr.
Qed.
Lemma sub_der1_norm G H : G^`(1) \subset H -> H \subset G -> G \subset 'N(H).
Proof.
by move=> sG'H sHG; rewrite -commg_subr (subset_trans _ sG'H) ?commgS.
Qed.
Lemma sub_der1_normal G H : G^`(1) \subset H -> H \subset G -> H <| G.
Proof. by move=> sG'H sHG; rewrite /(H <| G) sHG sub_der1_norm. Qed.
Lemma sub_der1_abelian G H : G^`(1) \subset H -> abelian (G / H).
Proof. by move=> sG'H; apply: quotient_cents2r. Qed.
Lemma der1_min G H : G \subset 'N(H) -> abelian (G / H) -> G^`(1) \subset H.
Proof. by move=> nHG abGH; rewrite -quotient_cents2. Qed.
Lemma der_abelian n G : abelian (G^`(n) / G^`(n.+1)).
Proof. by rewrite sub_der1_abelian // der_subS. Qed.
Lemma commg_normSl G H K : G \subset 'N(H) -> [~: G, H] \subset 'N([~: K, H]).
Proof. by move=> nHG; rewrite normsRr // commg_subr. Qed.
Lemma commg_normSr G H K : G \subset 'N(H) -> [~: H, G] \subset 'N([~: H, K]).
Proof. by move=> nHG; rewrite !(commGC H) commg_normSl. Qed.
Lemma commMGr G H K : [~: G, K] * [~: H, K] \subset [~: G * H , K].
Proof. by rewrite mul_subG ?commSg ?(mulG_subl, mulG_subr). Qed.
Lemma commMG G H K :
H \subset 'N([~: G, K]) -> [~: G * H , K] = [~: G, K] * [~: H, K].
Proof.
move=> nRH; apply/eqP; rewrite eqEsubset commMGr andbT.
have nRHK: [~: H, K] \subset 'N([~: G, K]) by rewrite comm_subG ?commg_normr.
have defM := norm_joinEr nRHK; rewrite -defM gen_subG /=.
apply/subsetP=> _ /imset2P[_ z /imset2P[x y Gx Hy ->] Kz ->].
by rewrite commMgJ {}defM mem_mulg ?memJ_norm ?mem_commg // (subsetP nRH).
Qed.
Lemma comm3G1P A B C :
reflect {in A & B & C, forall h k l, [~ h, k, l] = 1} ([~: A, B, C] :==: 1).
Proof.
have R_C := sameP trivgP commG1P.
rewrite -subG1 R_C gen_subG -{}R_C gen_subG.
apply: (iffP subsetP) => [cABC x y z Ax By Cz | cABC xyz].
by apply/set1P; rewrite cABC // !imset2_f.
by case/imset2P=> _ z /imset2P[x y Ax By ->] Cz ->; rewrite cABC.
Qed.
Lemma three_subgroup G H K :
[~: G, H, K] :=: 1 -> [~: H, K, G] :=: 1-> [~: K, G, H] :=: 1.
Proof.
move/eqP/comm3G1P=> cGHK /eqP/comm3G1P cHKG.
apply/eqP/comm3G1P=> x y z Kx Gy Hz; symmetry.
rewrite -(conj1g y) -(Hall_Witt_identity y^-1 z x) invgK.
by rewrite cGHK ?groupV // cHKG ?groupV // !conj1g !mul1g conjgKV.
Qed.
Lemma der1_joing_cycles (x y : gT) :
let XY := <[x]> <*> <[y]> in let xy := [~ x, y] in
xy \in 'C(XY) -> XY^`(1) = <[xy]>.
Proof.
rewrite joing_idl joing_idr /= -sub_cent1 => /norms_gen nRxy.
apply/eqP; rewrite eqEsubset cycle_subG mem_commg ?mem_gen ?set21 ?set22 //.
rewrite der1_min // quotient_gen -1?gen_subG // quotientU abelian_gen.
rewrite /abelian subUset centU !subsetI andbC centsC -andbA -!abelianE.
rewrite !quotient_abelian ?(abelianS (subset_gen _) (cycle_abelian _)) //=.
by rewrite andbb quotient_cents2r ?genS // /commg_set imset2_set1l imset_set1.
Qed.
Lemma commgAC G x y z : x \in G -> y \in G -> z \in G ->
commute y z -> abelian [~: [set x], G] -> [~ x, y, z] = [~ x, z, y].
Proof.
move=> Gx Gy Gz cyz /centsP cRxG; pose cx' u := [~ x^-1, u].
have xR3 u v: [~ x, u, v] = x^-1 * (cx' u * cx' v) * x ^ (u * v).
rewrite mulgA -conjg_mulR conjVg [cx' v]commgEl mulgA -invMg.
by rewrite -mulgA conjgM -conjMg -!commgEl.
suffices RxGcx' u: u \in G -> cx' u \in [~: [set x], G].
by rewrite !xR3 {}cyz; congr (_ * _ * _); rewrite cRxG ?RxGcx'.
move=> Gu; suffices/groupMl <-: [~ x, u] ^ x^-1 \in [~: [set x], G].
by rewrite -commMgJ mulgV comm1g group1.
by rewrite memJ_norm ?mem_commg ?set11 // groupV (subsetP (commg_normr _ _)).
Qed.
(* Aschbacher, exercise 3.6 (used in proofs of Aschbacher 24.7 and B & G 1.10 *)
Lemma comm_norm_cent_cent H G K :
H \subset 'N(G) -> H \subset 'C(K) -> G \subset 'N(K) ->
[~: G, H] \subset 'C(K).
Proof.
move=> nGH /centsP cKH nKG; rewrite commGC gen_subG centsC.
apply/centsP=> x Kx _ /imset2P[y z Hy Gz ->]; red.
rewrite mulgA -[x * _]cKH ?groupV // -!mulgA; congr (_ * _).
rewrite (mulgA x) (conjgC x) (conjgCV z) 3!mulgA; congr (_ * _).
by rewrite -2!mulgA (cKH y) // -mem_conjg (normsP nKG).
Qed.
Lemma charR H K G : H \char G -> K \char G -> [~: H, K] \char G.
Proof.
case/charP=> sHG chH /charP[sKG chK]; apply/charP.
by split=> [|f infj Gf]; [rewrite comm_subG | rewrite morphimR // chH // chK].
Qed.
Lemma der_char n G : G^`(n) \char G.
Proof. by elim: n => [|n IHn]; rewrite ?char_refl // dergSn charR. Qed.
Lemma der_sub n G : G^`(n) \subset G.
Proof. by rewrite char_sub ?der_char. Qed.
Lemma der_norm n G : G \subset 'N(G^`(n)).
Proof. by rewrite char_norm ?der_char. Qed.
Lemma der_normal n G : G^`(n) <| G.
Proof. by rewrite char_normal ?der_char. Qed.
Lemma der_subS n G : G^`(n.+1) \subset G^`(n).
Proof. by rewrite comm_subG. Qed.
Lemma der_normalS n G : G^`(n.+1) <| G^`(n).
Proof. by rewrite sub_der1_normal // der_subS. Qed.
Lemma morphim_der rT D (f : {morphism D >-> rT}) n G :
G \subset D -> f @* G^`(n) = (f @* G)^`(n).
Proof.
move=> sGD; elim: n => // n IHn.
by rewrite !dergSn -IHn morphimR ?(subset_trans (der_sub n G)).
Qed.
Lemma dergS n G H : G \subset H -> G^`(n) \subset H^`(n).
Proof. by move=> sGH; elim: n => // n IHn; apply: commgSS. Qed.
Lemma quotient_der n G H : G \subset 'N(H) -> G^`(n) / H = (G / H)^`(n).
Proof. exact: morphim_der. Qed.
Lemma derJ G n x : (G :^ x)^`(n) = G^`(n) :^ x.
Proof. by elim: n => //= n IHn; rewrite !dergSn IHn -conjsRg. Qed.
Lemma derG1P G : reflect (G^`(1) = 1) (abelian G).
Proof. exact: commG1P. Qed.
End Commutator_properties.
Arguments derG1P {gT G}.
Lemma der_cont n : GFunctor.continuous (@derived_at n).
Proof. by move=> aT rT G f; rewrite morphim_der. Qed.
Canonical der_igFun n := [igFun by der_sub^~ n & der_cont n].
Canonical der_gFun n := [gFun by der_cont n].
Canonical der_mgFun n := [mgFun by dergS^~ n].
Lemma isog_der (aT rT : finGroupType) n (G : {group aT}) (H : {group rT}) :
G \isog H -> G^`(n) \isog H^`(n).
Proof. exact: gFisog. Qed.
|
PowerBasis.lean
|
/-
Copyright (c) 2021 Anne Baanen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anne Baanen
-/
import Mathlib.RingTheory.Adjoin.Basic
import Mathlib.RingTheory.PowerBasis
import Mathlib.LinearAlgebra.Matrix.Basis
/-!
# Power basis for `Algebra.adjoin R {x}`
This file defines the canonical power basis on `Algebra.adjoin R {x}`,
where `x` is an integral element over `R`.
-/
open Module Polynomial PowerBasis
variable {K S : Type*} [Field K] [CommRing S] [Algebra K S]
namespace Algebra
/-- The elements `1, x, ..., x ^ (d - 1)` for a basis for the `K`-module `K[x]`,
where `d` is the degree of the minimal polynomial of `x`. -/
noncomputable def adjoin.powerBasisAux {x : S} (hx : IsIntegral K x) :
Basis (Fin (minpoly K x).natDegree) K (adjoin K ({x} : Set S)) := by
have hST : Function.Injective (algebraMap (adjoin K ({x} : Set S)) S) := Subtype.coe_injective
have hx' :
IsIntegral K (β¨x, subset_adjoin (Set.mem_singleton x)β© : adjoin K ({x} : Set S)) := by
apply (isIntegral_algebraMap_iff hST).mp
convert hx
apply Basis.mk (v := fun i : Fin _ β¦ β¨x, subset_adjoin (Set.mem_singleton x)β© ^ (i : β))
Β· have : LinearIndependent K _ := linearIndependent_pow
(β¨x, self_mem_adjoin_singleton _ _β© : adjoin K {x})
rwa [β minpoly.algebraMap_eq hST] at this
Β· rintro β¨y, hyβ© _
have := hx'.mem_span_pow (y := β¨y, hyβ©)
rw [β minpoly.algebraMap_eq hST] at this
apply this
rw [adjoin_singleton_eq_range_aeval] at hy
obtain β¨f, rflβ© := (aeval x).mem_range.mp hy
use f
ext
exact aeval_algebraMap_apply S (β¨x, _β© : adjoin K {x}) _
/-- The power basis `1, x, ..., x ^ (d - 1)` for `K[x]`,
where `d` is the degree of the minimal polynomial of `x`. See `Algebra.adjoin.powerBasis'` for
a version over a more general base ring. -/
@[simps gen dim]
noncomputable def adjoin.powerBasis {x : S} (hx : IsIntegral K x) :
PowerBasis K (adjoin K ({x} : Set S)) where
gen := β¨x, subset_adjoin (Set.mem_singleton x)β©
dim := (minpoly K x).natDegree
basis := adjoin.powerBasisAux hx
basis_eq_pow i := by rw [adjoin.powerBasisAux, Basis.mk_apply]
end Algebra
open Algebra
/-- The power basis given by `x` if `B.gen β adjoin K {x}`. See `PowerBasis.ofGenMemAdjoin'`
for a version over a more general base ring. -/
@[simps!]
noncomputable def PowerBasis.ofGenMemAdjoin {x : S} (B : PowerBasis K S) (hint : IsIntegral K x)
(hx : B.gen β adjoin K ({x} : Set S)) : PowerBasis K S :=
(Algebra.adjoin.powerBasis hint).map <|
(Subalgebra.equivOfEq _ _ <| PowerBasis.adjoin_eq_top_of_gen_mem_adjoin hx).trans
Subalgebra.topEquiv
section IsIntegral
namespace PowerBasis
open Polynomial
variable {R : Type*} [CommRing R] [Algebra R S] [Algebra R K] [IsScalarTower R K S]
variable {A : Type*} [CommRing A] [Algebra R A] [Algebra S A]
variable [IsScalarTower R S A] {B : PowerBasis S A}
/-- If `B : PowerBasis S A` is such that `IsIntegral R B.gen`, then
`IsIntegral R (B.basis.repr (B.gen ^ n) i)` for all `i` if
`minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case if `R` is a GCD domain
and `S` is its fraction ring. -/
theorem repr_gen_pow_isIntegral (hB : IsIntegral R B.gen)
(hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) (n : β) :
β i, IsIntegral R (B.basis.repr (B.gen ^ n) i) := by
intro i
nontriviality S
let Q := X ^ n %β minpoly R B.gen
have : B.gen ^ n = aeval B.gen Q := by
rw [β @aeval_X_pow R _ _ _ _ B.gen, β modByMonic_add_div (X ^ n) (minpoly.monic hB)]
simp [Q]
by_cases hQ : Q = 0
Β· simp [this, hQ, isIntegral_zero]
have hlt : Q.natDegree < B.dim := by
rw [β B.natDegree_minpoly, hmin, (minpoly.monic hB).natDegree_map,
natDegree_lt_natDegree_iff hQ]
letI : Nontrivial R := Nontrivial.of_polynomial_ne hQ
exact degree_modByMonic_lt _ (minpoly.monic hB)
rw [this, aeval_eq_sum_range' hlt]
simp only [map_sum, Finset.sum_apply']
refine IsIntegral.sum _ fun j hj => ?_
replace hj := Finset.mem_range.1 hj
rw [β Fin.val_mk hj, β B.basis_eq_pow, Algebra.smul_def, IsScalarTower.algebraMap_apply R S A, β
Algebra.smul_def, LinearEquiv.map_smul]
simp only [algebraMap_smul, Finsupp.coe_smul, Pi.smul_apply, B.basis.repr_self_apply]
by_cases hij : (β¨j, hjβ© : Fin _) = i
Β· simp only [hij, if_true]
rw [Algebra.smul_def, mul_one]
exact isIntegral_algebraMap
Β· simp [hij, isIntegral_zero]
/-- Let `B : PowerBasis S A` be such that `IsIntegral R B.gen`, and let `x y : A` be elements with
integral coordinates in the base `B.basis`. Then `IsIntegral R ((B.basis.repr (x * y) i)` for all
`i` if `minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case if `R` is a GCD
domain and `S` is its fraction ring. -/
theorem repr_mul_isIntegral (hB : IsIntegral R B.gen) {x y : A}
(hx : β i, IsIntegral R (B.basis.repr x i)) (hy : β i, IsIntegral R (B.basis.repr y i))
(hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) :
β i, IsIntegral R (B.basis.repr (x * y) i) := by
intro i
rw [β B.basis.sum_repr x, β B.basis.sum_repr y, Finset.sum_mul_sum, β Finset.sum_product',
map_sum, Finset.sum_apply']
refine IsIntegral.sum _ fun I _ => ?_
simp only [Algebra.smul_mul_assoc, Algebra.mul_smul_comm, LinearEquiv.map_smulββ,
RingHom.id_apply, Finsupp.coe_smul, Pi.smul_apply, id.smul_eq_mul]
refine (hy _).mul ((hx _).mul ?_)
simp only [coe_basis, β pow_add]
exact repr_gen_pow_isIntegral hB hmin _ _
/-- Let `B : PowerBasis S A` be such that `IsIntegral R B.gen`, and let `x : A` be an element
with integral coordinates in the base `B.basis`. Then `IsIntegral R ((B.basis.repr (x ^ n) i)` for
all `i` and all `n` if `minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)`. This is the case
if `R` is a GCD domain and `S` is its fraction ring. -/
theorem repr_pow_isIntegral (hB : IsIntegral R B.gen) {x : A}
(hx : β i, IsIntegral R (B.basis.repr x i))
(hmin : minpoly S B.gen = (minpoly R B.gen).map (algebraMap R S)) (n : β) :
β i, IsIntegral R (B.basis.repr (x ^ n) i) := by
nontriviality A using Subsingleton.elim (x ^ n) 0, isIntegral_zero
revert hx
refine Nat.case_strong_induction_on
-- Porting note: had to hint what to induct on
(p := fun n β¦ _ β β (i : Fin B.dim), IsIntegral R (B.basis.repr (x ^ n) i))
n ?_ fun n hn => ?_
Β· intro _ i
rw [pow_zero, β pow_zero B.gen, β Fin.val_mk B.dim_pos, β B.basis_eq_pow,
B.basis.repr_self_apply]
split_ifs
Β· exact isIntegral_one
Β· exact isIntegral_zero
Β· intro hx
rw [pow_succ]
exact repr_mul_isIntegral hB (fun _ => hn _ le_rfl (fun _ => hx _) _) hx hmin
/-- Let `B B' : PowerBasis K S` be such that `IsIntegral R B.gen`, and let `P : R[X]` be such that
`aeval B.gen P = B'.gen`. Then `IsIntegral R (B.basis.to_matrix B'.basis i j)` for all `i` and `j`
if `minpoly K B.gen = (minpoly R B.gen).map (algebraMap R L)`. This is the case
if `R` is a GCD domain and `K` is its fraction ring. -/
theorem toMatrix_isIntegral {B B' : PowerBasis K S} {P : R[X]} (h : aeval B.gen P = B'.gen)
(hB : IsIntegral R B.gen) (hmin : minpoly K B.gen = (minpoly R B.gen).map (algebraMap R K)) :
β i j, IsIntegral R (B.basis.toMatrix B'.basis i j) := by
intro i j
rw [B.basis.toMatrix_apply, B'.coe_basis]
refine repr_pow_isIntegral hB (fun i => ?_) hmin _ _
rw [β h, aeval_eq_sum_range, map_sum, Finset.sum_apply']
refine IsIntegral.sum _ fun n _ => ?_
rw [Algebra.smul_def, IsScalarTower.algebraMap_apply R K S, β Algebra.smul_def,
LinearEquiv.map_smul, algebraMap_smul]
exact (repr_gen_pow_isIntegral hB hmin _ _).smul _
end PowerBasis
end IsIntegral
|
InducedMaps.lean
|
/-
Copyright (c) 2022 Praneeth Kolichala. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Praneeth Kolichala
-/
import Mathlib.Topology.Homotopy.Equiv
import Mathlib.CategoryTheory.Equivalence
import Mathlib.AlgebraicTopology.FundamentalGroupoid.Product
/-!
# Homotopic maps induce naturally isomorphic functors
## Main definitions
- `FundamentalGroupoidFunctor.homotopicMapsNatIso H` The natural isomorphism
between the induced functors `f : Ο(X) β₯€ Ο(Y)` and `g : Ο(X) β₯€ Ο(Y)`, given a homotopy
`H : f βΌ g`
- `FundamentalGroupoidFunctor.equivOfHomotopyEquiv hequiv` The equivalence of the categories
`Ο(X)` and `Ο(Y)` given a homotopy equivalence `hequiv : X ββ Y` between them.
## Implementation notes
- In order to be more universe polymorphic, we define `ContinuousMap.Homotopy.uliftMap`
which lifts a homotopy from `I Γ X β Y` to `(TopCat.of ((ULift I) Γ X)) β Y`. This is because
this construction uses `FundamentalGroupoidFunctor.prodToProdTop` to convert between
pairs of paths in I and X and the corresponding path after passing through a homotopy `H`.
But `FundamentalGroupoidFunctor.prodToProdTop` requires two spaces in the same universe.
-/
noncomputable section
universe u
open FundamentalGroupoid
open CategoryTheory
open FundamentalGroupoidFunctor
open scoped FundamentalGroupoid
open scoped unitInterval
namespace unitInterval
/-- The path 0 βΆ 1 in `I` -/
def path01 : Path (0 : I) 1 where
toFun := id
source' := rfl
target' := rfl
/-- The path 0 βΆ 1 in `ULift I` -/
def upath01 : Path (ULift.up 0 : ULift.{u} I) (ULift.up 1) where
toFun := ULift.up
source' := rfl
target' := rfl
attribute [local instance] Path.Homotopic.setoid
/-- The homotopy path class of 0 β 1 in `ULift I` -/
def uhpath01 : @fromTop (TopCat.of <| ULift.{u} I) (ULift.up (0 : I)) βΆ fromTop (ULift.up 1) :=
β¦upath01β§
end unitInterval
namespace ContinuousMap.Homotopy
open unitInterval (uhpath01)
attribute [local instance] Path.Homotopic.setoid
section Casts
/-- Abbreviation for `eqToHom` that accepts points in a topological space -/
abbrev hcast {X : TopCat} {xβ xβ : X} (hx : xβ = xβ) : fromTop xβ βΆ fromTop xβ :=
eqToHom <| FundamentalGroupoid.ext hx
@[simp]
theorem hcast_def {X : TopCat} {xβ xβ : X} (hxβ : xβ = xβ) :
hcast hxβ = eqToHom (FundamentalGroupoid.ext hxβ) :=
rfl
variable {Xβ Xβ Y : TopCat.{u}} {f : C(Xβ, Y)} {g : C(Xβ, Y)} {xβ xβ : Xβ} {xβ xβ : Xβ}
{p : Path xβ xβ} {q : Path xβ xβ} (hfg : β t, f (p t) = g (q t))
include hfg
/-- If `f(p(t) = g(q(t))` for two paths `p` and `q`, then the induced path homotopy classes
`f(p)` and `g(p)` are the same as well, despite having a priori different types -/
theorem heq_path_of_eq_image :
(Οβ (TopCat.ofHom f)).map β¦pβ§ β (Οβ (TopCat.ofHom g)).map β¦qβ§ := by
simp only [map_eq, β Path.Homotopic.map_lift]; apply Path.Homotopic.hpath_hext; exact hfg
private theorem start_path : f xβ = g xβ := by convert hfg 0 <;> simp only [Path.source]
private theorem end_path : f xβ = g xβ := by convert hfg 1 <;> simp only [Path.target]
theorem eq_path_of_eq_image :
(Οβ (TopCat.ofHom f)).map β¦pβ§ =
hcast (start_path hfg) β« (Οβ (TopCat.ofHom g)).map β¦qβ§ β« hcast (end_path hfg).symm := by
rw [conj_eqToHom_iff_heq
((Οβ (TopCat.ofHom f)).map β¦pβ§) ((Οβ (TopCat.ofHom g)).map β¦qβ§)
(FundamentalGroupoid.ext <| start_path hfg)
(FundamentalGroupoid.ext <| end_path hfg)]
exact heq_path_of_eq_image hfg
end Casts
-- We let `X` and `Y` be spaces, and `f` and `g` be homotopic maps between them
variable {X Y : TopCat.{u}} {f g : C(X, Y)} (H : ContinuousMap.Homotopy f g) {xβ xβ : X}
(p : fromTop xβ βΆ fromTop xβ)
/-!
These definitions set up the following diagram, for each path `p`:
f(p)
*--------*
| \ |
Hβ | \ d | Hβ
| \ |
*--------*
g(p)
Here, `Hβ = H.evalAt xβ` is the path from `f(xβ)` to `g(xβ)`,
and similarly for `Hβ`. Similarly, `f(p)` denotes the
path in Y that the induced map `f` takes `p`, and similarly for `g(p)`.
Finally, `d`, the diagonal path, is H(0 βΆ 1, p), the result of the induced `H` on
`Path.Homotopic.prod (0 βΆ 1) p`, where `(0 βΆ 1)` denotes the path from `0` to `1` in `I`.
It is clear that the diagram commutes (`Hβ β« g(p) = d = f(p) β« Hβ`), but unfortunately,
many of the paths do not have defeq starting/ending points, so we end up needing some casting.
-/
/-- Interpret a homotopy `H : C(I Γ X, Y)` as a map `C(ULift I Γ X, Y)` -/
def uliftMap : C(TopCat.of (ULift.{u} I Γ X), Y) :=
β¨fun x => H (x.1.down, x.2),
H.continuous.comp ((continuous_uliftDown.comp continuous_fst).prodMk continuous_snd)β©
theorem ulift_apply (i : ULift.{u} I) (x : X) : H.uliftMap (i, x) = H (i.down, x) :=
rfl
/-- An abbreviation for `prodToProdTop`, with some types already in place to help the
typechecker. In particular, the first path should be on the ulifted unit interval. -/
abbrev prodToProdTopI {aβ aβ : TopCat.of (ULift I)} {bβ bβ : X} (pβ : fromTop aβ βΆ fromTop aβ)
(pβ : fromTop bβ βΆ fromTop bβ) :=
(prodToProdTop (TopCat.of <| ULift I) X).map (X := (β¨aββ©, β¨bββ©)) (Y := (β¨aββ©, β¨bββ©)) (pβ, pβ)
/-- The diagonal path `d` of a homotopy `H` on a path `p` -/
def diagonalPath : fromTop (H (0, xβ)) βΆ fromTop (H (1, xβ)) :=
(Οβ (TopCat.ofHom H.uliftMap)).map (prodToProdTopI uhpath01 p)
/-- The diagonal path, but starting from `f xβ` and going to `g xβ` -/
def diagonalPath' : fromTop (f xβ) βΆ fromTop (g xβ) :=
hcast (H.apply_zero xβ).symm β« H.diagonalPath p β« hcast (H.apply_one xβ)
/-- Proof that `f(p) = H(0 βΆ 0, p)`, with the appropriate casts -/
theorem apply_zero_path : (Οβ (TopCat.ofHom f)).map p = hcast (H.apply_zero xβ).symm β«
(Οβ (TopCat.ofHom H.uliftMap)).map
(prodToProdTopI (π (@fromTop (TopCat.of _) (ULift.up 0))) p) β«
hcast (H.apply_zero xβ) :=
Quotient.inductionOn p fun p' => by
apply @eq_path_of_eq_image _ _ _ _ H.uliftMap _ _ _ _ _ ((Path.refl (ULift.up _)).prod p')
intros
rw [Path.prod_coe, ulift_apply H]
simp
/-- Proof that `g(p) = H(1 βΆ 1, p)`, with the appropriate casts -/
theorem apply_one_path : (Οβ (TopCat.ofHom g)).map p = hcast (H.apply_one xβ).symm β«
(Οβ (TopCat.ofHom H.uliftMap)).map
(prodToProdTopI (π (@fromTop (TopCat.of _) (ULift.up 1))) p) β«
hcast (H.apply_one xβ) :=
Quotient.inductionOn p fun p' => by
apply @eq_path_of_eq_image _ _ _ _ H.uliftMap _ _ _ _ _ ((Path.refl (ULift.up _)).prod p')
intros
rw [Path.prod_coe, ulift_apply H]
simp
/-- Proof that `H.evalAt x = H(0 βΆ 1, x βΆ x)`, with the appropriate casts -/
theorem evalAt_eq (x : X) : β¦H.evalAt xβ§ = hcast (H.apply_zero x).symm β«
(Οβ (TopCat.ofHom H.uliftMap)).map (prodToProdTopI uhpath01 (π (fromTop x))) β«
hcast (H.apply_one x).symm.symm := by
dsimp only [prodToProdTopI, uhpath01, hcast]
refine (@conj_eqToHom_iff_heq (Οβ Y) _ _ _ _ _ _ _ _
(FundamentalGroupoid.ext <| H.apply_one x).symm).mpr ?_
simp only [map_eq]
apply Path.Homotopic.hpath_hext; intro; rfl
-- Finally, we show `d = f(p) β« Hβ = Hβ β« g(p)`
theorem eq_diag_path : (Οβ (TopCat.ofHom f)).map p β« β¦H.evalAt xββ§ = H.diagonalPath' p β§
(β¦H.evalAt xββ§ β« (Οβ (TopCat.ofHom g)).map p :
fromTop (f xβ) βΆ fromTop (g xβ)) = H.diagonalPath' p := by
rw [H.apply_zero_path, H.apply_one_path, H.evalAt_eq]
erw [H.evalAt_eq]
dsimp only [prodToProdTopI]
constructor
Β· slice_lhs 2 4 => rw [eqToHom_trans, eqToHom_refl] -- Porting note: this β `simp` didn't do this
slice_lhs 2 4 => simp [β CategoryTheory.Functor.map_comp]
rfl
Β· slice_lhs 2 4 => rw [eqToHom_trans, eqToHom_refl] -- Porting note: this β `simp` didn't do this
slice_lhs 2 4 => simp [β CategoryTheory.Functor.map_comp]
rfl
end ContinuousMap.Homotopy
namespace FundamentalGroupoidFunctor
open CategoryTheory
open scoped FundamentalGroupoid
attribute [local instance] Path.Homotopic.setoid
variable {X Y : TopCat.{u}} {f g : C(X, Y)} (H : ContinuousMap.Homotopy f g)
/-- Given a homotopy H : f βΌ g, we have an associated natural isomorphism between the induced
functors `f` and `g` -/
-- Porting note: couldn't use category arrow `\hom` in statement, needed to expand
def homotopicMapsNatIso : @Quiver.Hom _ Functor.category.toQuiver
(Οβ (TopCat.ofHom f))
(Οβ (TopCat.ofHom g)) where
app x := β¦H.evalAt x.asβ§
naturality x y p := by erw [(H.eq_diag_path p).1, (H.eq_diag_path p).2]
instance : IsIso (homotopicMapsNatIso H) := by apply NatIso.isIso_of_isIso_app
open scoped ContinuousMap
/-- Homotopy equivalent topological spaces have equivalent fundamental groupoids. -/
def equivOfHomotopyEquiv (hequiv : X ββ Y) : Οβ X β Οβ Y := by
apply CategoryTheory.Equivalence.mk (Οβ (TopCat.ofHom hequiv.toFun) : Οβ X β₯€ Οβ Y)
(Οβ (TopCat.ofHom hequiv.invFun) : Οβ Y β₯€ Οβ X) <;>
simp only [Grpd.id_to_functor]
Β· convert (asIso (homotopicMapsNatIso hequiv.left_inv.some)).symm
exacts [((Ο).map_id X).symm, ((Ο).map_comp _ _).symm]
Β· convert asIso (homotopicMapsNatIso hequiv.right_inv.some)
exacts [((Ο).map_comp _ _).symm, ((Ο).map_id Y).symm]
end FundamentalGroupoidFunctor
|
Basic.lean
|
/-
Copyright (c) 2020 Joseph Myers. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Joseph Myers, Manuel Candales
-/
import Mathlib.Analysis.InnerProductSpace.Subspace
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Inverse
/-!
# Angles between vectors
This file defines unoriented angles in real inner product spaces.
## Main definitions
* `InnerProductGeometry.angle` is the undirected angle between two vectors.
## TODO
Prove the triangle inequality for the angle.
-/
assert_not_exists HasFDerivAt ConformalAt
noncomputable section
open Real Set
open Real
open RealInnerProductSpace
namespace InnerProductGeometry
variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace β V] {x y : V}
/-- The undirected angle between two vectors. If either vector is 0,
this is Ο/2. See `Orientation.oangle` for the corresponding oriented angle
definition. -/
def angle (x y : V) : β :=
Real.arccos (βͺx, yβ« / (βxβ * βyβ))
theorem continuousAt_angle {x : V Γ V} (hx1 : x.1 β 0) (hx2 : x.2 β 0) :
ContinuousAt (fun y : V Γ V => angle y.1 y.2) x := by
unfold angle
fun_prop (disch := simp [*])
theorem angle_smul_smul {c : β} (hc : c β 0) (x y : V) : angle (c β’ x) (c β’ y) = angle x y := by
have : c * c β 0 := mul_ne_zero hc hc
rw [angle, angle, real_inner_smul_left, inner_smul_right, norm_smul, norm_smul, Real.norm_eq_abs,
mul_mul_mul_comm _ βxβ, abs_mul_abs_self, β mul_assoc c c, mul_div_mul_left _ _ this]
@[simp]
theorem _root_.LinearIsometry.angle_map {E F : Type*} [NormedAddCommGroup E] [NormedAddCommGroup F]
[InnerProductSpace β E] [InnerProductSpace β F] (f : E ββα΅’[β] F) (u v : E) :
angle (f u) (f v) = angle u v := by
rw [angle, angle, f.inner_map_map, f.norm_map, f.norm_map]
@[simp, norm_cast]
theorem _root_.Submodule.angle_coe {s : Submodule β V} (x y : s) :
angle (x : V) (y : V) = angle x y :=
s.subtypeβα΅’.angle_map x y
/-- The cosine of the angle between two vectors. -/
theorem cos_angle (x y : V) : Real.cos (angle x y) = βͺx, yβ« / (βxβ * βyβ) :=
Real.cos_arccos (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
(abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
/-- The angle between two vectors does not depend on their order. -/
theorem angle_comm (x y : V) : angle x y = angle y x := by
unfold angle
rw [real_inner_comm, mul_comm]
/-- The angle between the negation of two vectors. -/
@[simp]
theorem angle_neg_neg (x y : V) : angle (-x) (-y) = angle x y := by
unfold angle
rw [inner_neg_neg, norm_neg, norm_neg]
/-- The angle between two vectors is nonnegative. -/
theorem angle_nonneg (x y : V) : 0 β€ angle x y :=
Real.arccos_nonneg _
/-- The angle between two vectors is at most Ο. -/
theorem angle_le_pi (x y : V) : angle x y β€ Ο :=
Real.arccos_le_pi _
/-- The sine of the angle between two vectors is nonnegative. -/
theorem sin_angle_nonneg (x y : V) : 0 β€ sin (angle x y) :=
sin_nonneg_of_nonneg_of_le_pi (angle_nonneg x y) (angle_le_pi x y)
/-- The angle between a vector and the negation of another vector. -/
theorem angle_neg_right (x y : V) : angle x (-y) = Ο - angle x y := by
unfold angle
rw [β Real.arccos_neg, norm_neg, inner_neg_right, neg_div]
/-- The angle between the negation of a vector and another vector. -/
theorem angle_neg_left (x y : V) : angle (-x) y = Ο - angle x y := by
rw [β angle_neg_neg, neg_neg, angle_neg_right]
proof_wanted angle_triangle (x y z : V) : angle x z β€ angle x y + angle y z
/-- The angle between the zero vector and a vector. -/
@[simp]
theorem angle_zero_left (x : V) : angle 0 x = Ο / 2 := by
unfold angle
rw [inner_zero_left, zero_div, Real.arccos_zero]
/-- The angle between a vector and the zero vector. -/
@[simp]
theorem angle_zero_right (x : V) : angle x 0 = Ο / 2 := by
unfold angle
rw [inner_zero_right, zero_div, Real.arccos_zero]
/-- The angle between a nonzero vector and itself. -/
@[simp]
theorem angle_self {x : V} (hx : x β 0) : angle x x = 0 := by
unfold angle
rw [β real_inner_self_eq_norm_mul_norm, div_self (inner_self_ne_zero.2 hx : βͺx, xβ« β 0),
Real.arccos_one]
/-- The angle between a nonzero vector and its negation. -/
@[simp]
theorem angle_self_neg_of_nonzero {x : V} (hx : x β 0) : angle x (-x) = Ο := by
rw [angle_neg_right, angle_self hx, sub_zero]
/-- The angle between the negation of a nonzero vector and that
vector. -/
@[simp]
theorem angle_neg_self_of_nonzero {x : V} (hx : x β 0) : angle (-x) x = Ο := by
rw [angle_comm, angle_self_neg_of_nonzero hx]
/-- The angle between a vector and a positive multiple of a vector. -/
@[simp]
theorem angle_smul_right_of_pos (x y : V) {r : β} (hr : 0 < r) : angle x (r β’ y) = angle x y := by
unfold angle
rw [inner_smul_right, norm_smul, Real.norm_eq_abs, abs_of_nonneg (le_of_lt hr), β mul_assoc,
mul_comm _ r, mul_assoc, mul_div_mul_left _ _ (ne_of_gt hr)]
/-- The angle between a positive multiple of a vector and a vector. -/
@[simp]
theorem angle_smul_left_of_pos (x y : V) {r : β} (hr : 0 < r) : angle (r β’ x) y = angle x y := by
rw [angle_comm, angle_smul_right_of_pos y x hr, angle_comm]
/-- The angle between a vector and a negative multiple of a vector. -/
@[simp]
theorem angle_smul_right_of_neg (x y : V) {r : β} (hr : r < 0) :
angle x (r β’ y) = angle x (-y) := by
rw [β neg_neg r, neg_smul, angle_neg_right, angle_smul_right_of_pos x y (neg_pos_of_neg hr),
angle_neg_right]
/-- The angle between a negative multiple of a vector and a vector. -/
@[simp]
theorem angle_smul_left_of_neg (x y : V) {r : β} (hr : r < 0) : angle (r β’ x) y = angle (-x) y := by
rw [angle_comm, angle_smul_right_of_neg y x hr, angle_comm]
/-- The cosine of the angle between two vectors, multiplied by the
product of their norms. -/
theorem cos_angle_mul_norm_mul_norm (x y : V) : Real.cos (angle x y) * (βxβ * βyβ) = βͺx, yβ« := by
rw [cos_angle, div_mul_cancel_of_imp]
simp +contextual [or_imp]
/-- The sine of the angle between two vectors, multiplied by the
product of their norms. -/
theorem sin_angle_mul_norm_mul_norm (x y : V) :
Real.sin (angle x y) * (βxβ * βyβ) = β(βͺx, xβ« * βͺy, yβ« - βͺx, yβ« * βͺx, yβ«) := by
unfold angle
rw [Real.sin_arccos, β Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),
β Real.sqrt_mul' _ (mul_self_nonneg _), sq,
Real.sqrt_mul_self (mul_nonneg (norm_nonneg x) (norm_nonneg y)),
real_inner_self_eq_norm_mul_norm, real_inner_self_eq_norm_mul_norm]
by_cases h : βxβ * βyβ = 0
Β· rw [show βxβ * βxβ * (βyβ * βyβ) = βxβ * βyβ * (βxβ * βyβ) by ring, h, mul_zero,
mul_zero, zero_sub]
rcases eq_zero_or_eq_zero_of_mul_eq_zero h with hx | hy
Β· rw [norm_eq_zero] at hx
rw [hx, inner_zero_left, zero_mul, neg_zero]
Β· rw [norm_eq_zero] at hy
rw [hy, inner_zero_right, zero_mul, neg_zero]
Β· -- takes 600ms; squeezing the "equivalent" simp call yields an invalid result
field_simp [h]
ring_nf
/-- The angle between two vectors is zero if and only if they are
nonzero and one is a positive multiple of the other. -/
theorem angle_eq_zero_iff {x y : V} : angle x y = 0 β x β 0 β§ β r : β, 0 < r β§ y = r β’ x := by
rw [angle, β real_inner_div_norm_mul_norm_eq_one_iff, Real.arccos_eq_zero, LE.le.ge_iff_eq',
eq_comm]
exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).2
/-- The angle between two vectors is Ο if and only if they are nonzero
and one is a negative multiple of the other. -/
theorem angle_eq_pi_iff {x y : V} : angle x y = Ο β x β 0 β§ β r : β, r < 0 β§ y = r β’ x := by
rw [angle, β real_inner_div_norm_mul_norm_eq_neg_one_iff, Real.arccos_eq_pi, LE.le.ge_iff_eq']
exact (abs_le.mp (abs_real_inner_div_norm_mul_norm_le_one x y)).1
/-- If the angle between two vectors is Ο, the angles between those
vectors and a third vector add to Ο. -/
theorem angle_add_angle_eq_pi_of_angle_eq_pi {x y : V} (z : V) (h : angle x y = Ο) :
angle x z + angle y z = Ο := by
rcases angle_eq_pi_iff.1 h with β¨_, β¨r, β¨hr, rflβ©β©β©
rw [angle_smul_left_of_neg x z hr, angle_neg_left, add_sub_cancel]
/-- Two vectors have inner product 0 if and only if the angle between
them is Ο/2. -/
theorem inner_eq_zero_iff_angle_eq_pi_div_two (x y : V) : βͺx, yβ« = 0 β angle x y = Ο / 2 :=
Iff.symm <| by simp +contextual [angle, or_imp]
/-- If the angle between two vectors is Ο, the inner product equals the negative product
of the norms. -/
theorem inner_eq_neg_mul_norm_of_angle_eq_pi {x y : V} (h : angle x y = Ο) :
βͺx, yβ« = -(βxβ * βyβ) := by
simp [β cos_angle_mul_norm_mul_norm, h]
/-- If the angle between two vectors is 0, the inner product equals the product of the norms. -/
theorem inner_eq_mul_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) : βͺx, yβ« = βxβ * βyβ := by
simp [β cos_angle_mul_norm_mul_norm, h]
/-- The inner product of two non-zero vectors equals the negative product of their norms
if and only if the angle between the two vectors is Ο. -/
theorem inner_eq_neg_mul_norm_iff_angle_eq_pi {x y : V} (hx : x β 0) (hy : y β 0) :
βͺx, yβ« = -(βxβ * βyβ) β angle x y = Ο := by
refine β¨fun h => ?_, inner_eq_neg_mul_norm_of_angle_eq_piβ©
have hβ : βxβ * βyβ β 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'
rw [angle, h, neg_div, div_self hβ, Real.arccos_neg_one]
/-- The inner product of two non-zero vectors equals the product of their norms
if and only if the angle between the two vectors is 0. -/
theorem inner_eq_mul_norm_iff_angle_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
βͺx, yβ« = βxβ * βyβ β angle x y = 0 := by
refine β¨fun h => ?_, inner_eq_mul_norm_of_angle_eq_zeroβ©
have hβ : βxβ * βyβ β 0 := (mul_pos (norm_pos_iff.mpr hx) (norm_pos_iff.mpr hy)).ne'
rw [angle, h, div_self hβ, Real.arccos_one]
/-- If the angle between two vectors is Ο, the norm of their difference equals
the sum of their norms. -/
theorem norm_sub_eq_add_norm_of_angle_eq_pi {x y : V} (h : angle x y = Ο) :
βx - yβ = βxβ + βyβ := by
rw [β sq_eq_sqβ (norm_nonneg (x - y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
norm_sub_pow_two_real, inner_eq_neg_mul_norm_of_angle_eq_pi h]
ring
/-- If the angle between two vectors is 0, the norm of their sum equals
the sum of their norms. -/
theorem norm_add_eq_add_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :
βx + yβ = βxβ + βyβ := by
rw [β sq_eq_sqβ (norm_nonneg (x + y)) (add_nonneg (norm_nonneg x) (norm_nonneg y)),
norm_add_pow_two_real, inner_eq_mul_norm_of_angle_eq_zero h]
ring
/-- If the angle between two vectors is 0, the norm of their difference equals
the absolute value of the difference of their norms. -/
theorem norm_sub_eq_abs_sub_norm_of_angle_eq_zero {x y : V} (h : angle x y = 0) :
βx - yβ = |βxβ - βyβ| := by
rw [β sq_eq_sqβ (norm_nonneg (x - y)) (abs_nonneg (βxβ - βyβ)), norm_sub_pow_two_real,
inner_eq_mul_norm_of_angle_eq_zero h, sq_abs (βxβ - βyβ)]
ring
/-- The norm of the difference of two non-zero vectors equals the sum of their norms
if and only the angle between the two vectors is Ο. -/
theorem norm_sub_eq_add_norm_iff_angle_eq_pi {x y : V} (hx : x β 0) (hy : y β 0) :
βx - yβ = βxβ + βyβ β angle x y = Ο := by
refine β¨fun h => ?_, norm_sub_eq_add_norm_of_angle_eq_piβ©
rw [β inner_eq_neg_mul_norm_iff_angle_eq_pi hx hy]
obtain β¨hxyβ, hxyββ© := norm_nonneg (x - y), add_nonneg (norm_nonneg x) (norm_nonneg y)
rw [β sq_eq_sqβ hxyβ hxyβ, norm_sub_pow_two_real] at h
calc
βͺx, yβ« = (βxβ ^ 2 + βyβ ^ 2 - (βxβ + βyβ) ^ 2) / 2 := by linarith
_ = -(βxβ * βyβ) := by ring
/-- The norm of the sum of two non-zero vectors equals the sum of their norms
if and only the angle between the two vectors is 0. -/
theorem norm_add_eq_add_norm_iff_angle_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
βx + yβ = βxβ + βyβ β angle x y = 0 := by
refine β¨fun h => ?_, norm_add_eq_add_norm_of_angle_eq_zeroβ©
rw [β inner_eq_mul_norm_iff_angle_eq_zero hx hy]
obtain β¨hxyβ, hxyββ© := norm_nonneg (x + y), add_nonneg (norm_nonneg x) (norm_nonneg y)
rw [β sq_eq_sqβ hxyβ hxyβ, norm_add_pow_two_real] at h
calc
βͺx, yβ« = ((βxβ + βyβ) ^ 2 - βxβ ^ 2 - βyβ ^ 2) / 2 := by linarith
_ = βxβ * βyβ := by ring
/-- The norm of the difference of two non-zero vectors equals the absolute value
of the difference of their norms if and only the angle between the two vectors is 0. -/
theorem norm_sub_eq_abs_sub_norm_iff_angle_eq_zero {x y : V} (hx : x β 0) (hy : y β 0) :
βx - yβ = |βxβ - βyβ| β angle x y = 0 := by
refine β¨fun h => ?_, norm_sub_eq_abs_sub_norm_of_angle_eq_zeroβ©
rw [β inner_eq_mul_norm_iff_angle_eq_zero hx hy]
have h1 : βx - yβ ^ 2 = (βxβ - βyβ) ^ 2 := by
rw [h]
exact sq_abs (βxβ - βyβ)
rw [norm_sub_pow_two_real] at h1
calc
βͺx, yβ« = ((βxβ + βyβ) ^ 2 - βxβ ^ 2 - βyβ ^ 2) / 2 := by linarith
_ = βxβ * βyβ := by ring
/-- The norm of the sum of two vectors equals the norm of their difference if and only if
the angle between them is Ο/2. -/
theorem norm_add_eq_norm_sub_iff_angle_eq_pi_div_two (x y : V) :
βx + yβ = βx - yβ β angle x y = Ο / 2 := by
rw [β sq_eq_sqβ (norm_nonneg (x + y)) (norm_nonneg (x - y)),
β inner_eq_zero_iff_angle_eq_pi_div_two x y, norm_add_pow_two_real, norm_sub_pow_two_real]
constructor <;> intro h <;> linarith
/-- The cosine of the angle between two vectors is 1 if and only if the angle is 0. -/
theorem cos_eq_one_iff_angle_eq_zero : cos (angle x y) = 1 β angle x y = 0 := by
rw [β cos_zero]
exact injOn_cos.eq_iff β¨angle_nonneg x y, angle_le_pi x yβ© (left_mem_Icc.2 pi_pos.le)
/-- The cosine of the angle between two vectors is 0 if and only if the angle is Ο / 2. -/
theorem cos_eq_zero_iff_angle_eq_pi_div_two : cos (angle x y) = 0 β angle x y = Ο / 2 := by
rw [β cos_pi_div_two]
apply injOn_cos.eq_iff β¨angle_nonneg x y, angle_le_pi x yβ©
constructor <;> linarith [pi_pos]
/-- The cosine of the angle between two vectors is -1 if and only if the angle is Ο. -/
theorem cos_eq_neg_one_iff_angle_eq_pi : cos (angle x y) = -1 β angle x y = Ο := by
rw [β cos_pi]
exact injOn_cos.eq_iff β¨angle_nonneg x y, angle_le_pi x yβ© (right_mem_Icc.2 pi_pos.le)
/-- The sine of the angle between two vectors is 0 if and only if the angle is 0 or Ο. -/
theorem sin_eq_zero_iff_angle_eq_zero_or_angle_eq_pi :
sin (angle x y) = 0 β angle x y = 0 β¨ angle x y = Ο := by
rw [sin_eq_zero_iff_cos_eq, cos_eq_one_iff_angle_eq_zero, cos_eq_neg_one_iff_angle_eq_pi]
/-- The sine of the angle between two vectors is 1 if and only if the angle is Ο / 2. -/
theorem sin_eq_one_iff_angle_eq_pi_div_two : sin (angle x y) = 1 β angle x y = Ο / 2 := by
refine β¨fun h => ?_, fun h => by rw [h, sin_pi_div_two]β©
rw [β cos_eq_zero_iff_angle_eq_pi_div_two, β abs_eq_zero, abs_cos_eq_sqrt_one_sub_sin_sq, h]
simp
end InnerProductGeometry
|
Tensor.lean
|
/-
Copyright (c) 2024 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Module.Presentation.Basic
import Mathlib.LinearAlgebra.TensorProduct.Basic
/-!
# Presentation of the tensor product of two modules
Given presentations of two `A`-modules `Mβ` and `Mβ`, we obtain a presentation of `Mβ β[A] Mβ`.
-/
universe w wββ wββ wββ wββ u vβ vβ
namespace Module
open TensorProduct
variable {A : Type u} [CommRing A] {Mβ : Type vβ} {Mβ : Type vβ}
[AddCommGroup Mβ] [AddCommGroup Mβ] [Module A Mβ] [Module A Mβ]
namespace Relations
variable (relationsβ : Relations.{wββ, wββ} A) (relationsβ : Relations.{wββ, wββ} A)
/-- The tensor product of systems of linear equations. -/
@[simps]
noncomputable def tensor :
Relations A where
G := relationsβ.G Γ relationsβ.G
R := Sum (relationsβ.R Γ relationsβ.G) (relationsβ.G Γ relationsβ.R)
relation
| .inl β¨rβ, gββ© => Finsupp.embDomain (Function.Embedding.sectL relationsβ.G gβ)
(relationsβ.relation rβ)
| .inr β¨gβ, rββ© => Finsupp.embDomain (Function.Embedding.sectR gβ relationsβ.G)
(relationsβ.relation rβ)
namespace Solution
variable {relationsβ relationsβ} (solutionβ : relationsβ.Solution Mβ)
(solutionβ : relationsβ.Solution Mβ)
/-- Given solutions in `Mβ` and `Mβ` to systems of linear equations, this is the obvious
solution to the tensor product of these systems in `Mβ β[A] Mβ`. -/
@[simps]
noncomputable def tensor : (relationsβ.tensor relationsβ).Solution (Mβ β[A] Mβ) where
var := fun β¨gβ, gββ© => solutionβ.var gβ ββ solutionβ.var gβ
linearCombination_var_relation := by
rintro (β¨rβ, gββ© | β¨gβ, rββ©)
Β· dsimp
rw [Finsupp.linearCombination_embDomain]
exact (solutionβ.postcomp (curry (TensorProduct.comm A Mβ Mβ).toLinearMap
(solutionβ.var gβ))).linearCombination_var_relation rβ
Β· dsimp
rw [Finsupp.linearCombination_embDomain]
exact (solutionβ.postcomp (curry .id (solutionβ.var gβ))).linearCombination_var_relation rβ
variable {solutionβ solutionβ} (hβ : solutionβ.IsPresentation) (hβ : solutionβ.IsPresentation)
/-- The tensor product of two modules admits a presentation by generators and relations. -/
noncomputable def isPresentationCoreTensor :
Solution.IsPresentationCore.{w} (solutionβ.tensor solutionβ) where
desc s := uncurry _ _ _ _ (hβ.desc
{ var := fun gβ β¦ hβ.desc
{ var := fun gβ β¦ s.var β¨gβ, gββ©
linearCombination_var_relation := fun rβ β¦ by
erw [β Finsupp.linearCombination_embDomain A
(Function.Embedding.sectR gβ relationsβ.G)]
exact s.linearCombination_var_relation (.inr β¨gβ, rββ©) }
linearCombination_var_relation := fun rβ β¦ hβ.postcomp_injective (by
ext gβ
dsimp
erw [Finsupp.apply_linearCombination A (LinearMap.applyβ (solutionβ.var gβ))]
have := s.linearCombination_var_relation (.inl β¨rβ, gββ©)
erw [Finsupp.linearCombination_embDomain] at this
convert this
ext gβ
simp) })
postcomp_desc _ := by aesop
postcomp_injective h := curry_injective (hβ.postcomp_injective (by
ext gβ : 2
refine hβ.postcomp_injective ?_
ext gβ
exact congr_var h β¨gβ, gββ©))
include hβ hβ in
lemma IsPresentation.tensor : (solutionβ.tensor solutionβ).IsPresentation :=
(isPresentationCoreTensor hβ hβ).isPresentation
end Solution
end Relations
namespace Presentation
variable (presβ : Presentation.{wββ, wββ} A Mβ) (presβ : Presentation.{wββ, wββ} A Mβ)
/-- The presentation of the `A`-module `Mβ β[A] Mβ` that is deduced from
a presentation of `Mβ` and a presentation of `Mβ`. -/
@[simps!]
noncomputable def tensor : Presentation A (Mβ β[A] Mβ) where
G := _
R := _
relation := _
toSolution := presβ.toSolution.tensor presβ.toSolution
toIsPresentation := presβ.toIsPresentation.tensor presβ.toIsPresentation
end Presentation
end Module
|
Equalizer.lean
|
/-
Copyright (c) 2024 Jack McKoen. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jack McKoen
-/
import Mathlib.CategoryTheory.Limits.Shapes.Reflexive
import Mathlib.CategoryTheory.Limits.Shapes.SplitEqualizer
import Mathlib.CategoryTheory.Monad.Algebra
/-!
# Special equalizers associated to a comonad
Associated to a comonad `T : C β₯€ C` we have important equalizer constructions:
Any coalgebra is an equalizer (in the category of coalgebras) of cofree coalgebras. Furthermore,
this equalizer is coreflexive.
In `C`, this fork diagram is a split equalizer (in particular, it is still an equalizer).
This split equalizer is known as the Beck equalizer (as it features heavily in Beck's
comonadicity theorem).
This file is adapted from `Mathlib/CategoryTheory/Monad/Coequalizer.lean`.
Please try to keep them in sync.
-/
universe vβ uβ
namespace CategoryTheory
namespace Comonad
open Limits
variable {C : Type uβ}
variable [Category.{vβ} C]
variable {T : Comonad C} (X : Coalgebra T)
/-!
Show that any coalgebra is an equalizer of cofree coalgebras.
-/
/-- The top map in the equalizer diagram we will construct. -/
@[simps!]
def CofreeEqualizer.topMap : (Comonad.cofree T).obj X.A βΆ (Comonad.cofree T).obj (T.obj X.A) :=
(Comonad.cofree T).map X.a
/-- The bottom map in the equalizer diagram we will construct. -/
@[simps]
def CofreeEqualizer.bottomMap :
(Comonad.cofree T).obj X.A βΆ (Comonad.cofree T).obj (T.obj X.A) where
f := T.Ξ΄.app X.A
h := T.coassoc X.A
/-- The fork map in the equalizer diagram we will construct. -/
@[simps]
def CofreeEqualizer.ΞΉ : X βΆ (Comonad.cofree T).obj X.A where
f := X.a
h := X.coassoc.symm
theorem CofreeEqualizer.condition :
CofreeEqualizer.ΞΉ X β« CofreeEqualizer.topMap X =
CofreeEqualizer.ΞΉ X β« CofreeEqualizer.bottomMap X :=
Coalgebra.Hom.ext X.coassoc.symm
instance : IsCoreflexivePair (CofreeEqualizer.topMap X) (CofreeEqualizer.bottomMap X) := by
apply IsCoreflexivePair.mk' _ _ _
Β· apply (cofree T).map (T.Ξ΅.app X.A)
Β· ext
dsimp
rw [β Functor.map_comp, X.counit, Functor.map_id]
Β· ext
apply Comonad.right_counit
/-- Construct the Beck fork in the category of coalgebras. This fork is coreflexive as well as an
equalizer.
-/
@[simps!]
def beckCoalgebraFork : Fork (CofreeEqualizer.topMap X) (CofreeEqualizer.bottomMap X) :=
Fork.ofΞΉ _ (CofreeEqualizer.condition X)
/-- The fork constructed is a limit. This shows that any coalgebra is a (coreflexive) equalizer of
cofree coalgebras.
-/
def beckCoalgebraEqualizer : IsLimit (beckCoalgebraFork X) :=
Fork.IsLimit.mk' _ fun s => by
have hβ : s.ΞΉ.f β« (T : C β₯€ C).map X.a = s.ΞΉ.f β« T.Ξ΄.app X.A :=
congr_arg Comonad.Coalgebra.Hom.f s.condition
have hβ : s.pt.a β« (T : C β₯€ C).map s.ΞΉ.f = s.ΞΉ.f β« T.Ξ΄.app X.A := s.ΞΉ.h
refine β¨β¨s.ΞΉ.f β« T.Ξ΅.app _, ?_β©, ?_, ?_β©
Β· dsimp
rw [Functor.map_comp, reassoc_of% hβ, Comonad.right_counit]
dsimp
rw [Category.comp_id, Category.assoc, β T.counit_naturality,
reassoc_of% hβ, Comonad.left_counit]
simp
Β· ext
simpa [β T.Ξ΅.naturality_assoc, T.left_counit_assoc] using hβ =β« T.Ξ΅.app ((T : C β₯€ C).obj X.A)
Β· intro m hm
ext
dsimp only
rw [β hm]
simp [beckCoalgebraFork, X.counit]
/-- The Beck fork is a split equalizer. -/
def beckSplitEqualizer : IsSplitEqualizer (T.map X.a) (T.Ξ΄.app _) X.a :=
β¨T.Ξ΅.app _, T.Ξ΅.app _, X.coassoc.symm, X.counit, T.left_counit _, (T.Ξ΅.naturality _)β©
/-- This is the Beck fork. It is a split equalizer, in particular a equalizer. -/
@[simps! pt]
def beckFork : Fork (T.map X.a) (T.Ξ΄.app _) :=
(beckSplitEqualizer X).asFork
@[simp]
theorem beckFork_ΞΉ : (beckFork X).ΞΉ = X.a :=
rfl
/-- The Beck fork is a equalizer. -/
def beckEqualizer : IsLimit (beckFork X) :=
(beckSplitEqualizer X).isEqualizer
@[simp]
theorem beckEqualizer_lift (s : Fork (T.toFunctor.map X.a) (T.Ξ΄.app X.A)) :
(beckEqualizer X).lift s = s.ΞΉ β« T.Ξ΅.app _ :=
rfl
end Comonad
end CategoryTheory
|
Monotone.lean
|
/-
Copyright (c) 2017 Johannes HΓΆlzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes HΓΆlzl
-/
import Mathlib.Order.BoundedOrder.Basic
import Mathlib.Order.Monotone.Basic
/-!
# Monotone functions on bounded orders
-/
assert_not_exists SemilatticeSup
open Function OrderDual
universe u v
variable {Ξ± : Type u} {Ξ² : Type v}
/-! ### Top, bottom element -/
section OrderTop
variable [PartialOrder Ξ±] [OrderTop Ξ±] [Preorder Ξ²] {f : Ξ± β Ξ²} {a b : Ξ±}
theorem StrictMono.apply_eq_top_iff (hf : StrictMono f) : f a = f β€ β a = β€ :=
β¨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne h, congr_arg _β©
theorem StrictAnti.apply_eq_top_iff (hf : StrictAnti f) : f a = f β€ β a = β€ :=
β¨fun h => not_lt_top_iff.1 fun ha => (hf ha).ne' h, congr_arg _β©
end OrderTop
theorem StrictMono.maximal_preimage_top [LinearOrder Ξ±] [Preorder Ξ²] [OrderTop Ξ²] {f : Ξ± β Ξ²}
(H : StrictMono f) {a} (h_top : f a = β€) (x : Ξ±) : x β€ a :=
H.maximal_of_maximal_image
(fun p => by
rw [h_top]
exact le_top)
x
section OrderBot
variable [PartialOrder Ξ±] [OrderBot Ξ±] [Preorder Ξ²] {f : Ξ± β Ξ²} {a b : Ξ±}
theorem StrictMono.apply_eq_bot_iff (hf : StrictMono f) : f a = f β₯ β a = β₯ :=
hf.dual.apply_eq_top_iff
theorem StrictAnti.apply_eq_bot_iff (hf : StrictAnti f) : f a = f β₯ β a = β₯ :=
hf.dual.apply_eq_top_iff
end OrderBot
theorem StrictMono.minimal_preimage_bot [LinearOrder Ξ±] [Preorder Ξ²] [OrderBot Ξ²] {f : Ξ± β Ξ²}
(H : StrictMono f) {a} (h_bot : f a = β₯) (x : Ξ±) : a β€ x :=
H.minimal_of_minimal_image
(fun p => by
rw [h_bot]
exact bot_le)
x
section Logic
/-!
#### In this section we prove some properties about monotone and antitone operations on `Prop`
-/
section Preorder
variable [Preorder Ξ±]
theorem monotone_and {p q : Ξ± β Prop} (m_p : Monotone p) (m_q : Monotone q) :
Monotone fun x => p x β§ q x :=
fun _ _ h => And.imp (m_p h) (m_q h)
-- Note: by finish [monotone] doesn't work
theorem monotone_or {p q : Ξ± β Prop} (m_p : Monotone p) (m_q : Monotone q) :
Monotone fun x => p x β¨ q x :=
fun _ _ h => Or.imp (m_p h) (m_q h)
theorem monotone_le {x : Ξ±} : Monotone (x β€ Β·) := fun _ _ h' h => h.trans h'
theorem monotone_lt {x : Ξ±} : Monotone (x < Β·) := fun _ _ h' h => h.trans_le h'
theorem antitone_le {x : Ξ±} : Antitone (Β· β€ x) := fun _ _ h' h => h'.trans h
theorem antitone_lt {x : Ξ±} : Antitone (Β· < x) := fun _ _ h' h => h'.trans_lt h
theorem Monotone.forall {P : Ξ² β Ξ± β Prop} (hP : β x, Monotone (P x)) :
Monotone fun y => β x, P x y :=
fun _ _ hy h x => hP x hy <| h x
theorem Antitone.forall {P : Ξ² β Ξ± β Prop} (hP : β x, Antitone (P x)) :
Antitone fun y => β x, P x y :=
fun _ _ hy h x => hP x hy (h x)
theorem Monotone.ball {P : Ξ² β Ξ± β Prop} {s : Set Ξ²} (hP : β x β s, Monotone (P x)) :
Monotone fun y => β x β s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx)
theorem Antitone.ball {P : Ξ² β Ξ± β Prop} {s : Set Ξ²} (hP : β x β s, Antitone (P x)) :
Antitone fun y => β x β s, P x y := fun _ _ hy h x hx => hP x hx hy (h x hx)
theorem Monotone.exists {P : Ξ² β Ξ± β Prop} (hP : β x, Monotone (P x)) :
Monotone fun y => β x, P x y :=
fun _ _ hy β¨x, hxβ© β¦ β¨x, hP x hy hxβ©
theorem Antitone.exists {P : Ξ² β Ξ± β Prop} (hP : β x, Antitone (P x)) :
Antitone fun y => β x, P x y :=
fun _ _ hy β¨x, hxβ© β¦ β¨x, hP x hy hxβ©
theorem forall_ge_iff {P : Ξ± β Prop} {xβ : Ξ±} (hP : Monotone P) :
(β x β₯ xβ, P x) β P xβ :=
β¨fun H β¦ H xβ le_rfl, fun H _ hx β¦ hP hx Hβ©
theorem forall_le_iff {P : Ξ± β Prop} {xβ : Ξ±} (hP : Antitone P) :
(β x β€ xβ, P x) β P xβ :=
β¨fun H β¦ H xβ le_rfl, fun H _ hx β¦ hP hx Hβ©
end Preorder
end Logic
|
ProperConstSMul.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.Algebra.ConstMulAction
import Mathlib.Topology.Maps.Proper.Basic
/-!
# Actions by proper maps
In this file we define `ProperConstSMul M X` to be a mixin `Prop`-value class
stating that `(c β’ Β·)` is a proper map for all `c`.
Note that this is **not** the same as a proper action (not yet in `Mathlib`)
which requires `(c, x) β¦ (c β’ x, x)` to be a proper map.
We also provide 4 instances:
- for a continuous action on a compact Hausdorff space,
- and for a continuous group action on a general space;
- for the action on `X Γ Y`;
- for the action on `β i, X i`.
-/
/-- A mixin typeclass saying that the `(c +α΅₯ Β·)` is a proper map for all `c`.
Note that this is **not** the same as a proper additive action (not yet in `Mathlib`). -/
class ProperConstVAdd (M X : Type*) [VAdd M X] [TopologicalSpace X] : Prop where
/-- `(c +α΅₯ Β·)` is a proper map. -/
isProperMap_vadd (c : M) : IsProperMap ((c +α΅₯ Β·) : X β X)
/-- A mixin typeclass saying that `(c β’ Β·)` is a proper map for all `c`.
Note that this is **not** the same as a proper multiplicative action (not yet in `Mathlib`). -/
@[to_additive]
class ProperConstSMul (M X : Type*) [SMul M X] [TopologicalSpace X] : Prop where
/-- `(c β’ Β·)` is a proper map. -/
isProperMap_smul (c : M) : IsProperMap ((c β’ Β·) : X β X)
/-- `(c β’ Β·)` is a proper map. -/
@[to_additive /-- `(c +α΅₯ Β·)` is a proper map. -/]
theorem isProperMap_smul {M : Type*} (c : M) (X : Type*) [SMul M X] [TopologicalSpace X]
[h : ProperConstSMul M X] : IsProperMap ((c β’ Β·) : X β X) := h.1 c
/-- The preimage of a compact set under `(c β’ Β·)` is a compact set. -/
@[to_additive /-- The preimage of a compact set under `(c +α΅₯ Β·)` is a compact set. -/]
theorem IsCompact.preimage_smul {M X : Type*} [SMul M X] [TopologicalSpace X]
[ProperConstSMul M X] {s : Set X} (hs : IsCompact s) (c : M) : IsCompact ((c β’ Β·) β»ΒΉ' s) :=
(isProperMap_smul c X).isCompact_preimage hs
@[to_additive]
instance (priority := 100) {M X : Type*} [SMul M X] [TopologicalSpace X] [ContinuousConstSMul M X]
[T2Space X] [CompactSpace X] : ProperConstSMul M X :=
β¨fun c β¦ (continuous_const_smul c).isProperMapβ©
@[to_additive]
instance (priority := 100) {G X : Type*} [Group G] [MulAction G X] [TopologicalSpace X]
[ContinuousConstSMul G X] : ProperConstSMul G X :=
β¨fun c β¦ (Homeomorph.smul c).isProperMapβ©
instance {M X Y : Type*}
[SMul M X] [TopologicalSpace X] [ProperConstSMul M X]
[SMul M Y] [TopologicalSpace Y] [ProperConstSMul M Y] :
ProperConstSMul M (X Γ Y) :=
β¨fun c β¦ (isProperMap_smul c X).prodMap (isProperMap_smul c Y)β©
instance {M ΞΉ : Type*} {X : ΞΉ β Type*}
[β i, SMul M (X i)] [β i, TopologicalSpace (X i)] [β i, ProperConstSMul M (X i)] :
ProperConstSMul M (β i, X i) :=
β¨fun c β¦ .pi_map fun i β¦ isProperMap_smul c (X i)β©
|
alt.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice.
From mathcomp Require Import div fintype tuple tuple bigop prime finset ssralg.
From mathcomp Require Import zmodp fingroup morphism perm automorphism quotient.
From mathcomp Require Import action cyclic pgroup gseries sylow.
From mathcomp Require Import primitive_action nilpotent maximal.
(******************************************************************************)
(* Definitions of the symmetric and alternate groups, and some properties. *)
(* 'Sym_T == The symmetric group over type T (which must have a finType *)
(* structure). *)
(* := [set: {perm T}] *)
(* 'Alt_T == The alternating group over type T. *)
(******************************************************************************)
Unset Printing Implicit Defensive.
Set Implicit Arguments.
Unset Strict Implicit.
Import GroupScope GRing.
HB.instance Definition _ := isMulGroup.Build bool addbA addFb addbb.
Section SymAltDef.
Variable T : finType.
Implicit Types (s : {perm T}) (x y z : T).
(** Definitions of the alternate groups and some Properties **)
Definition Sym : {set {perm T}} := setT.
Canonical Sym_group := Eval hnf in [group of Sym].
Local Notation "'Sym_T" := Sym.
Canonical sign_morph := @Morphism _ _ 'Sym_T _ (in2W (@odd_permM _)).
Definition Alt := 'ker (@odd_perm T).
Canonical Alt_group := Eval hnf in [group of Alt].
Local Notation "'Alt_T" := Alt.
Lemma Alt_even p : (p \in 'Alt_T) = ~~ p.
Proof. by rewrite !inE /=; case: odd_perm. Qed.
Lemma Alt_subset : 'Alt_T \subset 'Sym_T.
Proof. exact: subsetT. Qed.
Lemma Alt_normal : 'Alt_T <| 'Sym_T.
Proof. exact: ker_normal. Qed.
Lemma Alt_norm : 'Sym_T \subset 'N('Alt_T).
Proof. by case/andP: Alt_normal. Qed.
Let n := #|T|.
Lemma Alt_index : 1 < n -> #|'Sym_T : 'Alt_T| = 2.
Proof.
move=> lt1n; rewrite -card_quotient ?Alt_norm //=.
have : ('Sym_T / 'Alt_T) \isog (@odd_perm T @* 'Sym_T) by apply: first_isog.
case/isogP=> g /injmP/card_in_imset <-.
rewrite /morphim setIid=> ->; rewrite -card_bool; apply: eq_card => b.
apply/imsetP; case: b => /=; last first.
by exists (1 : {perm T}); [rewrite setIid inE | rewrite odd_perm1].
case: (pickP T) lt1n => [x1 _ | d0]; last by rewrite /n eq_card0.
rewrite /n (cardD1 x1) ltnS lt0n => /existsP[x2 /=].
by rewrite eq_sym andbT -odd_tperm; exists (tperm x1 x2); rewrite ?inE.
Qed.
Lemma card_Sym : #|'Sym_T| = n`!.
Proof.
rewrite -[n]cardsE -card_perm; apply: eq_card => p.
by apply/idP/subsetP=> [? ?|]; rewrite !inE.
Qed.
Lemma card_Alt : 1 < n -> (2 * #|'Alt_T|)%N = n`!.
Proof.
by move/Alt_index <-; rewrite mulnC (Lagrange Alt_subset) card_Sym.
Qed.
Lemma Sym_trans : [transitive^n 'Sym_T, on setT | 'P].
Proof.
apply/imsetP; pose t1 := [tuple of enum T].
have dt1: t1 \in n.-dtuple(setT) by rewrite inE enum_uniq; apply/subsetP.
exists t1 => //; apply/setP=> t; apply/idP/imsetP=> [|[a _ ->{t}]]; last first.
by apply: n_act_dtuple => //; apply/astabsP=> x; rewrite !inE.
case/dtuple_onP=> injt _; have injf := inj_comp injt enum_rank_inj.
exists (perm injf); first by rewrite inE.
apply: eq_from_tnth => i; rewrite tnth_map /= [aperm _ _]permE; congr tnth.
by rewrite (tnth_nth (enum_default i)) enum_valK.
Qed.
Lemma Alt_trans : [transitive^n.-2 'Alt_T, on setT | 'P].
Proof.
case n_m2: n Sym_trans => [|[|m]] /= tr_m2; try exact: ntransitive0.
have tr_m := ntransitive_weak (leqW (leqnSn m)) tr_m2.
case/imsetP: tr_m2; case/tupleP=> x; case/tupleP=> y t.
rewrite !dtuple_on_add 2![x \in _]inE inE negb_or /= -!andbA.
case/and4P=> nxy ntx nty dt _; apply/imsetP; exists t => //; apply/setP=> u.
apply/idP/imsetP=> [|[a _ ->{u}]]; last first.
by apply: n_act_dtuple => //; apply/astabsP=> z; rewrite !inE.
case/(atransP2 tr_m dt)=> /= a _ ->{u}.
case odd_a: (odd_perm a); last by exists a => //; rewrite !inE /= odd_a.
exists (tperm x y * a); first by rewrite !inE /= odd_permM odd_tperm nxy odd_a.
apply/val_inj/eq_in_map => z tz; rewrite actM /= /aperm; congr (a _).
by case: tpermP ntx nty => // <-; rewrite tz.
Qed.
Lemma aperm_faithful (A : {group {perm T}}) : [faithful A, on setT | 'P].
Proof.
by apply/faithfulP=> /= p _ np1; apply/eqP/perm_act1P=> y; rewrite np1 ?inE.
Qed.
End SymAltDef.
Arguments Sym T%_type.
Arguments Sym_group T%_type.
Arguments Alt T%_type.
Arguments Alt_group T%_type.
Notation "''Sym_' T" := (Sym T)
(at level 8, T at level 2, format "''Sym_' T") : group_scope.
Notation "''Sym_' T" := (Sym_group T) : Group_scope.
Notation "''Alt_' T" := (Alt T)
(at level 8, T at level 2, format "''Alt_' T") : group_scope.
Notation "''Alt_' T" := (Alt_group T) : Group_scope.
Lemma trivial_Alt_2 (T : finType) : #|T| <= 2 -> 'Alt_T = 1.
Proof.
rewrite leq_eqVlt => /predU1P[] oT.
by apply: card_le1_trivg; rewrite -leq_double -mul2n card_Alt oT.
suffices Sym1: 'Sym_T = 1 by apply/trivgP; rewrite -Sym1 subsetT.
by apply: card1_trivg; rewrite card_Sym; case: #|T| oT; do 2?case.
Qed.
Lemma simple_Alt_3 (T : finType) : #|T| = 3 -> simple 'Alt_T.
Proof.
move=> T3; have{T3} oA: #|'Alt_T| = 3.
by apply: double_inj; rewrite -mul2n card_Alt T3.
apply/simpleP; split=> [|K]; [by rewrite trivg_card1 oA | case/andP=> sKH _].
have:= cardSg sKH; rewrite oA dvdn_divisors // !inE orbC /= -oA.
case/pred2P=> eqK; [right | left]; apply/eqP.
by rewrite eqEcard sKH eqK leqnn.
by rewrite eq_sym eqEcard sub1G eqK cards1.
Qed.
Lemma not_simple_Alt_4 (T : finType) : #|T| = 4 -> ~~ simple 'Alt_T.
Proof.
move=> oT; set A := 'Alt_T.
have oA: #|A| = 12 by apply: double_inj; rewrite -mul2n card_Alt oT.
suffices [p]: exists p, [/\ prime p, 1 < #|A|`_p < #|A| & #|'Syl_p(A)| == 1%N].
case=> p_pr pA_int; rewrite /A; case/normal_sylowP=> P; case/pHallP.
rewrite /= -/A => sPA pP nPA; apply/simpleP=> [] [_]; rewrite -pP in pA_int.
by case/(_ P)=> // defP; rewrite defP oA ?cards1 in pA_int.
have: #|'Syl_3(A)| \in filter [pred d | d %% 3 == 1%N] (divisors 12).
by rewrite mem_filter -dvdn_divisors //= -oA card_Syl_dvd ?card_Syl_mod.
rewrite /= oA mem_seq2 orbC.
case/predU1P=> [oQ3|]; [exists 2 | exists 3]; split; rewrite ?p_part //.
pose A3 := [set x : {perm T} | #[x] == 3]; suffices oA3: #|A :&: A3| = 8.
have sQ2 P: P \in 'Syl_2(A) -> P :=: A :\: A3.
rewrite inE pHallE oA p_part -natTrecE /= => /andP[sPA /eqP oP].
apply/eqP; rewrite eqEcard -(leq_add2l 8) -{1}oA3 cardsID oA oP.
rewrite andbT subsetD sPA; apply/exists_inP=> -[x] /= Px.
by rewrite inE => /eqP ox; have:= order_dvdG Px; rewrite oP ox.
have [/= P sylP] := Sylow_exists 2 [group of A].
rewrite -(([set P] =P 'Syl_2(A)) _) ?cards1 // eqEsubset sub1set inE sylP.
by apply/subsetP=> Q sylQ; rewrite inE -val_eqE /= !sQ2 // inE.
rewrite -[8]/(4 * 2)%N -{}oQ3 -sum1_card -sum_nat_const.
rewrite (partition_big (fun x => <[x]>%G) [in 'Syl_3(A)]) => [|x]; last first.
by case/setIP=> Ax; rewrite /= !inE pHallE p_part cycle_subG Ax oA.
apply: eq_bigr => Q; rewrite inE pHallE oA p_part -?natTrecE //=.
case/andP=> sQA /eqP oQ; have:= oQ.
rewrite (cardsD1 1) group1 -sum1_card => [[/= <-]]; apply: eq_bigl => x.
rewrite setIC -val_eqE /= 2!inE in_setD1 -andbA -{4}[x]expg1 -order_dvdn dvdn1.
apply/and3P/andP=> [[/eqP-> _ /eqP <-] | [ntx Qx]]; first by rewrite cycle_id.
have:= order_dvdG Qx; rewrite oQ dvdn_divisors // mem_seq2 (negPf ntx) /=.
by rewrite eqEcard cycle_subG Qx (subsetP sQA) // oQ /order => /eqP->.
Qed.
Lemma simple_Alt5_base (T : finType) : #|T| = 5 -> simple 'Alt_T.
Proof.
move=> oT.
have F1: #|'Alt_T| = 60 by apply: double_inj; rewrite -mul2n card_Alt oT.
have FF (H : {group {perm T}}): H <| 'Alt_T -> H :<>: 1 -> 20 %| #|H|.
- move=> Hh1 Hh3.
have [x _]: exists x, x \in T by apply/existsP/eqP; rewrite oT.
have F2 := Alt_trans T; rewrite oT /= in F2.
have F3: [transitive 'Alt_T, on setT | 'P] by apply: ntransitive1 F2.
have F4: [primitive 'Alt_T, on setT | 'P] by apply: ntransitive_primitive F2.
case: (prim_trans_norm F4 Hh1) => F5.
by case: Hh3; apply/trivgP; apply: subset_trans F5 (aperm_faithful _).
have F6: 5 %| #|H| by rewrite -oT -cardsT (atrans_dvd F5).
have F7: 4 %| #|H|.
have F7: #|[set~ x]| = 4 by rewrite cardsC1 oT.
case: (pickP [in [set~ x]]) => [y Hy | ?]; last by rewrite eq_card0 in F7.
pose K := 'C_H[x | 'P]%G.
have F8 : K \subset H by apply: subsetIl.
pose Gx := 'C_('Alt_T)[x | 'P]%G.
have F9: [transitive^2 Gx, on [set~ x] | 'P].
by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE.
have F10: [transitive Gx, on [set~ x] | 'P].
exact: ntransitive1 F9.
have F11: [primitive Gx, on [set~ x] | 'P].
exact: ntransitive_primitive F9.
have F12: K \subset Gx by apply: setSI; apply: normal_sub.
have F13: K <| Gx by rewrite /(K <| _) F12 normsIG // normal_norm.
case: (prim_trans_norm F11 F13) => Ksub; last first.
by apply: dvdn_trans (cardSg F8); rewrite -F7; apply: atrans_dvd Ksub.
have F14: [faithful Gx, on [set~ x] | 'P].
apply/subsetP=> g; do 2![case/setIP] => Altg cgx cgx'.
apply: (subsetP (aperm_faithful 'Alt_T)).
rewrite inE Altg /=; apply/astabP=> z _.
case: (z =P x) => [->|]; first exact: (astab1P cgx).
by move/eqP=> nxz; rewrite (astabP cgx') ?inE //.
have Hreg g (z : T): g \in H -> g z = z -> g = 1.
have F15 h: h \in H -> h x = x -> h = 1.
move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P.
by rewrite (trivGP (subset_trans Ksub F14)) => /set1P.
move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //.
case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g.
apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz.
by case/normalP: Hh1 => _ nH1; rewrite -(nH1 _ Hg1) memJ_conjg.
clear K F8 F12 F13 Ksub F14.
case: (Cauchy _ F6) => // h Hh /eqP Horder.
have diff_hnx_x n: 0 < n -> n < 5 -> x != (h ^+ n) x.
move=> Hn1 Hn2; rewrite eq_sym; apply/negP => HH.
have: #[h ^+ n] = 5.
rewrite orderXgcd // (eqP Horder).
by move: Hn1 Hn2 {HH}; do 5 (case: n => [|n] //).
have Hhd2: h ^+ n \in H by rewrite groupX.
by rewrite (Hreg _ _ Hhd2 (eqP HH)) order1.
pose S1 := [tuple x; h x; (h ^+ 3) x].
have DnS1: S1 \in 3.-dtuple(setT).
rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT.
rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM.
by rewrite (inj_eq perm_inj) diff_hnx_x.
pose S2 := [tuple x; h x; (h ^+ 2) x].
have DnS2: S2 \in 3.-dtuple(setT).
rewrite inE memtE subset_all /= !inE /= !negb_or -!andbA /= andbT.
rewrite -{1}[h]expg1 !diff_hnx_x // expgSr permM.
by rewrite (inj_eq perm_inj) diff_hnx_x.
case: (atransP2 F2 DnS1 DnS2) => g Hg [/=].
rewrite /aperm => Hgx Hghx Hgh3x.
have h_g_com: h * g = g * h.
suff HH: (g * h * g^-1) * h^-1 = 1 by rewrite -[h * g]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hgx Hghx -!permM mulKVg mulgV perm1.
rewrite groupM // ?groupV // (conjgCV g) mulgK -mem_conjg.
by case/normalP: Hh1 => _ ->.
have: (g * (h ^+ 2) * g ^-1) x = (h ^+ 3) x.
rewrite !permM -Hgx.
have ->: h (h x) = (h ^+ 2) x by rewrite /= permM.
by rewrite {1}Hgh3x -!permM /= mulgV mulg1 -expgSr.
rewrite commuteX // mulgK {1}[expgn]lock expgS permM -lock.
by move/perm_inj=> eqxhx; case/eqP: (diff_hnx_x 1%N isT isT); rewrite expg1.
by rewrite (@Gauss_dvd 4 5) // F7.
apply/simpleP; split => [|H Hnorm]; first by rewrite trivg_card1 F1.
case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1.
by left; apply: card1_trivg; rewrite Hcard1.
right; case Hcard60: (#|H| == 60); move/eqP: Hcard60 => Hcard60.
by apply/eqP; rewrite eqEcard Hcard60 F1 andbT; case/andP: Hnorm.
have {Hcard1 Hcard60} Hcard20: #|H| = 20.
have Hdiv: 20 %| #|H| by apply: FF => // HH; case Hcard1; rewrite HH cards1.
case H20: (#|H| == 20); first exact/eqP.
case: Hcard60; case/andP: Hnorm; move/cardSg; rewrite F1 => Hdiv1 _.
by case/dvdnP: Hdiv H20 Hdiv1 => n ->; move: n; do 4!case=> //.
have prime_5: prime 5 by [].
have nSyl5: #|'Syl_5(H)| = 1%N.
move: (card_Syl_dvd 5 H) (card_Syl_mod H prime_5).
rewrite Hcard20; case: (card _) => // n Hdiv.
move: (dvdn_leq (isT: (0 < 20)%N) Hdiv).
by move: (n) Hdiv; do 20 (case=> //).
case: (Sylow_exists 5 H) => S; case/pHallP=> sSH oS.
have{} oS: #|S| = 5 by rewrite oS p_part Hcard20.
suff: 20 %| #|S| by rewrite oS.
apply: FF => [|S1]; last by rewrite S1 cards1 in oS.
apply: char_normal_trans Hnorm; apply: lone_subgroup_char => // Q sQH isoQS.
rewrite subEproper; apply/norP=> [[nQS _]]; move: nSyl5.
rewrite (cardsD1 S) (cardsD1 Q) 4!{1}inE nQS !pHallE sQH sSH Hcard20 p_part.
by rewrite (card_isog isoQS) oS.
Qed.
Section Restrict.
Variables (T : finType) (x : T).
Notation T' := {y | y != x}.
Lemma rfd_funP (p : {perm T}) (u : T') :
let p1 := if p x == x then p else 1 in p1 (val u) != x.
Proof.
case: (p x =P x) => /= [pxx | _]; last by rewrite perm1 (valP u).
by rewrite -[x in _ != x]pxx (inj_eq perm_inj); apply: (valP u).
Qed.
Definition rfd_fun p := [fun u => Sub ((_ : {perm T}) _) (rfd_funP p u) : T'].
Lemma rfdP p : injective (rfd_fun p).
Proof.
apply: can_inj (rfd_fun p^-1) _ => u; apply: val_inj => /=.
rewrite -(can_eq (permK p)) permKV eq_sym.
by case: eqP => _; rewrite !(perm1, permK).
Qed.
Definition rfd p := perm (@rfdP p).
Hypothesis card_T : 2 < #|T|.
Lemma rfd_morph : {in 'C_('Sym_T)[x | 'P] &, {morph rfd : y z / y * z}}.
Proof.
move=> p q; rewrite !setIA !setIid; move/astab1P=> p_x; move/astab1P=> q_x.
apply/permP=> u; apply: val_inj.
by rewrite permE /= !permM !permE /= [p x]p_x [q x]q_x eqxx permM /=.
Qed.
Canonical rfd_morphism := Morphism rfd_morph.
Definition rgd_fun (p : {perm T'}) :=
[fun x1 => if insub x1 is Some u then sval (p u) else x].
Lemma rgdP p : injective (rgd_fun p).
Proof.
apply: can_inj (rgd_fun p^-1) _ => y /=.
case: (insubP _ y) => [u _ val_u|]; first by rewrite valK permK.
by rewrite negbK; move/eqP->; rewrite insubF //= eqxx.
Qed.
Definition rgd p := perm (@rgdP p).
Lemma rfd_odd (p : {perm T}) : p x = x -> rfd p = p :> bool.
Proof.
have rfd1: rfd 1 = 1.
by apply/permP => u; apply: val_inj; rewrite permE /= if_same !perm1.
have [n] := ubnP #|[set x | p x != x]|; elim: n p => // n IHn p le_p_n px_x.
have [p_id | [x1 Hx1]] := set_0Vmem [set x | p x != x].
suffices ->: p = 1 by rewrite rfd1 !odd_perm1.
by apply/permP => z; apply: contraFeq (in_set0 z); rewrite perm1 -p_id inE.
have nx1x: x1 != x by apply: contraTneq Hx1 => ->; rewrite inE px_x eqxx.
have npxx1: p x != x1 by apply: contraNneq nx1x => <-; rewrite px_x.
have npx1x: p x1 != x by rewrite -px_x (inj_eq perm_inj).
pose p1 := p * tperm x1 (p x1).
have fix_p1 y: p y = y -> p1 y = y.
by move=> pyy; rewrite permM; have [<-|/perm_inj<-|] := tpermP; rewrite ?pyy.
have p1x_x: p1 x = x by apply: fix_p1.
have{le_p_n} lt_p1_n: #|[set x | p1 x != x]| < n.
move: le_p_n; rewrite ltnS (cardsD1 x1) Hx1; apply/leq_trans/subset_leq_card.
rewrite subsetD1 inE permM tpermR eqxx andbT.
by apply/subsetP=> y /[!inE]; apply: contraNneq=> /fix_p1->.
transitivity (p1 (+) true); last first.
by rewrite odd_permM odd_tperm -Hx1 inE eq_sym addbK.
have ->: p = p1 * tperm x1 (p x1) by rewrite -tpermV mulgK.
rewrite morphM; last 2 first; first by rewrite 2!inE; apply/astab1P.
by rewrite 2!inE; apply/astab1P; rewrite -[RHS]p1x_x permM px_x.
rewrite odd_permM IHn //=; congr (_ (+) _).
pose x2 : T' := Sub x1 nx1x; pose px2 : T' := Sub (p x1) npx1x.
suffices ->: rfd (tperm x1 (p x1)) = tperm x2 px2.
by rewrite odd_tperm eq_sym; rewrite inE in Hx1.
apply/permP => z; apply/val_eqP; rewrite permE /= tpermD // eqxx.
by rewrite !permE /= -!val_eqE /= !(fun_if sval) /=.
Qed.
Lemma rfd_iso : 'C_('Alt_T)[x | 'P] \isog 'Alt_T'.
Proof.
have rgd_x p: rgd p x = x by rewrite permE /= insubF //= eqxx.
have rfd_rgd p: rfd (rgd p) = p.
apply/permP => [[z Hz]]; apply/val_eqP; rewrite !permE.
by rewrite /= [rgd _ _]permE /= insubF eqxx // permE /= insubT.
have sSd: 'C_('Alt_T)[x | 'P] \subset 'dom rfd.
by apply/subsetP=> p /[!inE]/= /andP[].
apply/isogP; exists [morphism of restrm sSd rfd] => /=; last first.
rewrite morphim_restrm setIid; apply/setP=> z; apply/morphimP/idP=> [[p _]|].
case/setIP; rewrite Alt_even => Hp; move/astab1P=> Hp1 ->.
by rewrite Alt_even rfd_odd.
have dz': rgd z x == x by rewrite rgd_x.
move=> kz; exists (rgd z); last by rewrite /= rfd_rgd.
by rewrite 2!inE (sameP astab1P eqP).
rewrite 4!inE /= (sameP astab1P eqP) dz' -rfd_odd; last exact/eqP.
by rewrite rfd_rgd mker // ?set11.
apply/injmP=> x1 y1 /=.
case/setIP=> Hax1; move/astab1P; rewrite /= /aperm => Hx1.
case/setIP=> Hay1; move/astab1P; rewrite /= /aperm => Hy1 Hr.
apply/permP => z.
case (z =P x) => [->|]; [by rewrite Hx1 | move/eqP => nzx].
move: (congr1 (fun q : {perm T'} => q (Sub z nzx)) Hr).
by rewrite !permE => [[]]; rewrite Hx1 Hy1 !eqxx.
Qed.
End Restrict.
Lemma simple_Alt5 (T : finType) : #|T| >= 5 -> simple 'Alt_T.
Proof.
suff F1 n: #|T| = n + 5 -> simple 'Alt_T by move/subnK/esym/F1.
elim: n T => [| n Hrec T Hde]; first exact: simple_Alt5_base.
have oT: 5 < #|T| by rewrite Hde addnC.
apply/simpleP; split=> [|H Hnorm]; last have [Hh1 nH] := andP Hnorm.
rewrite trivg_card1 -[#|_|]half_double -mul2n card_Alt Hde addnC //.
by rewrite addSn factS mulnC -(prednK (fact_gt0 _)).
case E1: (pred0b T); first by rewrite /pred0b in E1; rewrite (eqP E1) in oT.
case/pred0Pn: E1 => x _; have Hx := in_setT x.
have F2: [transitive^4 'Alt_T, on setT | 'P].
by apply: ntransitive_weak (Alt_trans T); rewrite -(subnKC oT).
have F3 := ntransitive1 (isT: 0 < 4) F2.
have F4 := ntransitive_primitive (isT: 1 < 4) F2.
case Hcard1: (#|H| == 1%N); move/eqP: Hcard1 => Hcard1.
by left; apply: card1_trivg; rewrite Hcard1.
right; case: (prim_trans_norm F4 Hnorm) => F5.
by rewrite (trivGP (subset_trans F5 (aperm_faithful _))) cards1 in Hcard1.
case E1: (pred0b (predD1 T x)).
rewrite /pred0b in E1; move: oT.
by rewrite (cardD1 x) (eqP E1); case: (T x).
case/pred0Pn: E1 => y Hdy; case/andP: (Hdy) => diff_x_y Hy.
pose K := 'C_H[x | 'P]%G.
have F8: K \subset H by apply: subsetIl.
pose Gx := 'C_('Alt_T)[x | 'P].
have F9: [transitive^3 Gx, on [set~ x] | 'P].
by rewrite -[[set~ x]]setTI -setDE stab_ntransitive ?inE.
have F10: [transitive Gx, on [set~ x] | 'P].
by apply: ntransitive1 F9.
have F11: [primitive Gx, on [set~ x] | 'P].
by apply: ntransitive_primitive F9.
have F12: K \subset Gx by rewrite setSI // normal_sub.
have F13: K <| Gx by apply/andP; rewrite normsIG.
have:= prim_trans_norm F11; case/(_ K) => //= => Ksub; last first.
have F14: Gx * H = 'Alt_T by apply/(subgroup_transitiveP _ _ F3).
have: simple Gx.
by rewrite (isog_simple (rfd_iso x)) Hrec //= card_sig cardC1 Hde.
case/simpleP=> _ simGx; case/simGx: F13 => /= HH2.
case Ez: (pred0b (predD1 (predD1 T x) y)).
move: oT; rewrite /pred0b in Ez.
by rewrite (cardD1 x) (cardD1 y) (eqP Ez) inE /= inE /= diff_x_y.
case/pred0Pn: Ez => z; case/andP => diff_y_z Hdz.
have [diff_x_z Hz] := andP Hdz.
have: z \in [set~ x] by rewrite !inE.
rewrite -(atransP Ksub y) ?inE //; case/imsetP => g.
rewrite /= HH2 inE; move/eqP=> -> HH4.
by case/negP: diff_y_z; rewrite HH4 act1.
by rewrite /= -F14 -[Gx]HH2 (mulSGid F8).
have F14: [faithful Gx, on [set~ x] | 'P].
apply: subset_trans (aperm_faithful 'Sym_T); rewrite subsetI subsetT.
apply/subsetP=> g; do 2![case/setIP]=> _ cgx cgx'; apply/astabP=> z _ /=.
case: (z =P x) => [->|]; first exact: (astab1P cgx).
by move/eqP=> zx; rewrite [_ g](astabP cgx') ?inE.
have Hreg g z: g \in H -> g z = z -> g = 1.
have F15 h: h \in H -> h x = x -> h = 1.
move=> Hh Hhx; have: h \in K by rewrite inE Hh; apply/astab1P.
by rewrite [K](trivGP (subset_trans Ksub F14)) => /set1P.
move=> Hg Hgz; have:= in_setT x; rewrite -(atransP F3 z) ?inE //.
case/imsetP=> g1 Hg1 Hg2; apply: (conjg_inj g1); rewrite conj1g.
apply: F15; last by rewrite Hg2 -permM mulKVg permM Hgz.
by rewrite memJ_norm ?(subsetP nH).
clear K F8 F12 F13 Ksub F14.
have Hcard: 5 < #|H|.
apply: (leq_trans oT); apply: dvdn_leq; first exact: cardG_gt0.
by rewrite -cardsT (atrans_dvd F5).
case Eh: (pred0b [predD1 H & 1]).
by move: Hcard; rewrite /pred0b in Eh; rewrite (cardD1 1) group1 (eqP Eh).
case/pred0Pn: Eh => h; case/andP => diff_1_h /= Hh.
case Eg: (pred0b (predD1 (predD1 [predD1 H & 1] h) h^-1)).
move: Hcard; rewrite ltnNge; case/negP.
rewrite (cardD1 1) group1 (cardD1 h) (cardD1 h^-1) (eqnP Eg).
by do 2!case: (_ \in _).
case/pred0Pn: Eg => g; case/andP => diff_h1_g; case/andP => diff_h_g.
case/andP => diff_1_g /= Hg.
case diff_hx_x: (h x == x).
by case/negP: diff_1_h; apply/eqP; apply: (Hreg _ _ Hh (eqP diff_hx_x)).
case diff_gx_x: (g x == x).
case/negP: diff_1_g; apply/eqP; apply: (Hreg _ _ Hg (eqP diff_gx_x)).
case diff_gx_hx: (g x == h x).
case/negP: diff_h_g; apply/eqP; symmetry; apply: (mulIg g^-1); rewrite gsimp.
apply: (Hreg _ x); first by rewrite groupM // groupV.
by rewrite permM -(eqP diff_gx_hx) -permM mulgV perm1.
case diff_hgx_x: ((h * g) x == x).
case/negP: diff_h1_g; apply/eqP; apply: (mulgI h); rewrite !gsimp.
by apply: (Hreg _ x); [apply: groupM | apply/eqP].
case diff_hgx_hx: ((h * g) x == h x).
case/negP: diff_1_g; apply/eqP.
by apply: (Hreg _ (h x)) => //; apply/eqP; rewrite -permM.
case diff_hgx_gx: ((h * g) x == g x).
by case/idP: diff_hx_x; rewrite -(can_eq (permK g)) -permM.
case Ez: (pred0b
(predD1 (predD1 (predD1 (predD1 T x) (h x)) (g x)) ((h * g) x))).
- move: oT; rewrite /pred0b in Ez.
rewrite (cardD1 x) (cardD1 (h x)) (cardD1 (g x)) (cardD1 ((h * g) x)).
by rewrite (eqP Ez) addnC; do 3!case: (_ x \in _).
case/pred0Pn: Ez => z.
case/and5P=> diff_hgx_z diff_gx_z diff_hx_z diff_x_z /= Hz.
pose S1 := [tuple x; h x; g x; z].
have DnS1: S1 \in 4.-dtuple(setT).
rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT.
rewrite -!(eq_sym z) diff_gx_z diff_x_z diff_hx_z.
by rewrite !(eq_sym x) diff_hx_x diff_gx_x eq_sym diff_gx_hx.
pose S2 := [tuple x; h x; g x; (h * g) x].
have DnS2: S2 \in 4.-dtuple(setT).
rewrite inE memtE subset_all -!andbA !negb_or /= !inE !andbT !(eq_sym x).
rewrite diff_hx_x diff_gx_x diff_hgx_x.
by rewrite !(eq_sym (h x)) diff_gx_hx diff_hgx_hx eq_sym diff_hgx_gx.
case: (atransP2 F2 DnS1 DnS2) => k Hk [/=].
rewrite /aperm => Hkx Hkhx Hkgx Hkhgx.
have h_k_com: h * k = k * h.
suff HH: (k * h * k^-1) * h^-1 = 1 by rewrite -[h * k]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hkx Hkhx -!permM mulKVg mulgV perm1.
by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH).
have g_k_com: g * k = k * g.
suff HH: (k * g * k^-1) * g^-1 = 1 by rewrite -[g * k]mul1g -HH !gnorm.
apply: (Hreg _ x); last first.
by rewrite !permM -Hkx Hkgx -!permM mulKVg mulgV perm1.
by rewrite groupM // ?groupV // (conjgCV k) mulgK -mem_conjg (normsP nH).
have HH: (k * (h * g) * k ^-1) x = z.
by rewrite 2!permM -Hkx Hkhgx -permM mulgV perm1.
case/negP: diff_hgx_z.
rewrite -HH !mulgA -h_k_com -!mulgA [k * _]mulgA.
by rewrite -g_k_com -!mulgA mulgV mulg1.
Qed.
Lemma gen_tperm_circular_shift (X : finType) x y c : prime #|X| ->
x != y -> #[c]%g = #|X| ->
<<[set tperm x y; c]>>%g = ('Sym_X)%g.
Proof.
move=> Xprime neq_xy ord_c; apply/eqP; rewrite eqEsubset subsetT/=.
have c_gt1 : (1 < #[c]%g)%N by rewrite ord_c prime_gt1.
have cppSS : #[c]%g.-2.+2 = #|X| by rewrite ?prednK ?ltn_predRL.
pose f (i : 'Z_#[c]%g) : X := Zpm i x.
have [g fK gK] : bijective f.
apply: inj_card_bij; rewrite ?cppSS ?card_ord// /f /Zpm => i j cijx.
pose stabx := ('C_<[c]>[x | 'P])%g.
have cjix : (c ^+ (j - i)%R)%g x = x.
by apply: (@perm_inj _ (c ^+ i)%g); rewrite -permM -expgD_Zp// addrNK.
have : (c ^+ (j - i)%R)%g \in stabx.
by rewrite !inE ?groupX ?mem_gen ?sub1set ?inE// ['P%act _ _]cjix eqxx.
rewrite [stabx]perm_prime_astab// => /set1gP.
move=> /(congr1 (mulg (c ^+ i))); rewrite -expgD_Zp// addrC addrNK mulg1.
by move=> /eqP; rewrite eq_expg_ord// ?cppSS ?ord_c// => /eqP->.
pose gsf s := g \o s \o f.
have gsf_inj (s : {perm X}) : injective (gsf s).
apply: inj_comp; last exact: can_inj fK.
by apply: inj_comp; [exact: can_inj gK|exact: perm_inj].
pose fsg s := f \o s \o g.
have fsg_inj (s : {perm _}) : injective (fsg s).
apply: inj_comp; last exact: can_inj gK.
by apply: inj_comp; [exact: can_inj fK|exact: perm_inj].
have gsf_morphic : morphic 'Sym_X (fun s => perm (gsf_inj s)).
apply/morphicP => u v _ _; apply/permP => /= i.
by rewrite !permE/= !permE /gsf /= gK permM.
pose phi := morphm gsf_morphic; rewrite /= in phi.
have phi_inj : ('injm phi)%g.
apply/subsetP => /= u /mker/=; rewrite morphmE => gsfu1.
apply/set1gP/permP=> z; have /permP/(_ (g z)) := gsfu1.
by rewrite !perm1 permE /gsf/= gK => /(can_inj gK).
have phiT : (phi @* 'Sym_X)%g = [set: {perm 'Z_#[c]%g}].
apply/eqP; rewrite eqEsubset subsetT/=; apply/subsetP => /= u _.
apply/morphimP; exists (perm (fsg_inj u)); rewrite ?in_setT//.
by apply/permP => /= i; rewrite morphmE permE /gsf/fsg/= permE/= !fK.
have f0 : f 0%R = x by rewrite /f /Zpm permX.
pose k := g y; have k_gt0 : (k > 0)%N.
by rewrite lt0n (val_eqE k 0%R) -(can_eq fK) eq_sym gK f0.
have phixy : phi (tperm x y) = tperm (0%R : 'Z_#[c]) k.
apply/permP => i; rewrite permE/= /gsf/=; apply: (canLR fK).
by rewrite !permE/= -f0 -[y]gK !(can_eq fK) -!fun_if.
have phic : phi c = perm (addrI (1%R : 'Z_#[c])).
apply/permP => i; rewrite /phi morphmE !permE /gsf/=; apply: (canLR fK).
by rewrite /f /Zpm -permM addrC expgD_Zp.
rewrite -(injmSK phi_inj)//= morphim_gen/= ?subsetT//= -/phi.
rewrite phiT /morphim !setTI/= -/phi imsetU1 imset_set1/= phixy phic.
suff /gen_tpermn_circular_shift<- : coprime #[c]%g.-2.+2 (k - 0)%R by [].
by rewrite subr0 prime_coprime ?gtnNdvd// ?cppSS.
Qed.
Section Perm_solvable.
Local Open Scope nat_scope.
Variable T : finType.
Lemma solvable_AltF : 4 < #|T| -> solvable 'Alt_T = false.
Proof.
move=> card_T; apply/negP => Alt_solvable.
have/simple_Alt5 Alt_simple := card_T.
have := simple_sol_prime Alt_solvable Alt_simple.
have lt_T n : n <= 4 -> n < #|T| by move/leq_ltn_trans; apply.
have -> : #|('Alt_T)%G| = #|T|`! %/ 2 by rewrite -card_Alt ?mulKn ?lt_T.
move/even_prime => [/eqP|]; apply/negP.
rewrite neq_ltn leq_divRL // mulnC -[2 * 3]/(3`!).
by apply/orP; right; apply/ltnW/ltn_fact/lt_T.
by rewrite -dvdn2 dvdn_divRL dvdn_fact //=; apply/ltnW/lt_T.
Qed.
Lemma solvable_SymF : 4 < #|T| -> solvable 'Sym_T = false.
Proof. by rewrite (series_sol (Alt_normal T)) => /solvable_AltF->. Qed.
End Perm_solvable.
|
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.
|
Inversion.lean
|
/-
Copyright (c) 2024 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.MeasureTheory.Integral.PeakFunction
import Mathlib.Analysis.SpecialFunctions.Gaussian.FourierTransform
/-!
# Fourier inversion formula
In a finite-dimensional real inner product space, we show the Fourier inversion formula, i.e.,
`πβ» (π f) v = f v` if `f` and `π f` are integrable, and `f` is continuous at `v`. This is proved
in `MeasureTheory.Integrable.fourier_inversion`. See also `Continuous.fourier_inversion`
giving `πβ» (π f) = f` under an additional continuity assumption for `f`.
We use the following proof. A naΓ―ve computation gives
`πβ» (π f) v
= β«_w exp (2 I Ο βͺw, vβ«) π f (w) dw
= β«_w exp (2 I Ο βͺw, vβ«) β«_x, exp (-2 I Ο βͺw, xβ«) f x dx) dw
= β«_x (β«_ w, exp (2 I Ο βͺw, v - xβ« dw) f x dx `
However, the Fubini step does not make sense for lack of integrability, and the middle integral
`β«_ w, exp (2 I Ο βͺw, v - xβ« dw` (which one would like to be a Dirac at `v - x`) is not defined.
To gain integrability, one multiplies with a Gaussian function `exp (-cβ»ΒΉ βwβ^2)`, with a large
(but finite) `c`. As this function converges pointwise to `1` when `c β β`, we get
`β«_w exp (2 I Ο βͺw, vβ«) π f (w) dw = lim_c β«_w exp (-cβ»ΒΉ βwβ^2 + 2 I Ο βͺw, vβ«) π f (w) dw`.
One can perform Fubini on the right hand side for fixed `c`, writing the integral as
`β«_x (β«_w exp (-cβ»ΒΉβwβ^2 + 2 I Ο βͺw, v - xβ« dw)) f x dx`.
The middle factor is the Fourier transform of a more and more flat function
(converging to the constant `1`), hence it becomes more and more concentrated, around the
point `v`. (Morally, it converges to the Dirac at `v`). Moreover, it has integral one.
Therefore, multiplying by `f` and integrating, one gets a term converging to `f v` as `c β β`.
Since it also converges to `πβ» (π f) v`, this proves the result.
To check the concentration property of the middle factor and the fact that it has integral one, we
rely on the explicit computation of the Fourier transform of Gaussians.
-/
open Filter MeasureTheory Complex Module Metric Real Bornology
open scoped Topology FourierTransform RealInnerProductSpace Complex
variable {V E : Type*} [NormedAddCommGroup V] [InnerProductSpace β V]
[MeasurableSpace V] [BorelSpace V] [FiniteDimensional β V]
[NormedAddCommGroup E] [NormedSpace β E] {f : V β E}
namespace Real
lemma tendsto_integral_cexp_sq_smul (hf : Integrable f) :
Tendsto (fun (c : β) β¦ (β« v : V, cexp (- cβ»ΒΉ * βvβ^2) β’ f v))
atTop (π (β« v : V, f v)) := by
apply tendsto_integral_filter_of_dominated_convergence _ _ _ hf.norm
Β· filter_upwards with v
nth_rewrite 2 [show f v = cexp (- (0 : β) * βvβ^2) β’ f v by simp]
apply (Tendsto.cexp _).smul_const
exact tendsto_inv_atTop_zero.ofReal.neg.mul_const _
Β· filter_upwards with c using
AEStronglyMeasurable.smul (Continuous.aestronglyMeasurable (by fun_prop)) hf.1
Β· filter_upwards [Ici_mem_atTop (0 : β)] with c (hc : 0 β€ c)
filter_upwards with v
simp only [ofReal_inv, neg_mul, norm_smul]
norm_cast
conv_rhs => rw [β one_mul (βf vβ)]
gcongr
simp only [norm_eq_abs, abs_exp, exp_le_one_iff, Left.neg_nonpos_iff]
positivity
variable [CompleteSpace E]
lemma tendsto_integral_gaussian_smul (hf : Integrable f) (h'f : Integrable (π f)) (v : V) :
Tendsto (fun (c : β) β¦
β« w : V, ((Ο * c) ^ (finrank β V / 2 : β) * cexp (-Ο ^ 2 * c * βv - wβ ^ 2)) β’ f w)
atTop (π (πβ» (π f) v)) := by
have A : Tendsto (fun (c : β) β¦ (β« w : V, cexp (- cβ»ΒΉ * βwβ^2 + 2 * Ο * I * βͺv, wβ«)
β’ (π f) w)) atTop (π (πβ» (π f) v)) := by
have : Integrable (fun w β¦ π βͺw, vβ« β’ (π f) w) := by
have B : Continuous fun p : V Γ V => (- innerβ V) p.1 p.2 := continuous_inner.neg
simpa using
(VectorFourier.fourierIntegral_convergent_iff Real.continuous_fourierChar B v).2 h'f
convert tendsto_integral_cexp_sq_smul this using 4 with c w
Β· rw [Submonoid.smul_def, Real.fourierChar_apply, smul_smul, β Complex.exp_add, real_inner_comm]
congr 3
simp only [ofReal_mul, ofReal_ofNat]
ring
Β· simp [fourierIntegralInv_eq]
have B : Tendsto (fun (c : β) β¦ (β« w : V,
π (fun w β¦ cexp (- cβ»ΒΉ * βwβ^2 + 2 * Ο * I * βͺv, wβ«)) w β’ f w)) atTop
(π (πβ» (π f) v)) := by
apply A.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
have J : Integrable (fun w β¦ cexp (- cβ»ΒΉ * βwβ^2 + 2 * Ο * I * βͺv, wβ«)) :=
GaussianFourier.integrable_cexp_neg_mul_sq_norm_add (by simpa) _ _
simpa using (VectorFourier.integral_fourierIntegral_smul_eq_flip (L := innerβ V)
Real.continuous_fourierChar continuous_inner J hf).symm
apply B.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
congr with w
rw [fourierIntegral_gaussian_innerProductSpace' (by simpa)]
congr
Β· simp
Β· simp; ring
lemma tendsto_integral_gaussian_smul' (hf : Integrable f) {v : V} (h'f : ContinuousAt f v) :
Tendsto (fun (c : β) β¦
β« w : V, ((Ο * c : β) ^ (finrank β V / 2 : β) * cexp (-Ο ^ 2 * c * βv - wβ ^ 2)) β’ f w)
atTop (π (f v)) := by
let Ο : V β β := fun w β¦ Ο ^ (finrank β V / 2 : β) * Real.exp (-Ο^2 * βwβ^2)
have A : Tendsto (fun (c : β) β¦ β« w : V, (c ^ finrank β V * Ο (c β’ (v - w))) β’ f w)
atTop (π (f v)) := by
apply tendsto_integral_comp_smul_smul_of_integrable'
Β· exact fun x β¦ by positivity
Β· rw [integral_const_mul, GaussianFourier.integral_rexp_neg_mul_sq_norm (by positivity)]
nth_rewrite 2 [β pow_one Ο]
rw [β rpow_natCast, β rpow_natCast, β rpow_sub pi_pos, β rpow_mul pi_nonneg,
β rpow_add pi_pos]
ring_nf
exact rpow_zero _
Β· have A : Tendsto (fun (w : V) β¦ Ο^2 * βwβ^2) (cobounded V) atTop := by
rw [tendsto_const_mul_atTop_of_pos (by positivity)]
apply (tendsto_pow_atTop two_ne_zero).comp tendsto_norm_cobounded_atTop
have B := tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (finrank β V / 2) 1
zero_lt_one |>.comp A |>.const_mul (Ο ^ (-finrank β V / 2 : β))
rw [mul_zero] at B
convert B using 2 with x
simp only [neg_mul, one_mul, Function.comp_apply, β mul_assoc, β rpow_natCast, Ο]
congr 1
rw [mul_rpow (by positivity) (by positivity), β rpow_mul pi_nonneg,
β rpow_mul (norm_nonneg _), β mul_assoc, β rpow_add pi_pos, mul_comm]
congr <;> ring
Β· exact hf
Β· exact h'f
have B : Tendsto
(fun (c : β) β¦ β« w : V, ((c^(1/2 : β)) ^ finrank β V * Ο ((c^(1/2 : β)) β’ (v - w))) β’ f w)
atTop (π (f v)) :=
A.comp (tendsto_rpow_atTop (by simp))
apply B.congr'
filter_upwards [Ioi_mem_atTop 0] with c (hc : 0 < c)
congr with w
rw [β coe_smul]
congr
rw [ofReal_mul, ofReal_mul, ofReal_exp, β mul_assoc]
congr
Β· rw [mul_cpow_ofReal_nonneg pi_nonneg hc.le, β rpow_natCast, β rpow_mul hc.le, mul_comm,
ofReal_cpow pi_nonneg, ofReal_cpow hc.le]
simp [div_eq_inv_mul]
Β· norm_cast
simp only [one_div, norm_smul, Real.norm_eq_abs, mul_pow, sq_abs, neg_mul, neg_inj,
β rpow_natCast, β rpow_mul hc.le, mul_assoc]
norm_num
end Real
variable [CompleteSpace E]
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is integrable, and its Fourier transform `π f` is also integrable, then `πβ» (π f) = f` at
continuity points of `f`. -/
theorem MeasureTheory.Integrable.fourier_inversion
(hf : Integrable f) (h'f : Integrable (π f)) {v : V}
(hv : ContinuousAt f v) : πβ» (π f) v = f v :=
tendsto_nhds_unique (Real.tendsto_integral_gaussian_smul hf h'f v)
(Real.tendsto_integral_gaussian_smul' hf hv)
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is continuous, integrable, and its Fourier transform `π f` is also integrable,
then `πβ» (π f) = f`. -/
theorem Continuous.fourier_inversion (h : Continuous f)
(hf : Integrable f) (h'f : Integrable (π f)) :
πβ» (π f) = f := by
ext v
exact hf.fourier_inversion h'f h.continuousAt
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is integrable, and its Fourier transform `π f` is also integrable, then `π (πβ» f) = f` at
continuity points of `f`. -/
theorem MeasureTheory.Integrable.fourier_inversion_inv
(hf : Integrable f) (h'f : Integrable (π f)) {v : V}
(hv : ContinuousAt f v) : π (πβ» f) v = f v := by
rw [fourierIntegralInv_comm]
exact fourier_inversion hf h'f hv
/-- **Fourier inversion formula**: If a function `f` on a finite-dimensional real inner product
space is continuous, integrable, and its Fourier transform `π f` is also integrable,
then `π (πβ» f) = f`. -/
theorem Continuous.fourier_inversion_inv (h : Continuous f)
(hf : Integrable f) (h'f : Integrable (π f)) :
π (πβ» f) = f := by
ext v
exact hf.fourier_inversion_inv h'f h.continuousAt
|
Basic.lean
|
/-
Copyright (c) 2018 Mario Carneiro, Kevin Buzzard. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Kevin Buzzard
-/
import Mathlib.Algebra.Order.PartialSups
import Mathlib.LinearAlgebra.Quotient.Basic
import Mathlib.RingTheory.Noetherian.Defs
import Mathlib.RingTheory.Finiteness.Cardinality
import Mathlib.RingTheory.Finiteness.Finsupp
import Mathlib.RingTheory.Ideal.Prod
/-!
# Noetherian rings and modules
The following are equivalent for a module M over a ring R:
1. Every increasing chain of submodules Mβ β Mβ β Mβ β β― eventually stabilises.
2. Every submodule is finitely generated.
A module satisfying these equivalent conditions is said to be a *Noetherian* R-module.
A ring is a *Noetherian ring* if it is Noetherian as a module over itself.
(Note that we do not assume yet that our rings are commutative,
so perhaps this should be called "left Noetherian".
To avoid cumbersome names once we specialize to the commutative case,
we don't make this explicit in the declaration names.)
## Main definitions
Let `R` be a ring and let `M` and `P` be `R`-modules. Let `N` be an `R`-submodule of `M`.
* `IsNoetherian R M` is the proposition that `M` is a Noetherian `R`-module. It is a class,
implemented as the predicate that all `R`-submodules of `M` are finitely generated.
## Main statements
* `isNoetherian_iff` is the theorem that an R-module M is Noetherian iff `>` is well-founded on
`Submodule R M`.
Note that the Hilbert basis theorem, that if a commutative ring R is Noetherian then so is R[X],
is proved in `RingTheory.Polynomial`.
## References
* [M. F. Atiyah and I. G. Macdonald, *Introduction to commutative algebra*][atiyah-macdonald]
* [P. Samuel, *Algebraic Theory of Numbers*][samuel1967]
## Tags
Noetherian, noetherian, Noetherian ring, Noetherian module, noetherian ring, noetherian module
-/
assert_not_exists Matrix
open Set Pointwise
section
variable {R M P : Type*}
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid P]
variable [Module R M] [Module R P]
open IsNoetherian
variable (M) in
theorem isNoetherian_of_surjective (f : M ββ[R] P) (hf : LinearMap.range f = β€) [IsNoetherian R M] :
IsNoetherian R P :=
β¨fun s =>
have : (s.comap f).map f = s := Submodule.map_comap_eq_self <| hf.symm βΈ le_top
this βΈ (noetherian _).map _β©
instance isNoetherian_range (f : M ββ[R] P) [IsNoetherian R M] :
IsNoetherian R (LinearMap.range f) :=
isNoetherian_of_surjective _ _ f.range_rangeRestrict
instance isNoetherian_quotient {A M : Type*} [Ring A] [AddCommGroup M] [SMul R A] [Module R M]
[Module A M] [IsScalarTower R A M] (N : Submodule A M) [IsNoetherian R M] :
IsNoetherian R (M β§Έ N) :=
isNoetherian_of_surjective M ((Submodule.mkQ N).restrictScalars R) <|
LinearMap.range_eq_top.mpr N.mkQ_surjective
theorem isNoetherian_of_linearEquiv (f : M ββ[R] P) [IsNoetherian R M] : IsNoetherian R P :=
isNoetherian_of_surjective _ f.toLinearMap f.range
theorem LinearEquiv.isNoetherian_iff (f : M ββ[R] P) : IsNoetherian R M β IsNoetherian R P :=
β¨fun _ β¦ isNoetherian_of_linearEquiv f, fun _ β¦ isNoetherian_of_linearEquiv f.symmβ©
theorem isNoetherian_top_iff : IsNoetherian R (β€ : Submodule R M) β IsNoetherian R M :=
Submodule.topEquiv.isNoetherian_iff
theorem isNoetherian_of_injective [IsNoetherian R P] (f : M ββ[R] P) (hf : Function.Injective f) :
IsNoetherian R M :=
isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f hf).symm
theorem fg_of_injective [IsNoetherian R P] {N : Submodule R M} (f : M ββ[R] P)
(hf : Function.Injective f) : N.FG :=
haveI := isNoetherian_of_injective f hf
IsNoetherian.noetherian N
end
namespace Module
variable {R M N : Type*}
variable [Semiring R] [AddCommMonoid M] [AddCommMonoid N] [Module R M] [Module R N]
variable (R M)
-- see Note [lower instance priority]
instance (priority := 80) _root_.isNoetherian_of_finite [Finite M] : IsNoetherian R M :=
β¨fun s => β¨(s : Set M).toFinite.toFinset, by rw [Set.Finite.coe_toFinset, Submodule.span_eq]β©β©
-- see Note [lower instance priority]
instance (priority := 100) IsNoetherian.finite [IsNoetherian R M] : Module.Finite R M :=
β¨IsNoetherian.noetherian β€β©
instance {Rβ S : Type*} [CommSemiring Rβ] [Semiring S] [Algebra Rβ S]
[IsNoetherian Rβ S] (I : Ideal S) : Module.Finite Rβ I :=
IsNoetherian.finite Rβ ((I : Submodule S S).restrictScalars Rβ)
variable {R M}
theorem Finite.of_injective [IsNoetherian R N] (f : M ββ[R] N) (hf : Function.Injective f) :
Module.Finite R M :=
β¨fg_of_injective f hfβ©
end Module
section
variable {R M N P : Type*}
variable [Ring R] [AddCommGroup M] [AddCommGroup N] [AddCommGroup P]
variable [Module R M] [Module R N] [Module R P]
open IsNoetherian
theorem isNoetherian_of_ker_bot [IsNoetherian R P] (f : M ββ[R] P) (hf : LinearMap.ker f = β₯) :
IsNoetherian R M :=
isNoetherian_of_linearEquiv (LinearEquiv.ofInjective f <| LinearMap.ker_eq_bot.mp hf).symm
theorem fg_of_ker_bot [IsNoetherian R P] {N : Submodule R M} (f : M ββ[R] P)
(hf : LinearMap.ker f = β₯) : N.FG :=
haveI := isNoetherian_of_ker_bot f hf
IsNoetherian.noetherian N
-- False over a semiring: β is a Noetherian β-module but β Γ β is not.
instance isNoetherian_prod [IsNoetherian R M] [IsNoetherian R P] : IsNoetherian R (M Γ P) :=
β¨fun s =>
Submodule.fg_of_fg_map_of_fg_inf_ker (LinearMap.snd R M P) (noetherian _) <|
have : s β LinearMap.ker (LinearMap.snd R M P) β€ LinearMap.range (LinearMap.inl R M P) :=
fun x β¨_, hx2β© => β¨x.1, Prod.ext rfl <| Eq.symm <| LinearMap.mem_ker.1 hx2β©
Submodule.map_comap_eq_self this βΈ (noetherian _).map _β©
instance isNoetherian_sup (Mβ Mβ : Submodule R P) [IsNoetherian R Mβ] [IsNoetherian R Mβ] :
IsNoetherian R β₯(Mβ β Mβ) := by
have := isNoetherian_range (Mβ.subtype.coprod Mβ.subtype)
rwa [LinearMap.range_coprod, Submodule.range_subtype, Submodule.range_subtype] at this
variable {ΞΉ : Type*} [Finite ΞΉ]
instance isNoetherian_pi :
β {M : ΞΉ β Type*} [β i, AddCommGroup (M i)]
[β i, Module R (M i)] [β i, IsNoetherian R (M i)], IsNoetherian R (Ξ i, M i) := by
apply Finite.induction_empty_option _ _ _ ΞΉ
Β· exact fun e h β¦ isNoetherian_of_linearEquiv (LinearEquiv.piCongrLeft R _ e)
Β· infer_instance
Β· exact fun ih β¦ isNoetherian_of_linearEquiv (LinearEquiv.piOptionEquivProd R).symm
/-- A version of `isNoetherian_pi` for non-dependent functions. We need this instance because
sometimes Lean fails to apply the dependent version in non-dependent settings (e.g., it fails to
prove that `ΞΉ β β` is finite dimensional over `β`). -/
instance isNoetherian_pi' [IsNoetherian R M] : IsNoetherian R (ΞΉ β M) :=
isNoetherian_pi
instance isNoetherian_iSup :
β {M : ΞΉ β Submodule R P} [β i, IsNoetherian R (M i)], IsNoetherian R β₯(β¨ i, M i) := by
apply Finite.induction_empty_option _ _ _ ΞΉ
Β· intro _ _ e h _ _; rw [β e.iSup_comp]; apply h
Β· intros; rw [iSup_of_empty]; infer_instance
Β· intro _ _ ih _ _; rw [iSup_option]; infer_instance
/-- If the first and final modules in an exact sequence are Noetherian,
then the middle module is also Noetherian. -/
theorem isNoetherian_of_range_eq_ker [IsNoetherian R M] [IsNoetherian R P]
(f : M ββ[R] N) (g : N ββ[R] P) (h : LinearMap.range f = LinearMap.ker g) :
IsNoetherian R N :=
isNoetherian_mk <|
wellFounded_gt_exact_sequence
(LinearMap.range f)
(Submodule.map ((LinearMap.ker f).liftQ f le_rfl))
(Submodule.comap ((LinearMap.ker f).liftQ f le_rfl))
(Submodule.comap g.rangeRestrict) (Submodule.map g.rangeRestrict)
(Submodule.gciMapComap <| LinearMap.ker_eq_bot.mp <| Submodule.ker_liftQ_eq_bot _ _ _ le_rfl)
(Submodule.giMapComap g.surjective_rangeRestrict)
(by simp [Submodule.map_comap_eq, inf_comm, Submodule.range_liftQ])
(by simp [Submodule.comap_map_eq, h])
theorem isNoetherian_iff_submodule_quotient (S : Submodule R P) :
IsNoetherian R P β IsNoetherian R S β§ IsNoetherian R (P β§Έ S) := by
refine β¨fun _ β¦ β¨inferInstance, inferInstanceβ©, fun β¨_, _β© β¦ ?_β©
apply isNoetherian_of_range_eq_ker S.subtype S.mkQ
rw [Submodule.ker_mkQ, Submodule.range_subtype]
end
section CommRing
variable (R M N : Type*) [CommRing R] [AddCommGroup M] [AddCommGroup N] [Module R M] [Module R N]
[IsNoetherian R M] [Module.Finite R N]
instance isNoetherian_linearMap_pi {ΞΉ : Type*} [Finite ΞΉ] : IsNoetherian R ((ΞΉ β R) ββ[R] M) :=
let _i : Fintype ΞΉ := Fintype.ofFinite ΞΉ; isNoetherian_of_linearEquiv (Module.piEquiv ΞΉ R M)
instance isNoetherian_linearMap : IsNoetherian R (N ββ[R] M) := by
obtain β¨n, f, hfβ© := Module.Finite.exists_fin' R N
let g : (N ββ[R] M) ββ[R] (Fin n β R) ββ[R] M := (LinearMap.llcomp R (Fin n β R) N M).flip f
exact isNoetherian_of_injective g hf.injective_linearMapComp_right
end CommRing
open IsNoetherian Submodule Function
section
variable {R M : Type*} [Semiring R] [AddCommMonoid M] [Module R M]
/-- If `β I > J, P I` implies `P J`, then `P` holds for all submodules. -/
theorem IsNoetherian.induction [IsNoetherian R M] {P : Submodule R M β Prop}
(hgt : β I, (β J > I, P J) β P I) (I : Submodule R M) : P I :=
IsWellFounded.induction _ I hgt
theorem LinearMap.isNoetherian_iff_of_bijective {S P} [Semiring S] [AddCommMonoid P] [Module S P]
{Ο : R β+* S} [RingHomSurjective Ο] (l : M βββ[Ο] P) (hl : Function.Bijective l) :
IsNoetherian R M β IsNoetherian S P := by
simp_rw [isNoetherian_iff']
let e := Submodule.orderIsoMapComapOfBijective l hl
exact β¨fun _ β¦ e.symm.strictMono.wellFoundedGT, fun _ β¦ e.strictMono.wellFoundedGTβ©
end
section
variable {R M N P : Type*} [Semiring R] [AddCommMonoid M] [Module R M] [IsNoetherian R M]
lemma Submodule.finite_ne_bot_of_iSupIndep {ΞΉ : Type*} {N : ΞΉ β Submodule R M}
(h : iSupIndep N) :
Set.Finite {i | N i β β₯} :=
WellFoundedGT.finite_ne_bot_of_iSupIndep h
/-- A linearly-independent family of vectors in a module over a non-trivial ring must be finite if
the module is Noetherian. -/
theorem LinearIndependent.finite_of_isNoetherian [Nontrivial R] {ΞΉ} {v : ΞΉ β M}
(hv : LinearIndependent R v) : Finite ΞΉ := by
refine WellFoundedGT.finite_of_iSupIndep
hv.iSupIndep_span_singleton
fun i contra => ?_
apply hv.ne_zero i
have : v i β R β v i := Submodule.mem_span_singleton_self (v i)
rwa [contra, Submodule.mem_bot] at this
theorem LinearIndependent.set_finite_of_isNoetherian [Nontrivial R] {s : Set M}
(hi : LinearIndependent R ((β) : s β M)) : s.Finite :=
@Set.toFinite _ _ hi.finite_of_isNoetherian
/-- A sequence `f` of submodules of a noetherian module,
with `f (n+1)` disjoint from the supremum of `f 0`, ..., `f n`,
is eventually zero. -/
theorem IsNoetherian.disjoint_partialSups_eventually_bot
(f : β β Submodule R M) (h : β n, Disjoint (partialSups f n) (f (n + 1))) :
β n : β, β m, n β€ m β f m = β₯ := by
-- A little off-by-one cleanup first:
suffices t : β n : β, β m, n β€ m β f (m + 1) = β₯ by
obtain β¨n, wβ© := t
use n + 1
rintro (_ | m) p
Β· cases p
Β· apply w
exact Nat.succ_le_succ_iff.mp p
obtain β¨n, wβ© := monotone_stabilizes_iff_noetherian.mpr inferInstance (partialSups f)
refine β¨n, fun m p β¦ (h m).eq_bot_of_ge <| sup_eq_left.mp ?_β©
simpa only [partialSups_add_one] using (w (m + 1) <| le_add_right p).symm.trans <| w m p
end
-- see Note [lower instance priority]
/-- Modules over the trivial ring are Noetherian. -/
instance (priority := 100) isNoetherian_of_subsingleton (R M) [Subsingleton R] [Semiring R]
[AddCommMonoid M] [Module R M] : IsNoetherian R M :=
haveI := Module.subsingleton R M
isNoetherian_of_finite R M
theorem isNoetherian_of_submodule_of_noetherian (R M) [Semiring R] [AddCommMonoid M] [Module R M]
(N : Submodule R M) (h : IsNoetherian R M) : IsNoetherian R N :=
isNoetherian_mk β¨OrderEmbedding.wellFounded (Submodule.MapSubtype.orderEmbedding N).dual h.wfβ©
/-- If `M / S / R` is a scalar tower, and `M / R` is Noetherian, then `M / S` is
also noetherian. -/
theorem isNoetherian_of_tower (R) {S M} [Semiring R] [Semiring S] [AddCommMonoid M] [SMul R S]
[Module S M] [Module R M] [IsScalarTower R S M] (h : IsNoetherian R M) : IsNoetherian S M :=
isNoetherian_mk β¨(Submodule.restrictScalarsEmbedding R S M).dual.wellFounded h.wfβ©
instance isNoetherian_of_isNoetherianRing_of_finite (R M : Type*)
[Ring R] [AddCommGroup M] [Module R M] [IsNoetherianRing R] [Module.Finite R M] :
IsNoetherian R M :=
have β¨_, _, hβ© := Module.Finite.exists_fin' R M
isNoetherian_of_surjective _ _ (LinearMap.range_eq_top.mpr h)
theorem isNoetherian_of_fg_of_noetherian {R M} [Ring R] [AddCommGroup M] [Module R M]
(N : Submodule R M) [I : IsNoetherianRing R] (hN : N.FG) : IsNoetherian R N := by
rw [β Module.Finite.iff_fg] at hN; infer_instance
/-- In a module over a Noetherian ring, the submodule generated by finitely many vectors is
Noetherian. -/
theorem isNoetherian_span_of_finite (R) {M} [Ring R] [AddCommGroup M] [Module R M]
[IsNoetherianRing R] {A : Set M} (hA : A.Finite) : IsNoetherian R (Submodule.span R A) :=
isNoetherian_of_fg_of_noetherian _ (Submodule.fg_def.mpr β¨A, hA, rflβ©)
theorem IsNoetherianRing.of_finite (R S) [Ring R] [Ring S] [Module R S] [IsScalarTower R S S]
[IsNoetherianRing R] [Module.Finite R S] : IsNoetherianRing S :=
isNoetherian_of_tower R inferInstance
theorem isNoetherianRing_of_surjective (R) [Semiring R] (S) [Semiring S] (f : R β+* S)
(hf : Function.Surjective f) [H : IsNoetherianRing R] : IsNoetherianRing S :=
isNoetherian_mk β¨OrderEmbedding.wellFounded (Ideal.orderEmbeddingOfSurjective f hf).dual H.wfβ©
instance isNoetherianRing_rangeS {R} [Semiring R] {S} [Semiring S] (f : R β+* S)
[IsNoetherianRing R] : IsNoetherianRing f.rangeS :=
isNoetherianRing_of_surjective R f.rangeS f.rangeSRestrict f.rangeSRestrict_surjective
instance isNoetherianRing_range {R} [Ring R] {S} [Ring S] (f : R β+* S)
[IsNoetherianRing R] : IsNoetherianRing f.range :=
isNoetherianRing_rangeS f
theorem isNoetherianRing_of_ringEquiv (R) [Semiring R] {S} [Semiring S] (f : R β+* S)
[IsNoetherianRing R] : IsNoetherianRing S :=
isNoetherianRing_of_surjective R S f.toRingHom f.toEquiv.surjective
instance {R S} [Semiring R] [Semiring S] [IsNoetherianRing R] [IsNoetherianRing S] :
IsNoetherianRing (R Γ S) := by
rw [IsNoetherianRing, isNoetherian_iff'] at *
exact Ideal.idealProdEquiv.toOrderEmbedding.wellFoundedGT
instance {ΞΉ} [Finite ΞΉ] : β {R : ΞΉ β Type*} [Ξ i, Semiring (R i)] [β i, IsNoetherianRing (R i)],
IsNoetherianRing (Ξ i, R i) := by
apply Finite.induction_empty_option _ _ _ ΞΉ
Β· exact fun e h β¦ isNoetherianRing_of_ringEquiv _ (.piCongrLeft _ e)
Β· infer_instance
Β· exact fun ih β¦ isNoetherianRing_of_ringEquiv _ (.symm .piOptionEquivProd)
|
Equicontinuity.lean
|
/-
Copyright (c) 2022 Anatole Dedecker. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Anatole Dedecker
-/
import Mathlib.Topology.UniformSpace.Equicontinuity
import Mathlib.Topology.MetricSpace.Pseudo.Lemmas
/-!
# Equicontinuity in metric spaces
This files contains various facts about (uniform) equicontinuity in metric spaces. Most
importantly, we prove the usual characterization of equicontinuity of `F` at `xβ` in the case of
(pseudo) metric spaces: `β Ξ΅ > 0, β Ξ΄ > 0, β x, dist x xβ < Ξ΄ β β i, dist (F i xβ) (F i x) < Ξ΅`,
and we prove that functions sharing a common (local or global) continuity modulus are
(locally or uniformly) equicontinuous.
## Main statements
* `Metric.equicontinuousAt_iff`: characterization of equicontinuity for families of functions
between (pseudo) metric spaces.
* `Metric.equicontinuousAt_of_continuity_modulus`: convenient way to prove equicontinuity at a
point of a family of functions to a (pseudo) metric space by showing that they share a common
*local* continuity modulus.
* `Metric.uniformEquicontinuous_of_continuity_modulus`: convenient way to prove uniform
equicontinuity of a family of functions to a (pseudo) metric space by showing that they share a
common *global* continuity modulus.
## Tags
equicontinuity, continuity modulus
-/
open Filter Topology Uniformity
variable {Ξ± Ξ² ΞΉ : Type*} [PseudoMetricSpace Ξ±]
namespace Metric
/-- Characterization of equicontinuity for families of functions taking values in a (pseudo) metric
space. -/
theorem equicontinuousAt_iff_right {ΞΉ : Type*} [TopologicalSpace Ξ²] {F : ΞΉ β Ξ² β Ξ±} {xβ : Ξ²} :
EquicontinuousAt F xβ β β Ξ΅ > 0, βαΆ x in π xβ, β i, dist (F i xβ) (F i x) < Ξ΅ :=
uniformity_basis_dist.equicontinuousAt_iff_right
/-- Characterization of equicontinuity for families of functions between (pseudo) metric spaces. -/
theorem equicontinuousAt_iff {ΞΉ : Type*} [PseudoMetricSpace Ξ²] {F : ΞΉ β Ξ² β Ξ±} {xβ : Ξ²} :
EquicontinuousAt F xβ β β Ξ΅ > 0, β Ξ΄ > 0, β x, dist x xβ < Ξ΄ β β i, dist (F i xβ) (F i x) < Ξ΅ :=
nhds_basis_ball.equicontinuousAt_iff uniformity_basis_dist
/-- Reformulation of `equicontinuousAt_iff_pair` for families of functions taking values in a
(pseudo) metric space. -/
protected theorem equicontinuousAt_iff_pair {ΞΉ : Type*} [TopologicalSpace Ξ²] {F : ΞΉ β Ξ² β Ξ±}
{xβ : Ξ²} :
EquicontinuousAt F xβ β
β Ξ΅ > 0, β U β π xβ, β x β U, β x' β U, β i, dist (F i x) (F i x') < Ξ΅ := by
rw [equicontinuousAt_iff_pair]
constructor <;> intro H
Β· intro Ξ΅ hΞ΅
exact H _ (dist_mem_uniformity hΞ΅)
Β· intro U hU
rcases mem_uniformity_dist.mp hU with β¨Ξ΅, hΞ΅, hΞ΅Uβ©
refine Exists.imp (fun V => And.imp_right fun h => ?_) (H _ hΞ΅)
exact fun x hx x' hx' i => hΞ΅U (h _ hx _ hx' i)
/-- Characterization of uniform equicontinuity for families of functions taking values in a
(pseudo) metric space. -/
theorem uniformEquicontinuous_iff_right {ΞΉ : Type*} [UniformSpace Ξ²] {F : ΞΉ β Ξ² β Ξ±} :
UniformEquicontinuous F β β Ξ΅ > 0, βαΆ xy : Ξ² Γ Ξ² in π€ Ξ², β i, dist (F i xy.1) (F i xy.2) < Ξ΅ :=
uniformity_basis_dist.uniformEquicontinuous_iff_right
/-- Characterization of uniform equicontinuity for families of functions between
(pseudo) metric spaces. -/
theorem uniformEquicontinuous_iff {ΞΉ : Type*} [PseudoMetricSpace Ξ²] {F : ΞΉ β Ξ² β Ξ±} :
UniformEquicontinuous F β
β Ξ΅ > 0, β Ξ΄ > 0, β x y, dist x y < Ξ΄ β β i, dist (F i x) (F i y) < Ξ΅ :=
uniformity_basis_dist.uniformEquicontinuous_iff uniformity_basis_dist
/-- For a family of functions to a (pseudo) metric spaces, a convenient way to prove
equicontinuity at a point is to show that all of the functions share a common *local* continuity
modulus. -/
theorem equicontinuousAt_of_continuity_modulus {ΞΉ : Type*} [TopologicalSpace Ξ²] {xβ : Ξ²}
(b : Ξ² β β) (b_lim : Tendsto b (π xβ) (π 0)) (F : ΞΉ β Ξ² β Ξ±)
(H : βαΆ x in π xβ, β i, dist (F i xβ) (F i x) β€ b x) : EquicontinuousAt F xβ := by
rw [Metric.equicontinuousAt_iff_right]
intro Ξ΅ Ξ΅0
-- Porting note: Lean 3 didn't need `Filter.mem_map.mp` here
filter_upwards [Filter.mem_map.mp <| b_lim (Iio_mem_nhds Ξ΅0), H] using
fun x hxβ hxβ i => (hxβ i).trans_lt hxβ
/-- For a family of functions between (pseudo) metric spaces, a convenient way to prove
uniform equicontinuity is to show that all of the functions share a common *global* continuity
modulus. -/
theorem uniformEquicontinuous_of_continuity_modulus {ΞΉ : Type*} [PseudoMetricSpace Ξ²] (b : β β β)
(b_lim : Tendsto b (π 0) (π 0)) (F : ΞΉ β Ξ² β Ξ±)
(H : β (x y : Ξ²) (i), dist (F i x) (F i y) β€ b (dist x y)) : UniformEquicontinuous F := by
rw [Metric.uniformEquicontinuous_iff]
intro Ξ΅ Ξ΅0
rcases tendsto_nhds_nhds.1 b_lim Ξ΅ Ξ΅0 with β¨Ξ΄, Ξ΄0, hΞ΄β©
refine β¨Ξ΄, Ξ΄0, fun x y hxy i => ?_β©
calc
dist (F i x) (F i y) β€ b (dist x y) := H x y i
_ β€ |b (dist x y)| := le_abs_self _
_ = dist (b (dist x y)) 0 := by simp [Real.dist_eq]
_ < Ξ΅ := hΞ΄ (by simpa only [Real.dist_eq, tsub_zero, abs_dist] using hxy)
/-- For a family of functions between (pseudo) metric spaces, a convenient way to prove
equicontinuity is to show that all of the functions share a common *global* continuity modulus. -/
theorem equicontinuous_of_continuity_modulus {ΞΉ : Type*} [PseudoMetricSpace Ξ²] (b : β β β)
(b_lim : Tendsto b (π 0) (π 0)) (F : ΞΉ β Ξ² β Ξ±)
(H : β (x y : Ξ²) (i), dist (F i x) (F i y) β€ b (dist x y)) : Equicontinuous F :=
(uniformEquicontinuous_of_continuity_modulus b b_lim F H).equicontinuous
end Metric
|
ExistsUnique.lean
|
/-
Copyright (c) 2014 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura, Jeremy Avigad, Floris van Doorn
-/
import Mathlib.Tactic.TypeStar
import Batteries.Tactic.Alias
/-!
# `ExistsUnique`
This file defines the `ExistsUnique` predicate, notated as `β!`, and proves some of its
basic properties.
-/
variable {Ξ± : Sort*}
/-- For `p : Ξ± β Prop`, `ExistsUnique p` means that there exists a unique `x : Ξ±` with `p x`. -/
def ExistsUnique (p : Ξ± β Prop) := β x, p x β§ β y, p y β y = x
namespace Mathlib.Notation
open Lean
/-- Checks to see that `xs` has only one binder. -/
def isExplicitBinderSingular (xs : TSyntax ``explicitBinders) : Bool :=
match xs with
| `(explicitBinders| $_:binderIdent $[: $_]?) => true
| `(explicitBinders| ($_:binderIdent : $_)) => true
| _ => false
open TSyntax.Compat in
/--
`β! x : Ξ±, p x` means that there exists a unique `x` in `Ξ±` such that `p x`.
This is notation for `ExistsUnique (fun (x : Ξ±) β¦ p x)`.
This notation does not allow multiple binders like `β! (x : Ξ±) (y : Ξ²), p x y`
as a shorthand for `β! (x : Ξ±), β! (y : Ξ²), p x y` since it is liable to be misunderstood.
Often, the intended meaning is instead `β! q : Ξ± Γ Ξ², p q.1 q.2`.
-/
macro "β!" xs:explicitBinders ", " b:term : term => do
if !isExplicitBinderSingular xs then
Macro.throwErrorAt xs "\
The `ExistsUnique` notation should not be used with more than one binder.\n\
\n\
The reason for this is that `β! (x : Ξ±), β! (y : Ξ²), p x y` has a completely different \
meaning from `β! q : Ξ± Γ Ξ², p q.1 q.2`. \
To prevent confusion, this notation requires that you be explicit \
and use one with the correct interpretation."
expandExplicitBinders ``ExistsUnique xs b
/--
Pretty-printing for `ExistsUnique`, following the same pattern as pretty printing for `Exists`.
However, it does *not* merge binders.
-/
@[app_unexpander ExistsUnique] def unexpandExistsUnique : Lean.PrettyPrinter.Unexpander
| `($(_) fun $x:ident β¦ $b) => `(β! $x:ident, $b)
| `($(_) fun ($x:ident : $t) β¦ $b) => `(β! $x:ident : $t, $b)
| _ => throw ()
/--
`β! x β s, p x` means `β! x, x β s β§ p x`, which is to say that there exists a unique `x β s`
such that `p x`.
Similarly, notations such as `β! x β€ n, p n` are supported,
using any relation defined using the `binder_predicate` command.
-/
syntax "β! " binderIdent binderPred ", " term : term
macro_rules
| `(β! $x:ident $p:binderPred, $b) => `(β! $x:ident, satisfies_binder_pred% $x $p β§ $b)
| `(β! _ $p:binderPred, $b) => `(β! x, satisfies_binder_pred% x $p β§ $b)
end Mathlib.Notation
-- @[intro] -- TODO
theorem ExistsUnique.intro {p : Ξ± β Prop} (w : Ξ±)
(hβ : p w) (hβ : β y, p y β y = w) : β! x, p x := β¨w, hβ, hββ©
theorem ExistsUnique.elim {p : Ξ± β Prop} {b : Prop}
(hβ : β! x, p x) (hβ : β x, p x β (β y, p y β y = x) β b) : b :=
Exists.elim hβ (fun w hw β¦ hβ w (And.left hw) (And.right hw))
theorem existsUnique_of_exists_of_unique {p : Ξ± β Prop}
(hex : β x, p x) (hunique : β yβ yβ, p yβ β p yβ β yβ = yβ) : β! x, p x :=
Exists.elim hex (fun x px β¦ ExistsUnique.intro x px (fun y (h : p y) β¦ hunique y x h px))
theorem ExistsUnique.exists {p : Ξ± β Prop} : (β! x, p x) β β x, p x | β¨x, h, _β© => β¨x, hβ©
theorem ExistsUnique.unique {p : Ξ± β Prop}
(h : β! x, p x) {yβ yβ : Ξ±} (pyβ : p yβ) (pyβ : p yβ) : yβ = yβ :=
let β¨_, _, hyβ© := h; (hy _ pyβ).trans (hy _ pyβ).symm
-- TODO
-- attribute [congr] forall_congr'
-- attribute [congr] exists_congr'
-- @[congr]
theorem existsUnique_congr {p q : Ξ± β Prop} (h : β a, p a β q a) : (β! a, p a) β β! a, q a :=
exists_congr fun _ β¦ and_congr (h _) <| forall_congr' fun _ β¦ imp_congr_left (h _)
@[simp] theorem existsUnique_iff_exists [Subsingleton Ξ±] {p : Ξ± β Prop} :
(β! x, p x) β β x, p x :=
β¨fun h β¦ h.exists, Exists.imp fun x hx β¦ β¨hx, fun y _ β¦ Subsingleton.elim y xβ©β©
theorem existsUnique_const {b : Prop} (Ξ± : Sort*) [i : Nonempty Ξ±] [Subsingleton Ξ±] :
(β! _ : Ξ±, b) β b := by simp
@[simp] theorem existsUnique_eq {a' : Ξ±} : β! a, a = a' := by
simp only [eq_comm, ExistsUnique, and_self, forall_eq', exists_eq']
/-- The difference with `existsUnique_eq` is that the equality is reversed. -/
@[simp] theorem existsUnique_eq' {a' : Ξ±} : β! a, a' = a := by
simp only [ExistsUnique, and_self, forall_eq', exists_eq']
theorem existsUnique_prop {p q : Prop} : (β! _ : p, q) β p β§ q := by simp
@[simp] theorem existsUnique_false : Β¬β! _ : Ξ±, False := fun β¨_, h, _β© β¦ h
theorem existsUnique_prop_of_true {p : Prop} {q : p β Prop} (h : p) : (β! h' : p, q h') β q h :=
@existsUnique_const (q h) p β¨hβ© _
theorem ExistsUnique.elimβ {p : Ξ± β Sort*} [β x, Subsingleton (p x)]
{q : β (x) (_ : p x), Prop} {b : Prop} (hβ : β! x, β! h : p x, q x h)
(hβ : β (x) (h : p x), q x h β (β (y) (hy : p y), q y hy β y = x) β b) : b := by
simp only [existsUnique_iff_exists] at hβ
apply hβ.elim
exact fun x β¨hxp, hxqβ© H β¦ hβ x hxp hxq fun y hyp hyq β¦ H y β¨hyp, hyqβ©
theorem ExistsUnique.introβ {p : Ξ± β Sort*} [β x, Subsingleton (p x)]
{q : β (x : Ξ±) (_ : p x), Prop} (w : Ξ±) (hp : p w) (hq : q w hp)
(H : β (y) (hy : p y), q y hy β y = w) : β! x, β! hx : p x, q x hx := by
simp only [existsUnique_iff_exists]
exact ExistsUnique.intro w β¨hp, hqβ© fun y β¨hyp, hyqβ© β¦ H y hyp hyq
theorem ExistsUnique.existsβ {p : Ξ± β Sort*} {q : β (x : Ξ±) (_ : p x), Prop}
(h : β! x, β! hx : p x, q x hx) : β (x : _) (hx : p x), q x hx :=
h.exists.imp fun _ hx β¦ hx.exists
theorem ExistsUnique.uniqueβ {p : Ξ± β Sort*} [β x, Subsingleton (p x)]
{q : β (x : Ξ±) (_ : p x), Prop} (h : β! x, β! hx : p x, q x hx) {yβ yβ : Ξ±}
(hpyβ : p yβ) (hqyβ : q yβ hpyβ) (hpyβ : p yβ) (hqyβ : q yβ hpyβ) : yβ = yβ := by
simp only [existsUnique_iff_exists] at h
exact h.unique β¨hpyβ, hqyββ© β¨hpyβ, hqyββ©
/-- This invokes the two `Decidable` arguments $O(n)$ times. -/
instance List.decidableBExistsUnique {Ξ± : Type*} [DecidableEq Ξ±] (p : Ξ± β Prop) [DecidablePred p] :
(l : List Ξ±) β Decidable (β! x, x β l β§ p x)
| [] => .isFalse <| by simp
| x :: xs =>
if hx : p x then
decidable_of_iff (β y β xs, p y β x = y) (β¨fun h β¦ β¨x, by grindβ©,
fun β¨z, hβ© y hy hp β¦ (h.2 x β¨mem_cons_self, hxβ©).trans (by grind)β©)
else
have := List.decidableBExistsUnique p xs
decidable_of_iff (β! x, x β xs β§ p x) (by grind)
|
ProjectiveFamilyContent.lean
|
/-
Copyright (c) 2025 RΓ©my Degenne. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: RΓ©my Degenne, Peter Pfaffelhuber
-/
import Mathlib.MeasureTheory.Constructions.Projective
import Mathlib.MeasureTheory.Measure.AddContent
import Mathlib.MeasureTheory.SetAlgebra
/-!
# Additive content built from a projective family of measures
Let `P` be a projective family of measures on a family of measurable spaces indexed by `ΞΉ`.
That is, for each finite set `I` of indices, `P I` is a measure on `Ξ j : I, Ξ± j`, and for `J β I`,
the projection from `Ξ i : I, Ξ± i` to `Ξ i : J, Ξ± i` maps `P I` to `P J`.
We build an additive content `projectiveFamilyContent` on the measurable cylinders, by setting
`projectiveFamilyContent s = P I S` for `s = cylinder I S`, where `I` is a finite set of indices
and `S` is a measurable set in `Ξ i : I, Ξ± i`.
This content will be used to define the projective limit of the family of measures `P`.
For a countable index set and a projective family given by a sequence of kernels,
the projective limit is given by the Ionescu-Tulcea theorem.
For an arbitrary index set but under topological conditions on the spaces, this is the result of
the Kolmogorov extension theorem.
(both results are not yet in Mathlib)
## Main definitions
* `projectiveFamilyContent`: additive content on the measurable cylinders, defined from a projective
family of measures.
-/
open Finset
open scoped ENNReal
namespace MeasureTheory
variable {ΞΉ : Type*} {Ξ± : ΞΉ β Type*} {mΞ± : β i, MeasurableSpace (Ξ± i)}
{P : β J : Finset ΞΉ, Measure (Ξ j : J, Ξ± j)} {s t : Set (Ξ i, Ξ± i)} {I : Finset ΞΉ}
{S : Set (Ξ i : I, Ξ± i)}
section MeasurableCylinders
lemma isSetAlgebra_measurableCylinders : IsSetAlgebra (measurableCylinders Ξ±) where
empty_mem := empty_mem_measurableCylinders Ξ±
compl_mem _ := compl_mem_measurableCylinders
union_mem _ _ := union_mem_measurableCylinders
lemma isSetRing_measurableCylinders : IsSetRing (measurableCylinders Ξ±) :=
isSetAlgebra_measurableCylinders.isSetRing
lemma isSetSemiring_measurableCylinders : MeasureTheory.IsSetSemiring (measurableCylinders Ξ±) :=
isSetRing_measurableCylinders.isSetSemiring
end MeasurableCylinders
section ProjectiveFamilyFun
open Classical in
/-- For `P` a family of measures, with `P J` a measure on `Ξ j : J, Ξ± j`, we define a function
`projectiveFamilyFun P s` by setting it to `P I S` if `s = cylinder I S` for a measurable `S` and
to 0 if `s` is not a measurable cylinder. -/
noncomputable def projectiveFamilyFun (P : β J : Finset ΞΉ, Measure (Ξ j : J, Ξ± j))
(s : Set (Ξ i, Ξ± i)) : ββ₯0β :=
if hs : s β measurableCylinders Ξ±
then P (measurableCylinders.finset hs) (measurableCylinders.set hs) else 0
lemma projectiveFamilyFun_congr (hP : IsProjectiveMeasureFamily P)
(hs : s β measurableCylinders Ξ±) (hs_eq : s = cylinder I S) (hS : MeasurableSet S) :
projectiveFamilyFun P s = P I S := by
rw [projectiveFamilyFun, dif_pos hs]
exact hP.congr_cylinder (measurableCylinders.measurableSet hs) hS
((measurableCylinders.eq_cylinder hs).symm.trans hs_eq)
lemma projectiveFamilyFun_empty (hP : IsProjectiveMeasureFamily P) :
projectiveFamilyFun P β
= 0 := by
rw [projectiveFamilyFun_congr hP (empty_mem_measurableCylinders Ξ±) (cylinder_empty β
).symm
MeasurableSet.empty, measure_empty]
lemma projectiveFamilyFun_union (hP : IsProjectiveMeasureFamily P)
(hs : s β measurableCylinders Ξ±) (ht : t β measurableCylinders Ξ±) (hst : Disjoint s t) :
projectiveFamilyFun P (s βͺ t) = projectiveFamilyFun P s + projectiveFamilyFun P t := by
obtain β¨I, S, hS, hs_eqβ© := (mem_measurableCylinders _).1 hs
obtain β¨J, T, hT, ht_eqβ© := (mem_measurableCylinders _).1 ht
classical
let S' := restrictβ (subset_union_left (sβ := J)) β»ΒΉ' S
let T' := restrictβ (subset_union_right (sβ := I)) β»ΒΉ' T
have hS' : MeasurableSet S' := measurable_restrictβ _ hS
have hT' : MeasurableSet T' := measurable_restrictβ _ hT
have h_eq1 : s = cylinder (I βͺ J) S' := by rw [hs_eq]; exact cylinder_eq_cylinder_union I S J
have h_eq2 : t = cylinder (I βͺ J) T' := by rw [ht_eq]; exact cylinder_eq_cylinder_union J T I
have h_eq3 : s βͺ t = cylinder (I βͺ J) (S' βͺ T') := by
rw [hs_eq, ht_eq]; exact union_cylinder _ _ _ _
rw [projectiveFamilyFun_congr hP hs h_eq1 hS', projectiveFamilyFun_congr hP ht h_eq2 hT',
projectiveFamilyFun_congr hP (union_mem_measurableCylinders hs ht) h_eq3 (hS'.union hT')]
cases isEmpty_or_nonempty (Ξ i, Ξ± i) with
| inl h => simp [hP.eq_zero_of_isEmpty]
| inr h =>
rw [measure_union _ hT']
rwa [hs_eq, ht_eq, disjoint_cylinder_iff] at hst
end ProjectiveFamilyFun
section ProjectiveFamilyContent
/-- For `P` a projective family of measures, we define an additive content on the measurable
cylinders, by setting `projectiveFamilyContent s = P I S` for `s = cylinder I S`, where `I` is
a finite set of indices and `S` is a measurable set in `Ξ i : I, Ξ± i`. -/
noncomputable def projectiveFamilyContent (hP : IsProjectiveMeasureFamily P) :
AddContent (measurableCylinders Ξ±) :=
isSetRing_measurableCylinders.addContent_of_union (projectiveFamilyFun P)
(projectiveFamilyFun_empty hP) (projectiveFamilyFun_union hP)
lemma projectiveFamilyContent_eq (hP : IsProjectiveMeasureFamily P) :
projectiveFamilyContent hP s = projectiveFamilyFun P s := rfl
lemma projectiveFamilyContent_congr (hP : IsProjectiveMeasureFamily P) (s : Set (Ξ i, Ξ± i))
(hs_eq : s = cylinder I S) (hS : MeasurableSet S) :
projectiveFamilyContent hP s = P I S := by
rw [projectiveFamilyContent_eq,
projectiveFamilyFun_congr hP ((mem_measurableCylinders s).mpr β¨I, S, hS, hs_eqβ©) hs_eq hS]
lemma projectiveFamilyContent_cylinder (hP : IsProjectiveMeasureFamily P) (hS : MeasurableSet S) :
projectiveFamilyContent hP (cylinder I S) = P I S := projectiveFamilyContent_congr _ _ rfl hS
lemma projectiveFamilyContent_mono (hP : IsProjectiveMeasureFamily P)
(hs : s β measurableCylinders Ξ±) (ht : t β measurableCylinders Ξ±) (hst : s β t) :
projectiveFamilyContent hP s β€ projectiveFamilyContent hP t :=
addContent_mono isSetSemiring_measurableCylinders hs ht hst
lemma projectiveFamilyContent_iUnion_le (hP : IsProjectiveMeasureFamily P)
{s : β β Set (Ξ i : ΞΉ, Ξ± i)} (hs : β n, s n β measurableCylinders Ξ±) (n : β) :
projectiveFamilyContent hP (β i β€ n, s i)
β€ β i β range (n + 1), projectiveFamilyContent hP (s i) :=
calc projectiveFamilyContent hP (β i β€ n, s i)
_ = projectiveFamilyContent hP (β i β range (n + 1), s i) := by
simp only [mem_range_succ_iff]
_ β€ β i β range (n + 1), projectiveFamilyContent hP (s i) :=
addContent_biUnion_le isSetRing_measurableCylinders (fun i _ β¦ hs i)
lemma projectiveFamilyContent_ne_top [β J, IsFiniteMeasure (P J)]
(hP : IsProjectiveMeasureFamily P) :
projectiveFamilyContent hP s β β := by
rw [projectiveFamilyContent_eq hP, projectiveFamilyFun]
split_ifs with hs
Β· exact measure_ne_top _ _
Β· exact ENNReal.zero_ne_top
lemma projectiveFamilyContent_diff (hP : IsProjectiveMeasureFamily P)
(hs : s β measurableCylinders Ξ±) (ht : t β measurableCylinders Ξ±) :
projectiveFamilyContent hP s - projectiveFamilyContent hP t
β€ projectiveFamilyContent hP (s \ t) :=
le_addContent_diff (projectiveFamilyContent hP) isSetRing_measurableCylinders hs ht
lemma projectiveFamilyContent_diff_of_subset [β J, IsFiniteMeasure (P J)]
(hP : IsProjectiveMeasureFamily P) (hs : s β measurableCylinders Ξ±)
(ht : t β measurableCylinders Ξ±) (hts : t β s) :
projectiveFamilyContent hP (s \ t)
= projectiveFamilyContent hP s - projectiveFamilyContent hP t :=
addContent_diff_of_ne_top (projectiveFamilyContent hP) isSetRing_measurableCylinders
(fun _ _ β¦ projectiveFamilyContent_ne_top hP) hs ht hts
end ProjectiveFamilyContent
end MeasureTheory
|
Bitwise.lean
|
/-
Copyright (c) 2016 Jeremy Avigad. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad
-/
import Mathlib.Algebra.Ring.Int.Defs
import Mathlib.Data.Nat.Bitwise
import Mathlib.Data.Nat.Size
import Batteries.Data.Int
/-!
# Bitwise operations on integers
Possibly only of archaeological significance.
## Recursors
* `Int.bitCasesOn`: Parity disjunction. Something is true/defined on `β€` if it's true/defined for
even and for odd values.
-/
namespace Int
/-- `div2 n = n/2` -/
def div2 : β€ β β€
| (n : β) => n.div2
| -[n +1] => negSucc n.div2
/-- `bodd n` returns `true` if `n` is odd -/
def bodd : β€ β Bool
| (n : β) => n.bodd
| -[n +1] => not (n.bodd)
/-- `bit b` appends the digit `b` to the binary representation of
its integer input. -/
def bit (b : Bool) : β€ β β€ :=
cond b (2 * Β· + 1) (2 * Β·)
/-- `Int.natBitwise` is an auxiliary definition for `Int.bitwise`. -/
def natBitwise (f : Bool β Bool β Bool) (m n : β) : β€ :=
cond (f false false) -[ Nat.bitwise (fun x y => not (f x y)) m n +1] (Nat.bitwise f m n)
/-- `Int.bitwise` applies the function `f` to pairs of bits in the same position in
the binary representations of its inputs. -/
def bitwise (f : Bool β Bool β Bool) : β€ β β€ β β€
| (m : β), (n : β) => natBitwise f m n
| (m : β), -[n +1] => natBitwise (fun x y => f x (not y)) m n
| -[m +1], (n : β) => natBitwise (fun x y => f (not x) y) m n
| -[m +1], -[n +1] => natBitwise (fun x y => f (not x) (not y)) m n
/-- `lnot` flips all the bits in the binary representation of its input -/
def lnot : β€ β β€
| (m : β) => -[m +1]
| -[m +1] => m
/-- `lor` takes two integers and returns their bitwise `or` -/
def lor : β€ β β€ β β€
| (m : β), (n : β) => m ||| n
| (m : β), -[n +1] => -[Nat.ldiff n m +1]
| -[m +1], (n : β) => -[Nat.ldiff m n +1]
| -[m +1], -[n +1] => -[m &&& n +1]
/-- `land` takes two integers and returns their bitwise `and` -/
def land : β€ β β€ β β€
| (m : β), (n : β) => m &&& n
| (m : β), -[n +1] => Nat.ldiff m n
| -[m +1], (n : β) => Nat.ldiff n m
| -[m +1], -[n +1] => -[m ||| n +1]
/-- `ldiff a b` performs bitwise set difference. For each corresponding
pair of bits taken as booleans, say `aα΅’` and `bα΅’`, it applies the
boolean operation `aα΅’ β§ Β¬bα΅’` to obtain the `iα΅Κ°` bit of the result. -/
def ldiff : β€ β β€ β β€
| (m : β), (n : β) => Nat.ldiff m n
| (m : β), -[n +1] => m &&& n
| -[m +1], (n : β) => -[m ||| n +1]
| -[m +1], -[n +1] => Nat.ldiff n m
/-- `xor` computes the bitwise `xor` of two natural numbers -/
protected def xor : β€ β β€ β β€
| (m : β), (n : β) => (m ^^^ n)
| (m : β), -[n +1] => -[(m ^^^ n) +1]
| -[m +1], (n : β) => -[(m ^^^ n) +1]
| -[m +1], -[n +1] => (m ^^^ n)
/-- `m <<< n` produces an integer whose binary representation
is obtained by left-shifting the binary representation of `m` by `n` places -/
instance : ShiftLeft β€ where
shiftLeft
| (m : β), (n : β) => Nat.shiftLeft' false m n
| (m : β), -[n +1] => m >>> (Nat.succ n)
| -[m +1], (n : β) => -[Nat.shiftLeft' true m n +1]
| -[m +1], -[n +1] => -[m >>> (Nat.succ n) +1]
/-- `m >>> n` produces an integer whose binary representation
is obtained by right-shifting the binary representation of `m` by `n` places -/
instance : ShiftRight β€ where
shiftRight m n := m <<< (-n)
/-! ### bitwise ops -/
@[simp]
theorem bodd_zero : bodd 0 = false :=
rfl
@[simp]
theorem bodd_one : bodd 1 = true :=
rfl
theorem bodd_two : bodd 2 = false :=
rfl
@[simp, norm_cast]
theorem bodd_coe (n : β) : Int.bodd n = Nat.bodd n :=
rfl
@[simp]
theorem bodd_subNatNat (m n : β) : bodd (subNatNat m n) = xor m.bodd n.bodd := by
apply subNatNat_elim m n fun m n i => bodd i = xor m.bodd n.bodd <;>
intros i j <;>
simp only [Int.bodd, Nat.bodd_add] <;>
cases Nat.bodd i <;> simp
@[simp]
theorem bodd_negOfNat (n : β) : bodd (negOfNat n) = n.bodd := by
cases n <;> simp +decide
rfl
@[simp]
theorem bodd_neg (n : β€) : bodd (-n) = bodd n := by
cases n <;> simp only [β negOfNat_eq, bodd_negOfNat, neg_negSucc] <;> simp [bodd]
@[simp]
theorem bodd_add (m n : β€) : bodd (m + n) = xor (bodd m) (bodd n) := by
rcases m with m | m <;>
rcases n with n | n <;>
simp only [ofNat_eq_coe, ofNat_add_negSucc, negSucc_add_ofNat,
negSucc_add_negSucc, bodd_subNatNat, β Nat.cast_add] <;>
simp [bodd, Bool.xor_comm]
@[simp]
theorem bodd_mul (m n : β€) : bodd (m * n) = (bodd m && bodd n) := by
rcases m with m | m <;> rcases n with n | n <;>
simp only [ofNat_eq_coe, ofNat_mul_negSucc, negSucc_mul_ofNat, ofNat_mul_ofNat,
negSucc_mul_negSucc] <;>
simp only [negSucc_eq, β Int.natCast_succ, bodd_neg, bodd_coe, Nat.bodd_mul]
theorem bodd_add_div2 : β n, cond (bodd n) 1 0 + 2 * div2 n = n
| (n : β) => by
rw [show (cond (bodd n) 1 0 : β€) = (cond (bodd n) 1 0 : β) by cases bodd n <;> rfl]
exact congr_arg ofNat n.bodd_add_div2
| -[n+1] => by
refine Eq.trans ?_ (congr_arg negSucc n.bodd_add_div2)
dsimp [bodd]; cases Nat.bodd n <;> dsimp [cond, not, div2, Int.mul]
Β· change -[2 * Nat.div2 n+1] = _
rw [zero_add]
Β· rw [zero_add, add_comm]
rfl
theorem div2_val : β n, div2 n = n / 2
| (n : β) => congr_arg ofNat n.div2_val
| -[n+1] => congr_arg negSucc n.div2_val
theorem bit_val (b n) : bit b n = 2 * n + cond b 1 0 := by
cases b
Β· apply (add_zero _).symm
Β· rfl
theorem bit_decomp (n : β€) : bit (bodd n) (div2 n) = n :=
(bit_val _ _).trans <| (add_comm _ _).trans <| bodd_add_div2 _
/-- Defines a function from `β€` conditionally, if it is defined for odd and even integers separately
using `bit`. -/
def bitCasesOn.{u} {C : β€ β Sort u} (n) (h : β b n, C (bit b n)) : C n := by
rw [β bit_decomp n]
apply h
@[simp]
theorem bit_zero : bit false 0 = 0 :=
rfl
@[simp]
theorem bit_coe_nat (b) (n : β) : bit b n = Nat.bit b n := by
rw [bit_val, Nat.bit_val]
cases b <;> rfl
@[simp]
theorem bit_negSucc (b) (n : β) : bit b -[n+1] = -[Nat.bit (not b) n+1] := by
rw [bit_val, Nat.bit_val]
cases b <;> rfl
@[simp]
theorem bodd_bit (b n) : bodd (bit b n) = b := by
rw [bit_val]
cases b <;> cases bodd n <;> simp [(show bodd 2 = false by rfl)]
@[simp]
theorem testBit_bit_zero (b) : β n, testBit (bit b n) 0 = b
| (n : β) => by rw [bit_coe_nat]; apply Nat.testBit_bit_zero
| -[n+1] => by
rw [bit_negSucc]; dsimp [testBit]; rw [Nat.testBit_bit_zero]; clear testBit_bit_zero
cases b <;>
rfl
@[simp]
theorem testBit_bit_succ (m b) : β n, testBit (bit b n) (Nat.succ m) = testBit n m
| (n : β) => by rw [bit_coe_nat]; apply Nat.testBit_bit_succ
| -[n+1] => by
dsimp only [testBit]
simp only [bit_negSucc]
cases b <;> simp only [Bool.not_false, Bool.not_true, Nat.testBit_bit_succ]
-- Porting note (https://github.com/leanprover-community/mathlib4/issues/11215): TODO
-- private unsafe def bitwise_tac : tactic Unit :=
-- sorry
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_or : bitwise or = lor := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.or_true, cond_true, lor, Nat.ldiff,
negSucc.injEq, Bool.true_or]
Β· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
Β· simp
Β· congr
simp
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_and : bitwise and = land := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false,
cond_false, cond_true, Bool.and_true,
Bool.and_false]
Β· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
Β· congr
simp
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_diff : (bitwise fun a b => a && not b) = ldiff := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false,
cond_false, cond_true, Nat.ldiff, Bool.and_true, negSucc.injEq,
Bool.and_false, Bool.not_true, ldiff]
Β· congr
simp
Β· congr
simp
Β· rw [Nat.bitwise_swap, Function.swap]
congr
funext x y
cases x <;> cases y <;> rfl
-- Porting note: Was `bitwise_tac` in mathlib
theorem bitwise_xor : bitwise xor = Int.xor := by
funext m n
rcases m with m | m <;> rcases n with n | n <;> try {rfl}
<;> simp only [bitwise, natBitwise, Bool.not_false, Bool.bne_eq_xor,
cond_false, cond_true, negSucc.injEq, Bool.false_xor,
Bool.true_xor, Bool.not_true,
Int.xor, HXor.hXor, XorOp.xor, Nat.xor] <;> simp
@[simp]
theorem bitwise_bit (f : Bool β Bool β Bool) (a m b n) :
bitwise f (bit a m) (bit b n) = bit (f a b) (bitwise f m n) := by
rcases m with m | m <;> rcases n with n | n <;>
simp [bitwise, ofNat_eq_coe, bit_coe_nat, natBitwise, Bool.not_false,
bit_negSucc]
Β· by_cases h : f false false <;> simp +decide [h]
Β· by_cases h : f false true <;> simp +decide [h]
Β· by_cases h : f true false <;> simp +decide [h]
Β· by_cases h : f true true <;> simp +decide [h]
@[simp]
theorem lor_bit (a m b n) : lor (bit a m) (bit b n) = bit (a || b) (lor m n) := by
rw [β bitwise_or, bitwise_bit]
@[simp]
theorem land_bit (a m b n) : land (bit a m) (bit b n) = bit (a && b) (land m n) := by
rw [β bitwise_and, bitwise_bit]
@[simp]
theorem ldiff_bit (a m b n) : ldiff (bit a m) (bit b n) = bit (a && not b) (ldiff m n) := by
rw [β bitwise_diff, bitwise_bit]
@[simp]
theorem lxor_bit (a m b n) : Int.xor (bit a m) (bit b n) = bit (xor a b) (Int.xor m n) := by
rw [β bitwise_xor, bitwise_bit]
@[simp]
theorem lnot_bit (b) : β n, lnot (bit b n) = bit (not b) (lnot n)
| (n : β) => by simp [lnot]
| -[n+1] => by simp [lnot]
@[simp]
theorem testBit_bitwise (f : Bool β Bool β Bool) (m n k) :
testBit (bitwise f m n) k = f (testBit m k) (testBit n k) := by
cases m <;> cases n <;> simp only [testBit, bitwise, natBitwise]
Β· by_cases h : f false false <;> simp [h]
Β· by_cases h : f false true <;> simp [h]
Β· by_cases h : f true false <;> simp [h]
Β· by_cases h : f true true <;> simp [h]
@[simp]
theorem testBit_lor (m n k) : testBit (lor m n) k = (testBit m k || testBit n k) := by
rw [β bitwise_or, testBit_bitwise]
@[simp]
theorem testBit_land (m n k) : testBit (land m n) k = (testBit m k && testBit n k) := by
rw [β bitwise_and, testBit_bitwise]
@[simp]
theorem testBit_ldiff (m n k) : testBit (ldiff m n) k = (testBit m k && not (testBit n k)) := by
rw [β bitwise_diff, testBit_bitwise]
@[simp]
theorem testBit_lxor (m n k) : testBit (Int.xor m n) k = xor (testBit m k) (testBit n k) := by
rw [β bitwise_xor, testBit_bitwise]
@[simp]
theorem testBit_lnot : β n k, testBit (lnot n) k = not (testBit n k)
| (n : β), k => by simp [lnot, testBit]
| -[n+1], k => by simp [lnot, testBit]
@[simp]
theorem shiftLeft_neg (m n : β€) : m <<< (-n) = m >>> n :=
rfl
@[simp]
theorem shiftRight_neg (m n : β€) : m >>> (-n) = m <<< n := by rw [β shiftLeft_neg, neg_neg]
@[simp]
theorem shiftLeft_natCast (m n : β) : (m : β€) <<< (n : β€) = β(m <<< n) := by
unfold_projs; simp
@[simp]
theorem shiftRight_natCast (m n : β) : (m : β€) >>> (n : β€) = m >>> n := by cases n <;> rfl
@[deprecated (since := "2025-03-10")] alias shiftLeft_coe_nat := shiftLeft_natCast
@[deprecated (since := "2025-03-10")] alias shiftRight_coe_nat := shiftRight_natCast
@[simp]
theorem shiftLeft_negSucc (m n : β) : -[m+1] <<< (n : β€) = -[Nat.shiftLeft' true m n+1] :=
rfl
@[simp]
theorem shiftRight_negSucc (m n : β) : -[m+1] >>> (n : β€) = -[m >>> n+1] := by cases n <;> rfl
/-- Compare with `Int.shiftRight_add`, which doesn't have the coercions `β β β€`. -/
theorem shiftRight_add' : β (m : β€) (n k : β), m >>> (n + k : β€) = (m >>> (n : β€)) >>> (k : β€)
| (m : β), n, k => by
rw [shiftRight_natCast, shiftRight_natCast, β Int.natCast_add, shiftRight_natCast,
Nat.shiftRight_add]
| -[m+1], n, k => by
rw [shiftRight_negSucc, shiftRight_negSucc, β Int.natCast_add, shiftRight_negSucc,
Nat.shiftRight_add]
/-! ### bitwise ops -/
theorem shiftLeft_add : β (m : β€) (n : β) (k : β€), m <<< (n + k) = (m <<< (n : β€)) <<< k
| (m : β), n, (k : β) =>
congr_arg ofNat (by simp [Nat.shiftLeft_eq, Nat.pow_add, mul_assoc])
| -[_+1], _, (k : β) => congr_arg negSucc (Nat.shiftLeft'_add _ _ _ _)
| (m : β), n, -[k+1] =>
subNatNat_elim n k.succ (fun n k i => (βm) <<< i = (Nat.shiftLeft' false m n) >>> k)
(fun (i n : β) =>
by simp [β Nat.shiftLeft_sub _ , Nat.add_sub_cancel_left])
fun i n => by
dsimp
simp_rw [negSucc_eq, shiftLeft_neg, Nat.shiftLeft'_false, Nat.shiftRight_add,
β Nat.shiftLeft_sub _ le_rfl, Nat.sub_self, Nat.shiftLeft_zero, β shiftRight_natCast,
β shiftRight_add', Nat.cast_one]
| -[m+1], n, -[k+1] =>
subNatNat_elim n k.succ
(fun n k i => -[m+1] <<< i = -[(Nat.shiftLeft' true m n) >>> k+1])
(fun i n =>
congr_arg negSucc <| by
rw [β Nat.shiftLeft'_sub, Nat.add_sub_cancel_left]; apply Nat.le_add_right)
fun i n =>
congr_arg negSucc <| by rw [add_assoc, Nat.shiftRight_add, β Nat.shiftLeft'_sub _ _ le_rfl,
Nat.sub_self, Nat.shiftLeft']
theorem shiftLeft_sub (m : β€) (n : β) (k : β€) : m <<< (n - k) = (m <<< (n : β€)) >>> k :=
shiftLeft_add _ _ _
theorem shiftLeft_eq_mul_pow : β (m : β€) (n : β), m <<< (n : β€) = m * (2 ^ n : β)
| (m : β), _ => congr_arg ((β) : β β β€) (by simp [Nat.shiftLeft_eq])
| -[_+1], _ => @congr_arg β β€ _ _ (fun i => -i) (Nat.shiftLeft'_tt_eq_mul_pow _ _)
theorem one_shiftLeft (n : β) : 1 <<< (n : β€) = (2 ^ n : β) :=
congr_arg ((β) : β β β€) (by simp [Nat.shiftLeft_eq])
@[simp]
theorem zero_shiftLeft : β n : β€, 0 <<< n = 0
| (n : β) => congr_arg ((β) : β β β€) (by simp)
| -[_+1] => congr_arg ((β) : β β β€) (by simp)
/-- Compare with `Int.zero_shiftRight`, which has `n : β`. -/
@[simp]
theorem zero_shiftRight' (n : β€) : 0 >>> n = 0 :=
zero_shiftLeft _
end Int
|
Sigma.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov
-/
import Mathlib.Topology.CompactOpen
/-!
# Equivalence between `C(X, Ξ£ i, Y i)` and `Ξ£ i, C(X, Y i)`
If `X` is a connected topological space, then for every continuous map `f` from `X` to the disjoint
union of a collection of topological spaces `Y i` there exists a unique index `i` and a continuous
map from `g` to `Y i` such that `f` is the composition of the natural embedding
`Sigma.mk i : Y i β Ξ£ i, Y i` with `g`.
This defines an equivalence between `C(X, Ξ£ i, Y i)` and `Ξ£ i, C(X, Y i)`. In fact, this equivalence
is a homeomorphism if the spaces of continuous maps are equipped with the compact-open topology.
## Implementation notes
There are two natural ways to talk about this result: one is to say that for each `f` there exist
unique `i` and `g`; another one is to define a noncomputable equivalence. We choose the second way
because it is easier to use an equivalence in applications.
## TODO
Some results in this file can be generalized to the case when `X` is a preconnected space. However,
if `X` is empty, then any index `i` will work, so there is no 1-to-1 correspondence.
## Keywords
continuous map, sigma type, disjoint union
-/
noncomputable section
open Filter Topology
variable {X ΞΉ : Type*} {Y : ΞΉ β Type*} [TopologicalSpace X] [β i, TopologicalSpace (Y i)]
namespace ContinuousMap
theorem isEmbedding_sigmaMk_comp [Nonempty X] :
IsEmbedding (fun g : Ξ£ i, C(X, Y i) β¦ (sigmaMk g.1).comp g.2) where
toIsInducing := inducing_sigma.2
β¨fun i β¦ (sigmaMk i).isInducing_postcomp IsEmbedding.sigmaMk.isInducing, fun i β¦
let β¨xβ© := βΉNonempty XβΊ
β¨_, (isOpen_sigma_fst_preimage {i}).preimage (continuous_eval_const x), fun _ β¦ Iff.rflβ©β©
injective := by
rintro β¨i, gβ© β¨i', g'β© h
obtain β¨rfl, hgβ© : i = i' β§ βg β βg' :=
Function.eq_of_sigmaMk_comp <| congr_arg DFunLike.coe h
simpa using hg
section ConnectedSpace
variable [ConnectedSpace X]
/-- Every continuous map from a connected topological space to the disjoint union of a family of
topological spaces is a composition of the embedding `ContinuousMap.sigmaMk i : C(Y i, Ξ£ i, Y i)`
for some `i` and a continuous map `g : C(X, Y i)`. See also `Continuous.exists_lift_sigma` for a
version with unbundled functions and `ContinuousMap.sigmaCodHomeomorph` for a homeomorphism defined
using this fact. -/
theorem exists_lift_sigma (f : C(X, Ξ£ i, Y i)) : β i g, f = (sigmaMk i).comp g :=
let β¨i, g, hg, hfgβ© := (map_continuous f).exists_lift_sigma
β¨i, β¨g, hgβ©, DFunLike.ext' hfgβ©
variable (X Y)
/-- Homeomorphism between the type `C(X, Ξ£ i, Y i)` of continuous maps from a connected topological
space to the disjoint union of a family of topological spaces and the disjoint union of the types of
continuous maps `C(X, Y i)`.
The inverse map sends `β¨i, gβ©` to `ContinuousMap.comp (ContinuousMap.sigmaMk i) g`. -/
@[simps! symm_apply]
def sigmaCodHomeomorph : C(X, Ξ£ i, Y i) ββ Ξ£ i, C(X, Y i) :=
.symm <| Equiv.toHomeomorphOfIsInducing
(.ofBijective _ β¨isEmbedding_sigmaMk_comp.injective, fun f β¦
let β¨i, g, hgβ© := f.exists_lift_sigma; β¨β¨i, gβ©, hg.symmβ©β©)
isEmbedding_sigmaMk_comp.isInducing
end ConnectedSpace
end ContinuousMap
|
Basic.lean
|
/-
Copyright (c) 2019 Alexander Bentkamp. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alexander Bentkamp, Yury Kudryashov, YaΓ«l Dillies
-/
import Mathlib.Algebra.Order.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.Module.OrderedSMul
import Mathlib.Algebra.Order.Module.Synonym
import Mathlib.Algebra.Ring.Action.Pointwise.Set
import Mathlib.Analysis.Convex.Star
import Mathlib.Tactic.FieldSimp
import Mathlib.Tactic.NoncommRing
import Mathlib.LinearAlgebra.AffineSpace.AffineSubspace.Defs
/-!
# Convex sets and functions in vector spaces
In a π-vector space, we define the following objects and properties.
* `Convex π s`: A set `s` is convex if for any two points `x y β s` it includes `segment π x y`.
* `stdSimplex π ΞΉ`: The standard simplex in `ΞΉ β π` (currently requires `Fintype ΞΉ`). It is the
intersection of the positive quadrant with the hyperplane `s.sum = 1`.
We also provide various equivalent versions of the definitions above, prove that some specific sets
are convex.
## TODO
Generalize all this file to affine spaces.
-/
variable {π E F Ξ² : Type*}
open LinearMap Set
open scoped Convex Pointwise
/-! ### Convexity of sets -/
section OrderedSemiring
variable [Semiring π] [PartialOrder π]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F]
section SMul
variable (π) [SMul π E] [SMul π F] (s : Set E) {x : E}
/-- Convexity of sets. -/
def Convex : Prop :=
β β¦x : Eβ¦, x β s β StarConvex π x s
variable {π s}
theorem Convex.starConvex (hs : Convex π s) (hx : x β s) : StarConvex π x s :=
hs hx
theorem convex_iff_segment_subset : Convex π s β β β¦xβ¦, x β s β β β¦yβ¦, y β s β [x -[π] y] β s :=
forallβ_congr fun _ _ => starConvex_iff_segment_subset
theorem Convex.segment_subset (h : Convex π s) {x y : E} (hx : x β s) (hy : y β s) :
[x -[π] y] β s :=
convex_iff_segment_subset.1 h hx hy
theorem Convex.openSegment_subset (h : Convex π s) {x y : E} (hx : x β s) (hy : y β s) :
openSegment π x y β s :=
(openSegment_subset_segment π x y).trans (h.segment_subset hx hy)
theorem convex_iff_add_mem : Convex π s β
β β¦xβ¦, x β s β β β¦yβ¦, y β s β β β¦a b : πβ¦, 0 β€ a β 0 β€ b β a + b = 1 β a β’ x + b β’ y β s := by
simp_rw [convex_iff_segment_subset, segment_subset_iff]
/-- Alternative definition of set convexity, in terms of pointwise set operations. -/
theorem convex_iff_pointwise_add_subset :
Convex π s β β β¦a b : πβ¦, 0 β€ a β 0 β€ b β a + b = 1 β a β’ s + b β’ s β s :=
Iff.intro
(by
rintro hA a b ha hb hab w β¨au, β¨u, hu, rflβ©, bv, β¨v, hv, rflβ©, rflβ©
exact hA hu hv ha hb hab)
fun h _ hx _ hy _ _ ha hb hab => (h ha hb hab) (Set.add_mem_add β¨_, hx, rflβ© β¨_, hy, rflβ©)
alias β¨Convex.set_combo_subset, _β© := convex_iff_pointwise_add_subset
theorem convex_empty : Convex π (β
: Set E) := fun _ => False.elim
theorem convex_univ : Convex π (Set.univ : Set E) := fun _ _ => starConvex_univ _
theorem Convex.inter {t : Set E} (hs : Convex π s) (ht : Convex π t) : Convex π (s β© t) :=
fun _ hx => (hs hx.1).inter (ht hx.2)
theorem convex_sInter {S : Set (Set E)} (h : β s β S, Convex π s) : Convex π (ββ S) := fun _ hx =>
starConvex_sInter fun _ hs => h _ hs <| hx _ hs
theorem convex_iInter {ΞΉ : Sort*} {s : ΞΉ β Set E} (h : β i, Convex π (s i)) :
Convex π (β i, s i) :=
sInter_range s βΈ convex_sInter <| forall_mem_range.2 h
theorem convex_iInterβ {ΞΉ : Sort*} {ΞΊ : ΞΉ β Sort*} {s : (i : ΞΉ) β ΞΊ i β Set E}
(h : β i j, Convex π (s i j)) : Convex π (β (i) (j), s i j) :=
convex_iInter fun i => convex_iInter <| h i
theorem Convex.prod {s : Set E} {t : Set F} (hs : Convex π s) (ht : Convex π t) :
Convex π (s ΓΛ’ t) := fun _ hx => (hs hx.1).prod (ht hx.2)
theorem convex_pi {ΞΉ : Type*} {E : ΞΉ β Type*} [β i, AddCommMonoid (E i)] [β i, SMul π (E i)]
{s : Set ΞΉ} {t : β i, Set (E i)} (ht : β β¦iβ¦, i β s β Convex π (t i)) : Convex π (s.pi t) :=
fun _ hx => starConvex_pi fun _ hi => ht hi <| hx _ hi
theorem Directed.convex_iUnion {ΞΉ : Sort*} {s : ΞΉ β Set E} (hdir : Directed (Β· β Β·) s)
(hc : β β¦i : ΞΉβ¦, Convex π (s i)) : Convex π (β i, s i) := by
rintro x hx y hy a b ha hb hab
rw [mem_iUnion] at hx hy β’
obtain β¨i, hxβ© := hx
obtain β¨j, hyβ© := hy
obtain β¨k, hik, hjkβ© := hdir i j
exact β¨k, hc (hik hx) (hjk hy) ha hb habβ©
theorem DirectedOn.convex_sUnion {c : Set (Set E)} (hdir : DirectedOn (Β· β Β·) c)
(hc : β β¦A : Set Eβ¦, A β c β Convex π A) : Convex π (ββ c) := by
rw [sUnion_eq_iUnion]
exact (directedOn_iff_directed.1 hdir).convex_iUnion fun A => hc A.2
end SMul
section Module
variable [Module π E] [Module π F] {s : Set E} {x : E}
theorem convex_iff_openSegment_subset [ZeroLEOneClass π] :
Convex π s β β β¦xβ¦, x β s β β β¦yβ¦, y β s β openSegment π x y β s :=
forallβ_congr fun _ => starConvex_iff_openSegment_subset
theorem convex_iff_forall_pos :
Convex π s β
β β¦xβ¦, x β s β β β¦yβ¦, y β s β β β¦a b : πβ¦, 0 < a β 0 < b β a + b = 1 β a β’ x + b β’ y β s :=
forallβ_congr fun _ => starConvex_iff_forall_pos
theorem convex_iff_pairwise_pos : Convex π s β
s.Pairwise fun x y => β β¦a b : πβ¦, 0 < a β 0 < b β a + b = 1 β a β’ x + b β’ y β s := by
refine convex_iff_forall_pos.trans β¨fun h x hx y hy _ => h hx hy, ?_β©
intro h x hx y hy a b ha hb hab
obtain rfl | hxy := eq_or_ne x y
Β· rwa [Convex.combo_self hab]
Β· exact h hx hy hxy ha hb hab
theorem Convex.starConvex_iff [ZeroLEOneClass π] (hs : Convex π s) (h : s.Nonempty) :
StarConvex π x s β x β s :=
β¨fun hxs => hxs.mem h, hs.starConvexβ©
protected theorem Set.Subsingleton.convex {s : Set E} (h : s.Subsingleton) : Convex π s :=
convex_iff_pairwise_pos.mpr (h.pairwise _)
@[simp] theorem convex_singleton (c : E) : Convex π ({c} : Set E) :=
subsingleton_singleton.convex
theorem convex_zero : Convex π (0 : Set E) :=
convex_singleton _
theorem convex_segment [IsOrderedRing π] (x y : E) : Convex π [x -[π] y] := by
rintro p β¨ap, bp, hap, hbp, habp, rflβ© q β¨aq, bq, haq, hbq, habq, rflβ© a b ha hb hab
refine
β¨a * ap + b * aq, a * bp + b * bq, add_nonneg (mul_nonneg ha hap) (mul_nonneg hb haq),
add_nonneg (mul_nonneg ha hbp) (mul_nonneg hb hbq), ?_, ?_β©
Β· rw [add_add_add_comm, β mul_add, β mul_add, habp, habq, mul_one, mul_one, hab]
Β· match_scalars <;> noncomm_ring
theorem Convex.linear_image (hs : Convex π s) (f : E ββ[π] F) : Convex π (f '' s) := by
rintro _ β¨x, hx, rflβ© _ β¨y, hy, rflβ© a b ha hb hab
exact β¨a β’ x + b β’ y, hs hx hy ha hb hab, by rw [f.map_add, f.map_smul, f.map_smul]β©
theorem Convex.is_linear_image (hs : Convex π s) {f : E β F} (hf : IsLinearMap π f) :
Convex π (f '' s) :=
hs.linear_image <| hf.mk' f
theorem Convex.linear_preimage {πβ : Type*} [Semiring πβ] [Module πβ E] [Module πβ F] {s : Set F}
[SMul π πβ] [IsScalarTower π πβ E] [IsScalarTower π πβ F] (hs : Convex π s) (f : E ββ[πβ] F) :
Convex π (f β»ΒΉ' s) := fun x hx y hy a b ha hb hab => by
rw [mem_preimage, f.map_add, LinearMap.map_smul_of_tower, LinearMap.map_smul_of_tower]
exact hs hx hy ha hb hab
theorem Convex.is_linear_preimage {πβ : Type*} [Semiring πβ] [Module πβ E] [Module πβ F] {s : Set F}
[SMul π πβ] [IsScalarTower π πβ E] [IsScalarTower π πβ F] (hs : Convex π s) {f : E β F}
(hf : IsLinearMap πβ f) :
Convex π (f β»ΒΉ' s) :=
hs.linear_preimage <| hf.mk' f
theorem Convex.add {t : Set E} (hs : Convex π s) (ht : Convex π t) : Convex π (s + t) := by
rw [β add_image_prod]
exact (hs.prod ht).is_linear_image IsLinearMap.isLinearMap_add
variable (π E)
/-- The convex sets form an additive submonoid under pointwise addition. -/
noncomputable def convexAddSubmonoid : AddSubmonoid (Set E) where
carrier := {s : Set E | Convex π s}
zero_mem' := convex_zero
add_mem' := Convex.add
@[simp, norm_cast]
theorem coe_convexAddSubmonoid : β(convexAddSubmonoid π E) = {s : Set E | Convex π s} :=
rfl
variable {π E}
@[simp]
theorem mem_convexAddSubmonoid {s : Set E} : s β convexAddSubmonoid π E β Convex π s :=
Iff.rfl
theorem convex_list_sum {l : List (Set E)} (h : β i β l, Convex π i) : Convex π l.sum :=
(convexAddSubmonoid π E).list_sum_mem h
theorem convex_multiset_sum {s : Multiset (Set E)} (h : β i β s, Convex π i) : Convex π s.sum :=
(convexAddSubmonoid π E).multiset_sum_mem _ h
theorem convex_sum {ΞΉ} {s : Finset ΞΉ} (t : ΞΉ β Set E) (h : β i β s, Convex π (t i)) :
Convex π (β i β s, t i) :=
(convexAddSubmonoid π E).sum_mem h
theorem Convex.vadd (hs : Convex π s) (z : E) : Convex π (z +α΅₯ s) := by
simp_rw [β image_vadd, vadd_eq_add, β singleton_add]
exact (convex_singleton _).add hs
theorem Convex.translate (hs : Convex π s) (z : E) : Convex π ((fun x => z + x) '' s) :=
hs.vadd _
/-- The translation of a convex set is also convex. -/
theorem Convex.translate_preimage_right (hs : Convex π s) (z : E) :
Convex π ((fun x => z + x) β»ΒΉ' s) := by
intro x hx y hy a b ha hb hab
have h := hs hx hy ha hb hab
rwa [smul_add, smul_add, add_add_add_comm, β add_smul, hab, one_smul] at h
/-- The translation of a convex set is also convex. -/
theorem Convex.translate_preimage_left (hs : Convex π s) (z : E) :
Convex π ((fun x => x + z) β»ΒΉ' s) := by
simpa only [add_comm] using hs.translate_preimage_right z
section OrderedAddCommMonoid
variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π Ξ²] [OrderedSMul π Ξ²]
theorem convex_Iic (r : Ξ²) : Convex π (Iic r) := fun x hx y hy a b ha hb hab =>
calc
a β’ x + b β’ y β€ a β’ r + b β’ r :=
add_le_add (smul_le_smul_of_nonneg_left hx ha) (smul_le_smul_of_nonneg_left hy hb)
_ = r := Convex.combo_self hab _
theorem convex_Ici (r : Ξ²) : Convex π (Ici r) :=
convex_Iic (Ξ² := Ξ²α΅α΅) r
theorem convex_Icc (r s : Ξ²) : Convex π (Icc r s) :=
Ici_inter_Iic.subst ((convex_Ici r).inter <| convex_Iic s)
theorem convex_halfSpace_le {f : E β Ξ²} (h : IsLinearMap π f) (r : Ξ²) : Convex π { w | f w β€ r } :=
(convex_Iic r).is_linear_preimage h
theorem convex_halfSpace_ge {f : E β Ξ²} (h : IsLinearMap π f) (r : Ξ²) : Convex π { w | r β€ f w } :=
(convex_Ici r).is_linear_preimage h
theorem convex_hyperplane {f : E β Ξ²} (h : IsLinearMap π f) (r : Ξ²) : Convex π { w | f w = r } := by
simp_rw [le_antisymm_iff]
exact (convex_halfSpace_le h r).inter (convex_halfSpace_ge h r)
end OrderedAddCommMonoid
section OrderedCancelAddCommMonoid
variable [AddCommMonoid Ξ²] [PartialOrder Ξ²] [IsOrderedCancelAddMonoid Ξ²]
[Module π Ξ²] [OrderedSMul π Ξ²]
theorem convex_Iio (r : Ξ²) : Convex π (Iio r) := by
intro x hx y hy a b ha hb hab
obtain rfl | ha' := ha.eq_or_lt
Β· rw [zero_add] at hab
rwa [zero_smul, zero_add, hab, one_smul]
rw [mem_Iio] at hx hy
calc
a β’ x + b β’ y < a β’ r + b β’ r := add_lt_add_of_lt_of_le
(smul_lt_smul_of_pos_left hx ha') (smul_le_smul_of_nonneg_left hy.le hb)
_ = r := Convex.combo_self hab _
theorem convex_Ioi (r : Ξ²) : Convex π (Ioi r) :=
convex_Iio (Ξ² := Ξ²α΅α΅) r
theorem convex_Ioo (r s : Ξ²) : Convex π (Ioo r s) :=
Ioi_inter_Iio.subst ((convex_Ioi r).inter <| convex_Iio s)
theorem convex_Ico (r s : Ξ²) : Convex π (Ico r s) :=
Ici_inter_Iio.subst ((convex_Ici r).inter <| convex_Iio s)
theorem convex_Ioc (r s : Ξ²) : Convex π (Ioc r s) :=
Ioi_inter_Iic.subst ((convex_Ioi r).inter <| convex_Iic s)
theorem convex_halfSpace_lt {f : E β Ξ²} (h : IsLinearMap π f) (r : Ξ²) : Convex π { w | f w < r } :=
(convex_Iio r).is_linear_preimage h
theorem convex_halfSpace_gt {f : E β Ξ²} (h : IsLinearMap π f) (r : Ξ²) : Convex π { w | r < f w } :=
(convex_Ioi r).is_linear_preimage h
end OrderedCancelAddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid Ξ²] [LinearOrder Ξ²] [IsOrderedAddMonoid Ξ²] [Module π Ξ²] [OrderedSMul π Ξ²]
theorem convex_uIcc (r s : Ξ²) : Convex π (uIcc r s) :=
convex_Icc _ _
end LinearOrderedAddCommMonoid
end Module
end AddCommMonoid
section LinearOrderedAddCommMonoid
variable [AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E]
[PartialOrder Ξ²] [Module π E] [OrderedSMul π E]
{s : Set E} {f : E β Ξ²}
theorem MonotoneOn.convex_le (hf : MonotoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | f x β€ r }) := fun x hx y hy _ _ ha hb hab =>
β¨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1) (Convex.combo_le_max x y ha hb hab)).trans
(max_rec' { x | f x β€ r } hx.2 hy.2)β©
theorem MonotoneOn.convex_lt (hf : MonotoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | f x < r }) := fun x hx y hy _ _ ha hb hab =>
β¨hs hx.1 hy.1 ha hb hab,
(hf (hs hx.1 hy.1 ha hb hab) (max_rec' s hx.1 hy.1)
(Convex.combo_le_max x y ha hb hab)).trans_lt
(max_rec' { x | f x < r } hx.2 hy.2)β©
theorem MonotoneOn.convex_ge (hf : MonotoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | r β€ f x }) :=
MonotoneOn.convex_le (E := Eα΅α΅) (Ξ² := Ξ²α΅α΅) hf.dual hs r
theorem MonotoneOn.convex_gt (hf : MonotoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | r < f x }) :=
MonotoneOn.convex_lt (E := Eα΅α΅) (Ξ² := Ξ²α΅α΅) hf.dual hs r
theorem AntitoneOn.convex_le (hf : AntitoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | f x β€ r }) :=
MonotoneOn.convex_ge (Ξ² := Ξ²α΅α΅) hf hs r
theorem AntitoneOn.convex_lt (hf : AntitoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | f x < r }) :=
MonotoneOn.convex_gt (Ξ² := Ξ²α΅α΅) hf hs r
theorem AntitoneOn.convex_ge (hf : AntitoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | r β€ f x }) :=
MonotoneOn.convex_le (Ξ² := Ξ²α΅α΅) hf hs r
theorem AntitoneOn.convex_gt (hf : AntitoneOn f s) (hs : Convex π s) (r : Ξ²) :
Convex π ({ x β s | r < f x }) :=
MonotoneOn.convex_lt (Ξ² := Ξ²α΅α΅) hf hs r
theorem Monotone.convex_le (hf : Monotone f) (r : Ξ²) : Convex π { x | f x β€ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Monotone.convex_lt (hf : Monotone f) (r : Ξ²) : Convex π { x | f x β€ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Monotone.convex_ge (hf : Monotone f) (r : Ξ²) : Convex π { x | r β€ f x } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_ge convex_univ r)
theorem Monotone.convex_gt (hf : Monotone f) (r : Ξ²) : Convex π { x | f x β€ r } :=
Set.sep_univ.subst ((hf.monotoneOn univ).convex_le convex_univ r)
theorem Antitone.convex_le (hf : Antitone f) (r : Ξ²) : Convex π { x | f x β€ r } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_le convex_univ r)
theorem Antitone.convex_lt (hf : Antitone f) (r : Ξ²) : Convex π { x | f x < r } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_lt convex_univ r)
theorem Antitone.convex_ge (hf : Antitone f) (r : Ξ²) : Convex π { x | r β€ f x } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_ge convex_univ r)
theorem Antitone.convex_gt (hf : Antitone f) (r : Ξ²) : Convex π { x | r < f x } :=
Set.sep_univ.subst ((hf.antitoneOn univ).convex_gt convex_univ r)
end LinearOrderedAddCommMonoid
end OrderedSemiring
section OrderedCommSemiring
variable [CommSemiring π] [PartialOrder π]
section AddCommMonoid
variable [AddCommMonoid E] [AddCommMonoid F] [Module π E] [Module π F] {s : Set E}
theorem Convex.smul (hs : Convex π s) (c : π) : Convex π (c β’ s) :=
hs.linear_image (LinearMap.lsmul _ _ c)
theorem Convex.smul_preimage (hs : Convex π s) (c : π) : Convex π ((fun z => c β’ z) β»ΒΉ' s) :=
hs.linear_preimage (LinearMap.lsmul _ _ c)
theorem Convex.affinity (hs : Convex π s) (z : E) (c : π) :
Convex π ((fun x => z + c β’ x) '' s) := by
simpa only [β image_smul, β image_vadd, image_image] using (hs.smul c).vadd z
end AddCommMonoid
end OrderedCommSemiring
section StrictOrderedCommSemiring
variable [CommSemiring π] [PartialOrder π] [IsStrictOrderedRing π] [AddCommGroup E] [Module π E]
theorem convex_openSegment (a b : E) : Convex π (openSegment π a b) := by
rw [convex_iff_openSegment_subset]
rintro p β¨ap, bp, hap, hbp, habp, rflβ© q β¨aq, bq, haq, hbq, habq, rflβ© z β¨a, b, ha, hb, hab, rflβ©
refine β¨a * ap + b * aq, a * bp + b * bq, by positivity, by positivity, ?_, ?_β©
Β· linear_combination (norm := noncomm_ring) a * habp + b * habq + hab
Β· module
end StrictOrderedCommSemiring
section OrderedRing
variable [Ring π] [PartialOrder π]
section AddCommGroup
variable [AddCommGroup E] [AddCommGroup F] [Module π E] [Module π F] {s t : Set E}
@[simp]
theorem convex_vadd (a : E) : Convex π (a +α΅₯ s) β Convex π s :=
β¨fun h β¦ by simpa using h.vadd (-a), fun h β¦ h.vadd _β©
/-- Affine subspaces are convex. -/
theorem AffineSubspace.convex (Q : AffineSubspace π E) : Convex π (Q : Set E) :=
fun x hx y hy a b _ _ hab β¦ by simpa [Convex.combo_eq_smul_sub_add hab] using Q.2 _ hy hx hx
/-- The preimage of a convex set under an affine map is convex. -/
theorem Convex.affine_preimage (f : E βα΅[π] F) {s : Set F} (hs : Convex π s) : Convex π (f β»ΒΉ' s) :=
fun _ hx => (hs hx).affine_preimage _
/-- The image of a convex set under an affine map is convex. -/
theorem Convex.affine_image (f : E βα΅[π] F) (hs : Convex π s) : Convex π (f '' s) := by
rintro _ β¨x, hx, rflβ©
exact (hs hx).affine_image _
theorem Convex.neg (hs : Convex π s) : Convex π (-s) :=
hs.is_linear_preimage IsLinearMap.isLinearMap_neg (πβ := π)
theorem Convex.sub (hs : Convex π s) (ht : Convex π t) : Convex π (s - t) := by
rw [sub_eq_add_neg]
exact hs.add ht.neg
variable [AddRightMono π]
theorem Convex.add_smul_mem (hs : Convex π s) {x y : E} (hx : x β s) (hy : x + y β s) {t : π}
(ht : t β Icc (0 : π) 1) : x + t β’ y β s := by
have h : x + t β’ y = (1 - t) β’ x + t β’ (x + y) := by match_scalars <;> noncomm_ring
rw [h]
exact hs hx hy (sub_nonneg_of_le ht.2) ht.1 (sub_add_cancel _ _)
theorem Convex.smul_mem_of_zero_mem (hs : Convex π s) {x : E} (zero_mem : (0 : E) β s) (hx : x β s)
{t : π} (ht : t β Icc (0 : π) 1) : t β’ x β s := by
simpa using hs.add_smul_mem zero_mem (by simpa using hx) ht
theorem Convex.mapsTo_lineMap (h : Convex π s) {x y : E} (hx : x β s) (hy : y β s) :
MapsTo (AffineMap.lineMap x y) (Icc (0 : π) 1) s := by
simpa only [mapsTo', segment_eq_image_lineMap] using h.segment_subset hx hy
theorem Convex.lineMap_mem (h : Convex π s) {x y : E} (hx : x β s) (hy : y β s) {t : π}
(ht : t β Icc 0 1) : AffineMap.lineMap x y t β s :=
h.mapsTo_lineMap hx hy ht
theorem Convex.add_smul_sub_mem (h : Convex π s) {x y : E} (hx : x β s) (hy : y β s) {t : π}
(ht : t β Icc (0 : π) 1) : x + t β’ (y - x) β s := by
rw [add_comm]
exact h.lineMap_mem hx hy ht
end AddCommGroup
end OrderedRing
section LinearOrderedSemiring
variable [Semiring π] [LinearOrder π] [IsOrderedRing π] [AddCommMonoid E]
theorem Convex_subadditive_le [SMul π E] {f : E β π} (hf1 : β x y, f (x + y) β€ (f x) + (f y))
(hf2 : β β¦cβ¦ x, 0 β€ c β f (c β’ x) β€ c * f x) (B : π) :
Convex π { x | f x β€ B } := by
rw [convex_iff_segment_subset]
rintro x hx y hy z β¨a, b, ha, hb, hs, rflβ©
calc
_ β€ a β’ (f x) + b β’ (f y) := le_trans (hf1 _ _) (add_le_add (hf2 x ha) (hf2 y hb))
_ β€ a β’ B + b β’ B := by gcongr <;> assumption
_ β€ B := by rw [β add_smul, hs, one_smul]
end LinearOrderedSemiring
theorem Convex.midpoint_mem [Ring π] [LinearOrder π] [IsStrictOrderedRing π]
[AddCommGroup E] [Module π E] [Invertible (2 : π)] {s : Set E} {x y : E}
(h : Convex π s) (hx : x β s) (hy : y β s) : midpoint π x y β s :=
h.segment_subset hx hy <| midpoint_mem_segment x y
section LinearOrderedField
variable [Field π] [LinearOrder π] [IsStrictOrderedRing π]
section AddCommGroup
variable [AddCommGroup E] [AddCommGroup F] [Module π E] [Module π F] {s : Set E}
/-- Alternative definition of set convexity, using division. -/
theorem convex_iff_div :
Convex π s β β β¦xβ¦, x β s β β β¦yβ¦, y β s β
β β¦a b : πβ¦, 0 β€ a β 0 β€ b β 0 < a + b β (a / (a + b)) β’ x + (b / (a + b)) β’ y β s :=
forallβ_congr fun _ _ => starConvex_iff_div
theorem Convex.mem_smul_of_zero_mem (h : Convex π s) {x : E} (zero_mem : (0 : E) β s) (hx : x β s)
{t : π} (ht : 1 β€ t) : x β t β’ s := by
rw [mem_smul_set_iff_inv_smul_memβ (zero_lt_one.trans_le ht).ne']
exact h.smul_mem_of_zero_mem zero_mem hx
β¨inv_nonneg.2 (zero_le_one.trans ht), inv_le_one_of_one_leβ htβ©
theorem Convex.exists_mem_add_smul_eq (h : Convex π s) {x y : E} {p q : π} (hx : x β s) (hy : y β s)
(hp : 0 β€ p) (hq : 0 β€ q) : β z β s, (p + q) β’ z = p β’ x + q β’ y := by
rcases _root_.em (p = 0 β§ q = 0) with (β¨rfl, rflβ© | hpq)
Β· use x, hx
simp
Β· replace hpq : 0 < p + q :=
(add_nonneg hp hq).lt_of_ne' (mt (add_eq_zero_iff_of_nonneg hp hq).1 hpq)
refine β¨_, convex_iff_div.1 h hx hy hp hq hpq, ?_β©
match_scalars <;> field_simp
theorem Convex.add_smul (h_conv : Convex π s) {p q : π} (hp : 0 β€ p) (hq : 0 β€ q) :
(p + q) β’ s = p β’ s + q β’ s := (add_smul_subset _ _ _).antisymm <| by
rintro _ β¨_, β¨vβ, hβ, rflβ©, _, β¨vβ, hβ, rflβ©, rflβ©
exact h_conv.exists_mem_add_smul_eq hβ hβ hp hq
end AddCommGroup
end LinearOrderedField
/-!
#### Convex sets in an ordered space
Relates `Convex` and `OrdConnected`.
-/
section
theorem Set.OrdConnected.convex_of_chain [Semiring π] [PartialOrder π]
[AddCommMonoid E] [PartialOrder E] [IsOrderedAddMonoid E] [Module π E]
[OrderedSMul π E] {s : Set E} (hs : s.OrdConnected) (h : IsChain (Β· β€ Β·) s) : Convex π s := by
refine convex_iff_segment_subset.mpr fun x hx y hy => ?_
obtain hxy | hyx := h.total hx hy
Β· exact (segment_subset_Icc hxy).trans (hs.out hx hy)
Β· rw [segment_symm]
exact (segment_subset_Icc hyx).trans (hs.out hy hx)
theorem Set.OrdConnected.convex [Semiring π] [PartialOrder π]
[AddCommMonoid E] [LinearOrder E] [IsOrderedAddMonoid E] [Module π E]
[OrderedSMul π E] {s : Set E} (hs : s.OrdConnected) : Convex π s :=
hs.convex_of_chain <| isChain_of_trichotomous s
theorem convex_iff_ordConnected [Field π] [LinearOrder π] [IsStrictOrderedRing π] {s : Set π} :
Convex π s β s.OrdConnected := by
simp_rw [convex_iff_segment_subset, segment_eq_uIcc, ordConnected_iff_uIcc_subset]
alias β¨Convex.ordConnected, _β© := convex_iff_ordConnected
end
/-! #### Convexity of submodules/subspaces -/
namespace Submodule
variable [Semiring π] [PartialOrder π] [AddCommMonoid E] [Module π E]
protected theorem convex (K : Submodule π E) : Convex π (βK : Set E) := by
repeat' intro
refine add_mem (smul_mem _ _ ?_) (smul_mem _ _ ?_) <;> assumption
protected theorem starConvex (K : Submodule π E) : StarConvex π (0 : E) K :=
K.convex K.zero_mem
end Submodule
/-! ### Simplex -/
section Simplex
section OrderedSemiring
variable (π) (ΞΉ : Type*) [Semiring π] [PartialOrder π] [Fintype ΞΉ]
/-- The standard simplex in the space of functions `ΞΉ β π` is the set of vectors with non-negative
coordinates with total sum `1`. This is the free object in the category of convex spaces. -/
def stdSimplex : Set (ΞΉ β π) :=
{ f | (β x, 0 β€ f x) β§ β x, f x = 1 }
theorem stdSimplex_eq_inter : stdSimplex π ΞΉ = (β x, { f | 0 β€ f x }) β© { f | β x, f x = 1 } := by
ext f
simp only [stdSimplex, Set.mem_inter_iff, Set.mem_iInter, Set.mem_setOf_eq]
theorem convex_stdSimplex [IsOrderedRing π] : Convex π (stdSimplex π ΞΉ) := by
refine fun f hf g hg a b ha hb hab => β¨fun x => ?_, ?_β©
Β· apply_rules [add_nonneg, mul_nonneg, hf.1, hg.1]
Β· simp_rw [Pi.add_apply, Pi.smul_apply]
rwa [Finset.sum_add_distrib, β Finset.smul_sum, β Finset.smul_sum, hf.2, hg.2, smul_eq_mul,
smul_eq_mul, mul_one, mul_one]
@[nontriviality] lemma stdSimplex_of_subsingleton [Subsingleton π] : stdSimplex π ΞΉ = univ :=
eq_univ_of_forall fun _ β¦ β¨fun _ β¦ (Subsingleton.elim _ _).le, Subsingleton.elim _ _β©
/-- The standard simplex in the zero-dimensional space is empty. -/
lemma stdSimplex_of_isEmpty_index [IsEmpty ΞΉ] [Nontrivial π] : stdSimplex π ΞΉ = β
:=
eq_empty_of_forall_notMem <| by rintro f β¨-, hfβ©; simp at hf
lemma stdSimplex_unique [ZeroLEOneClass π] [Nonempty ΞΉ] [Subsingleton ΞΉ] :
stdSimplex π ΞΉ = {fun _ β¦ 1} := by
cases nonempty_unique ΞΉ
refine eq_singleton_iff_unique_mem.2 β¨β¨fun _ β¦ zero_le_one, Fintype.sum_unique _β©, ?_β©
rintro f β¨-, hfβ©
rw [Fintype.sum_unique] at hf
exact funext (Unique.forall_iff.2 hf)
variable {ΞΉ} [DecidableEq ΞΉ] [ZeroLEOneClass π]
theorem single_mem_stdSimplex (i : ΞΉ) : Pi.single i 1 β stdSimplex π ΞΉ :=
β¨le_update_iff.2 β¨zero_le_one, fun _ _ β¦ le_rflβ©, by simpβ©
theorem ite_eq_mem_stdSimplex (i : ΞΉ) : (if i = Β· then (1 : π) else 0) β stdSimplex π ΞΉ := by
simpa only [@eq_comm _ i, β Pi.single_apply] using single_mem_stdSimplex π i
variable [IsOrderedRing π]
#adaptation_note /-- nightly-2024-03-11
we need a type annotation on the segment in the following two lemmas. -/
/-- The edges are contained in the simplex. -/
lemma segment_single_subset_stdSimplex (i j : ΞΉ) :
([Pi.single i 1 -[π] Pi.single j 1] : Set (ΞΉ β π)) β stdSimplex π ΞΉ :=
(convex_stdSimplex π ΞΉ).segment_subset (single_mem_stdSimplex _ _) (single_mem_stdSimplex _ _)
lemma stdSimplex_fin_two :
stdSimplex π (Fin 2) = ([Pi.single 0 1 -[π] Pi.single 1 1] : Set (Fin 2 β π)) := by
refine Subset.antisymm ?_ (segment_single_subset_stdSimplex π (0 : Fin 2) 1)
rintro f β¨hfβ, hfββ©
rw [Fin.sum_univ_two] at hfβ
refine β¨f 0, f 1, hfβ 0, hfβ 1, hfβ, funext <| Fin.forall_fin_two.2 ?_β©
simp
end OrderedSemiring
section OrderedRing
variable (π) [Ring π] [PartialOrder π] [IsOrderedRing π]
/-- The standard one-dimensional simplex in `Fin 2 β π` is equivalent to the unit interval. -/
@[simps -fullyApplied]
def stdSimplexEquivIcc : stdSimplex π (Fin 2) β Icc (0 : π) 1 where
toFun f := β¨f.1 0, f.2.1 _, f.2.2 βΈ
Finset.single_le_sum (fun i _ β¦ f.2.1 i) (Finset.mem_univ _)β©
invFun x := β¨![x, 1 - x], Fin.forall_fin_two.2 β¨x.2.1, sub_nonneg.2 x.2.2β©,
calc
β i : Fin 2, ![(x : π), 1 - x] i = x + (1 - x) := Fin.sum_univ_two _
_ = 1 := add_sub_cancel _ _β©
left_inv f := Subtype.eq <| funext <| Fin.forall_fin_two.2 <| .intro rfl <|
calc
(1 : π) - f.1 0 = f.1 0 + f.1 1 - f.1 0 := by rw [β Fin.sum_univ_two f.1, f.2.2]
_ = f.1 1 := add_sub_cancel_left _ _
end OrderedRing
end Simplex
|
AnalyticManifold.lean
|
/-
Copyright (c) 2023 Michael Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Lee, Geoffrey Irving
-/
import Mathlib.Deprecated.AnalyticManifold
deprecated_module
"Analytic manifolds are deprecated, use `IsManifold I Ο M`" (since := "2025-04-13")
set_option linter.directoryDependency false
|
Monomorphisms.lean
|
/-
Copyright (c) 2025 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.Abelian.GrothendieckCategory.Basic
import Mathlib.CategoryTheory.Abelian.GrothendieckAxioms.Colim
import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition
/-!
# Monomorphisms in Grothendieck abelian categories
In this file, we show that in a Grothendieck abelian category,
monomorphisms are stable under transfinite composition.
-/
universe w v u
namespace CategoryTheory
namespace IsGrothendieckAbelian
open MorphismProperty
instance {C : Type u} [Category.{v} C] [Abelian C] [IsGrothendieckAbelian.{w} C] :
IsStableUnderTransfiniteComposition.{w} (monomorphisms C) := by
infer_instance
end IsGrothendieckAbelian
end CategoryTheory
|
Yoneda.lean
|
/-
Copyright (c) 2024 Markus Himmel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Markus Himmel
-/
import Mathlib.CategoryTheory.Limits.Preserves.Ulift
import Mathlib.CategoryTheory.Limits.FunctorToTypes
/-!
# Yoneda preserves certain colimits
Given a bifunctor `F : J β₯€ Cα΅α΅ β₯€ Type v`, we prove the isomorphism
`Hom(YX, colim_j F(j, -)) β
colim_j Hom(YX, F(j, -))`, where `Y` is the Yoneda embedding.
We state this in two ways. One is functorial in `X` and stated as a natural isomorphism of functors
`yoneda.op β yoneda.obj (colimit F) β
yoneda.op β colimit (F β yoneda)`, and from this we
deduce the more traditional preservation statement
`PreservesColimit F (coyoneda.obj (op (yoneda.obj X)))`.
The proof combines the Yoneda lemma with the fact that colimits in functor categories are computed
pointwise.
## See also
There is also a relative version of this statement where `F : J β₯€ Over A` for some presheaf
`A`, see `Mathlib/CategoryTheory/Comma/Presheaf/Colimit.lean`.
-/
universe vβ vβ vβ uβ uβ uβ
namespace CategoryTheory
open CategoryTheory.Limits Opposite Functor
variable {C : Type uβ} [Category.{vβ} C]
variable {J : Type uβ} [Category.{vβ} J] [HasColimitsOfShape J (Type vβ)]
[HasColimitsOfShape J (Type (max uβ vβ))] (F : J β₯€ Cα΅α΅ β₯€ Type vβ)
/-- Naturally in `X`, we have `Hom(YX, colim_i Fi) β
colim_i Hom(YX, Fi)`. -/
noncomputable def yonedaYonedaColimit :
yoneda.op β yoneda.obj (colimit F) β
yoneda.op β colimit (F β yoneda) := calc
yoneda.op β yoneda.obj (colimit F)
β
colimit F β uliftFunctor.{uβ} := yonedaOpCompYonedaObj (colimit F)
_ β
F.flip β colim β uliftFunctor.{uβ} :=
isoWhiskerRight (colimitIsoFlipCompColim F) uliftFunctor.{uβ}
_ β
F.flip β (whiskeringRight _ _ _).obj uliftFunctor.{uβ} β colim :=
isoWhiskerLeft F.flip (preservesColimitNatIso uliftFunctor.{uβ})
_ β
(yoneda.op β coyoneda β (whiskeringLeft _ _ _).obj F) β colim := isoWhiskerRight
(isoWhiskerRight largeCurriedYonedaLemma.symm ((whiskeringLeft _ _ _).obj F)) colim
_ β
yoneda.op β colimit (F β yoneda) :=
isoWhiskerLeft yoneda.op (colimitIsoFlipCompColim (F β yoneda)).symm
theorem yonedaYonedaColimit_app_inv {X : C} : ((yonedaYonedaColimit F).app (op X)).inv =
(colimitObjIsoColimitCompEvaluation _ _).hom β«
(colimit.post F (coyoneda.obj (op (yoneda.obj X)))) := by
dsimp [yonedaYonedaColimit]
simp only [Iso.cancel_iso_hom_left]
apply colimit.hom_ext
intro j
rw [colimit.ΞΉ_post, ΞΉ_colimMap_assoc]
simp only [β CategoryTheory.Functor.assoc, comp_evaluation]
rw [ΞΉ_preservesColimitIso_inv_assoc, β Functor.map_comp_assoc]
simp only [β comp_evaluation]
rw [colimitObjIsoColimitCompEvaluation_ΞΉ_inv, whiskerLeft_app]
ext Ξ· Y f
simp [largeCurriedYonedaLemma, yonedaOpCompYonedaObj, FunctorToTypes.colimit.map_ΞΉ_apply,
map_yonedaEquiv]
noncomputable instance {X : C} : PreservesColimit F (coyoneda.obj (op (yoneda.obj X))) := by
suffices IsIso (colimit.post F (coyoneda.obj (op (yoneda.obj X)))) from
preservesColimit_of_isIso_post _ _
suffices colimit.post F (coyoneda.obj (op (yoneda.obj X))) =
(colimitObjIsoColimitCompEvaluation _ _).inv β« ((yonedaYonedaColimit F).app (op X)).inv from
this βΈ inferInstance
rw [yonedaYonedaColimit_app_inv, Iso.inv_hom_id_assoc]
end CategoryTheory
|
Complex.lean
|
/-
Copyright (c) 2022 Heather Macbeth. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Heather Macbeth
-/
import Mathlib.Analysis.Complex.AbsMax
import Mathlib.Analysis.LocallyConvex.WithSeminorms
import Mathlib.Geometry.Manifold.MFDeriv.Basic
import Mathlib.Topology.LocallyConstant.Basic
/-! # Holomorphic functions on complex manifolds
Thanks to the rigidity of complex-differentiability compared to real-differentiability, there are
many results about complex manifolds with no analogue for manifolds over a general normed field. For
now, this file contains just two (closely related) such results:
## Main results
* `MDifferentiable.isLocallyConstant`: A complex-differentiable function on a compact complex
manifold is locally constant.
* `MDifferentiable.exists_eq_const_of_compactSpace`: A complex-differentiable function on a compact
preconnected complex manifold is constant.
## TODO
There is a whole theory to develop here. Maybe a next step would be to develop a theory of
holomorphic vector/line bundles, including:
* the finite-dimensionality of the space of sections of a holomorphic vector bundle
* Siegel's theorem: for any `n + 1` formal ratios `g 0 / h 0`, `g 1 / h 1`, .... `g n / h n` of
sections of a fixed line bundle `L` over a complex `n`-manifold, there exists a polynomial
relationship `P (g 0 / h 0, g 1 / h 1, .... g n / h n) = 0`
Another direction would be to develop the relationship with sheaf theory, building the sheaves of
holomorphic and meromorphic functions on a complex manifold and proving algebraic results about the
stalks, such as the Weierstrass preparation theorem.
-/
open scoped Manifold Topology Filter
open Function Set Filter Complex
variable {E : Type*} [NormedAddCommGroup E] [NormedSpace β E]
variable {F : Type*} [NormedAddCommGroup F] [NormedSpace β F]
variable {H : Type*} [TopologicalSpace H] {I : ModelWithCorners β E H} [I.Boundaryless]
variable {M : Type*} [TopologicalSpace M] [ChartedSpace H M]
[IsManifold I 1 M]
/-- **Maximum modulus principle**: if `f : M β F` is complex differentiable in a neighborhood of `c`
and the norm `βf zβ` has a local maximum at `c`, then `βf zβ` is locally constant in a neighborhood
of `c`. This is a manifold version of `Complex.norm_eventually_eq_of_isLocalMax`. -/
theorem Complex.norm_eventually_eq_of_mdifferentiableAt_of_isLocalMax {f : M β F} {c : M}
(hd : βαΆ z in π c, MDifferentiableAt I π(β, F) f z) (hc : IsLocalMax (norm β f) c) :
βαΆ y in π c, βf yβ = βf cβ := by
set e := extChartAt I c
have hI : range I = univ := ModelWithCorners.Boundaryless.range_eq_univ
have Hβ : π[range I] (e c) = π (e c) := by rw [hI, nhdsWithin_univ]
have Hβ : map e.symm (π (e c)) = π c := by
rw [β map_extChartAt_symm_nhdsWithin_range (I := I) c, Hβ]
rw [β Hβ, eventually_map]
replace hd : βαΆ y in π (e c), DifferentiableAt β (f β e.symm) y := by
have : e.target β π (e c) := Hβ βΈ extChartAt_target_mem_nhdsWithin c
filter_upwards [this, Tendsto.eventually Hβ.le hd] with y hyt hyβ
have hys : e.symm y β (chartAt H c).source := by
rw [β extChartAt_source I c]
exact (extChartAt I c).map_target hyt
have hfy : f (e.symm y) β (chartAt F (0 : F)).source := mem_univ _
rw [mdifferentiableAt_iff_of_mem_source hys hfy, hI, differentiableWithinAt_univ,
e.right_inv hyt] at hyβ
exact hyβ.2
convert norm_eventually_eq_of_isLocalMax hd _
Β· exact congr_arg f (extChartAt_to_inv _).symm
Β· simpa only [e, IsLocalMax, IsMaxFilter, β Hβ, (Β· β Β·), extChartAt_to_inv] using hc
/-!
### Functions holomorphic on a set
-/
namespace MDifferentiableOn
/-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a
complex normed space. Let `f : E β F` be a function that is complex differentiable on `U`. Suppose
that `βf xβ` takes its maximum value on `U` at `c β U`. Then `βf xβ = βf cβ` for all `x β U`. -/
theorem norm_eqOn_of_isPreconnected_of_isMaxOn {f : M β F} {U : Set M} {c : M}
(hd : MDifferentiableOn I π(β, F) f U) (hc : IsPreconnected U) (ho : IsOpen U)
(hcU : c β U) (hm : IsMaxOn (norm β f) U c) : EqOn (norm β f) (const M βf cβ) U := by
set V := {z β U | βf zβ = βf cβ}
suffices U β V from fun x hx β¦ (this hx).2
have hVo : IsOpen V := by
refine isOpen_iff_mem_nhds.2 fun x hx β¦ inter_mem (ho.mem_nhds hx.1) ?_
replace hm : IsLocalMax (βf Β·β) x :=
mem_of_superset (ho.mem_nhds hx.1) fun z hz β¦ (hm hz).out.trans_eq hx.2.symm
replace hd : βαΆ y in π x, MDifferentiableAt I π(β, F) f y :=
(eventually_mem_nhds_iff.2 (ho.mem_nhds hx.1)).mono fun z β¦ hd.mdifferentiableAt
exact (Complex.norm_eventually_eq_of_mdifferentiableAt_of_isLocalMax hd hm).mono fun _ β¦
(Eq.trans Β· hx.2)
have hVne : (U β© V).Nonempty := β¨c, hcU, hcU, rflβ©
set W := U β© {z | βf zβ = βf cβ}αΆ
have hWo : IsOpen W := hd.continuousOn.norm.isOpen_inter_preimage ho isOpen_ne
have hdVW : Disjoint V W := disjoint_compl_right.mono inf_le_right inf_le_right
have hUVW : U β V βͺ W := fun x hx => (eq_or_ne βf xβ βf cβ).imp (.intro hx) (.intro hx)
exact hc.subset_left_of_subset_union hVo hWo hdVW hUVW hVne
/-- **Maximum modulus principle** on a connected set. Let `U` be a (pre)connected open set in a
complex normed space. Let `f : E β F` be a function that is complex differentiable on `U`. Suppose
that `βf xβ` takes its maximum value on `U` at `c β U`. Then `f x = f c` for all `x β U`.
TODO: change assumption from `IsMaxOn` to `IsLocalMax`. -/
theorem eqOn_of_isPreconnected_of_isMaxOn_norm [StrictConvexSpace β F] {f : M β F} {U : Set M}
{c : M} (hd : MDifferentiableOn I π(β, F) f U) (hc : IsPreconnected U) (ho : IsOpen U)
(hcU : c β U) (hm : IsMaxOn (norm β f) U c) : EqOn f (const M (f c)) U := fun x hx =>
have Hβ : βf xβ = βf cβ := hd.norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hcU hm hx
-- TODO: Add `MDifferentiableOn.add` etc; does it mean importing `Manifold.Algebra.Monoid`?
have hd' : MDifferentiableOn I π(β, F) (f Β· + f c) U := fun x hx β¦
β¨(hd x hx).1.add continuousWithinAt_const, (hd x hx).2.add_const _β©
have Hβ : βf x + f cβ = βf c + f cβ :=
hd'.norm_eqOn_of_isPreconnected_of_isMaxOn hc ho hcU hm.norm_add_self hx
eq_of_norm_eq_of_norm_add_eq Hβ <| by simp only [Hβ, SameRay.rfl.norm_add, Hβ, Function.const]
/-- If a function `f : M β F` from a complex manifold to a complex normed space is holomorphic on a
(pre)connected compact open set, then it is a constant on this set. -/
theorem apply_eq_of_isPreconnected_isCompact_isOpen {f : M β F} {U : Set M} {a b : M}
(hd : MDifferentiableOn I π(β, F) f U) (hpc : IsPreconnected U) (hc : IsCompact U)
(ho : IsOpen U) (ha : a β U) (hb : b β U) : f a = f b := by
refine ?_
-- Subtract `f b` to avoid the assumption `[StrictConvexSpace β F]`
wlog hbβ : f b = 0 generalizing f
Β· have hd' : MDifferentiableOn I π(β, F) (f Β· - f b) U := fun x hx β¦
β¨(hd x hx).1.sub continuousWithinAt_const, (hd x hx).2.sub_const _β©
simpa [sub_eq_zero] using this hd' (sub_self _)
rcases hc.exists_isMaxOn β¨a, haβ© hd.continuousOn.norm with β¨c, hcU, hcβ©
have : β x β U, βf xβ = βf cβ :=
norm_eqOn_of_isPreconnected_of_isMaxOn hd hpc ho hcU hc
rw [hbβ, β norm_eq_zero, this a ha, β this b hb, hbβ, norm_zero]
end MDifferentiableOn
/-!
### Functions holomorphic on the whole manifold
Porting note: lemmas in this section were generalized from `π(β, E)` to an unspecified boundaryless
model so that it works, e.g., on a product of two manifolds without a boundary. This can break
`apply MDifferentiable.apply_eq_of_compactSpace`, use
`apply MDifferentiable.apply_eq_of_compactSpace (I := I)` instead or dot notation on an existing
`MDifferentiable` hypothesis.
-/
namespace MDifferentiable
variable [CompactSpace M]
/-- A holomorphic function on a compact complex manifold is locally constant. -/
protected theorem isLocallyConstant {f : M β F} (hf : MDifferentiable I π(β, F) f) :
IsLocallyConstant f :=
haveI : LocallyConnectedSpace H := I.toHomeomorph.locallyConnectedSpace
haveI : LocallyConnectedSpace M := ChartedSpace.locallyConnectedSpace H M
IsLocallyConstant.of_constant_on_preconnected_clopens fun _ hpc hclo _a ha _b hb β¦
hf.mdifferentiableOn.apply_eq_of_isPreconnected_isCompact_isOpen hpc
hclo.isClosed.isCompact hclo.isOpen hb ha
/-- A holomorphic function on a compact connected complex manifold is constant. -/
theorem apply_eq_of_compactSpace [PreconnectedSpace M] {f : M β F}
(hf : MDifferentiable I π(β, F) f) (a b : M) : f a = f b :=
hf.isLocallyConstant.apply_eq_of_preconnectedSpace _ _
/-- A holomorphic function on a compact connected complex manifold is the constant function `f β‘ v`,
for some value `v`. -/
theorem exists_eq_const_of_compactSpace [PreconnectedSpace M] {f : M β F}
(hf : MDifferentiable I π(β, F) f) : β v : F, f = Function.const M v :=
hf.isLocallyConstant.exists_eq_const
end MDifferentiable
|
Evaluation.lean
|
/-
Copyright (c) 2024 Antoine Chambert-Loir, 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
-/
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.RingTheory.Ideal.BigOperators
import Mathlib.RingTheory.MvPowerSeries.PiTopology
import Mathlib.RingTheory.MvPowerSeries.Trunc
import Mathlib.Topology.Algebra.Algebra
import Mathlib.Topology.Algebra.TopologicallyNilpotent
import Mathlib.Topology.Algebra.LinearTopology
import Mathlib.Topology.Algebra.UniformRing
/-! # Evaluation of multivariate power series
Let `Ο`, `R`, `S` be types, with `CommRing R`, `CommRing S`.
One assumes that `IsTopologicalRing R` and `IsUniformAddGroup R`,
and that `S` is a complete and separated topological `R`-algebra,
with `IsLinearTopology S S`, which means there is a basis of neighborhoods of 0
consisting of ideals.
Given `Ο : R β+* S`, `a : Ο β S`, and `f : MvPowerSeries Ο R`,
`MvPowerSeries.evalβ f Ο a` is the evaluation of the multivariate power series `f` at `a`.
It `f` is (the coercion of) a polynomial, it coincides with the evaluation of that polynomial.
Otherwise, it is defined by density from polynomials;
its values are irrelevant unless `Ο` is continuous and `a` satisfies two conditions
bundled in `MvPowerSeries.HasEval a` :
- for all `s : Ο`, `a s` is topologically nilpotent,
meaning that `(a s) ^ n` tends to 0 when `n` tends to infinity
- when `a s` tends to zero for the filter of cofinite subsets of `Ο`.
Under `Continuous Ο` and `HasEval a`, the following lemmas furnish the properties of evaluation:
* `MvPowerSeries.evalβHom`: the evaluation of multivariate power series, as a ring morphism,
* `MvPowerSeries.aeval`: the evaluation map as an algebra morphism
* `MvPowerSeries.uniformContinuous_evalβ`: uniform continuity of the evaluation
* `MvPowerSeries.continuous_evalβ`: continuity of the evaluation
* `MvPowerSeries.evalβ_eq_tsum`: the evaluation is given by the sum of its monomials, evaluated.
-/
namespace MvPowerSeries
open Topology
open Filter MvPolynomial RingHom Set TopologicalSpace UniformSpace
/- ## Necessary conditions -/
section
variable {Ο : Type*}
variable {R : Type*} [CommRing R] [TopologicalSpace R]
variable {S : Type*} [CommRing S] [TopologicalSpace S]
variable {Ο : R β+* S}
-- We endow MvPowerSeries Ο R with the Pi topology
open WithPiTopology
/-- Families at which power series can be consistently evaluated -/
@[mk_iff hasEval_def]
structure HasEval (a : Ο β S) : Prop where
hpow : β s, IsTopologicallyNilpotent (a s)
tendsto_zero : Tendsto a cofinite (π 0)
theorem HasEval.mono {S : Type*} [CommRing S] {a : Ο β S}
{t u : TopologicalSpace S} (h : t β€ u) (ha : @HasEval _ _ _ t a) :
@HasEval _ _ _ u a :=
β¨fun s β¦ Filter.Tendsto.mono_right (@HasEval.hpow _ _ _ t a ha s) (nhds_mono h),
Filter.Tendsto.mono_right (@HasEval.tendsto_zero Ο _ _ t a ha) (nhds_mono h)β©
theorem HasEval.zero : HasEval (0 : Ο β S) where
hpow _ := .zero
tendsto_zero := tendsto_const_nhds
theorem HasEval.add [ContinuousAdd S] [IsLinearTopology S S]
{a b : Ο β S} (ha : HasEval a) (hb : HasEval b) : HasEval (a + b) where
hpow s := (ha.hpow s).add (hb.hpow s)
tendsto_zero := by rw [β add_zero 0]; exact ha.tendsto_zero.add hb.tendsto_zero
theorem HasEval.mul_left [IsLinearTopology S S]
(c : Ο β S) {x : Ο β S} (hx : HasEval x) : HasEval (c * x) where
hpow s := (hx.hpow s).mul_left (c s)
tendsto_zero := IsLinearTopology.tendsto_mul_zero_of_right _ _ hx.tendsto_zero
theorem HasEval.mul_right [IsLinearTopology S S]
(c : Ο β S) {x : Ο β S} (hx : HasEval x) : HasEval (x * c) :=
mul_comm x c βΈ HasEval.mul_left c hx
/-- [Bourbaki, *Algebra*, chap. 4, Β§4, nΒ°3, Prop. 4 (i) (a & b)][bourbaki1981]. -/
theorem HasEval.map (hΟ : Continuous Ο) {a : Ο β R} (ha : HasEval a) :
HasEval (fun s β¦ Ο (a s)) where
hpow s := (ha.hpow s).map hΟ
tendsto_zero := (map_zero Ο βΈ hΟ.tendsto 0).comp ha.tendsto_zero
protected theorem HasEval.X :
HasEval (fun s β¦ (MvPowerSeries.X s : MvPowerSeries Ο R)) where
hpow s := isTopologicallyNilpotent_of_constantCoeff_zero (constantCoeff_X s)
tendsto_zero := variables_tendsto_zero
variable [IsTopologicalRing S] [IsLinearTopology S S]
/-- The domain of evaluation of `MvPowerSeries`, as an ideal -/
@[simps]
def hasEvalIdeal : Ideal (Ο β S) where
carrier := {a | HasEval a}
add_mem' := HasEval.add
zero_mem' := HasEval.zero
smul_mem' := HasEval.mul_left
theorem mem_hasEvalIdeal_iff {a : Ο β S} :
a β hasEvalIdeal β HasEval a := by
simp [hasEvalIdeal]
end
/- ## Construction of an evaluation morphism for power series -/
section Evaluation
open WithPiTopology
variable {Ο : Type*}
variable {R : Type*} [CommRing R] [UniformSpace R]
variable {S : Type*} [CommRing S] [UniformSpace S]
variable {Ο : R β+* S}
-- We endow MvPowerSeries Ο R with the product uniform structure
private instance : UniformSpace (MvPolynomial Ο R) :=
comap toMvPowerSeries (Pi.uniformSpace _)
/-- The induced uniform structure of MvPolynomial Ο R is an add group uniform structure -/
private instance [IsUniformAddGroup R] : IsUniformAddGroup (MvPolynomial Ο R) :=
IsUniformAddGroup.comap coeToMvPowerSeries.ringHom
theorem _root_.MvPolynomial.toMvPowerSeries_isUniformInducing :
IsUniformInducing (toMvPowerSeries (Ο := Ο) (R := R)) :=
(isUniformInducing_iff toMvPowerSeries).mpr rfl
theorem _root_.MvPolynomial.toMvPowerSeries_isDenseInducing :
IsDenseInducing (toMvPowerSeries (Ο := Ο) (R := R)) :=
toMvPowerSeries_isUniformInducing.isDenseInducing denseRange_toMvPowerSeries
variable {a : Ο β S}
/- The evaluation map on multivariate polynomials is uniformly continuous
for the uniform structure induced by that on multivariate power series. -/
theorem _root_.MvPolynomial.toMvPowerSeries_uniformContinuous
[IsUniformAddGroup R] [IsUniformAddGroup S] [IsLinearTopology S S]
(hΟ : Continuous Ο) (ha : HasEval a) :
UniformContinuous (MvPolynomial.evalβHom Ο a) := by
classical
apply uniformContinuous_of_continuousAt_zero
rw [ContinuousAt, map_zero, IsLinearTopology.hasBasis_ideal.tendsto_right_iff]
intro I hI
let n : Ο β β := fun s β¦ sInf {n : β | (a s) ^ n.succ β I}
have hn_ne : β s, Set.Nonempty {n : β | (a s) ^ n.succ β I} := fun s β¦ by
rcases ha.hpow s |>.eventually_mem hI |>.exists_forall_of_atTop with β¨n, hnβ©
use n
simpa using hn n.succ n.le_succ
have hn : Set.Finite (n.support) := by
change n =αΆ [cofinite] 0
filter_upwards [ha.tendsto_zero.eventually_mem hI] with s has
simpa [n, Pi.zero_apply, Nat.sInf_eq_zero, or_iff_left (hn_ne s).ne_empty] using has
let nβ : Ο ββ β := .ofSupportFinite n hn
let D := Iic nβ
have hD : Set.Finite D := finite_Iic _
have : β d β D, βαΆ (p : MvPolynomial Ο R) in π 0, Ο (p.coeff d) β I := fun d hd β¦ by
have : Tendsto (Ο β coeff R d β toMvPowerSeries) (π 0) (π 0) :=
hΟ.comp (continuous_coeff R d) |>.comp continuous_induced_dom |>.tendsto' 0 0 (map_zero _)
filter_upwards [this.eventually_mem hI] with f hf
simpa using hf
rw [β hD.eventually_all] at this
filter_upwards [this] with p hp
rw [coe_evalβHom, SetLike.mem_coe, evalβ_eq]
apply Ideal.sum_mem
intro d _
by_cases hd : d β D
Β· exact Ideal.mul_mem_right _ _ (hp d hd)
Β· apply Ideal.mul_mem_left
simp only [mem_Iic, D, Finsupp.le_iff] at hd
push_neg at hd
rcases hd with β¨s, hs', hsβ©
exact I.prod_mem hs' (I.pow_mem_of_pow_mem (Nat.sInf_mem (hn_ne s)) hs)
variable (Ο a)
open scoped Classical in
/-- Evaluation of a multivariate power series at `f` at a point `a : Ο β S`.
It coincides with the evaluation of `f` as a polynomial if `f` is the coercion of a polynomial.
Otherwise, it is only relevant if `Ο` is continuous and `HasEval a`. -/
noncomputable def evalβ (f : MvPowerSeries Ο R) : S :=
if H : β p : MvPolynomial Ο R, p = f then (MvPolynomial.evalβ Ο a H.choose)
else IsDenseInducing.extend toMvPowerSeries_isDenseInducing (MvPolynomial.evalβ Ο a) f
@[simp, norm_cast]
theorem evalβ_coe (f : MvPolynomial Ο R) :
MvPowerSeries.evalβ Ο a f = MvPolynomial.evalβ Ο a f := by
have : β p : MvPolynomial Ο R, (p : MvPowerSeries Ο R) = f := β¨f, rflβ©
rw [evalβ, dif_pos this]
congr
rw [β MvPolynomial.coe_inj, this.choose_spec]
@[simp]
theorem evalβ_C (r : R) : evalβ Ο a (C Ο R r) = Ο r := by
rw [β coe_C, evalβ_coe, MvPolynomial.evalβ_C]
@[simp]
theorem evalβ_X (s : Ο) : evalβ Ο a (X s) = a s := by
rw [β coe_X, evalβ_coe, MvPolynomial.evalβ_X]
variable [IsTopologicalSemiring R] [IsUniformAddGroup R]
[IsUniformAddGroup S] [CompleteSpace S] [T2Space S]
[IsTopologicalRing S] [IsLinearTopology S S]
variable {Ο a}
/-- Evaluation of power series at adequate elements, as a `RingHom` -/
noncomputable def evalβHom (hΟ : Continuous Ο) (ha : HasEval a) :
MvPowerSeries Ο R β+* S :=
IsDenseInducing.extendRingHom (i := coeToMvPowerSeries.ringHom)
toMvPowerSeries_isUniformInducing
denseRange_toMvPowerSeries
(toMvPowerSeries_uniformContinuous hΟ ha)
theorem evalβHom_eq_extend (hΟ : Continuous Ο) (ha : HasEval a) (f : MvPowerSeries Ο R) :
evalβHom hΟ ha f =
toMvPowerSeries_isDenseInducing.extend (MvPolynomial.evalβ Ο a) f :=
rfl
theorem coe_evalβHom (hΟ : Continuous Ο) (ha : HasEval a) :
β(evalβHom hΟ ha) = evalβ Ο a := by
ext f
simp only [evalβHom_eq_extend, evalβ]
split_ifs with h
Β· obtain β¨p, rflβ© := h
simpa [MvPolynomial.coe_evalβHom] using
toMvPowerSeries_isDenseInducing.extend_eq
(toMvPowerSeries_uniformContinuous hΟ ha).continuous p
Β· rw [β evalβHom_eq_extend hΟ ha]
-- Note: this is still true without the `T2Space` hypothesis, by arguing that the case
-- disjunction in the definition of `evalβ` only replaces some values by topologically
-- inseparable ones.
theorem uniformContinuous_evalβ (hΟ : Continuous Ο) (ha : HasEval a) :
UniformContinuous (evalβ Ο a) := by
rw [β coe_evalβHom hΟ ha]
exact uniformContinuous_uniformly_extend
toMvPowerSeries_isUniformInducing
denseRange_toMvPowerSeries
(toMvPowerSeries_uniformContinuous hΟ ha)
theorem continuous_evalβ (hΟ : Continuous Ο) (ha : HasEval a) :
Continuous (evalβ Ο a : MvPowerSeries Ο R β S) :=
(uniformContinuous_evalβ hΟ ha).continuous
theorem hasSum_evalβ (hΟ : Continuous Ο) (ha : HasEval a) (f : MvPowerSeries Ο R) :
HasSum
(fun (d : Ο ββ β) β¦ Ο (coeff R d f) * (d.prod fun s e => (a s) ^ e))
(MvPowerSeries.evalβ Ο a f) := by
rw [β coe_evalβHom hΟ ha, evalβHom_eq_extend hΟ ha]
convert (hasSum_of_monomials_self f).map (evalβHom hΟ ha) (?_) with d
Β· simp only [Function.comp_apply, coe_evalβHom, β MvPolynomial.coe_monomial,
evalβ_coe, evalβ_monomial]
Β· rw [coe_evalβHom]; exact continuous_evalβ hΟ ha
theorem evalβ_eq_tsum (hΟ : Continuous Ο) (ha : HasEval a) (f : MvPowerSeries Ο R) :
MvPowerSeries.evalβ Ο a f =
β' (d : Ο ββ β), Ο (coeff R d f) * (d.prod fun s e => (a s) ^ e) :=
(hasSum_evalβ hΟ ha f).tsum_eq.symm
theorem evalβ_unique (hΟ : Continuous Ο) (ha : HasEval a)
{Ξ΅ : MvPowerSeries Ο R β S} (hΞ΅ : Continuous Ξ΅)
(h : β p : MvPolynomial Ο R, Ξ΅ p = MvPolynomial.evalβ Ο a p) :
Ξ΅ = evalβ Ο a := by
rw [β coe_evalβHom hΟ ha]
exact (toMvPowerSeries_isDenseInducing.extend_unique h hΞ΅).symm
theorem comp_evalβ (hΟ : Continuous Ο) (ha : HasEval a)
{T : Type*} [UniformSpace T] [CompleteSpace T] [T2Space T]
[CommRing T] [IsTopologicalRing T] [IsLinearTopology T T] [IsUniformAddGroup T]
{Ξ΅ : S β+* T} (hΞ΅ : Continuous Ξ΅) :
Ξ΅ β evalβ Ο a = evalβ (Ξ΅.comp Ο) (Ξ΅ β a) := by
apply evalβ_unique _ (ha.map hΞ΅)
Β· exact Continuous.comp hΞ΅ (continuous_evalβ hΟ ha)
Β· intro p
simp only [Function.comp_apply, evalβ_coe]
rw [β MvPolynomial.coe_evalβHom, β comp_apply, MvPolynomial.comp_evalβHom,
MvPolynomial.coe_evalβHom]
Β· simp only [coe_comp, Continuous.comp hΞ΅ hΟ]
variable [Algebra R S] [ContinuousSMul R S]
/-- Evaluation of power series at adequate elements, as an `AlgHom` -/
noncomputable def aeval (ha : HasEval a) : MvPowerSeries Ο R ββ[R] S where
toRingHom := MvPowerSeries.evalβHom (continuous_algebraMap R S) ha
commutes' r := by
simp only [toMonoidHom_eq_coe, OneHom.toFun_eq_coe, MonoidHom.toOneHom_coe, MonoidHom.coe_coe]
rw [β c_eq_algebraMap, coe_evalβHom, evalβ_C]
theorem coe_aeval (ha : HasEval a) :
β(aeval ha) = evalβ (algebraMap R S) a := by
simp only [aeval, AlgHom.coe_mk, coe_evalβHom]
theorem continuous_aeval (ha : HasEval a) :
Continuous (aeval ha : MvPowerSeries Ο R β S) := by
rw [coe_aeval]
exact continuous_evalβ (continuous_algebraMap R S) ha
@[simp]
theorem aeval_coe (ha : HasEval a) (p : MvPolynomial Ο R) :
aeval ha (p : MvPowerSeries Ο R) = p.aeval a := by
rw [coe_aeval, aeval_def, evalβ_coe]
theorem aeval_unique {Ξ΅ : MvPowerSeries Ο R ββ[R] S} (hΞ΅ : Continuous Ξ΅) :
aeval (HasEval.X.map hΞ΅) = Ξ΅ := by
apply DFunLike.ext'
rw [coe_aeval]
refine (evalβ_unique (continuous_algebraMap R S) (HasEval.X.map hΞ΅) hΞ΅ ?_).symm
intro p
trans Ξ΅.comp (coeToMvPowerSeries.algHom R) p
Β· simp
conv_lhs => rw [β p.aeval_X_left_apply, MvPolynomial.comp_aeval_apply, MvPolynomial.aeval_def]
simp
theorem hasSum_aeval (ha : HasEval a) (f : MvPowerSeries Ο R) :
HasSum (fun (d : Ο ββ β) β¦ (coeff R d f) β’ (d.prod fun s e => (a s) ^ e))
(MvPowerSeries.aeval ha f) := by
simp_rw [coe_aeval, β algebraMap_smul (R := R) S, smul_eq_mul]
exact hasSum_evalβ (continuous_algebraMap R S) ha f
theorem aeval_eq_sum (ha : HasEval a) (f : MvPowerSeries Ο R) :
MvPowerSeries.aeval ha f =
tsum (fun (d : Ο ββ β) β¦ (coeff R d f) β’ (d.prod fun s e => (a s) ^ e)) :=
(hasSum_aeval ha f).tsum_eq.symm
theorem comp_aeval (ha : HasEval a)
{T : Type*} [CommRing T] [UniformSpace T] [IsUniformAddGroup T]
[IsTopologicalRing T] [IsLinearTopology T T]
[T2Space T] [Algebra R T] [ContinuousSMul R T] [CompleteSpace T]
{Ξ΅ : S ββ[R] T} (hΞ΅ : Continuous Ξ΅) :
Ξ΅.comp (aeval ha) = aeval (ha.map hΞ΅) := by
apply DFunLike.ext'
simp only [AlgHom.coe_comp, coe_aeval ha]
rw [β RingHom.coe_coe,
comp_evalβ (continuous_algebraMap R S) ha (show Continuous (Ξ΅ : S β+* T) from hΞ΅), coe_aeval]
congr!
simp only [AlgHom.comp_algebraMap_of_tower]
end Evaluation
end MvPowerSeries
|
Guide.lean
|
/-
Copyright (c) 2023 Kyle Miller. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kyle Miller
-/
/-! # Guide: Conversion mode tactic
This is a curated guide to point you toward how `conv` mode works and what tactics are available.
It is not meant to be comprehensive, but rather a "cheat sheet." See also the
[`conv` introduction](https://leanprover-community.github.io/mathlib4_docs/docs/Conv/Introduction.html).
## Syntax
The syntax for the `conv` tactic is
```
"conv" ("at" ident)? ("in" ("(occs :=" ("*" <|> num+) ")")? term)? "=>" convSeq
```
where `convSeq` is any sequence of "`conv` tactics", which are tactics specifically written
for `conv` mode.
The `in` clause is exactly the same as the arguments to the `conv` tactic `pattern`.
```lean
conv in ...pattArgs... =>
...
```
is short for
```lean
conv =>
pattern ...patArgs...
...
```
Note that `conv in (occs := 1 2 3) pat => ...` starts with three goals (one for each occurrence),
but `conv in (occs := *) pat => ...` starts with a single goal that converts in all occurrences
simultaneously.
Mathlib also provides `conv_lhs` and `conv_rhs` variants to immediately apply either the
`lhs` or `rhs` tactic.
## What is `conv` mode?
`conv` mode is essentially the normal tactic mode but with two differences.
1. Only "`conv` tactics" can appear in the `conv` block. These are tactics with syntax
in the `conv` category.
2. The goals are all of the form `β’ lhs = ?rhs` with `?rhs` a metavariable, but the goals
are annotated in such a way that they display as `| lhs`.
Each `conv` tactic is aware that the goal is of this form, and in addition to solving for the
goal like normal, they also solve for the `?rhs` metavariable in some controlled way.
For example, the `rfl` tactic uses `rfl` to solve the goal, which sets `?rhs := lhs`.
Other tactics, like `congr`, partially solve for `?rhs` and create new goal metavariables
for each unsolved-for hole.
Once all the tactics have had a chance to run, `conv` mode itself uses `rfl` to solve
any remaining goals (note that in `conv` mode, every goal can be solved for by `rfl`!), and
then it uses the resulting `lhs = rhs` proof to rewrite the goal in the surrounding normal
tactic mode.
## Conv tactics from Lean 4, Batteries, and Mathlib
Unless they're annotated with "Batteries" or "Mathlib", the following tactics are defined
in Lean 4 core.
### Control
* `done` checks that there are no `conv` goals remaining.
* `skip` does nothing. It can be used to be the single tactic in an otherwise empty `conv` block.
It does *not* skip a `conv` goal.
* `rfl` skips/closes a `conv` goal by using `rfl`. (Remember, the actual goal is `β’ lhs = ?rhs`, so
this sets `?rhs := lhs` and uses `rfl` to prove `lhs = lhs`.)
* `conv => convSeq` is a nested `conv`. It uses `conv` to change the current goal without
closing it. For example, this is how you can do a `conv`-targeted rewrite of the current
expression and then apply `conv` tactics to the result.
* `all_goals convSeq` runs the `conv` tactics on every `conv` goal, collecting all the produced
subgoals (if any).
* `any_goals convSeq` is like `all_goals` but succeeds if the tactic sequence succeeds for any
of the goals.
* `case tag => convSeq` focuses on a goal with a given tag, runs the tactic sequence, and then
auto-closes the focused goal with `rfl`. Has the same syntax as the `case` tactic.
* `case' tag => convSeq` is like `case` but does not auto-close the goal if the tactics
do not close it.
* `next => convSeq` and `next x1 ... xn => convSeq` are like the `next` tactic, but they
auto-close the focused goal with `rfl`.
* `Β· convSeq` focuses on the current goal and auto-closes it with `rfl`.
* `focus => convSeq` focuses on the current goal. It does not auto-close the goal, unlike `next`.
* `{ convSeq }` is like `next`.
* `first | convSeq1 | convSeq2 | ...` tries each `conv` sequence one at a time until one
of them succeeds, or else fails.
* `try convSeq` runs the `conv` sequence and succeeds even if it fails.
Same as `first | convSeq | skip`.
* `repeat convSeq` repeatedly runs `convSeq` until it fails.
* `( convSeq )` is for grouping. Useful when using `conv` tactic combinators.
* `conv1 <;> conv2` is for running `conv1` and running `conv2` on every goal produced by `conv`.
* `tactic => tacticSeq` converts the goal into `β’ lhs = ?rhs` form and applies the tactic sequence.
The tactic does not have to solve the goal completely, and remaining goals are turned back
into `conv` goals. (Internal: there's also a `tactic' => tacticSeq` that does not remove
the `conv` annotations from the goal before applying the tactic sequence.)
* `discharge => tacticSeq` takes a goal `| p` with `p` a proposition, uses the tactic sequence
to prove `β’ p`, and then closes the goal to convert `p` to `True`. (Mathlib)
* `with_reducible convSeq` changes the transparency settings to `reducible` while evaluating the
`conv` sequence. (Mathlib)
### Navigation
* `congr` (synonym: `args`) creates subgoals for every immediate subexpression of the expression.
You can use `rfl` to skip any of these subgoals.
* `lhs` (synonym: `left`) traverses into the second-to-last argument of the expression.
(Implemented using `congr`.)
* `rhs` (synonym: `right`) traverses into the last argument of the expression.
(Implemented using `congr`.)
* `arg i` (and `arg @i`) traverses into the `i`th explicit argument (resp. the `i`th argument)
of the expression. (Implemented using `congr`.)
* `ext` (synonym: `intro`) traverses into lambda, forall, and `let` expressions.
`ext x` gives the resulting binder the name `x`.
`ext x y z ...` applies `ext` once for each provided binder.
* `enter [...]` is a compact way to describe a path to a subterm.
* `enter [i]` (where `i` is a natural number) is equivalent to `arg i`.
* `enter [@i]` is equivalent to `arg @i`.
* `enter [x]` (where `x` is an identifier) is equivalent to `ext x`.
* `enter [a,b,c,...]` is `enter [a]; enter [b]; enter [c]; enter [...]`.
* `pattern` is for navigating into subexpressions that match a given pattern
* `pattern pat` traverses to the first subterm of the target that matches `pat`.
* `pattern (occs := *) pat` traverses to every subterm of the target that matches `pat`
which is not contained in another match of `pat`. It generates one subgoal.
* `pattern (occs := 1 2 4) pat` matches occurrences `1, 2, 4` of `pat` and produces
three subgoals. Occurrences are numbered left to right from the outside in.
### Manipulation
* `change t` changes the expression to `t` if the expression and `t` are definitionally equal.
* `equals t => tacticSeq` changes the current expression, say `e`, to `t`, and asks you to prove
the equality `e = t`. (Batteries)
* `rw [thms...]` rewrites the expression using the given theorems. The syntax is similar to `rw`.
* `erw [thms...]` rewrites the expression using the given theorems. The syntax is similar to `erw`.
* `simp [thms...]` applies `simp` to rewrite the expression. The syntax is similar to `simp`.
* `dsimp [thms...]` applies `dsimp` to rewrite the expression. The syntax is similar to `dsimp`.
* `simp_match` simplifies `match` expressions.
* `apply e` applies `e` to the goal (which remember is `β’ lhs = ?rhs`) using the `apply` tactic.
Strange results may occur if the hypotheses of `e` are not equalities.
* `refine e` applies `e` to the goal (which remember is `β’ lhs = ?rhs`) using the `refine` tactic.
Strange results may occur if the placeholders in `e` are not equalities.
* `exact e` closes the goal, where `e : lhs = ?rhs`. (Batteries)
* Mathlib provides a number of tactics as `conv` tactics:
* `abel` and `abel_nf`
* `ring` and `ring_nf`
* `norm_cast`
* `norm_num1` and `norm_num`
* `push_neg`
* `apply_congr` applies a relevant `@[congr]` lemma, which can be better suited for a function
than the congruence lemma that the `congr` tactic might generate. (Mathlib)
* `slice i j` (for category theory) reassociates a composition of morphisms to focus on
the composition of morphisms `i` through `j`. (Mathlib)
### Reductions
* `whnf` reduces the expression to weak-head normal form.
* `zeta` applies zeta reduction to the expression (i.e., substitutes all `let` expressions
and expands all local variables).
* `reduce` reduces the expression like the `#reduce` command.
(Documentation says "for debugging purposes only.")
* `unfold id1 id2 ...` unfolds the definitions for the given constants using each
definitions equational lemmas. For recursive definitions, only one layer of unfolding
is performed.
* `delta id1 id2 ...` applies delta reduction for the given constants (i.e., substitutes
the values of each constant). It is primitive: it ignores definitional equations and
uses the raw definition of each constant. Using `unfold` is preferred.
### Debugging, for internal use, or otherwise technical
* `trace_state` prints the current goal state (runs the `trace_state` tactic)
* `fail_if_success convSeq` fails if the `conv` sequence succeeds.
* `guard_expr` and `guard_target` for asserting that certain expressions are equal to others.
(Batteries)
* `unreachable!`, which is the same as the `unreachable!` tactic. (Batteries)
* `run_tac doSeq` evaluates a monadic value and runs it as a tactic using `tactic'`. (Mathlib)
## Tactics and commands related to `conv`
* `conv_lhs ... => ...` and `conv_rhs ... => ...` are like `conv`, but they immediately use
`lhs` or `rhs` (respectively). (Mathlib)
* `conv' ... => ...` is like `conv` but assumes the goal is already annotated as a `conv` goal.
Used internally to go back and forth between tactic mode and conv mode.
* `#conv convTactic => e` is a command to apply the `convTactic` to the expression `e`, yielding
the converted expression (and dropping the generated proof).
This is used to implement `#simp`, `#whnf`, `#norm_num`, and `#push_neg`. (Mathlib)
-/
|
Ulift.lean
|
/-
Copyright (c) 2023 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson, Junyan Xu, Sophie Morel
-/
import Mathlib.CategoryTheory.Limits.Creates
import Mathlib.CategoryTheory.Limits.Types.Limits
import Mathlib.CategoryTheory.Limits.Types.Colimits
import Mathlib.Data.Set.Subsingleton
/-!
# `ULift` creates small (co)limits
This file shows that `uliftFunctor.{v, u}` preserves all limits and colimits, including those
potentially too big to exist in `Type u`.
As this functor is fully faithful, we also deduce that it creates `u`-small limits and
colimits.
-/
universe v w w' u
namespace CategoryTheory.Limits.Types
/--
The equivalence between `K.sections` and `(K β uliftFunctor.{v, u}).sections`. This is used to show
that `uliftFunctor` preserves limits that are potentially too large to exist in the source
category.
-/
def sectionsEquiv {J : Type*} [Category J] (K : J β₯€ Type u) :
K.sections β (K β uliftFunctor.{v, u}).sections where
toFun := fun β¨u, huβ© => β¨fun j => β¨u jβ©, fun f => by simp [hu f]β©
invFun := fun β¨u, huβ© => β¨fun j => (u j).down, @fun j j' f => by simp [β hu f]β©
/--
The functor `uliftFunctor : Type u β₯€ Type (max u v)` preserves limits of arbitrary size.
-/
noncomputable instance : PreservesLimitsOfSize.{w', w} uliftFunctor.{v, u} where
preservesLimitsOfShape {J} := {
preservesLimit := fun {K} => {
preserves := fun {c} hc => by
rw [Types.isLimit_iff ((uliftFunctor.{v, u}).mapCone c)]
intro s hs
obtain β¨x, hxβ, hxββ© := (Types.isLimit_iff c).mp β¨hcβ© _ ((sectionsEquiv K).symm β¨s, hsβ©).2
exact β¨β¨xβ©, fun i => ULift.ext _ _ (hxβ i),
fun y hy => ULift.ext _ _ (hxβ y.down fun i β¦ ULift.ext_iff.mp (hy i))β© } }
/--
The functor `uliftFunctor : Type u β₯€ Type (max u v)` creates `u`-small limits.
-/
noncomputable instance : CreatesLimitsOfSize.{w, u} uliftFunctor.{v, u} where
CreatesLimitsOfShape := { CreatesLimit := fun {_} β¦ createsLimitOfFullyFaithfulOfPreserves }
variable {J : Type*} [Category J] {K : J β₯€ Type u} {c : Cocone K} (hc : IsColimit c)
variable {lc : Cocone (K β uliftFunctor.{v, u})}
/--
The functor `uliftFunctor : Type u β₯€ Type (max u v)` preserves colimits of arbitrary size.
-/
noncomputable instance : PreservesColimitsOfSize.{w', w} uliftFunctor.{v, u} where
preservesColimitsOfShape {J _} :=
{ preservesColimit := fun {F} β¦
{ preserves := fun {c} hc β¦ by
rw [isColimit_iff_coconeTypesIsColimit]
exact (((isColimit_iff_coconeTypesIsColimit _).1 β¨hcβ©).precompose
(G := F β uliftFunctor.{v}) (fun _ β¦ Equiv.ulift)
(fun _ β¦ rfl)).of_equiv Equiv.ulift.symm (fun _ _ β¦ rfl) } }
/--
The functor `uliftFunctor : Type u β₯€ Type (max u v)` creates `u`-small colimits.
-/
noncomputable instance : CreatesColimitsOfSize.{w, u} uliftFunctor.{v, u} where
CreatesColimitsOfShape :=
{ CreatesColimit := fun {_} β¦ createsColimitOfReflectsIsomorphismsOfPreserves }
end CategoryTheory.Limits.Types
|
Curry.lean
|
/-
Copyright (c) 2020 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel
-/
import Mathlib.Analysis.NormedSpace.Multilinear.Basic
import Mathlib.LinearAlgebra.Multilinear.Curry
/-!
# Currying and uncurrying continuous multilinear maps
We associate to a continuous multilinear map in `n+1` variables (i.e., based on `Fin n.succ`) two
curried functions, named `f.curryLeft` (which is a continuous linear map on `E 0` taking values
in continuous multilinear maps in `n` variables) and `f.curryRight` (which is a continuous
multilinear map in `n` variables taking values in continuous linear maps on `E (last n)`).
The inverse operations are called `uncurryLeft` and `uncurryRight`.
We also register continuous linear equiv versions of these correspondences, in
`continuousMultilinearCurryLeftEquiv` and `continuousMultilinearCurryRightEquiv`.
## Main results
* `ContinuousMultilinearMap.curryLeft`, `ContinuousLinearMap.uncurryLeft` and
`continuousMultilinearCurryLeftEquiv`
* `ContinuousMultilinearMap.curryRight`, `ContinuousMultilinearMap.uncurryRight` and
`continuousMultilinearCurryRightEquiv`.
* `ContinuousMultilinearMap.curryMid`, `ContinuousLinearMap.uncurryMid` and
`ContinuousMultilinearMap.curryMidEquiv`
-/
suppress_compilation
noncomputable section
open NNReal Finset Metric ContinuousMultilinearMap Fin Function
/-!
### Type variables
We use the following type variables in this file:
* `π` : a `NontriviallyNormedField`;
* `ΞΉ`, `ΞΉ'` : finite index types with decidable equality;
* `E`, `Eβ` : families of normed vector spaces over `π` indexed by `i : ΞΉ`;
* `E'` : a family of normed vector spaces over `π` indexed by `i' : ΞΉ'`;
* `Ei` : a family of normed vector spaces over `π` indexed by `i : Fin (Nat.succ n)`;
* `G`, `G'` : normed vector spaces over `π`.
-/
universe u v v' wE wEβ wE' wEi wG wG'
variable {π : Type u} {ΞΉ : Type v} {ΞΉ' : Type v'} {n : β} {E : ΞΉ β Type wE}
{Ei : Fin n.succ β Type wEi} {G : Type wG} {G' : Type wG'} [Fintype ΞΉ]
[Fintype ΞΉ'] [NontriviallyNormedField π] [β i, NormedAddCommGroup (E i)]
[β i, NormedSpace π (E i)] [β i, NormedAddCommGroup (Ei i)] [β i, NormedSpace π (Ei i)]
[NormedAddCommGroup G] [NormedSpace π G] [NormedAddCommGroup G'] [NormedSpace π G']
theorem ContinuousLinearMap.norm_map_removeNth_le {i : Fin (n + 1)}
(f : Ei i βL[π] ContinuousMultilinearMap π (fun j β¦ Ei (i.succAbove j)) G) (m : β i, Ei i) :
βf (m i) (i.removeNth m)β β€ βfβ * β j, βm jβ := by
rw [i.prod_univ_succAbove, β mul_assoc]
exact (f (m i)).le_of_opNorm_le (f.le_opNorm _) _
theorem ContinuousLinearMap.norm_map_tail_le
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) (m : β i, Ei i) :
βf (m 0) (tail m)β β€ βfβ * β i, βm iβ :=
ContinuousLinearMap.norm_map_removeNth_le (i := 0) f m
theorem ContinuousMultilinearMap.norm_map_init_le
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G))
(m : β i, Ei i) : βf (init m) (m (last n))β β€ βfβ * β i, βm iβ := by
rw [prod_univ_castSucc, β mul_assoc]
exact (f (init m)).le_of_opNorm_le (f.le_opNorm _) _
theorem ContinuousMultilinearMap.norm_map_insertNth_le (f : ContinuousMultilinearMap π Ei G)
{i : Fin (n + 1)} (x : Ei i) (m : β j, Ei (i.succAbove j)) :
βf (i.insertNth x m)β β€ βfβ * βxβ * β i, βm iβ := by
simpa [i.prod_univ_succAbove, mul_assoc] using f.le_opNorm (i.insertNth x m)
theorem ContinuousMultilinearMap.norm_map_cons_le (f : ContinuousMultilinearMap π Ei G) (x : Ei 0)
(m : β i : Fin n, Ei i.succ) : βf (cons x m)β β€ βfβ * βxβ * β i, βm iβ := by
simpa [prod_univ_succ, mul_assoc] using f.le_opNorm (cons x m)
theorem ContinuousMultilinearMap.norm_map_snoc_le (f : ContinuousMultilinearMap π Ei G)
(m : β i : Fin n, Ei <| castSucc i) (x : Ei (last n)) :
βf (snoc m x)β β€ (βfβ * β i, βm iβ) * βxβ := by
simpa [prod_univ_castSucc, mul_assoc] using f.le_opNorm (snoc m x)
/-! #### Left currying -/
/-- Given a continuous linear map `f` from `E 0` to continuous multilinear maps on `n` variables,
construct the corresponding continuous multilinear map on `n+1` variables obtained by concatenating
the variables, given by `m β¦ f (m 0) (tail m)` -/
def ContinuousLinearMap.uncurryLeft
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) :
ContinuousMultilinearMap π Ei G :=
(ContinuousMultilinearMap.toMultilinearMapLinear ββ f.toLinearMap).uncurryLeft.mkContinuous
βfβ fun m => by exact ContinuousLinearMap.norm_map_tail_le f m
@[simp]
theorem ContinuousLinearMap.uncurryLeft_apply
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) (m : β i, Ei i) :
f.uncurryLeft m = f (m 0) (tail m) :=
rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the first variable to obtain
a continuous linear map into continuous multilinear maps in `n` variables, given by
`x β¦ (m β¦ f (cons x m))`. -/
def ContinuousMultilinearMap.curryLeft (f : ContinuousMultilinearMap π Ei G) :
Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G :=
MultilinearMap.mkContinuousLinear f.toMultilinearMap.curryLeft βfβ f.norm_map_cons_le
@[simp]
theorem ContinuousMultilinearMap.curryLeft_apply (f : ContinuousMultilinearMap π Ei G) (x : Ei 0)
(m : β i : Fin n, Ei i.succ) : f.curryLeft x m = f (cons x m) :=
rfl
@[simp]
theorem ContinuousLinearMap.curry_uncurryLeft
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) :
f.uncurryLeft.curryLeft = f := by
ext m x
rw [ContinuousMultilinearMap.curryLeft_apply, ContinuousLinearMap.uncurryLeft_apply, tail_cons,
cons_zero]
@[simp]
theorem ContinuousMultilinearMap.uncurry_curryLeft (f : ContinuousMultilinearMap π Ei G) :
f.curryLeft.uncurryLeft = f :=
ContinuousMultilinearMap.toMultilinearMap_injective <| f.toMultilinearMap.uncurry_curryLeft
variable (π Ei G)
/-- The space of continuous multilinear maps on `Ξ (i : Fin (n+1)), E i` is canonically isomorphic to
the space of continuous linear maps from `E 0` to the space of continuous multilinear maps on
`Ξ (i : Fin n), E i.succ`, by separating the first variable. We register this isomorphism in
`continuousMultilinearCurryLeftEquiv π E Eβ`. The algebraic version (without topology) is given
in `multilinearCurryLeftEquiv π E Eβ`.
The direct and inverse maps are given by `f.curryLeft` and `f.uncurryLeft`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuousMultilinearCurryLeftEquiv :
ContinuousMultilinearMap π Ei G ββα΅’[π]
Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G :=
LinearIsometryEquiv.ofBounds
{ toFun := ContinuousMultilinearMap.curryLeft
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl
invFun := ContinuousLinearMap.uncurryLeft
left_inv := ContinuousMultilinearMap.uncurry_curryLeft
right_inv := ContinuousLinearMap.curry_uncurryLeft }
(fun f => by dsimp; exact MultilinearMap.mkContinuousLinear_norm_le _ (norm_nonneg f) _)
(fun f => by
simp only [LinearEquiv.coe_symm_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg f) _)
variable {π Ei G}
@[simp]
theorem continuousMultilinearCurryLeftEquiv_apply
(f : ContinuousMultilinearMap π Ei G) (x : Ei 0) (v : Ξ i : Fin n, Ei i.succ) :
continuousMultilinearCurryLeftEquiv π Ei G f x v = f (cons x v) :=
rfl
@[simp]
theorem continuousMultilinearCurryLeftEquiv_symm_apply
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) (v : Ξ i, Ei i) :
(continuousMultilinearCurryLeftEquiv π Ei G).symm f v = f (v 0) (tail v) :=
rfl
@[simp]
theorem ContinuousMultilinearMap.curryLeft_norm (f : ContinuousMultilinearMap π Ei G) :
βf.curryLeftβ = βfβ :=
(continuousMultilinearCurryLeftEquiv π Ei G).norm_map f
@[simp]
theorem ContinuousLinearMap.uncurryLeft_norm
(f : Ei 0 βL[π] ContinuousMultilinearMap π (fun i : Fin n => Ei i.succ) G) :
βf.uncurryLeftβ = βfβ :=
(continuousMultilinearCurryLeftEquiv π Ei G).symm.norm_map f
/-! #### Right currying -/
/-- Given a continuous linear map `f` from continuous multilinear maps on `n` variables to
continuous linear maps on `E 0`, construct the corresponding continuous multilinear map on `n+1`
variables obtained by concatenating the variables, given by `m β¦ f (init m) (m (last n))`. -/
def ContinuousMultilinearMap.uncurryRight
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G)) :
ContinuousMultilinearMap π Ei G :=
let f' : MultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) ββ[π] G) :=
(ContinuousLinearMap.coeLM π).compMultilinearMap f.toMultilinearMap
f'.uncurryRight.mkContinuous βfβ fun m => f.norm_map_init_le m
@[simp]
theorem ContinuousMultilinearMap.uncurryRight_apply
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G))
(m : β i, Ei i) : f.uncurryRight m = f (init m) (m (last n)) :=
rfl
/-- Given a continuous multilinear map `f` in `n+1` variables, split the last variable to obtain
a continuous multilinear map in `n` variables into continuous linear maps, given by
`m β¦ (x β¦ f (snoc m x))`. -/
def ContinuousMultilinearMap.curryRight (f : ContinuousMultilinearMap π Ei G) :
ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G) :=
let f' : MultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G) :=
{ toFun := fun m =>
(f.toMultilinearMap.curryRight m).mkContinuous (βfβ * β i, βm iβ) fun x =>
f.norm_map_snoc_le m x
map_update_add' := fun m i x y => by
ext
simp
map_update_smul' := fun m i c x => by
ext
simp }
f'.mkContinuous βfβ fun m => by
simp only [f', MultilinearMap.coe_mk]
exact LinearMap.mkContinuous_norm_le _ (by positivity) _
@[simp]
theorem ContinuousMultilinearMap.curryRight_apply (f : ContinuousMultilinearMap π Ei G)
(m : β i : Fin n, Ei <| castSucc i) (x : Ei (last n)) : f.curryRight m x = f (snoc m x) :=
rfl
@[simp]
theorem ContinuousMultilinearMap.curry_uncurryRight
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G)) :
f.uncurryRight.curryRight = f := by
ext m x
rw [ContinuousMultilinearMap.curryRight_apply, ContinuousMultilinearMap.uncurryRight_apply,
snoc_last, init_snoc]
@[simp]
theorem ContinuousMultilinearMap.uncurry_curryRight (f : ContinuousMultilinearMap π Ei G) :
f.curryRight.uncurryRight = f := by
ext m
rw [uncurryRight_apply, curryRight_apply, snoc_init_self]
variable (π Ei G)
/--
The space of continuous multilinear maps on `Ξ (i : Fin (n+1)), Ei i` is canonically isomorphic to
the space of continuous multilinear maps on `Ξ (i : Fin n), Ei <| castSucc i` with values in the
space of continuous linear maps on `Ei (last n)`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuousMultilinearCurryRightEquiv π Ei G`.
The algebraic version (without topology) is given in `multilinearCurryRightEquiv π Ei G`.
The direct and inverse maps are given by `f.curryRight` and `f.uncurryRight`. Use these
unless you need the full framework of linear isometric equivs.
-/
def continuousMultilinearCurryRightEquiv :
ContinuousMultilinearMap π Ei G ββα΅’[π]
ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G) :=
LinearIsometryEquiv.ofBounds
{ toFun := ContinuousMultilinearMap.curryRight
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl
invFun := ContinuousMultilinearMap.uncurryRight
left_inv := ContinuousMultilinearMap.uncurry_curryRight
right_inv := ContinuousMultilinearMap.curry_uncurryRight }
(fun f => by
simp only [curryRight, LinearEquiv.coe_mk, LinearMap.coe_mk, AddHom.coe_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg f) _)
(fun f => by
simp only [uncurryRight, LinearEquiv.coe_symm_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg f) _)
variable (n G')
/-- The space of continuous multilinear maps on `Ξ (i : Fin (n+1)), G` is canonically isomorphic to
the space of continuous multilinear maps on `Ξ (i : Fin n), G` with values in the space
of continuous linear maps on `G`, by separating the last variable. We register this
isomorphism as a continuous linear equiv in `continuousMultilinearCurryRightEquiv' π n G G'`.
For a version allowing dependent types, see `continuousMultilinearCurryRightEquiv`. When there
are no dependent types, use the primed version as it helps Lean a lot for unification.
The direct and inverse maps are given by `f.curryRight` and `f.uncurryRight`. Use these
unless you need the full framework of linear isometric equivs. -/
def continuousMultilinearCurryRightEquiv' : (G [Γn.succ]βL[π] G') ββα΅’[π] G [Γn]βL[π] G βL[π] G' :=
continuousMultilinearCurryRightEquiv π (fun _ => G) G'
variable {n π G Ei G'}
@[simp]
theorem continuousMultilinearCurryRightEquiv_apply
(f : ContinuousMultilinearMap π Ei G) (v : Ξ i : Fin n, Ei <| castSucc i) (x : Ei (last n)) :
continuousMultilinearCurryRightEquiv π Ei G f v x = f (snoc v x) :=
rfl
@[simp]
theorem continuousMultilinearCurryRightEquiv_symm_apply
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G))
(v : Ξ i, Ei i) :
(continuousMultilinearCurryRightEquiv π Ei G).symm f v = f (init v) (v (last n)) :=
rfl
@[simp]
theorem continuousMultilinearCurryRightEquiv_apply'
(f : G [Γn.succ]βL[π] G') (v : Fin n β G) (x : G) :
continuousMultilinearCurryRightEquiv' π n G G' f v x = f (snoc v x) :=
rfl
@[simp]
theorem continuousMultilinearCurryRightEquiv_symm_apply'
(f : G [Γn]βL[π] G βL[π] G') (v : Fin (n + 1) β G) :
(continuousMultilinearCurryRightEquiv' π n G G').symm f v = f (init v) (v (last n)) :=
rfl
@[simp]
theorem ContinuousMultilinearMap.curryRight_norm (f : ContinuousMultilinearMap π Ei G) :
βf.curryRightβ = βfβ :=
(continuousMultilinearCurryRightEquiv π Ei G).norm_map f
@[simp]
theorem ContinuousMultilinearMap.uncurryRight_norm
(f : ContinuousMultilinearMap π (fun i : Fin n => Ei <| castSucc i) (Ei (last n) βL[π] G)) :
βf.uncurryRightβ = βfβ :=
(continuousMultilinearCurryRightEquiv π Ei G).symm.norm_map f
/-!
### Currying a variable in the middle
-/
/-- Given a continuous linear map from `M p` to the space of continuous multilinear maps
in `n` variables `M 0`, ..., `M n` with `M p` removed,
returns a continuous multilinear map in all `n + 1` variables. -/
@[simps! apply]
def ContinuousLinearMap.uncurryMid (p : Fin (n + 1))
(f : Ei p βL[π] ContinuousMultilinearMap π (fun i β¦ Ei (p.succAbove i)) G) :
ContinuousMultilinearMap π Ei G :=
(ContinuousMultilinearMap.toMultilinearMapLinear ββ f.toLinearMap).uncurryMid p
|>.mkContinuous βfβ fun m => by exact ContinuousLinearMap.norm_map_removeNth_le f m
/-- Interpret a continuous multilinear map in `n + 1` variables
as a continuous linear map in `p`th variable
with values in the continuous multilinear maps in the other variables. -/
def ContinuousMultilinearMap.curryMid (p : Fin (n + 1)) (f : ContinuousMultilinearMap π Ei G) :
Ei p βL[π] ContinuousMultilinearMap π (fun i β¦ Ei (p.succAbove i)) G :=
MultilinearMap.mkContinuousLinear (f.toMultilinearMap.curryMid p) βfβ f.norm_map_insertNth_le
@[simp]
theorem ContinuousMultilinearMap.curryMid_apply (p : Fin (n + 1))
(f : ContinuousMultilinearMap π Ei G) (x : Ei p) (m : β i, Ei (p.succAbove i)) :
f.curryMid p x m = f (p.insertNth x m) :=
rfl
@[simp]
theorem ContinuousLinearMap.curryMid_uncurryMid (p : Fin (n + 1))
(f : Ei p βL[π] ContinuousMultilinearMap π (fun i β¦ Ei (p.succAbove i)) G) :
(f.uncurryMid p).curryMid p = f := by ext; simp
@[simp]
theorem ContinuousMultilinearMap.uncurryMid_curryMid (p : Fin (n + 1))
(f : ContinuousMultilinearMap π Ei G) : (f.curryMid p).uncurryMid p = f :=
ContinuousMultilinearMap.toMultilinearMap_injective <| f.toMultilinearMap.uncurryMid_curryMid p
variable (π Ei G)
/-- `ContinuousMultilinearMap.curryMid` as a linear isometry equivalence. -/
@[simps! apply symm_apply]
def ContinuousMultilinearMap.curryMidEquiv (p : Fin (n + 1)) :
ContinuousMultilinearMap π Ei G ββα΅’[π]
Ei p βL[π] ContinuousMultilinearMap π (fun i β¦ Ei (p.succAbove i)) G :=
LinearIsometryEquiv.ofBounds
{ toFun := ContinuousMultilinearMap.curryMid p
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl
invFun := ContinuousLinearMap.uncurryMid p
left_inv := ContinuousMultilinearMap.uncurryMid_curryMid p
right_inv := ContinuousLinearMap.curryMid_uncurryMid p }
(fun f => by dsimp; exact MultilinearMap.mkContinuousLinear_norm_le _ (norm_nonneg f) _)
(fun f => by
simp only [LinearEquiv.coe_symm_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg f) _)
variable {π Ei G}
@[simp]
theorem ContinuousMultilinearMap.norm_curryMid (p : Fin (n + 1))
(f : ContinuousMultilinearMap π Ei G) : βf.curryMid pβ = βfβ :=
(ContinuousMultilinearMap.curryMidEquiv π Ei G p).norm_map f
@[simp]
theorem ContinuousLinearMap.norm_uncurryMid (p : Fin (n + 1))
(f : Ei p βL[π] ContinuousMultilinearMap π (fun i β¦ Ei (p.succAbove i)) G) :
βf.uncurryMid pβ = βfβ :=
(ContinuousMultilinearMap.curryMidEquiv π Ei G p).symm.norm_map f
/-!
#### Currying with `0` variables
The space of multilinear maps with `0` variables is trivial: such a multilinear map is just an
arbitrary constant (note that multilinear maps in `0` variables need not map `0` to `0`!).
Therefore, the space of continuous multilinear maps on `(Fin 0) β G` with values in `Eβ` is
isomorphic (and even isometric) to `Eβ`. As this is the zeroth step in the construction of iterated
derivatives, we register this isomorphism. -/
section
/-- Associating to a continuous multilinear map in `0` variables the unique value it takes. -/
def ContinuousMultilinearMap.curry0 (f : ContinuousMultilinearMap π (fun _ : Fin 0 => G) G') :
G' :=
f 0
variable (π G) in
/-- Associating to an element `x` of a vector space `Eβ` the continuous multilinear map in `0`
variables taking the (unique) value `x` -/
def ContinuousMultilinearMap.uncurry0 (x : G') : G [Γ0]βL[π] G' :=
ContinuousMultilinearMap.constOfIsEmpty π _ x
variable (π) in
@[simp]
theorem ContinuousMultilinearMap.uncurry0_apply (x : G') (m : Fin 0 β G) :
ContinuousMultilinearMap.uncurry0 π G x m = x :=
rfl
@[simp]
theorem ContinuousMultilinearMap.curry0_apply (f : G [Γ0]βL[π] G') : f.curry0 = f 0 :=
rfl
@[simp]
theorem ContinuousMultilinearMap.apply_zero_uncurry0 (f : G [Γ0]βL[π] G') {x : Fin 0 β G} :
ContinuousMultilinearMap.uncurry0 π G (f x) = f := by
ext m
simp [Subsingleton.elim x m]
theorem ContinuousMultilinearMap.uncurry0_curry0 (f : G [Γ0]βL[π] G') :
ContinuousMultilinearMap.uncurry0 π G f.curry0 = f := by simp
variable (π G) in
theorem ContinuousMultilinearMap.curry0_uncurry0 (x : G') :
(ContinuousMultilinearMap.uncurry0 π G x).curry0 = x :=
rfl
variable (π G) in
@[simp]
theorem ContinuousMultilinearMap.uncurry0_norm (x : G') :
βContinuousMultilinearMap.uncurry0 π G xβ = βxβ :=
norm_constOfIsEmpty _ _ _
@[simp]
theorem ContinuousMultilinearMap.fin0_apply_norm (f : G [Γ0]βL[π] G') {x : Fin 0 β G} :
βf xβ = βfβ := by
obtain rfl : x = 0 := Subsingleton.elim _ _
refine le_antisymm (by simpa using f.le_opNorm 0) ?_
have : βContinuousMultilinearMap.uncurry0 π G f.curry0β β€ βf.curry0β :=
ContinuousMultilinearMap.opNorm_le_bound (norm_nonneg _) fun m => by
simp [-ContinuousMultilinearMap.apply_zero_uncurry0]
simpa [-Matrix.zero_empty] using this
theorem ContinuousMultilinearMap.curry0_norm (f : G [Γ0]βL[π] G') : βf.curry0β = βfβ := by simp
variable (π G G')
/-- The continuous linear isomorphism between elements of a normed space, and continuous multilinear
maps in `0` variables with values in this normed space.
The direct and inverse maps are `uncurry0` and `curry0`. Use these unless you need the full
framework of linear isometric equivs. -/
def continuousMultilinearCurryFin0 : (G [Γ0]βL[π] G') ββα΅’[π] G' where
toFun f := ContinuousMultilinearMap.curry0 f
invFun f := ContinuousMultilinearMap.uncurry0 π G f
map_add' _ _ := rfl
map_smul' _ _ := rfl
left_inv := ContinuousMultilinearMap.uncurry0_curry0
right_inv := ContinuousMultilinearMap.curry0_uncurry0 π G
norm_map' := ContinuousMultilinearMap.curry0_norm
variable {π G G'}
@[simp]
theorem continuousMultilinearCurryFin0_apply (f : G [Γ0]βL[π] G') :
continuousMultilinearCurryFin0 π G G' f = f 0 :=
rfl
@[simp]
theorem continuousMultilinearCurryFin0_symm_apply (x : G') (v : Fin 0 β G) :
(continuousMultilinearCurryFin0 π G G').symm x v = x :=
rfl
end
/-! #### With 1 variable -/
variable (π G G')
/-- Continuous multilinear maps from `G^1` to `G'` are isomorphic with continuous linear maps from
`G` to `G'`. -/
def continuousMultilinearCurryFin1 : (G [Γ1]βL[π] G') ββα΅’[π] G βL[π] G' :=
(continuousMultilinearCurryRightEquiv π (fun _ : Fin 1 => G) G').trans
(continuousMultilinearCurryFin0 π G (G βL[π] G'))
variable {π G G'}
@[simp]
theorem continuousMultilinearCurryFin1_apply (f : G [Γ1]βL[π] G') (x : G) :
continuousMultilinearCurryFin1 π G G' f x = f (Fin.snoc 0 x) :=
rfl
@[simp]
theorem continuousMultilinearCurryFin1_symm_apply (f : G βL[π] G') (v : Fin 1 β G) :
(continuousMultilinearCurryFin1 π G G').symm f v = f (v 0) :=
rfl
namespace ContinuousMultilinearMap
variable (π G G')
@[simp]
theorem norm_domDomCongr (Ο : ΞΉ β ΞΉ') (f : ContinuousMultilinearMap π (fun _ : ΞΉ => G) G') :
βdomDomCongr Ο fβ = βfβ := by
simp only [norm_def, β Ο.prod_comp,
(Ο.arrowCongr (Equiv.refl G)).surjective.forall, domDomCongr_apply, Equiv.arrowCongr_apply,
Equiv.coe_refl, comp_apply, Equiv.symm_apply_apply, id]
/-- An equivalence of the index set defines a linear isometric equivalence between the spaces
of multilinear maps. -/
def domDomCongrβα΅’ (Ο : ΞΉ β ΞΉ') :
ContinuousMultilinearMap π (fun _ : ΞΉ => G) G' ββα΅’[π]
ContinuousMultilinearMap π (fun _ : ΞΉ' => G) G' :=
{ domDomCongrEquiv Ο with
map_add' := fun _ _ => rfl
map_smul' := fun _ _ => rfl
norm_map' := norm_domDomCongr π G G' Ο }
variable {π G G'}
section
/-- A continuous multilinear map with variables indexed by `ΞΉ β ΞΉ'` defines a continuous
multilinear map with variables indexed by `ΞΉ` taking values in the space of continuous multilinear
maps with variables indexed by `ΞΉ'`. -/
def currySum (f : ContinuousMultilinearMap π (fun _ : ΞΉ β ΞΉ' => G) G') :
ContinuousMultilinearMap π (fun _ : ΞΉ => G) (ContinuousMultilinearMap π (fun _ : ΞΉ' => G) G') :=
MultilinearMap.mkContinuousMultilinear (MultilinearMap.currySum f.toMultilinearMap) βfβ
fun m m' => by simpa [Fintype.prod_sum_type, mul_assoc] using f.le_opNorm (Sum.elim m m')
@[simp]
theorem currySum_apply (f : ContinuousMultilinearMap π (fun _ : ΞΉ β ΞΉ' => G) G') (m : ΞΉ β G)
(m' : ΞΉ' β G) : f.currySum m m' = f (Sum.elim m m') :=
rfl
/-- A continuous multilinear map with variables indexed by `ΞΉ` taking values in the space of
continuous multilinear maps with variables indexed by `ΞΉ'` defines a continuous multilinear map with
variables indexed by `ΞΉ β ΞΉ'`. -/
def uncurrySum (f : ContinuousMultilinearMap π (fun _ : ΞΉ => G)
(ContinuousMultilinearMap π (fun _ : ΞΉ' => G) G')) :
ContinuousMultilinearMap π (fun _ : ΞΉ β ΞΉ' => G) G' :=
MultilinearMap.mkContinuous
(toMultilinearMapLinear.compMultilinearMap f.toMultilinearMap).uncurrySum βfβ fun m => by
simpa [Fintype.prod_sum_type, mul_assoc] using
(f (m β Sum.inl)).le_of_opNorm_le (f.le_opNorm _) (m β Sum.inr)
@[simp]
theorem uncurrySum_apply (f : ContinuousMultilinearMap π (fun _ : ΞΉ => G)
(ContinuousMultilinearMap π (fun _ : ΞΉ' => G) G'))
(m : ΞΉ β ΞΉ' β G) : f.uncurrySum m = f (m β Sum.inl) (m β Sum.inr) :=
rfl
variable (π ΞΉ ΞΉ' G G')
/-- Linear isometric equivalence between the space of continuous multilinear maps with variables
indexed by `ΞΉ β ΞΉ'` and the space of continuous multilinear maps with variables indexed by `ΞΉ`
taking values in the space of continuous multilinear maps with variables indexed by `ΞΉ'`.
The forward and inverse functions are `ContinuousMultilinearMap.currySum`
and `ContinuousMultilinearMap.uncurrySum`. Use this definition only if you need
some properties of `LinearIsometryEquiv`. -/
def currySumEquiv : ContinuousMultilinearMap π (fun _ : ΞΉ β ΞΉ' => G) G' ββα΅’[π]
ContinuousMultilinearMap π (fun _ : ΞΉ => G) (ContinuousMultilinearMap π (fun _ : ΞΉ' => G) G') :=
LinearIsometryEquiv.ofBounds
{ toFun := currySum
invFun := uncurrySum
map_add' := fun f g => by
ext
rfl
map_smul' := fun c f => by
ext
rfl
left_inv := fun f => by
ext m
exact congr_arg f (Sum.elim_comp_inl_inr m) }
(fun f => MultilinearMap.mkContinuousMultilinear_norm_le _ (norm_nonneg f) _) fun f => by
simp only [LinearEquiv.coe_symm_mk]
exact MultilinearMap.mkContinuous_norm_le _ (norm_nonneg f) _
end
section
variable (π G G') {k l : β} {s : Finset (Fin n)}
/-- If `s : Finset (Fin n)` is a finite set of cardinality `k` and its complement has cardinality
`l`, then the space of continuous multilinear maps `G [Γn]βL[π] G'` of `n` variables is isomorphic
to the space of continuous multilinear maps `G [Γk]βL[π] G [Γl]βL[π] G'` of `k` variables taking
values in the space of continuous multilinear maps of `l` variables. -/
def curryFinFinset {k l n : β} {s : Finset (Fin n)} (hk : #s = k) (hl : #sαΆ = l) :
(G [Γn]βL[π] G') ββα΅’[π] G [Γk]βL[π] G [Γl]βL[π] G' :=
(domDomCongrβα΅’ π G G' (finSumEquivOfFinset hk hl).symm).trans
(currySumEquiv π (Fin k) (Fin l) G G')
variable {π G G'}
@[simp]
theorem curryFinFinset_apply (hk : #s = k) (hl : #sαΆ = l) (f : G [Γn]βL[π] G')
(mk : Fin k β G) (ml : Fin l β G) : curryFinFinset π G G' hk hl f mk ml =
f fun i => Sum.elim mk ml ((finSumEquivOfFinset hk hl).symm i) :=
rfl
@[simp]
theorem curryFinFinset_symm_apply (hk : #s = k) (hl : #sαΆ = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (m : Fin n β G) : (curryFinFinset π G G' hk hl).symm f m =
f (fun i => m <| finSumEquivOfFinset hk hl (Sum.inl i)) fun i =>
m <| finSumEquivOfFinset hk hl (Sum.inr i) :=
rfl
theorem curryFinFinset_symm_apply_piecewise_const (hk : #s = k) (hl : #sαΆ = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (x y : G) :
(curryFinFinset π G G' hk hl).symm f (s.piecewise (fun _ => x) fun _ => y) =
f (fun _ => x) fun _ => y :=
MultilinearMap.curryFinFinset_symm_apply_piecewise_const hk hl _ x y
@[simp]
theorem curryFinFinset_symm_apply_const (hk : #s = k) (hl : #sαΆ = l)
(f : G [Γk]βL[π] G [Γl]βL[π] G') (x : G) :
((curryFinFinset π G G' hk hl).symm f fun _ => x) = f (fun _ => x) fun _ => x :=
rfl
theorem curryFinFinset_apply_const (hk : #s = k) (hl : #sαΆ = l) (f : G [Γn]βL[π] G')
(x y : G) : (curryFinFinset π G G' hk hl f (fun _ => x) fun _ => y) =
f (s.piecewise (fun _ => x) fun _ => y) := by
refine (curryFinFinset_symm_apply_piecewise_const hk hl _ _ _).symm.trans ?_
rw [LinearIsometryEquiv.symm_apply_apply]
end
end ContinuousMultilinearMap
namespace ContinuousLinearMap
variable {F G : Type*} [NormedAddCommGroup F] [NormedSpace π F]
[NormedAddCommGroup G] [NormedSpace π G]
/-- Given a linear map into continuous multilinear maps
`B : G βL[π] ContinuousMultilinearMap π E F`, one can not always uncurry it as `G` and `E` might
live in a different universe. However, one can always lift it to a continuous multilinear map
on `(G Γ (Ξ i, E i)) ^ (1 + n)`, which maps `(v_0, ..., v_n)` to `B (g_0) (u_1, ..., u_n)` where
`g_0` is the `G`-coordinate of `v_0` and `u_i` is the `E_i` coordinate of `v_i`. -/
noncomputable def continuousMultilinearMapOption (B : G βL[π] ContinuousMultilinearMap π E F) :
ContinuousMultilinearMap π (fun (_ : Option ΞΉ) β¦ (G Γ (Ξ i, E i))) F :=
MultilinearMap.mkContinuous
{ toFun := fun p β¦ B (p none).1 (fun i β¦ (p i).2 i)
map_update_add' := by
intro inst v j x y
match j with
| none => simp
| some j =>
classical
have B z : (fun i β¦ (Function.update v (some j) z (some i)).2 i) =
Function.update (fun (i : ΞΉ) β¦ (v i).2 i) j (z.2 j) := by
ext i
rcases eq_or_ne i j with rfl | hij
Β· simp
Β· simp [hij]
simp [B]
map_update_smul' := by
intro inst v j c x
match j with
| none => simp
| some j =>
classical
have B z : (fun i β¦ (Function.update v (some j) z (some i)).2 i) =
Function.update (fun (i : ΞΉ) β¦ (v i).2 i) j (z.2 j) := by
ext i
rcases eq_or_ne i j with rfl | hij
Β· simp
Β· simp [hij]
simp [B] } (βBβ) <| by
intro b
simp only [MultilinearMap.coe_mk, Fintype.prod_option]
apply (ContinuousMultilinearMap.le_opNorm _ _).trans
rw [β mul_assoc]
gcongr with i _
Β· apply (B.le_opNorm _).trans
gcongr
exact norm_fst_le _
Β· exact (norm_le_pi_norm _ _).trans (norm_snd_le _)
lemma continuousMultilinearMapOption_apply_eq_self (B : G βL[π] ContinuousMultilinearMap π E F)
(a : G) (v : Ξ i, E i) : B.continuousMultilinearMapOption (fun _ β¦ (a, v)) = B a v := rfl
end ContinuousLinearMap
|
Basic.lean
|
/-
Copyright (c) 2018 Chris Hughes. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Chris Hughes, Michael Stoll
-/
import Mathlib.NumberTheory.LegendreSymbol.QuadraticChar.Basic
/-!
# Legendre symbol
This file contains results about Legendre symbols.
We define the Legendre symbol $\Bigl(\frac{a}{p}\Bigr)$ as `legendreSym p a`.
Note the order of arguments! The advantage of this form is that then `legendreSym p`
is a multiplicative map.
The Legendre symbol is used to define the Jacobi symbol, `jacobiSym a b`, for integers `a`
and (odd) natural numbers `b`, which extends the Legendre symbol.
## Main results
We also prove the supplementary laws that give conditions for when `-1`
is a square modulo a prime `p`:
`legendreSym.at_neg_one` and `ZMod.exists_sq_eq_neg_one_iff` for `-1`.
See `NumberTheory.LegendreSymbol.QuadraticReciprocity` for the conditions when `2` and `-2`
are squares:
`legendreSym.at_two` and `ZMod.exists_sq_eq_two_iff` for `2`,
`legendreSym.at_neg_two` and `ZMod.exists_sq_eq_neg_two_iff` for `-2`.
## Tags
quadratic residue, quadratic nonresidue, Legendre symbol
-/
open Nat
section Euler
namespace ZMod
variable (p : β) [Fact p.Prime]
/-- Euler's Criterion: A unit `x` of `ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion_units (x : (ZMod p)Λ£) : (β y : (ZMod p)Λ£, y ^ 2 = x) β x ^ (p / 2) = 1 := by
by_cases hc : p = 2
Β· subst hc
simp only [eq_iff_true_of_subsingleton, exists_const]
Β· have hβ := FiniteField.unit_isSquare_iff (by rwa [ringChar_zmod_n]) x
have hs : (β y : (ZMod p)Λ£, y ^ 2 = x) β IsSquare x := by
rw [isSquare_iff_exists_sq x]
simp_rw [eq_comm]
rw [hs]
rwa [card p] at hβ
/-- Euler's Criterion: a nonzero `a : ZMod p` is a square if and only if `x ^ (p / 2) = 1`. -/
theorem euler_criterion {a : ZMod p} (ha : a β 0) : IsSquare (a : ZMod p) β a ^ (p / 2) = 1 := by
apply (iff_congr _ (by simp [Units.ext_iff])).mp (euler_criterion_units p (Units.mk0 a ha))
simp only [Units.ext_iff, sq, Units.val_mk0, Units.val_mul]
constructor
Β· rintro β¨y, hyβ©; exact β¨y, hy.symmβ©
Β· rintro β¨y, rflβ©
have hy : y β 0 := by
rintro rfl
simp [mul_zero, ne_eq] at ha
refine β¨Units.mk0 y hy, ?_β©; simp
/-- If `a : ZMod p` is nonzero, then `a^(p/2)` is either `1` or `-1`. -/
theorem pow_div_two_eq_neg_one_or_one {a : ZMod p} (ha : a β 0) :
a ^ (p / 2) = 1 β¨ a ^ (p / 2) = -1 := by
rcases Prime.eq_two_or_odd (@Fact.out p.Prime _) with hp2 | hp_odd
Β· subst p; revert a ha; intro a; fin_cases a
Β· tauto
Β· simp
rw [β mul_self_eq_one_iff, β pow_add, β two_mul, two_mul_odd_div_two hp_odd]
exact pow_card_sub_one_eq_one ha
end ZMod
end Euler
section Legendre
/-!
### Definition of the Legendre symbol and basic properties
-/
open ZMod
variable (p : β) [Fact p.Prime]
/-- The Legendre symbol of `a : β€` and a prime `p`, `legendreSym p a`,
is an integer defined as
* `0` if `a` is `0` modulo `p`;
* `1` if `a` is a nonzero square modulo `p`
* `-1` otherwise.
Note the order of the arguments! The advantage of the order chosen here is
that `legendreSym p` is a multiplicative function `β€ β β€`.
-/
def legendreSym (a : β€) : β€ :=
quadraticChar (ZMod p) a
namespace legendreSym
/-- We have the congruence `legendreSym p a β‘ a ^ (p / 2) mod p`. -/
theorem eq_pow (a : β€) : (legendreSym p a : ZMod p) = (a : ZMod p) ^ (p / 2) := by
rcases eq_or_ne (ringChar (ZMod p)) 2 with hc | hc
Β· by_cases ha : (a : ZMod p) = 0
Β· rw [legendreSym, ha, quadraticChar_zero,
zero_pow (Nat.div_pos (@Fact.out p.Prime).two_le (succ_pos 1)).ne']
norm_cast
Β· have := (ringChar_zmod_n p).symm.trans hc
-- p = 2
subst p
rw [legendreSym, quadraticChar_eq_one_of_char_two hc ha]
revert ha
push_cast
generalize (a : ZMod 2) = b; fin_cases b
Β· tauto
Β· simp
Β· convert quadraticChar_eq_pow_of_char_ne_two' hc (a : ZMod p)
exact (card p).symm
/-- If `p β€ a`, then `legendreSym p a` is `1` or `-1`. -/
theorem eq_one_or_neg_one {a : β€} (ha : (a : ZMod p) β 0) :
legendreSym p a = 1 β¨ legendreSym p a = -1 :=
quadraticChar_dichotomy ha
theorem eq_neg_one_iff_not_one {a : β€} (ha : (a : ZMod p) β 0) :
legendreSym p a = -1 β Β¬legendreSym p a = 1 :=
quadraticChar_eq_neg_one_iff_not_one ha
/-- The Legendre symbol of `p` and `a` is zero iff `p β£ a`. -/
theorem eq_zero_iff (a : β€) : legendreSym p a = 0 β (a : ZMod p) = 0 :=
quadraticChar_eq_zero_iff
@[simp]
theorem at_zero : legendreSym p 0 = 0 := by rw [legendreSym, Int.cast_zero, MulChar.map_zero]
@[simp]
theorem at_one : legendreSym p 1 = 1 := by rw [legendreSym, Int.cast_one, MulChar.map_one]
/-- The Legendre symbol is multiplicative in `a` for `p` fixed. -/
protected theorem mul (a b : β€) : legendreSym p (a * b) = legendreSym p a * legendreSym p b := by
simp [legendreSym, Int.cast_mul, map_mul]
/-- The Legendre symbol is a homomorphism of monoids with zero. -/
@[simps]
def hom : β€ β*β β€ where
toFun := legendreSym p
map_zero' := at_zero p
map_one' := at_one p
map_mul' := legendreSym.mul p
/-- The square of the symbol is 1 if `p β€ a`. -/
theorem sq_one {a : β€} (ha : (a : ZMod p) β 0) : legendreSym p a ^ 2 = 1 :=
quadraticChar_sq_one ha
/-- The Legendre symbol of `a^2` at `p` is 1 if `p β€ a`. -/
theorem sq_one' {a : β€} (ha : (a : ZMod p) β 0) : legendreSym p (a ^ 2) = 1 := by
dsimp only [legendreSym]
rw [Int.cast_pow]
exact quadraticChar_sq_one' ha
/-- The Legendre symbol depends only on `a` mod `p`. -/
protected theorem mod (a : β€) : legendreSym p a = legendreSym p (a % p) := by
simp only [legendreSym, intCast_mod]
/-- When `p β€ a`, then `legendreSym p a = 1` iff `a` is a square mod `p`. -/
theorem eq_one_iff {a : β€} (ha0 : (a : ZMod p) β 0) : legendreSym p a = 1 β IsSquare (a : ZMod p) :=
quadraticChar_one_iff_isSquare ha0
theorem eq_one_iff' {a : β} (ha0 : (a : ZMod p) β 0) :
legendreSym p a = 1 β IsSquare (a : ZMod p) := by
rw [eq_one_iff]
Β· norm_cast
Β· exact mod_cast ha0
/-- `legendreSym p a = -1` iff `a` is a nonsquare mod `p`. -/
theorem eq_neg_one_iff {a : β€} : legendreSym p a = -1 β Β¬IsSquare (a : ZMod p) :=
quadraticChar_neg_one_iff_not_isSquare
theorem eq_neg_one_iff' {a : β} : legendreSym p a = -1 β Β¬IsSquare (a : ZMod p) := by
rw [eq_neg_one_iff]; norm_cast
/-- The number of square roots of `a` modulo `p` is determined by the Legendre symbol. -/
theorem card_sqrts (hp : p β 2) (a : β€) :
β{x : ZMod p | x ^ 2 = a}.toFinset.card = legendreSym p a + 1 :=
quadraticChar_card_sqrts ((ringChar_zmod_n p).substr hp) a
end legendreSym
end Legendre
section QuadraticForm
/-!
### Applications to binary quadratic forms
-/
namespace legendreSym
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `β€/pβ€`
of the equation `x^2 - a*y^2 = 0` with `y β 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero {p : β} [Fact p.Prime] {a : β€} (ha : (a : ZMod p) β 0)
{x y : ZMod p} (hy : y β 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
apply_fun (Β· * yβ»ΒΉ ^ 2) at hxy
simp only [zero_mul] at hxy
rw [(by ring : (x ^ 2 - βa * y ^ 2) * yβ»ΒΉ ^ 2 = (x * yβ»ΒΉ) ^ 2 - a * (y * yβ»ΒΉ) ^ 2),
mul_inv_cancelβ hy, one_pow, mul_one, sub_eq_zero, pow_two] at hxy
exact (eq_one_iff p ha).mpr β¨x * yβ»ΒΉ, hxy.symmβ©
/-- The Legendre symbol `legendreSym p a = 1` if there is a solution in `β€/pβ€`
of the equation `x^2 - a*y^2 = 0` with `x β 0`. -/
theorem eq_one_of_sq_sub_mul_sq_eq_zero' {p : β} [Fact p.Prime] {a : β€} (ha : (a : ZMod p) β 0)
{x y : ZMod p} (hx : x β 0) (hxy : x ^ 2 - a * y ^ 2 = 0) : legendreSym p a = 1 := by
haveI hy : y β 0 := by
rintro rfl
rw [zero_pow two_ne_zero, mul_zero, sub_zero, sq_eq_zero_iff] at hxy
exact hx hxy
exact eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy
/-- If `legendreSym p a = -1`, then the only solution of `x^2 - a*y^2 = 0` in `β€/pβ€`
is the trivial one. -/
theorem eq_zero_mod_of_eq_neg_one {p : β} [Fact p.Prime] {a : β€} (h : legendreSym p a = -1)
{x y : ZMod p} (hxy : x ^ 2 - a * y ^ 2 = 0) : x = 0 β§ y = 0 := by
have ha : (a : ZMod p) β 0 := by
intro hf
rw [(eq_zero_iff p a).mpr hf] at h
simp at h
by_contra hf
rcases imp_iff_or_not.mp (not_and'.mp hf) with hx | hy
Β· rw [eq_one_of_sq_sub_mul_sq_eq_zero' ha hx hxy, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
Β· rw [eq_one_of_sq_sub_mul_sq_eq_zero ha hy hxy, CharZero.eq_neg_self_iff] at h
exact one_ne_zero h
/-- If `legendreSym p a = -1` and `p` divides `x^2 - a*y^2`, then `p` must divide `x` and `y`. -/
theorem prime_dvd_of_eq_neg_one {p : β} [Fact p.Prime] {a : β€} (h : legendreSym p a = -1) {x y : β€}
(hxy : (p : β€) β£ x ^ 2 - a * y ^ 2) : βp β£ x β§ βp β£ y := by
simp_rw [β ZMod.intCast_zmod_eq_zero_iff_dvd] at hxy β’
push_cast at hxy
exact eq_zero_mod_of_eq_neg_one h hxy
end legendreSym
end QuadraticForm
section Values
/-!
### The value of the Legendre symbol at `-1`
See `jacobiSym.at_neg_one` for the corresponding statement for the Jacobi symbol.
-/
variable {p : β} [Fact p.Prime]
open ZMod
/-- `legendreSym p (-1)` is given by `Οβ p`. -/
theorem legendreSym.at_neg_one (hp : p β 2) : legendreSym p (-1) = Οβ p := by
simp only [legendreSym, card p, quadraticChar_neg_one ((ringChar_zmod_n p).substr hp),
Int.cast_neg, Int.cast_one]
namespace ZMod
/-- `-1` is a square in `ZMod p` iff `p` is not congruent to `3` mod `4`. -/
theorem exists_sq_eq_neg_one_iff : IsSquare (-1 : ZMod p) β p % 4 β 3 := by
rw [FiniteField.isSquare_neg_one_iff, card p]
theorem mod_four_ne_three_of_sq_eq_neg_one {y : ZMod p} (hy : y ^ 2 = -1) : p % 4 β 3 :=
exists_sq_eq_neg_one_iff.1 β¨y, hy βΈ pow_two yβ©
/-- If two nonzero squares are negatives of each other in `ZMod p`, then `p % 4 β 3`. -/
theorem mod_four_ne_three_of_sq_eq_neg_sq' {x y : ZMod p} (hy : y β 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 β 3 :=
@mod_four_ne_three_of_sq_eq_neg_one p _ (x / y)
(by
apply_fun fun z => z / y ^ 2 at hxy
rwa [neg_div, β div_pow, β div_pow, div_self hy, one_pow] at hxy)
theorem mod_four_ne_three_of_sq_eq_neg_sq {x y : ZMod p} (hx : x β 0) (hxy : x ^ 2 = -y ^ 2) :
p % 4 β 3 :=
mod_four_ne_three_of_sq_eq_neg_sq' hx (neg_eq_iff_eq_neg.mpr hxy).symm
end ZMod
end Values
|
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_}.
|
InfiniteSum.lean
|
/-
Copyright (c) 2021 SΓ©bastien GouΓ«zel. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: SΓ©bastien GouΓ«zel, Heather Macbeth, Johannes HΓΆlzl, Yury Kudryashov
-/
import Mathlib.Algebra.BigOperators.Intervals
import Mathlib.Analysis.Normed.Group.Uniform
import Mathlib.Topology.Instances.NNReal.Lemmas
import Mathlib.Topology.Instances.ENNReal.Lemmas
/-!
# Infinite sums in (semi)normed groups
In a complete (semi)normed group,
- `summable_iff_vanishing_norm`: a series `β' i, f i` is summable if and only if for any `Ξ΅ > 0`,
there exists a finite set `s` such that the sum `β i β t, f i` over any finite set `t` disjoint
with `s` has norm less than `Ξ΅`;
- `Summable.of_norm_bounded`, `Summable.of_norm_bounded_eventually`: if `βf iβ` is bounded above by
a summable series `β' i, g i`, then `β' i, f i` is summable as well; the same is true if the
inequality hold only off some finite set.
- `tsum_of_norm_bounded`, `HasSum.norm_le_of_bounded`: if `βf iβ β€ g i`, where `β' i, g i` is a
summable series, then `ββ' i, f iβ β€ β' i, g i`.
- versions of these lemmas for `nnnorm` and `enorm`.
## Tags
infinite series, absolute convergence, normed group
-/
open Topology ENNReal NNReal
open Finset Filter Metric
variable {ΞΉ Ξ± E F Ξ΅ : Type*} [SeminormedAddCommGroup E] [SeminormedAddCommGroup F]
[TopologicalSpace Ξ΅] [ESeminormedAddCommMonoid Ξ΅]
theorem cauchySeq_finset_iff_vanishing_norm {f : ΞΉ β E} :
(CauchySeq fun s : Finset ΞΉ => β i β s, f i) β
β Ξ΅ > (0 : β), β s : Finset ΞΉ, β t, Disjoint t s β ββ i β t, f iβ < Ξ΅ := by
rw [cauchySeq_finset_iff_sum_vanishing, nhds_basis_ball.forall_iff]
Β· simp only [ball_zero_eq, Set.mem_setOf_eq]
Β· rintro s t hst β¨s', hs'β©
exact β¨s', fun t' ht' => hst <| hs' _ ht'β©
theorem summable_iff_vanishing_norm [CompleteSpace E] {f : ΞΉ β E} :
Summable f β β Ξ΅ > (0 : β), β s : Finset ΞΉ, β t, Disjoint t s β ββ i β t, f iβ < Ξ΅ := by
rw [summable_iff_cauchySeq_finset, cauchySeq_finset_iff_vanishing_norm]
theorem cauchySeq_finset_of_norm_bounded_eventually {f : ΞΉ β E} {g : ΞΉ β β} (hg : Summable g)
(h : βαΆ i in cofinite, βf iβ β€ g i) : CauchySeq fun s => β i β s, f i := by
refine cauchySeq_finset_iff_vanishing_norm.2 fun Ξ΅ hΞ΅ => ?_
rcases summable_iff_vanishing_norm.1 hg Ξ΅ hΞ΅ with β¨s, hsβ©
classical
refine β¨s βͺ h.toFinset, fun t ht => ?_β©
have : β i β t, βf iβ β€ g i := by
intro i hi
simp only [disjoint_left, mem_union, not_or, h.mem_toFinset, Set.mem_compl_iff,
Classical.not_not] at ht
exact (ht hi).2
calc
ββ i β t, f iβ β€ β i β t, g i := norm_sum_le_of_le _ this
_ β€ ββ i β t, g iβ := le_abs_self _
_ < Ξ΅ := hs _ (ht.mono_right le_sup_left)
theorem cauchySeq_finset_of_norm_bounded {f : ΞΉ β E} {g : ΞΉ β β} (hg : Summable g)
(h : β i, βf iβ β€ g i) : CauchySeq fun s : Finset ΞΉ => β i β s, f i :=
cauchySeq_finset_of_norm_bounded_eventually hg <| Eventually.of_forall h
/-- A version of the **direct comparison test** for conditionally convergent series.
See `cauchySeq_finset_of_norm_bounded` for the same statement about absolutely convergent ones. -/
theorem cauchySeq_range_of_norm_bounded {f : β β E} {g : β β β}
(hg : CauchySeq fun n => β i β range n, g i) (hf : β i, βf iβ β€ g i) :
CauchySeq fun n => β i β range n, f i := by
refine Metric.cauchySeq_iff'.2 fun Ξ΅ hΞ΅ => ?_
refine (Metric.cauchySeq_iff'.1 hg Ξ΅ hΞ΅).imp fun N hg n hn => ?_
specialize hg n hn
rw [dist_eq_norm, β sum_Ico_eq_sub _ hn] at hg β’
calc
ββ k β Ico N n, f kβ β€ β k β _, βf kβ := norm_sum_le _ _
_ β€ β k β _, g k := sum_le_sum fun x _ => hf x
_ β€ ββ k β _, g kβ := le_abs_self _
_ < Ξ΅ := hg
theorem cauchySeq_finset_of_summable_norm {f : ΞΉ β E} (hf : Summable fun a => βf aβ) :
CauchySeq fun s : Finset ΞΉ => β a β s, f a :=
cauchySeq_finset_of_norm_bounded hf fun _i => le_rfl
/-- If a function `f` is summable in norm, and along some sequence of finsets exhausting the space
its sum is converging to a limit `a`, then this holds along all finsets, i.e., `f` is summable
with sum `a`. -/
theorem hasSum_of_subseq_of_summable {f : ΞΉ β E} (hf : Summable fun a => βf aβ) {s : Ξ± β Finset ΞΉ}
{p : Filter Ξ±} [NeBot p] (hs : Tendsto s p atTop) {a : E}
(ha : Tendsto (fun b => β i β s b, f i) p (π a)) : HasSum f a :=
tendsto_nhds_of_cauchySeq_of_subseq (cauchySeq_finset_of_summable_norm hf) hs ha
theorem hasSum_iff_tendsto_nat_of_summable_norm {f : β β E} {a : E} (hf : Summable fun i => βf iβ) :
HasSum f a β Tendsto (fun n : β => β i β range n, f i) atTop (π a) :=
β¨fun h => h.tendsto_sum_nat, fun h => hasSum_of_subseq_of_summable hf tendsto_finset_range hβ©
/-- The direct comparison test for series: if the norm of `f` is bounded by a real function `g`
which is summable, then `f` is summable. -/
theorem Summable.of_norm_bounded [CompleteSpace E] {f : ΞΉ β E} {g : ΞΉ β β} (hg : Summable g)
(h : β i, βf iβ β€ g i) : Summable f := by
rw [summable_iff_cauchySeq_finset]
exact cauchySeq_finset_of_norm_bounded hg h
theorem HasSum.enorm_le_of_bounded {f : ΞΉ β Ξ΅} {g : ΞΉ β ββ₯0β} {a : Ξ΅} {b : ββ₯0β} (hf : HasSum f a)
(hg : HasSum g b) (h : β i, βf iββ β€ g i) : βaββ β€ b := by
exact le_of_tendsto_of_tendsto' hf.enorm hg fun _s β¦ enorm_sum_le_of_le _ fun i _hi β¦ h i
theorem HasSum.norm_le_of_bounded {f : ΞΉ β E} {g : ΞΉ β β} {a : E} {b : β} (hf : HasSum f a)
(hg : HasSum g b) (h : β i, βf iβ β€ g i) : βaβ β€ b := by
exact le_of_tendsto_of_tendsto' hf.norm hg fun _s β¦ norm_sum_le_of_le _ fun i _hi β¦ h i
/-- Quantitative result associated to the direct comparison test for series: If, for all `i`,
`βf iββ β€ g i`, then `ββ' i, f iββ β€ β' i, g i`. Note that we do not assume that `β' i, f i` is
summable, and it might not be the case if `Ξ±` is not a complete space. -/
theorem tsum_of_enorm_bounded {f : ΞΉ β Ξ΅} {g : ΞΉ β ββ₯0β} {a : ββ₯0β} (hg : HasSum g a)
(h : β i, βf iββ β€ g i) : ββ' i : ΞΉ, f iββ β€ a := by
by_cases hf : Summable f
Β· exact hf.hasSum.enorm_le_of_bounded hg h
Β· simp [tsum_eq_zero_of_not_summable hf]
theorem enorm_tsum_le_tsum_enorm {f : ΞΉ β Ξ΅} :
ββ' i, f iββ β€ β' i, βf iββ :=
tsum_of_enorm_bounded ENNReal.summable.hasSum fun _i => le_rfl
/-- Quantitative result associated to the direct comparison test for series: If `β' i, g i` is
summable, and for all `i`, `βf iβ β€ g i`, then `ββ' i, f iβ β€ β' i, g i`. Note that we do not
assume that `β' i, f i` is summable, and it might not be the case if `Ξ±` is not a complete space. -/
theorem tsum_of_norm_bounded {f : ΞΉ β E} {g : ΞΉ β β} {a : β} (hg : HasSum g a)
(h : β i, βf iβ β€ g i) : ββ' i : ΞΉ, f iβ β€ a := by
by_cases hf : Summable f
Β· exact hf.hasSum.norm_le_of_bounded hg h
Β· rw [tsum_eq_zero_of_not_summable hf, norm_zero]
classical exact ge_of_tendsto' hg fun s => sum_nonneg fun i _hi => (norm_nonneg _).trans (h i)
/-- If `β' i, βf iβ` is summable, then `ββ' i, f iβ β€ (β' i, βf iβ)`. Note that we do not assume
that `β' i, f i` is summable, and it might not be the case if `Ξ±` is not a complete space. -/
theorem norm_tsum_le_tsum_norm {f : ΞΉ β E} (hf : Summable fun i => βf iβ) :
ββ' i, f iβ β€ β' i, βf iβ :=
tsum_of_norm_bounded hf.hasSum fun _i => le_rfl
/-- Quantitative result associated to the direct comparison test for series: If `β' i, g i` is
summable, and for all `i`, `βf iββ β€ g i`, then `ββ' i, f iββ β€ β' i, g i`. Note that we
do not assume that `β' i, f i` is summable, and it might not be the case if `Ξ±` is not a complete
space. -/
theorem tsum_of_nnnorm_bounded {f : ΞΉ β E} {g : ΞΉ β ββ₯0} {a : ββ₯0} (hg : HasSum g a)
(h : β i, βf iββ β€ g i) : ββ' i : ΞΉ, f iββ β€ a := by
simp only [β NNReal.coe_le_coe, β NNReal.hasSum_coe, coe_nnnorm] at *
exact tsum_of_norm_bounded hg h
/-- If `β' i, βf iββ` is summable, then `ββ' i, f iββ β€ β' i, βf iββ`. Note that
we do not assume that `β' i, f i` is summable, and it might not be the case if `Ξ±` is not a complete
space. -/
theorem nnnorm_tsum_le {f : ΞΉ β E} (hf : Summable fun i => βf iββ) : ββ' i, f iββ β€ β' i, βf iββ :=
tsum_of_nnnorm_bounded hf.hasSum fun _i => le_rfl
variable [CompleteSpace E]
/-- Variant of the direct comparison test for series: if the norm of `f` is eventually bounded by a
real function `g` which is summable, then `f` is summable. -/
theorem Summable.of_norm_bounded_eventually {f : ΞΉ β E} {g : ΞΉ β β} (hg : Summable g)
(h : βαΆ i in cofinite, βf iβ β€ g i) : Summable f :=
summable_iff_cauchySeq_finset.2 <| cauchySeq_finset_of_norm_bounded_eventually hg h
/-- Variant of the direct comparison test for series: if the norm of `f` is eventually bounded by a
real function `g` which is summable, then `f` is summable. -/
theorem Summable.of_norm_bounded_eventually_nat {f : β β E} {g : β β β} (hg : Summable g)
(h : βαΆ i in atTop, βf iβ β€ g i) : Summable f :=
.of_norm_bounded_eventually hg <| Nat.cofinite_eq_atTop βΈ h
theorem Summable.of_nnnorm_bounded {f : ΞΉ β E} {g : ΞΉ β ββ₯0} (hg : Summable g)
(h : β i, βf iββ β€ g i) : Summable f :=
.of_norm_bounded (NNReal.summable_coe.2 hg) h
theorem Summable.of_norm {f : ΞΉ β E} (hf : Summable fun a => βf aβ) : Summable f :=
.of_norm_bounded hf fun _i => le_rfl
theorem Summable.of_nnnorm {f : ΞΉ β E} (hf : Summable fun a => βf aββ) : Summable f :=
.of_nnnorm_bounded hf fun _i => le_rfl
|
AtPrime.lean
|
/-
Copyright (c) 2025 Yongle Hu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yongle Hu
-/
import Mathlib.Algebra.Module.LocalizedModule.Basic
import Mathlib.RingTheory.Ideal.Prime
/-!
# Localizations of modules at the complement of a prime ideal
-/
/-- Given a prime ideal `P` and `f : M ββ[R] M'`, `IsLocalizedModule.AtPrime P f` states that `M'`
is isomorphic to the localization of `M` at the complement of `P`. -/
protected abbrev IsLocalizedModule.AtPrime {R M M' : Type*} [CommSemiring R] (P : Ideal R)
[P.IsPrime] [AddCommMonoid M] [AddCommMonoid M'] [Module R M] [Module R M'] (f : M ββ[R] M') :=
IsLocalizedModule P.primeCompl f
/-- Given a prime ideal `P`, `LocalizedModule.AtPrime P M` is a localization of `M`
at the complement of `P`. -/
protected abbrev LocalizedModule.AtPrime {R : Type*} [CommSemiring R] (P : Ideal R) [P.IsPrime]
(M : Type*) [AddCommMonoid M] [Module R M] :=
LocalizedModule P.primeCompl M
|
Finite.lean
|
/-
Copyright (c) 2024 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Module.Presentation.Basic
import Mathlib.Algebra.Module.FinitePresentation
/-!
# Characterization of finitely presented modules
A module is finitely presented (in the sense of `Module.FinitePresentation`) iff
it admits a presentation with finitely many generators and relations.
-/
universe wβ wβ v u
namespace Module
variable {A : Type u} [Ring A] {M : Type v} [AddCommGroup M] [Module A M]
namespace Presentation
variable (pres : Presentation A M)
lemma finite [Finite pres.G] :
Module.Finite A M :=
Finite.of_surjective _ pres.surjective_Ο
lemma finitePresentation [Finite pres.G] [Finite pres.R] :
Module.FinitePresentation A M :=
Module.finitePresentation_of_surjective _ pres.surjective_Ο (by
rw [pres.ker_Ο]
exact Submodule.fg_span (Set.finite_range _))
end Presentation
lemma finitePresentation_iff_exists_presentation :
Module.FinitePresentation A M β
β (pres : Presentation.{wβ, wβ} A M), Finite pres.G β§ Finite pres.R := by
constructor
Β· intro
obtain β¨G : Type wβ, _, var, hGβ© :=
Submodule.fg_iff_exists_finite_generating_family.1
(finite_def.1 (inferInstanceAs (Module.Finite A M)))
obtain β¨R : Type wβ, _, relation, hRβ© :=
Submodule.fg_iff_exists_finite_generating_family.1
(Module.FinitePresentation.fg_ker (Finsupp.linearCombination A var) (by
rw [β LinearMap.range_eq_top, Finsupp.range_linearCombination, hG]))
exact
β¨{ G := G
R := R
relation := relation
var := var
linearCombination_var_relation := fun r β¦ by
rw [Submodule.ext_iff] at hR
exact (hR _).1 (Submodule.subset_span β¨_, rflβ©)
toIsPresentation := by
rw [Relations.Solution.isPresentation_iff]
exact β¨hG, hR.symmβ© },
inferInstance, inferInstanceβ©
Β· rintro β¨pres, _, _β©
exact pres.finitePresentation
end Module
|
HasColimits.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.Geometry.RingedSpace.PresheafedSpace
import Mathlib.Topology.Category.TopCat.Limits.Basic
import Mathlib.Topology.Sheaves.Limits
import Mathlib.CategoryTheory.ConcreteCategory.Elementwise
/-!
# `PresheafedSpace C` has colimits.
If `C` has limits, then the category `PresheafedSpace C` has colimits,
and the forgetful functor to `TopCat` preserves these colimits.
When restricted to a diagram where the underlying continuous maps are open embeddings,
this says that we can glue presheaved spaces.
Given a diagram `F : J β₯€ PresheafedSpace C`,
we first build the colimit of the underlying topological spaces,
as `colimit (F β PresheafedSpace.forget C)`. Call that colimit space `X`.
Our strategy is to push each of the presheaves `F.obj j`
forward along the continuous map `colimit.ΞΉ (F β PresheafedSpace.forget C) j` to `X`.
Since pushforward is functorial, we obtain a diagram `J β₯€ (presheaf C X)α΅α΅`
of presheaves on a single space `X`.
(Note that the arrows now point the other direction,
because this is the way `PresheafedSpace C` is set up.)
The limit of this diagram then constitutes the colimit presheaf.
-/
noncomputable section
universe v' u' v u
open CategoryTheory Opposite CategoryTheory.Category CategoryTheory.Functor CategoryTheory.Limits
TopCat TopCat.Presheaf TopologicalSpace
variable {J : Type u'} [Category.{v'} J] {C : Type u} [Category.{v} C]
namespace AlgebraicGeometry
namespace PresheafedSpace
attribute [local simp] eqToHom_map
-- Porting note: we used to have:
-- local attribute [tidy] tactic.auto_cases_opens
-- We would replace this by:
-- attribute [local aesop safe cases (rule_sets := [CategoryTheory])] Opens
-- although it doesn't appear to help in this file, in any case.
@[simp]
theorem map_id_c_app (F : J β₯€ PresheafedSpace.{_, _, v} C) (j) (U) :
(F.map (π j)).c.app U =
(Pushforward.id (F.obj j).presheaf).inv.app U β«
(pushforwardEq (by simp) (F.obj j).presheaf).hom.app U := by
simp [PresheafedSpace.congr_app (F.map_id j)]
@[simp]
theorem map_comp_c_app (F : J β₯€ PresheafedSpace.{_, _, v} C) {jβ jβ jβ}
(f : jβ βΆ jβ) (g : jβ βΆ jβ) (U) :
(F.map (f β« g)).c.app U =
(F.map g).c.app U β«
((pushforward C (F.map g).base).map (F.map f).c).app U β«
(pushforwardEq (congr_arg Hom.base (F.map_comp f g).symm) _).hom.app U := by
simp [PresheafedSpace.congr_app (F.map_comp f g)]
/-- Given a diagram of `PresheafedSpace C`s, its colimit is computed by pushing the sheaves onto
the colimit of the underlying spaces, and taking componentwise limit.
This is the componentwise diagram for an open set `U` of the colimit of the underlying spaces.
-/
@[simps]
def componentwiseDiagram (F : J β₯€ PresheafedSpace.{_, _, v} C) [HasColimit F]
(U : Opens (Limits.colimit F).carrier) : Jα΅α΅ β₯€ C where
obj j := (F.obj (unop j)).presheaf.obj (op ((Opens.map (colimit.ΞΉ F (unop j)).base).obj U))
map {j k} f := (F.map f.unop).c.app _ β«
(F.obj (unop k)).presheaf.map (eqToHom (by rw [β colimit.w F f.unop, comp_base]; rfl))
map_comp {i j k} f g := by
simp only [assoc, CategoryTheory.NatTrans.naturality_assoc]
simp
variable [HasColimitsOfShape J TopCat.{v}]
/-- Given a diagram of presheafed spaces,
we can push all the presheaves forward to the colimit `X` of the underlying topological spaces,
obtaining a diagram in `(Presheaf C X)α΅α΅`.
-/
@[simps]
def pushforwardDiagramToColimit (F : J β₯€ PresheafedSpace.{_, _, v} C) :
J β₯€ (Presheaf C (colimit (F β PresheafedSpace.forget C)))α΅α΅ where
obj j := op (colimit.ΞΉ (F β PresheafedSpace.forget C) j _* (F.obj j).presheaf)
map {j j'} f :=
((pushforward C (colimit.ΞΉ (F β PresheafedSpace.forget C) j')).map (F.map f).c β«
(Pushforward.comp ((F β PresheafedSpace.forget C).map f)
(colimit.ΞΉ (F β PresheafedSpace.forget C) j') (F.obj j).presheaf).inv β«
(pushforwardEq (colimit.w (F β PresheafedSpace.forget C) f) (F.obj j).presheaf).hom).op
map_id j := by
apply (opEquiv _ _).injective
refine NatTrans.ext (funext fun U => ?_)
induction U with
| op U =>
simp [opEquiv]
rfl
map_comp {jβ jβ jβ} f g := by
apply (opEquiv _ _).injective
refine NatTrans.ext (funext fun U => ?_)
dsimp [opEquiv]
have :
op ((Opens.map (F.map g).base).obj
((Opens.map (colimit.ΞΉ (F β forget C) jβ)).obj U.unop)) =
op ((Opens.map (colimit.ΞΉ (F β PresheafedSpace.forget C) jβ)).obj (unop U)) := by
apply unop_injective
rw [β Opens.map_comp_obj]
congr
exact colimit.w (F β PresheafedSpace.forget C) g
simp only [map_comp_c_app, pushforward_obj_obj, pushforward_map_app, comp_base,
pushforwardEq_hom_app, op_obj, Opens.map_comp_obj, id_comp, assoc, eqToHom_map_comp,
NatTrans.naturality_assoc, pushforward_obj_map, eqToHom_unop]
simp [NatTrans.congr (Ξ± := (F.map f).c) this]
variable [β X : TopCat.{v}, HasLimitsOfShape Jα΅α΅ (X.Presheaf C)]
/-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`.
-/
def colimit (F : J β₯€ PresheafedSpace.{_, _, v} C) : PresheafedSpace C where
carrier := Limits.colimit (F β PresheafedSpace.forget C)
presheaf := limit (pushforwardDiagramToColimit F).leftOp
@[simp]
theorem colimit_carrier (F : J β₯€ PresheafedSpace.{_, _, v} C) :
(colimit F).carrier = Limits.colimit (F β PresheafedSpace.forget C) :=
rfl
@[simp]
theorem colimit_presheaf (F : J β₯€ PresheafedSpace.{_, _, v} C) :
(colimit F).presheaf = limit (pushforwardDiagramToColimit F).leftOp :=
rfl
/-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`.
-/
@[simps]
def colimitCocone (F : J β₯€ PresheafedSpace.{_, _, v} C) : Cocone F where
pt := colimit F
ΞΉ :=
{ app := fun j =>
{ base := colimit.ΞΉ (F β PresheafedSpace.forget C) j
c := limit.Ο _ (op j) }
naturality := fun {j j'} f => by
ext1
Β· ext x
exact colimit.w_apply (F β PresheafedSpace.forget C) f x
Β· ext β¨U, hUβ©
dsimp [-Presheaf.comp_app]
rw [PresheafedSpace.id_c_app, map_id]
erw [id_comp]
rw [NatTrans.comp_app, PresheafedSpace.comp_c_app, whiskerRight_app, eqToHom_app,
β congr_arg NatTrans.app (limit.w (pushforwardDiagramToColimit F).leftOp f.op),
NatTrans.comp_app, Functor.leftOp_map, pushforwardDiagramToColimit_map]
simp }
variable [HasLimitsOfShape Jα΅α΅ C]
namespace ColimitCoconeIsColimit
/-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.colimitCoconeIsColimit`.
-/
def descCApp (F : J β₯€ PresheafedSpace.{_, _, v} C) (s : Cocone F) (U : (Opens s.pt.carrier)α΅α΅) :
s.pt.presheaf.obj U βΆ
(colimit.desc (F β PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s) _*
limit (pushforwardDiagramToColimit F).leftOp).obj
U := by
refine
limit.lift _
{ pt := s.pt.presheaf.obj U
Ο :=
{ app := fun j => ?_
naturality := fun j j' f => ?_ } } β«
(limitObjIsoLimitCompEvaluation _ _).inv
-- We still need to construct the `app` and `naturality'` fields omitted above.
Β· refine (s.ΞΉ.app (unop j)).c.app U β« (F.obj (unop j)).presheaf.map (eqToHom ?_)
dsimp
rw [β Opens.map_comp_obj]
simp
Β· dsimp
rw [PresheafedSpace.congr_app (s.w f.unop).symm U]
have w :=
Functor.congr_obj
(congr_arg Opens.map (colimit.ΞΉ_desc ((PresheafedSpace.forget C).mapCocone s) (unop j)))
(unop U)
simp only [Opens.map_comp_obj_unop] at w
replace w := congr_arg op w
have w' := NatTrans.congr (F.map f.unop).c w
rw [w']
simp
theorem desc_c_naturality (F : J β₯€ PresheafedSpace.{_, _, v} C) (s : Cocone F)
{U V : (Opens s.pt.carrier)α΅α΅} (i : U βΆ V) :
s.pt.presheaf.map i β« descCApp F s V =
descCApp F s U β«
(colimit.desc (F β forget C) ((forget C).mapCocone s) _* (colimitCocone F).pt.presheaf).map
i := by
dsimp [descCApp]
refine limit_obj_ext (fun j => ?_)
have w := Functor.congr_hom (congr_arg Opens.map
(colimit.ΞΉ_desc ((PresheafedSpace.forget C).mapCocone s) (unop j))) i.unop
simp only [Opens.map_comp_map] at w
simp [congr_arg Quiver.Hom.op w]
/-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.colimitCoconeIsColimit`.
-/
def desc (F : J β₯€ PresheafedSpace.{_, _, v} C) (s : Cocone F) : colimit F βΆ s.pt where
base := colimit.desc (F β PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s)
c :=
{ app := fun U => descCApp F s U
naturality := fun _ _ i => desc_c_naturality F s i }
theorem desc_fac (F : J β₯€ PresheafedSpace.{_, _, v} C) (s : Cocone F) (j : J) :
(colimitCocone F).ΞΉ.app j β« desc F s = s.ΞΉ.app j := by
ext U
Β· simp [desc]
Β· -- Porting note (https://github.com/leanprover-community/mathlib4/issues/11041): the original proof is just `ext; dsimp [desc, descCApp]; simpa`,
-- but this has to be expanded a bit
rw [NatTrans.comp_app, PresheafedSpace.comp_c_app, whiskerRight_app]
dsimp [desc, descCApp]
simp only [eqToHom_app, op_obj, Opens.map_comp_obj, eqToHom_map, Functor.leftOp, assoc]
rw [limitObjIsoLimitCompEvaluation_inv_Ο_app_assoc]
simp
end ColimitCoconeIsColimit
open ColimitCoconeIsColimit
/-- Auxiliary definition for `AlgebraicGeometry.PresheafedSpace.instHasColimits`.
-/
def colimitCoconeIsColimit (F : J β₯€ PresheafedSpace.{_, _, v} C) :
IsColimit (colimitCocone F) where
desc s := desc F s
fac s := desc_fac F s
uniq s m w := by
-- We need to use the identity on the continuous maps twice, so we prepare that first:
have t :
m.base =
colimit.desc (F β PresheafedSpace.forget C) ((PresheafedSpace.forget C).mapCocone s) := by
dsimp
-- `colimit.hom_ext` used to be automatically applied by `ext` before https://github.com/leanprover-community/mathlib4/pull/21302
apply colimit.hom_ext fun j => ?_
ext
rw [colimit.ΞΉ_desc, mapCocone_ΞΉ_app, β w j]
simp
ext : 1
Β· exact t
Β· refine NatTrans.ext (funext fun U => limit_obj_ext fun j => ?_)
simp [desc, descCApp,
PresheafedSpace.congr_app (w (unop j)).symm U,
NatTrans.congr (limit.Ο (pushforwardDiagramToColimit F).leftOp j)
(congr_arg op (Functor.congr_obj (congr_arg Opens.map t) (unop U)))]
instance : HasColimitsOfShape J (PresheafedSpace.{_, _, v} C) where
has_colimit F := β¨colimitCocone F, colimitCoconeIsColimit Fβ©
instance : PreservesColimitsOfShape J (PresheafedSpace.forget.{u, v, v} C) :=
β¨fun {F} => preservesColimit_of_preserves_colimit_cocone (colimitCoconeIsColimit F) <| by
apply IsColimit.ofIsoColimit (colimit.isColimit _)
fapply Cocones.ext
Β· rfl
Β· intro j
simpβ©
/-- When `C` has limits, the category of presheaved spaces with values in `C` itself has colimits.
-/
instance instHasColimits [HasLimits C] : HasColimits (PresheafedSpace.{_, _, v} C) :=
β¨fun {_ _} => β¨fun {F} => β¨colimitCocone F, colimitCoconeIsColimit Fβ©β©β©
/-- The underlying topological space of a colimit of presheaved spaces is
the colimit of the underlying topological spaces.
-/
instance forget_preservesColimits [HasLimits C] :
PreservesColimits (PresheafedSpace.forget.{_, _, v} C) where
preservesColimitsOfShape {J π₯} :=
{ preservesColimit := fun {F} => preservesColimit_of_preserves_colimit_cocone
(colimitCoconeIsColimit F)
(IsColimit.ofIsoColimit (colimit.isColimit _) (Cocones.ext (Iso.refl _))) }
/-- The components of the colimit of a diagram of `PresheafedSpace C` is obtained
via taking componentwise limits.
-/
def colimitPresheafObjIsoComponentwiseLimit (F : J β₯€ PresheafedSpace.{_, _, v} C) [HasColimit F]
(U : Opens (Limits.colimit F).carrier) :
(Limits.colimit F).presheaf.obj (op U) β
limit (componentwiseDiagram F U) := by
refine
((sheafIsoOfIso (colimit.isoColimitCocone β¨_, colimitCoconeIsColimit Fβ©).symm).app
(op U)).trans
?_
refine (limitObjIsoLimitCompEvaluation _ _).trans (Limits.lim.mapIso ?_)
fapply NatIso.ofComponents
Β· intro X
refine (F.obj (unop X)).presheaf.mapIso (eqToIso ?_)
simp only [Functor.op_obj, op_inj_iff, Opens.map_coe, SetLike.ext'_iff,
Set.preimage_preimage]
refine congr_arg (Set.preimage Β· U.1) (funext fun x => ?_)
erw [β TopCat.comp_app]
congr
exact ΞΉ_preservesColimitIso_inv (forget C) F (unop X)
Β· intro X Y f
change ((F.map f.unop).c.app _ β« _ β« _) β« (F.obj (unop Y)).presheaf.map _ = _ β« _
rw [TopCat.Presheaf.Pushforward.comp_inv_app]
erw [Category.id_comp]
rw [Category.assoc]
erw [β (F.obj (unop Y)).presheaf.map_comp, (F.map f.unop).c.naturality_assoc,
β (F.obj (unop Y)).presheaf.map_comp]
rfl
@[simp]
theorem colimitPresheafObjIsoComponentwiseLimit_inv_ΞΉ_app (F : J β₯€ PresheafedSpace.{_, _, v} C)
(U : Opens (Limits.colimit F).carrier) (j : J) :
(colimitPresheafObjIsoComponentwiseLimit F U).inv β« (colimit.ΞΉ F j).c.app (op U) =
limit.Ο _ (op j) := by
delta colimitPresheafObjIsoComponentwiseLimit
rw [Iso.trans_inv, Iso.trans_inv, Iso.app_inv, sheafIsoOfIso_inv, pushforwardToOfIso_app,
congr_app (Iso.symm_inv _)]
dsimp
rw [map_id, comp_id, assoc, assoc, assoc, NatTrans.naturality,
β comp_c_app_assoc,
congr_app (colimit.isoColimitCocone_ΞΉ_hom _ _), assoc]
erw [limitObjIsoLimitCompEvaluation_inv_Ο_app_assoc, limMap_Ο_assoc]
-- Porting note: `convert` doesn't work due to meta variable, so change to a `suffices` block
set f := _
change _ β« f = _
suffices f_eq : f = π _ by rw [f_eq, comp_id]
erw [β (F.obj j).presheaf.map_id]
change (F.obj j).presheaf.map _ β« _ = _
simp
@[simp]
theorem colimitPresheafObjIsoComponentwiseLimit_hom_Ο (F : J β₯€ PresheafedSpace.{_, _, v} C)
(U : Opens (Limits.colimit F).carrier) (j : J) :
(colimitPresheafObjIsoComponentwiseLimit F U).hom β« limit.Ο _ (op j) =
(colimit.ΞΉ F j).c.app (op U) := by
rw [β Iso.eq_inv_comp, colimitPresheafObjIsoComponentwiseLimit_inv_ΞΉ_app]
end PresheafedSpace
end AlgebraicGeometry
|
Reflection.lean
|
/-
Copyright (c) 2024 Dagur Asgeirsson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Dagur Asgeirsson
-/
import Mathlib.CategoryTheory.Adjunction.Restrict
import Mathlib.CategoryTheory.Closed.Monoidal
import Mathlib.CategoryTheory.Monad.Adjunction
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.Tactic.TFAE
/-!
# Day's reflection theorem
Let `D` be a symmetric monoidal closed category and let `C` be a reflective subcategory. Day's
reflection theorem proves the equivalence of four conditions, which are all of the form that a
map obtained by acting on the unit of the reflective adjunction, with the internal hom and
tensor functors, is an isomorphism.
Suppose that `C` is itself monoidal and that the reflector is a monoidal functor. Then we can
apply Day's reflection theorem to prove that `C` is also closed monoidal.
## References
- We follow the proof on nLab, see https://ncatlab.org/nlab/show/Day%27s+reflection+theorem.
- The original paper is [day1972] *A reflection theorem for closed categories*, by Day, 1972.
-/
namespace CategoryTheory.Monoidal.Reflective
open Category MonoidalCategory MonoidalClosed BraidedCategory Functor
variable {C D : Type*} [Category C] [Category D]
variable [MonoidalCategory D] [SymmetricCategory D] [MonoidalClosed D]
section
variable {R : C β₯€ D} [R.Faithful] [R.Full] {L : D β₯€ C} (adj : L β£ R)
/-- The uncurried retraction of the unit in the proof of `4 β 1` in `isIso_tfae` below. -/
private noncomputable def adjRetractionAux
(c : C) (d : D) [IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ββ adj.unit.app d))] :
d β ((L β R).obj ((ihom d).obj (R.obj c))) βΆ (R.obj c) :=
(Ξ²_ _ _).hom β« (_ β adj.unit.app _) β« adj.unit.app _ β«
R.map (inv (L.map (adj.unit.app _ ββ adj.unit.app _))) β« (L β R).map (Ξ²_ _ _).hom β«
(L β R).map ((ihom.ev _).app _) β« inv (adj.unit.app _)
/-- The retraction of the unit in the proof of `4 β 1` in `isIso_tfae` below. -/
private noncomputable def adjRetraction (c : C) (d : D)
[IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ββ adj.unit.app d))] :
(L β R).obj ((ihom d).obj (R.obj c)) βΆ ((ihom d).obj (R.obj c)) :=
curry <| adjRetractionAux adj c d
private lemma adjRetraction_is_retraction (c : C) (d : D)
[IsIso (L.map (adj.unit.app ((ihom d).obj (R.obj c)) ββ adj.unit.app d))] :
adj.unit.app ((ihom d).obj (R.obj c)) β« adjRetraction adj c d = π _ := by
suffices (_ β adj.unit.app _) β« adjRetractionAux adj c d = (ihom.ev _).app _ by
simp only [id_obj, comp_obj, adjRetraction, β curry_natural_left, this]
simp [curry_eq]
simp only [id_obj, comp_obj, adjRetractionAux, Functor.map_inv, Functor.comp_map,
braiding_naturality_right_assoc]
slice_lhs 2 3 =>
simp only [β id_tensorHom, β tensorHom_id, β tensor_comp, Category.id_comp, Category.comp_id]
slice_lhs 2 4 =>
rw [β adj.unit_naturality_assoc]
simp
attribute [local simp] Adjunction.homEquiv_unit Adjunction.homEquiv_counit
/--
Day's reflection theorem.
Let `D` be a symmetric monoidal closed category and let `C` be a reflective subcategory. Denote by
`R : C β₯€ D` the inclusion functor and by `L : D β₯€ C` the reflector. Let `u` denote the unit of the
adjunction `L β£ R`. Denote the internal hom by `[-,-]`. The following are equivalent:
1. `u : [d, Rc] βΆ RL[d, Rc]` is an isomorphism,
2. `[u, π] : [RLd, Rc] βΆ [d, Rc]` is an isomorphism,
3. `L(u β· d') : L(d β d') βΆ L(RLd β d')` is an isomorphism,
4. `L(u β u) : L(d β d') βΆ L(RLd β RLd')` is an isomorphism,
where `c, d, d'` are arbitrary objects of `C`/`D`, quantified over separately in each condition.
-/
theorem isIso_tfae : List.TFAE
[ β (c : C) (d : D), IsIso (adj.unit.app ((ihom d).obj (R.obj c)))
, β (c : C) (d : D), IsIso ((pre (adj.unit.app d)).app (R.obj c))
, β (d d' : D), IsIso (L.map ((adj.unit.app d) β· d'))
, β (d d' : D), IsIso (L.map ((adj.unit.app d) ββ (adj.unit.app d')))] := by
tfae_have 3 β 4
| h => by
-- We can commute the tensor product in the condition that `L.map ((adj.unit.app d) β· d')` is
-- an isomorphism:
have h' : β d d', IsIso (L.map (d β (adj.unit.app d'))) := by
intro d d'
have := braiding_naturality (π d) (adj.unit.app d')
rw [β Iso.eq_comp_inv, id_tensorHom] at this
rw [this]
simp only [map_comp, id_obj, comp_obj, tensorHom_id, Category.assoc]
infer_instance
intro d d'
-- We then write the tensor product of the two units as the composition of the whiskered units,
-- and conclude.
have : (adj.unit.app d) ββ (adj.unit.app d') =
(adj.unit.app d β· d') β« (((L β R).obj _) β adj.unit.app d') := by
simp [β tensorHom_id, β id_tensorHom, β tensor_comp]
rw [this, map_comp]
infer_instance
tfae_have 4 β 1
| _, _, _ => by
-- It is enough to show that the unit is a split monomorphism, and the retraction is given
-- by `adjRetraction` above.
let _ : Reflective R := { L := L, adj := adj }
have : IsIso adj.toMonad.ΞΌ := ΞΌ_iso_of_reflective (R := R)
erw [β adj.toMonad.isSplitMono_iff_isIso_unit]
exact β¨β¨adjRetraction adj _ _, adjRetraction_is_retraction adj _ _β©β©
tfae_have 1 β 3
| h, d, d' => by
rw [isIso_iff_isIso_coyoneda_map]
intro c
-- `wβ, wβ, wβ` are the three stacked commutative squares in the proof on nLab:
have wβ : (coyoneda.map (L.map (adj.unit.app d β· d')).op).app c = (adj.homEquiv _ _).symm β
(coyoneda.map (adj.unit.app d β· d').op).app (R.obj c) β adj.homEquiv _ _ := by ext; simp
rw [wβ, isIso_iff_bijective]
simp only [comp_obj, coyoneda_obj_obj, id_obj, EquivLike.comp_bijective,
EquivLike.bijective_comp]
-- We commute the tensor product using the auxiliary commutative square `wβ`.
have wβ : ((coyoneda.map (adj.unit.app d β· d').op).app (R.obj c)) =
((yoneda.obj (R.obj c)).mapIso (Ξ²_ _ _)).hom β
((coyoneda.map (d' β adj.unit.app d).op).app (R.obj c)) β
((yoneda.obj (R.obj c)).mapIso (Ξ²_ _ _)).hom := by ext; simp
rw [wβ, β types_comp, β types_comp, β isIso_iff_bijective]
refine IsIso.comp_isIso' (IsIso.comp_isIso' inferInstance ?_) inferInstance
have wβ : ((coyoneda.map (d' β adj.unit.app d).op).app (R.obj c)) =
((ihom.adjunction d').homEquiv _ _).symm β
((coyoneda.map (adj.unit.app _).op).app _) β (ihom.adjunction d').homEquiv _ _ := by
ext
simp only [id_obj, op_tensorObj, coyoneda_obj_obj, unop_tensorObj, comp_obj,
coyoneda_map_app, Quiver.Hom.unop_op, Function.comp_apply,
Adjunction.homEquiv_unit, Adjunction.homEquiv_counit]
simp
rw [wβ, isIso_iff_bijective]
simp only [comp_obj, op_tensorObj, coyoneda_obj_obj, unop_tensorObj, id_obj,
yoneda_obj_obj, curriedTensor_obj_obj, EquivLike.comp_bijective, EquivLike.bijective_comp]
have wβ : (coyoneda.map (adj.unit.app d).op).app ((ihom d').obj (R.obj c)) β«
(coyoneda.obj β¨dβ©).map (adj.unit.app ((ihom d').obj (R.obj c))) =
(coyoneda.obj β¨(L β R).obj dβ©).map (adj.unit.app ((ihom d').obj (R.obj c))) β«
(coyoneda.map (adj.unit.app d).op).app _ := by simp
rw [β isIso_iff_bijective]
suffices IsIso ((coyoneda.map (adj.unit.app d).op).app ((ihom d').obj (R.obj c)) β«
(coyoneda.obj β¨dβ©).map (adj.unit.app ((ihom d').obj (R.obj c)))) from
IsIso.of_isIso_comp_right _ ((coyoneda.obj β¨dβ©).map (adj.unit.app ((ihom d').obj (R.obj c))))
rw [wβ]
refine IsIso.comp_isIso' inferInstance ?_
constructor
-- We give the inverse of the bottom map in the stack of commutative squares:
refine β¨fun f β¦ R.map ((adj.homEquiv _ _).symm f), ?_, by ext; simpβ©
ext f
simp only [comp_obj, coyoneda_obj_obj, id_obj, Adjunction.homEquiv_counit,
map_comp, types_comp_apply, coyoneda_map_app, Quiver.Hom.unop_op, Category.assoc,
types_id_apply]
have : f = R.map (R.preimage f) := by simp
rw [this]
simp [β map_comp, -map_preimage]
tfae_have 2 β 3 := by
conv => lhs; intro c d; rw [isIso_iff_isIso_yoneda_map]
conv => rhs; intro d d'; rw [isIso_iff_isIso_coyoneda_map]
-- bring the quantifiers out of the `β`:
rw [forall_swap]; apply forall_congr'; intro d
rw [forall_swap]; apply forallβ_congr; intro d' c
-- `wβ, wβ,` are the two stacked commutative squares in the proof on nLab:
have wβ : ((coyoneda.map (L.map (adj.unit.app d β· d')).op).app c) =
(adj.homEquiv _ _).symm β
(coyoneda.map (adj.unit.app d β· d').op).app (R.obj c) β
(adj.homEquiv _ _) := by ext; simp
have wβ : ((yoneda.map ((pre (adj.unit.app d)).app (R.obj c))).app β¨d'β©) =
((ihom.adjunction d).homEquiv _ _) β
((coyoneda.map (adj.unit.app d β· d').op).app (R.obj c)) β
((ihom.adjunction ((L β R).obj d)).homEquiv _ _).symm := by
rw [β Function.comp_assoc, ((ihom.adjunction ((L β R).obj d)).homEquiv _ _).eq_comp_symm]
ext
simp only [id_obj, yoneda_obj_obj, comp_obj, Function.comp_apply,
yoneda_map_app, op_tensorObj, coyoneda_obj_obj, unop_tensorObj, op_whiskerRight,
coyoneda_map_app, unop_whiskerRight, Quiver.Hom.unop_op]
rw [Adjunction.homEquiv_unit, Adjunction.homEquiv_unit]
simp
rw [wβ, wβ, isIso_iff_bijective, isIso_iff_bijective]
simp
tfae_finish
end
section
open Functor.OplaxMonoidal Functor.LaxMonoidal Functor.Monoidal
variable [MonoidalCategory C]
variable {L : D β₯€ C} [L.Monoidal] {R : C β₯€ D} [R.Faithful] [R.Full] (adj : L β£ R)
instance (d d' : D) : IsIso (L.map ((adj.unit.app d) ββ (adj.unit.app d'))) := by
have := Ξ΄ _ _ _ β«= ΞΌ_natural L (adj.unit.app d) (adj.unit.app d')
rw [Ξ΄_ΞΌ_assoc] at this
rw [β this]
infer_instance
instance (c : C) (d : D) : IsIso (adj.unit.app ((ihom d).obj (R.obj c))) := by
revert c d
rw [((isIso_tfae adj).out 0 3:)]
intro d d'
infer_instance
/-- Auxiliary definition for `monoidalClosed`. -/
noncomputable def closed (c : C) : Closed c where
rightAdj := R β (ihom (R.obj c)) β L
adj := by
refine ((ihom.adjunction (R.obj c)).comp adj).restrictFullyFaithful
(FullyFaithful.ofFullyFaithful R)
(FullyFaithful.id _) ?_ ?_
Β· refine NatIso.ofComponents (fun _ β¦ (ΞΌIso L _ _).symm βͺβ«
asIso ((adj.counit.app _) ββ (adj.counit.app _))) (fun _ β¦ ?_)
dsimp
rw [Category.assoc, β Ξ΄_natural_right_assoc,
tensorHom_def', β MonoidalCategory.whiskerLeft_comp_assoc,
Adjunction.counit_naturality, whisker_exchange,
tensorHom_def_assoc, MonoidalCategory.whiskerLeft_comp]
Β· exact NatIso.ofComponents (fun _ β¦ asIso (adj.unit.app ((ihom _).obj _)))
/--
Given a reflective functor `R : C β₯€ D` with a monoidal left adjoint, such that `D` is symmetric
monoidal closed, then `C` is monoidal closed.
-/
noncomputable def monoidalClosed : MonoidalClosed C where
closed c := closed adj c
end
end CategoryTheory.Monoidal.Reflective
|
CharPZeroNeCharZero.lean
|
/-
Copyright (c) 2022 Damiano Testa. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Damiano Testa, Eric Wieser
-/
import Mathlib.Algebra.CharP.Lemmas
import Mathlib.Algebra.Ring.PUnit
/-! # `CharP R 0` and `CharZero R` need not coincide for semirings
For rings, the two notions coincide.
In fact, `CharP.ofCharZero` shows that `CharZero R` implies `CharP R 0` for any `CharZero`
`AddMonoid R` with `1`.
The reverse implication holds for any `AddLeftCancelMonoid R` with `1`, by `charP_to_charZero`.
This file shows that there are semirings `R` for which `CharP R 0` holds and `CharZero R` does not.
The example is `{0, 1}` with saturating addition.
-/
namespace Counterexample
@[simp]
theorem add_one_eq_one (x : WithZero Unit) : x + 1 = 1 :=
WithZero.cases_on x (by rfl) fun h => by rfl
theorem withZero_unit_charP_zero : CharP (WithZero Unit) 0 :=
β¨fun x => by cases x <;> simpβ©
theorem withZero_unit_not_charZero : Β¬CharZero (WithZero Unit) := fun β¨hβ© =>
h.ne (by simp : 1 + 1 β 0 + 1) (by simp [-Nat.reduceAdd])
end Counterexample
|
Monadicity.lean
|
/-
Copyright (c) 2020 Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Bhavik Mehta
-/
import Mathlib.CategoryTheory.Limits.Preserves.Shapes.Equalizers
import Mathlib.CategoryTheory.Limits.Shapes.Reflexive
import Mathlib.CategoryTheory.Monad.Coequalizer
import Mathlib.CategoryTheory.Monad.Limits
/-!
# Monadicity theorems
We prove monadicity theorems which can establish a given functor is monadic. In particular, we
show three versions of Beck's monadicity theorem, and the reflexive (crude) monadicity theorem:
`G` is a monadic right adjoint if it has a left adjoint, and:
* `D` has, `G` preserves and reflects `G`-split coequalizers, see
`CategoryTheory.Monad.monadicOfHasPreservesReflectsGSplitCoequalizers`
* `G` creates `G`-split coequalizers, see
`CategoryTheory.Monad.monadicOfCreatesGSplitCoequalizers`
(The converse of this is also shown, see
`CategoryTheory.Monad.createsGSplitCoequalizersOfMonadic`)
* `D` has and `G` preserves `G`-split coequalizers, and `G` reflects isomorphisms, see
`CategoryTheory.Monad.monadicOfHasPreservesGSplitCoequalizersOfReflectsIsomorphisms`
* `D` has and `G` preserves reflexive coequalizers, and `G` reflects isomorphisms, see
`CategoryTheory.Monad.monadicOfHasPreservesReflexiveCoequalizersOfReflectsIsomorphisms`
This file has been adapted to `Mathlib/CategoryTheory/Monad/Comonadicity.lean`.
Please try to keep them in sync.
## Tags
Beck, monadicity, descent
-/
universe vβ vβ uβ uβ
namespace CategoryTheory
namespace Monad
open Limits
noncomputable section
-- Hide the implementation details in this namespace.
namespace MonadicityInternal
variable {C : Type uβ} {D : Type uβ}
variable [Category.{vβ} C] [Category.{vβ} D]
variable {G : D β₯€ C} {F : C β₯€ D} (adj : F β£ G)
/-- The "main pair" for an algebra `(A, Ξ±)` is the pair of morphisms `(F Ξ±, Ξ΅_FA)`. It is always a
reflexive pair, and will be used to construct the left adjoint to the comparison functor and show it
is an equivalence.
-/
instance main_pair_reflexive (A : adj.toMonad.Algebra) :
IsReflexivePair (F.map A.a) (adj.counit.app (F.obj A.A)) := by
apply IsReflexivePair.mk' (F.map (adj.unit.app _)) _ _
Β· rw [β F.map_comp, β F.map_id]
exact congr_arg F.map A.unit
Β· rw [adj.left_triangle_components]
rfl
/-- The "main pair" for an algebra `(A, Ξ±)` is the pair of morphisms `(F Ξ±, Ξ΅_FA)`. It is always a
`G`-split pair, and will be used to construct the left adjoint to the comparison functor and show it
is an equivalence.
-/
instance main_pair_G_split (A : adj.toMonad.Algebra) :
G.IsSplitPair (F.map A.a)
(adj.counit.app (F.obj A.A)) where
splittable := β¨_, _, β¨beckSplitCoequalizer Aβ©β©
/-- The object function for the left adjoint to the comparison functor. -/
def comparisonLeftAdjointObj (A : adj.toMonad.Algebra)
[HasCoequalizer (F.map A.a) (adj.counit.app _)] : D :=
coequalizer (F.map A.a) (adj.counit.app _)
/--
We have a bijection of homsets which will be used to construct the left adjoint to the comparison
functor.
-/
@[simps!]
def comparisonLeftAdjointHomEquiv (A : adj.toMonad.Algebra) (B : D)
[HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] :
(comparisonLeftAdjointObj adj A βΆ B) β (A βΆ (comparison adj).obj B) :=
calc
(comparisonLeftAdjointObj adj A βΆ B) β { f : F.obj A.A βΆ B // _ } :=
Cofork.IsColimit.homIso (colimit.isColimit _) B
_ β { g : A.A βΆ G.obj B // G.map (F.map g) β« G.map (adj.counit.app B) = A.a β« g } := by
refine (adj.homEquiv _ _).subtypeEquiv ?_
intro f
rw [β (adj.homEquiv _ _).injective.eq_iff, Adjunction.homEquiv_naturality_left,
adj.homEquiv_unit, adj.homEquiv_unit, G.map_comp]
dsimp
rw [adj.right_triangle_components_assoc, β G.map_comp, F.map_comp, Category.assoc,
adj.counit_naturality, adj.left_triangle_components_assoc]
apply eq_comm
_ β (A βΆ (comparison adj).obj B) :=
{ toFun := fun g =>
{ f := _
h := g.prop }
invFun := fun f => β¨f.f, f.hβ© }
/-- Construct the adjunction to the comparison functor.
-/
def leftAdjointComparison
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a)
(adj.counit.app (F.obj A.A))] :
adj.toMonad.Algebra β₯€ D := by
refine
Adjunction.leftAdjointOfEquiv (G := comparison adj)
(F_obj := fun A => comparisonLeftAdjointObj adj A) (fun A B => ?_) ?_
Β· apply comparisonLeftAdjointHomEquiv
Β· intro A B B' g h
ext1
-- Porting note: the goal was previously closed by the following, which succeeds until
-- `Category.assoc`.
-- dsimp [comparisonLeftAdjointHomEquiv]
-- rw [β adj.homEquiv_naturality_right, Category.assoc]
simp [Cofork.IsColimit.homIso, Adjunction.homEquiv_unit]
/-- Provided we have the appropriate coequalizers, we have an adjunction to the comparison functor.
-/
@[simps! counit]
def comparisonAdjunction
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a)
(adj.counit.app (F.obj A.A))] :
leftAdjointComparison adj β£ comparison adj :=
Adjunction.adjunctionOfEquivLeft _ _
variable {adj}
theorem comparisonAdjunction_unit_f_aux
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a)
(adj.counit.app (F.obj A.A))]
(A : adj.toMonad.Algebra) :
((comparisonAdjunction adj).unit.app A).f =
adj.homEquiv A.A _
(coequalizer.Ο (F.map A.a) (adj.counit.app (F.obj A.A))) :=
congr_arg (adj.homEquiv _ _) (Category.comp_id _)
/-- This is a cofork which is helpful for establishing monadicity: the morphism from the Beck
coequalizer to this cofork is the unit for the adjunction on the comparison functor.
-/
@[simps! pt]
def unitCofork (A : adj.toMonad.Algebra)
[HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] :
Cofork (G.map (F.map A.a)) (G.map (adj.counit.app (F.obj A.A))) :=
Cofork.ofΟ (G.map (coequalizer.Ο (F.map A.a) (adj.counit.app (F.obj A.A))))
(by rw [β G.map_comp, coequalizer.condition, G.map_comp])
@[simp]
theorem unitCofork_Ο (A : adj.toMonad.Algebra)
[HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] :
(unitCofork A).Ο = G.map (coequalizer.Ο (F.map A.a) (adj.counit.app (F.obj A.A))) :=
rfl
theorem comparisonAdjunction_unit_f
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a)
(adj.counit.app (F.obj A.A))]
(A : adj.toMonad.Algebra) :
((comparisonAdjunction adj).unit.app A).f = (beckCoequalizer A).desc (unitCofork A) := by
apply Limits.Cofork.IsColimit.hom_ext (beckCoequalizer A)
rw [Cofork.IsColimit.Ο_desc]
dsimp only [beckCofork_Ο, unitCofork_Ο]
rw [comparisonAdjunction_unit_f_aux, β adj.homEquiv_naturality_left A.a, coequalizer.condition,
adj.homEquiv_naturality_right, adj.homEquiv_unit, Category.assoc]
apply adj.right_triangle_components_assoc
variable (adj)
/-- The cofork which describes the counit of the adjunction: the morphism from the coequalizer of
this pair to this morphism is the counit.
-/
@[simps!]
def counitCofork (B : D) :
Cofork (F.map (G.map (adj.counit.app B)))
(adj.counit.app (F.obj (G.obj B))) :=
Cofork.ofΟ (adj.counit.app B) (adj.counit_naturality _)
variable {adj} in
/-- The unit cofork is a colimit provided `G` preserves it. -/
def unitColimitOfPreservesCoequalizer (A : adj.toMonad.Algebra)
[HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))]
[PreservesColimit (parallelPair (F.map A.a) (adj.counit.app (F.obj A.A))) G] :
IsColimit (unitCofork (G := G) A) :=
isColimitOfHasCoequalizerOfPreservesColimit G _ _
/-- The counit cofork is a colimit provided `G` reflects it. -/
def counitCoequalizerOfReflectsCoequalizer (B : D)
[ReflectsColimit (parallelPair (F.map (G.map (adj.counit.app B)))
(adj.counit.app (F.obj (G.obj B)))) G] :
IsColimit (counitCofork (adj := adj) B) :=
isColimitOfIsColimitCoforkMap G _ (beckCoequalizer ((comparison adj).obj B))
-- Porting note: Lean 3 didn't seem to need this
instance
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))]
(B : D) : HasColimit (parallelPair
(F.map (G.map (NatTrans.app adj.counit B)))
(NatTrans.app adj.counit (F.obj (G.obj B)))) :=
inferInstanceAs <| HasCoequalizer
(F.map ((comparison adj).obj B).a)
(adj.counit.app (F.obj ((comparison adj).obj B).A))
theorem comparisonAdjunction_counit_app
[β A : adj.toMonad.Algebra, HasCoequalizer (F.map A.a) (adj.counit.app (F.obj A.A))] (B : D) :
(comparisonAdjunction adj).counit.app B = colimit.desc _ (counitCofork adj B) := by
apply coequalizer.hom_ext
change
coequalizer.Ο _ _ β« coequalizer.desc ((adj.homEquiv _ B).symm (π _)) _ =
coequalizer.Ο _ _ β« coequalizer.desc _ _
simp [Adjunction.homEquiv_counit]
end MonadicityInternal
open MonadicityInternal
variable {C : Type uβ} {D : Type uβ}
variable [Category.{vβ} C] [Category.{vβ} D]
variable {G : D β₯€ C} {F : C β₯€ D} (adj : F β£ G)
variable (G) in
/--
If `G` is monadic, it creates colimits of `G`-split pairs. This is the "boring" direction of Beck's
monadicity theorem, the converse is given in `monadicOfCreatesGSplitCoequalizers`.
-/
def createsGSplitCoequalizersOfMonadic [MonadicRightAdjoint G] β¦A Bβ¦ (f g : A βΆ B)
[G.IsSplitPair f g] : CreatesColimit (parallelPair f g) G := by
apply (config := {allowSynthFailures := true}) monadicCreatesColimitOfPreservesColimit
-- Porting note: oddly (config := {allowSynthFailures := true}) had no effect here and below
all_goals
apply @preservesColimit_of_iso_diagram _ _ _ _ _ _ _ _ _ (diagramIsoParallelPair.{vβ} _).symm ?_
dsimp
infer_instance
section BeckMonadicity
-- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311
-- When this is fixed the proofs below that struggle with instances should be reviewed.
-- [β β¦A Bβ¦ (f g : A βΆ B) [G.IsSplitPair f g], HasCoequalizer f g]
/-- Typeclass expressing that for all `G`-split pairs `f,g`, `f` and `g` have a coequalizer. -/
class HasCoequalizerOfIsSplitPair (G : D β₯€ C) : Prop where
out : β {A B} (f g : A βΆ B) [G.IsSplitPair f g], HasCoequalizer f g
-- Porting note: cannot find synth order
-- instance {A B} (f g : A βΆ B) [G.IsSplitPair f g] [HasCoequalizerOfIsSplitPair G] :
-- HasCoequalizer f g := HasCoequalizerOfIsSplitPair.out f g
instance [HasCoequalizerOfIsSplitPair G] : β (A : Algebra adj.toMonad),
HasCoequalizer (F.map A.a)
(adj.counit.app (F.obj A.A)) :=
fun _ => HasCoequalizerOfIsSplitPair.out G _ _
-- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311
-- [β β¦A Bβ¦ (f g : A βΆ B) [G.IsSplitPair f g], PreservesColimit (parallelPair f g) G]
/-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` preserves colimits of
`parallelPair f g`. -/
class PreservesColimitOfIsSplitPair (G : D β₯€ C) where
out : β {A B} (f g : A βΆ B) [G.IsSplitPair f g], PreservesColimit (parallelPair f g) G
instance {A B} (f g : A βΆ B) [G.IsSplitPair f g] [PreservesColimitOfIsSplitPair G] :
PreservesColimit (parallelPair f g) G := PreservesColimitOfIsSplitPair.out f g
instance [PreservesColimitOfIsSplitPair G] : β (A : Algebra adj.toMonad),
PreservesColimit (parallelPair (F.map A.a) (NatTrans.app adj.counit (F.obj A.A))) G :=
fun _ => PreservesColimitOfIsSplitPair.out _ _
-- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311
-- [β β¦A Bβ¦ (f g : A βΆ B) [G.IsSplitPair f g], ReflectsColimit (parallelPair f g) G] :
/-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` reflects colimits for
`parallelPair f g`. -/
class ReflectsColimitOfIsSplitPair (G : D β₯€ C) where
out : β {A B} (f g : A βΆ B) [G.IsSplitPair f g], ReflectsColimit (parallelPair f g) G
instance {A B} (f g : A βΆ B) [G.IsSplitPair f g] [ReflectsColimitOfIsSplitPair G] :
ReflectsColimit (parallelPair f g) G := ReflectsColimitOfIsSplitPair.out f g
instance [ReflectsColimitOfIsSplitPair G] : β (A : Algebra adj.toMonad),
ReflectsColimit (parallelPair (F.map A.a)
(NatTrans.app adj.counit (F.obj A.A))) G :=
fun _ => ReflectsColimitOfIsSplitPair.out _ _
/-- To show `G` is a monadic right adjoint, we can show it preserves and reflects `G`-split
coequalizers, and `D` has them.
-/
def monadicOfHasPreservesReflectsGSplitCoequalizers [HasCoequalizerOfIsSplitPair G]
[PreservesColimitOfIsSplitPair G] [ReflectsColimitOfIsSplitPair G] :
MonadicRightAdjoint G where
L := F
adj := adj
eqv := by
have : β (X : Algebra adj.toMonad), IsIso ((comparisonAdjunction adj).unit.app X) := by
intro X
apply @isIso_of_reflects_iso _ _ _ _ _ _ _ (Monad.forget adj.toMonad) ?_ _
Β· change IsIso ((comparisonAdjunction adj).unit.app X).f
rw [comparisonAdjunction_unit_f]
change
IsIso
(IsColimit.coconePointUniqueUpToIso (beckCoequalizer X)
(unitColimitOfPreservesCoequalizer X)).hom
exact (IsColimit.coconePointUniqueUpToIso _ _).isIso_hom
have : β (Y : D), IsIso ((comparisonAdjunction adj).counit.app Y) := by
intro Y
rw [comparisonAdjunction_counit_app]
-- Porting note: passing instances through
change IsIso (IsColimit.coconePointUniqueUpToIso _ ?_).hom
infer_instance
-- Porting note: passing instances through
apply @counitCoequalizerOfReflectsCoequalizer _ _ _ _ _ _ _ _ ?_
letI _ :
G.IsSplitPair (F.map (G.map (adj.counit.app Y)))
(adj.counit.app (F.obj (G.obj Y))) :=
MonadicityInternal.main_pair_G_split _ ((comparison adj).obj Y)
infer_instance
exact (comparisonAdjunction adj).toEquivalence.isEquivalence_inverse
-- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311
-- [β β¦A Bβ¦ (f g : A βΆ B) [G.IsSplitPair f g], CreatesColimit (parallelPair f g) G] :
/-- Typeclass expressing that for all `G`-split pairs `f,g`, `G` creates colimits of
`parallelPair f g`. -/
class CreatesColimitOfIsSplitPair (G : D β₯€ C) where
/-- For all `G`-split pairs `f,g`, `G` creates colimits of `parallelPair f g`. -/
out : β {A B} (f g : A βΆ B) [G.IsSplitPair f g], CreatesColimit (parallelPair f g) G
instance {A B} (f g : A βΆ B) [G.IsSplitPair f g] [CreatesColimitOfIsSplitPair G] :
CreatesColimit (parallelPair f g) G := CreatesColimitOfIsSplitPair.out f g
instance [CreatesColimitOfIsSplitPair G] : β (A : Algebra adj.toMonad),
CreatesColimit (parallelPair (F.map A.a)
(NatTrans.app adj.counit (F.obj A.A))) G :=
fun _ => CreatesColimitOfIsSplitPair.out _ _
/--
**Beck's monadicity theorem**: if `G` has a left adjoint and creates coequalizers of `G`-split
pairs, then it is monadic.
This is the converse of `createsGSplitCoequalizersOfMonadic`.
-/
def monadicOfCreatesGSplitCoequalizers [CreatesColimitOfIsSplitPair G] :
MonadicRightAdjoint G := by
have I {A B} (f g : A βΆ B) [G.IsSplitPair f g] : HasColimit (parallelPair f g β G) := by
rw [hasColimit_iff_of_iso (diagramIsoParallelPair.{vβ} _)]
exact inferInstanceAs <| HasCoequalizer (G.map f) (G.map g)
have : HasCoequalizerOfIsSplitPair G := β¨fun _ _ => hasColimit_of_created (parallelPair _ _) Gβ©
have : PreservesColimitOfIsSplitPair G := β¨by intros; infer_instanceβ©
have : ReflectsColimitOfIsSplitPair G := β¨by intros; infer_instanceβ©
exact monadicOfHasPreservesReflectsGSplitCoequalizers adj
/-- An alternate version of **Beck's monadicity theorem**: if `G` reflects isomorphisms, preserves
coequalizers of `G`-split pairs and `C` has coequalizers of `G`-split pairs, then it is monadic.
-/
def monadicOfHasPreservesGSplitCoequalizersOfReflectsIsomorphisms [G.ReflectsIsomorphisms]
[HasCoequalizerOfIsSplitPair G] [PreservesColimitOfIsSplitPair G] :
MonadicRightAdjoint G := by
have : ReflectsColimitOfIsSplitPair G := β¨fun f g _ => by
have := HasCoequalizerOfIsSplitPair.out G f g
apply reflectsColimit_of_reflectsIsomorphismsβ©
apply monadicOfHasPreservesReflectsGSplitCoequalizers adj
end BeckMonadicity
section ReflexiveMonadicity
variable [HasReflexiveCoequalizers D] [G.ReflectsIsomorphisms]
-- Porting note: added these to replace parametric instances https://github.com/leanprover/lean4/issues/2311
-- [β β¦A Bβ¦ (f g : A βΆ B) [G.IsReflexivePair f g], PreservesColimit (parallelPair f g) G] :
/-- Typeclass expressing that for all reflexive pairs `f,g`, `G` preserves colimits of
`parallelPair f g`. -/
class PreservesColimitOfIsReflexivePair (G : C β₯€ D) where
out : β β¦A Bβ¦ (f g : A βΆ B) [IsReflexivePair f g], PreservesColimit (parallelPair f g) G
instance {A B} (f g : A βΆ B) [IsReflexivePair f g] [PreservesColimitOfIsReflexivePair G] :
PreservesColimit (parallelPair f g) G := PreservesColimitOfIsReflexivePair.out f g
instance [PreservesColimitOfIsReflexivePair G] : β X : Algebra adj.toMonad,
PreservesColimit (parallelPair (F.map X.a)
(NatTrans.app adj.counit (F.obj X.A))) G :=
fun _ => PreservesColimitOfIsReflexivePair.out _ _
variable [PreservesColimitOfIsReflexivePair G]
/-- Reflexive (crude) monadicity theorem. If `G` has a right adjoint, `D` has and `G` preserves
reflexive coequalizers and `G` reflects isomorphisms, then `G` is monadic.
-/
def monadicOfHasPreservesReflexiveCoequalizersOfReflectsIsomorphisms : MonadicRightAdjoint G where
L := F
adj := adj
eqv := by
have : β (X : Algebra adj.toMonad), IsIso ((comparisonAdjunction adj).unit.app X) := by
intro X
apply
@isIso_of_reflects_iso _ _ _ _ _ _ _ (Monad.forget adj.toMonad) ?_ _
Β· change IsIso ((comparisonAdjunction adj).unit.app X).f
rw [comparisonAdjunction_unit_f]
exact (IsColimit.coconePointUniqueUpToIso (beckCoequalizer X)
(unitColimitOfPreservesCoequalizer X)).isIso_hom
have : β (Y : D), IsIso ((comparisonAdjunction adj).counit.app Y) := by
intro Y
rw [comparisonAdjunction_counit_app]
-- Porting note: passing instances through
change IsIso (IsColimit.coconePointUniqueUpToIso _ ?_).hom
infer_instance
-- Porting note: passing instances through
apply @counitCoequalizerOfReflectsCoequalizer _ _ _ _ _ _ _ _ ?_
apply reflectsColimit_of_reflectsIsomorphisms
exact (comparisonAdjunction adj).toEquivalence.isEquivalence_inverse
end ReflexiveMonadicity
end
end Monad
end CategoryTheory
|
LTSeries.lean
|
/-
Copyright (c) 2025 Yongle Hu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yongle Hu
-/
import Mathlib.RingTheory.Ideal.KrullsHeightTheorem
/-!
# Lemmas about `LTSeries` in the prime spectrum
## Main results
* `PrimeSpectrum.exist_ltSeries_mem_one_of_mem_last`: Let $R$ be a Noetherian ring,
$\mathfrak{p}_0 < \dots < \mathfrak{p}_n$ be a chain of primes, $x \in \mathfrak{p}_n$.
Then we can find another chain of primes $\mathfrak{q}_0 < \dots < \mathfrak{q}_n$ such that
$x \in \mathfrak{q}_1$, $\mathfrak{p}_0 = \mathfrak{q}_0$ and $\mathfrak{p}_n = \mathfrak{q}_n$.
-/
variable {R : Type*} [CommRing R] [IsNoetherianRing R]
local notation "πͺ" => IsLocalRing.maximalIdeal R
open Ideal IsLocalRing
namespace PrimeSpectrum
theorem exist_mem_one_of_mem_maximal_ideal [IsLocalRing R] {pβ pβ : PrimeSpectrum R}
(hβ : pβ < pβ) (hβ : pβ < closedPoint R) {x : R} (hx : x β πͺ) :
β q : PrimeSpectrum R, x β q.asIdeal β§ pβ < q β§ q.asIdeal < πͺ := by
by_cases hn : x β pβ.1
Β· exact β¨pβ, hβ.le hn, hβ, hββ©
let e := pβ.1.primeSpectrumQuotientOrderIsoZeroLocus.symm
obtain β¨q, hqβ© := (pβ.1 + span {x}).nonempty_minimalPrimes <|
sup_le (IsLocalRing.le_maximalIdeal_of_isPrime pβ.1) ((span_singleton_le_iff_mem πͺ).mpr hx)
|>.trans_lt (IsMaximal.isPrime' πͺ).1.lt_top |>.ne
let q : PrimeSpectrum R := β¨q, hq.1.1β©
have : q.1.IsPrime := q.2
have hxq : x β q.1 := le_sup_right.trans hq.1.2 (mem_span_singleton_self x)
refine β¨q, hxq, lt_of_le_not_ge (le_sup_left.trans hq.1.2) fun h β¦ hn (h hxq), ?_β©
refine lt_of_le_of_ne (IsLocalRing.le_maximalIdeal_of_isPrime q.1) fun hqm β¦ ?_
have h : (e β¨q, le_sup_left.trans hq.1.2β©).1.height β€ 1 :=
map_height_le_one_of_mem_minimalPrimes hq
simp_rw [show q = closedPoint R from PrimeSpectrum.ext hqm] at h
have hph : (e β¨pβ, hβ.leβ©).1.height β€ 0 :=
Order.lt_one_iff_nonpos.mp (height_le_iff.mp h _ inferInstance (by simpa using hβ))
refine ENat.not_lt_zero (e β¨pβ, le_refl pββ©).1.height (height_le_iff.mp hph _ inferInstance ?_)
simpa using hβ
theorem exist_mem_one_of_mem_two {pβ pβ pβ : PrimeSpectrum R}
(hβ : pβ < pβ) (hβ : pβ < pβ) {x : R} (hx : x β pβ.asIdeal) :
β q : (PrimeSpectrum R), x β q.asIdeal β§ pβ < q β§ q < pβ := by
let e := IsLocalization.AtPrime.primeSpectrumOrderIso (Localization.AtPrime pβ.1) pβ.1
have hm : closedPoint (Localization.AtPrime pβ.1) =
e.symm β¨pβ, le_refl pββ© := (PrimeSpectrum.ext Localization.AtPrime.map_eq_maximalIdeal).symm
obtain β¨q, hxq, hβ, hββ© :=
@exist_mem_one_of_mem_maximal_ideal (Localization.AtPrime pβ.1) _ _ _
(e.symm β¨pβ, hβ.leβ©) (e.symm β¨pβ, (hβ.trans hβ).leβ©) (e.symm.lt_iff_lt.mpr hβ)
(by simp [hm, hβ]) (algebraMap R (Localization.AtPrime pβ.1) x) <| by
rw [β Localization.AtPrime.map_eq_maximalIdeal]
exact mem_map_of_mem (algebraMap R (Localization.AtPrime pβ.1)) hx
rw [β e.symm_apply_apply q] at hβ hβ hxq
have hq : (e q).1 < pβ := by
have h : e.symm (e q) < e.symm β¨pβ, le_refl pββ© :=
hβ.trans_eq Localization.AtPrime.map_eq_maximalIdeal.symm
rwa [OrderIso.lt_iff_lt, Subtype.mk_lt_mk] at h
exact Exists.intro (e q).1
β¨(pβ.1.under_map_of_isLocalizationAtPrime hq.le).le hxq, e.symm.lt_iff_lt.mp hβ, hqβ©
/-- Let $R$ be a Noetherian ring, $\mathfrak{p}_0 < \dots < \mathfrak{p}_n$ be a
chain of primes, $x \in \mathfrak{p}_n$. Then we can find another chain of primes
$\mathfrak{q}_0 < \dots < \mathfrak{q}_n$ such that $x \in \mathfrak{q}_1$,
$\mathfrak{p}_0 = \mathfrak{q}_0$ and $\mathfrak{p}_n = \mathfrak{q}_n$. -/
theorem exist_ltSeries_mem_one_of_mem_last (p : LTSeries (PrimeSpectrum R))
{x : R} (hx : x β p.last.asIdeal) : β q : LTSeries (PrimeSpectrum R),
x β (q 1).asIdeal β§ p.length = q.length β§ p.head = q.head β§ p.last = q.last := by
generalize hp : p.length = n
induction' n with n hn generalizing p
Β· use RelSeries.singleton _ p.last
simp only [RelSeries.singleton_toFun, hx, RelSeries.singleton_length, RelSeries.head,
RelSeries.last_singleton, and_true, true_and]
rw [show 0 = Fin.last p.length from Fin.zero_eq_mk.mpr hp, RelSeries.last]
by_cases h0 : n = 0
Β· use p
have h1 : 1 = Fin.last p.length := by
rw [Fin.last, hp, h0, zero_add]
exact Fin.natCast_eq_mk (Nat.one_lt_succ_succ 0)
simpa [h1, hp] using hx
obtain β¨q, hxq, h2, hqβ© : β q : PrimeSpectrum R, x β q.1 β§ p β¨p.length - 2, _β© < q β§ q < p.last :=
(p β¨p.length - 1, p.length.sub_lt_succ 1β©).exist_mem_one_of_mem_two
(p.strictMono (Nat.pred_lt (by simpa [hp]))) (p.strictMono (Nat.pred_lt (by simp [hp]))) hx
obtain β¨Q, hx, hQ, hh, hlβ© := hn (p.eraseLast.eraseLast.snoc q h2) (by simpa using hxq) <| by
simpa [hp] using Nat.succ_pred_eq_of_ne_zero h0
have h1 : 1 < Q.length + 1 := Nat.lt_of_sub_ne_zero (hQ.symm.trans_ne h0)
have h : 1 = (1 : Fin (Q.length + 1)).castSucc := by simp [Fin.one_eq_mk_of_lt h1]
exact β¨Q.snoc p.last (by simpa [β hl] using hq), by simpa [h], by simpa, by simp [β hh], by simpβ©
end PrimeSpectrum
|
Indicator.lean
|
/-
Copyright (c) 2020 Zhouhang Zhou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Zhouhang Zhou
-/
import Mathlib.Algebra.Notation.Support
import Mathlib.Data.Set.Piecewise
/-!
# Indicator function
This file defines the indicator function of a set. More lemmas can be found in
`Mathlib/Algebra/Group/Indicator.lean`.
## Main declarations
- `Set.indicator (s : Set Ξ±) (f : Ξ± β Ξ²) (a : Ξ±)` is `f a` if `a β s` and is `0` otherwise.
- `Set.mulIndicator (s : Set Ξ±) (f : Ξ± β Ξ²) (a : Ξ±)` is `f a` if `a β s` and is `1` otherwise.
## Implementation note
In mathematics, an indicator function or a characteristic function is a function
used to indicate membership of an element in a set `s`,
having the value `1` for all elements of `s` and the value `0` otherwise.
But since it is usually used to restrict a function to a certain set `s`,
we let the indicator function take the value `f x` for some function `f`, instead of `1`.
If the usual indicator function is needed, just set `f` to be the constant function `fun _ β¦ 1`.
The indicator function is implemented non-computably, to avoid having to pass around `Decidable`
arguments. This is in contrast with the design of `Pi.single` or `Set.piecewise`.
## Tags
indicator, characteristic
-/
assert_not_exists Monoid
open Function
variable {Ξ± Ξ² M N : Type*}
namespace Set
variable [One M] [One N] {s t : Set Ξ±} {f g : Ξ± β M} {a : Ξ±}
/-- `Set.mulIndicator s f a` is `f a` if `a β s`, `1` otherwise. -/
@[to_additive /-- `Set.indicator s f a` is `f a` if `a β s`, `0` otherwise. -/]
noncomputable def mulIndicator (s : Set Ξ±) (f : Ξ± β M) (x : Ξ±) : M :=
haveI := Classical.decPred (Β· β s)
if x β s then f x else 1
@[to_additive (attr := simp)]
lemma piecewise_eq_mulIndicator [DecidablePred (Β· β s)] : s.piecewise f 1 = s.mulIndicator f :=
funext fun _ => @if_congr _ _ _ _ (id _) _ _ _ _ Iff.rfl rfl rfl
@[to_additive]
lemma mulIndicator_apply (s : Set Ξ±) (f : Ξ± β M) (a : Ξ±) [Decidable (a β s)] :
mulIndicator s f a = if a β s then f a else 1 := by
unfold mulIndicator
congr
@[to_additive (attr := simp)]
lemma mulIndicator_of_mem (h : a β s) (f : Ξ± β M) : mulIndicator s f a = f a := if_pos h
@[to_additive (attr := simp)]
lemma mulIndicator_of_notMem (h : a β s) (f : Ξ± β M) : mulIndicator s f a = 1 := if_neg h
@[deprecated (since := "2025-05-23")]
alias indicator_of_not_mem := indicator_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias mulIndicator_of_not_mem := mulIndicator_of_notMem
@[to_additive]
lemma mulIndicator_eq_one_or_self (s : Set Ξ±) (f : Ξ± β M) (a : Ξ±) :
mulIndicator s f a = 1 β¨ mulIndicator s f a = f a := by
by_cases h : a β s
Β· exact Or.inr (mulIndicator_of_mem h f)
Β· exact Or.inl (mulIndicator_of_notMem h f)
@[to_additive (attr := simp)]
lemma mulIndicator_apply_eq_self : s.mulIndicator f a = f a β a β s β f a = 1 :=
letI := Classical.dec (a β s)
ite_eq_left_iff.trans (by rw [@eq_comm _ (f a)])
@[to_additive (attr := simp)]
lemma mulIndicator_eq_self : s.mulIndicator f = f β mulSupport f β s := by
simp only [funext_iff, subset_def, mem_mulSupport, mulIndicator_apply_eq_self, not_imp_comm]
@[to_additive]
lemma mulIndicator_eq_self_of_superset (h1 : s.mulIndicator f = f) (h2 : s β t) :
t.mulIndicator f = f := by
rw [mulIndicator_eq_self] at h1 β’
exact Subset.trans h1 h2
@[to_additive (attr := simp)]
lemma mulIndicator_apply_eq_one : mulIndicator s f a = 1 β a β s β f a = 1 :=
letI := Classical.dec (a β s)
ite_eq_right_iff
@[to_additive (attr := simp)]
lemma mulIndicator_eq_one : (mulIndicator s f = fun _ => 1) β Disjoint (mulSupport f) s := by
simp only [funext_iff, mulIndicator_apply_eq_one, Set.disjoint_left, mem_mulSupport,
not_imp_not]
@[to_additive (attr := simp)]
lemma mulIndicator_eq_one' : mulIndicator s f = 1 β Disjoint (mulSupport f) s :=
mulIndicator_eq_one
@[to_additive]
lemma mulIndicator_apply_ne_one {a : Ξ±} : s.mulIndicator f a β 1 β a β s β© mulSupport f := by
simp only [Ne, mulIndicator_apply_eq_one, Classical.not_imp, mem_inter_iff, mem_mulSupport]
@[to_additive (attr := simp)]
lemma mulSupport_mulIndicator :
Function.mulSupport (s.mulIndicator f) = s β© Function.mulSupport f :=
ext fun x => by simp [Function.mem_mulSupport, mulIndicator_apply_eq_one]
/-- If a multiplicative indicator function is not equal to `1` at a point, then that point is in the
set. -/
@[to_additive
/-- If an additive indicator function is not equal to `0` at a point, then that point is in the set.
-/]
lemma mem_of_mulIndicator_ne_one (h : mulIndicator s f a β 1) : a β s :=
not_imp_comm.1 (fun hn => mulIndicator_of_notMem hn f) h
/-- See `Set.eqOn_mulIndicator'` for the version with `sαΆ`. -/
@[to_additive /-- See `Set.eqOn_indicator'` for the version with `sαΆ`. -/]
lemma eqOn_mulIndicator : EqOn (mulIndicator s f) f s := fun _ hx => mulIndicator_of_mem hx f
/-- See `Set.eqOn_mulIndicator` for the version with `s`. -/
@[to_additive /-- See `Set.eqOn_indicator` for the version with `s`. -/]
lemma eqOn_mulIndicator' : EqOn (mulIndicator s f) 1 sαΆ :=
fun _ hx => mulIndicator_of_notMem hx f
@[to_additive]
lemma mulSupport_mulIndicator_subset : mulSupport (s.mulIndicator f) β s := fun _ hx =>
hx.imp_symm fun h => mulIndicator_of_notMem h f
@[to_additive (attr := simp)]
lemma mulIndicator_mulSupport : mulIndicator (mulSupport f) f = f :=
mulIndicator_eq_self.2 Subset.rfl
@[to_additive (attr := simp)]
lemma mulIndicator_range_comp {ΞΉ : Sort*} (f : ΞΉ β Ξ±) (g : Ξ± β M) :
mulIndicator (range f) g β f = g β f :=
letI := Classical.decPred (Β· β range f)
piecewise_range_comp _ _ _
@[to_additive]
lemma mulIndicator_congr (h : EqOn f g s) : mulIndicator s f = mulIndicator s g :=
funext fun x => by
simp only [mulIndicator]
split_ifs with h_1
Β· exact h h_1
rfl
@[to_additive]
lemma mulIndicator_eq_mulIndicator {t : Set Ξ²} {g : Ξ² β M} {b : Ξ²}
(h1 : a β s β b β t) (h2 : f a = g b) :
s.mulIndicator f a = t.mulIndicator g b := by
by_cases a β s <;> simp_all
@[to_additive]
lemma mulIndicator_const_eq_mulIndicator_const {t : Set Ξ²} {b : Ξ²} {c : M} (h : a β s β b β t) :
s.mulIndicator (fun _ β¦ c) a = t.mulIndicator (fun _ β¦ c) b :=
mulIndicator_eq_mulIndicator h rfl
@[to_additive (attr := simp)]
lemma mulIndicator_univ (f : Ξ± β M) : mulIndicator (univ : Set Ξ±) f = f :=
mulIndicator_eq_self.2 <| subset_univ _
@[to_additive (attr := simp)]
lemma mulIndicator_empty (f : Ξ± β M) : mulIndicator (β
: Set Ξ±) f = fun _ => 1 :=
mulIndicator_eq_one.2 <| disjoint_empty _
@[to_additive]
lemma mulIndicator_empty' (f : Ξ± β M) : mulIndicator (β
: Set Ξ±) f = 1 :=
mulIndicator_empty f
variable (M)
@[to_additive (attr := simp)]
lemma mulIndicator_one (s : Set Ξ±) : (mulIndicator s fun _ => (1 : M)) = fun _ => (1 : M) :=
mulIndicator_eq_one.2 <| by simp only [mulSupport_fun_one, empty_disjoint]
@[to_additive (attr := simp)]
lemma mulIndicator_one' {s : Set Ξ±} : s.mulIndicator (1 : Ξ± β M) = 1 :=
mulIndicator_one M s
variable {M}
@[to_additive]
lemma mulIndicator_mulIndicator (s t : Set Ξ±) (f : Ξ± β M) :
mulIndicator s (mulIndicator t f) = mulIndicator (s β© t) f :=
funext fun x => by
simp only [mulIndicator]
split_ifs <;> simp_all +contextual
@[to_additive (attr := simp)]
lemma mulIndicator_inter_mulSupport (s : Set Ξ±) (f : Ξ± β M) :
mulIndicator (s β© mulSupport f) f = mulIndicator s f := by
rw [β mulIndicator_mulIndicator, mulIndicator_mulSupport]
@[to_additive]
lemma comp_mulIndicator (h : M β Ξ²) (f : Ξ± β M) {s : Set Ξ±} {x : Ξ±} [DecidablePred (Β· β s)] :
h (s.mulIndicator f x) = s.piecewise (h β f) (const Ξ± (h 1)) x := by
letI := Classical.decPred (Β· β s)
convert s.apply_piecewise f (const Ξ± 1) (fun _ => h) (x := x) using 2
@[to_additive]
lemma mulIndicator_comp_right {s : Set Ξ±} (f : Ξ² β Ξ±) {g : Ξ± β M} {x : Ξ²} :
mulIndicator (f β»ΒΉ' s) (g β f) x = mulIndicator s g (f x) := by
tauto
@[to_additive]
lemma mulIndicator_image {s : Set Ξ±} {f : Ξ² β M} {g : Ξ± β Ξ²} (hg : Injective g) {x : Ξ±} :
mulIndicator (g '' s) f (g x) = mulIndicator s (f β g) x := by
rw [β mulIndicator_comp_right, preimage_image_eq _ hg]
@[to_additive]
lemma mulIndicator_comp_of_one {g : M β N} (hg : g 1 = 1) :
mulIndicator s (g β f) = g β mulIndicator s f := by
funext
simp only [mulIndicator]
split_ifs <;> simp [*]
@[to_additive]
lemma comp_mulIndicator_const (c : M) (f : M β N) (hf : f 1 = 1) :
(fun x => f (s.mulIndicator (fun _ => c) x)) = s.mulIndicator fun _ => f c :=
(mulIndicator_comp_of_one hf).symm
@[to_additive]
lemma mulIndicator_preimage (s : Set Ξ±) (f : Ξ± β M) (B : Set M) :
mulIndicator s f β»ΒΉ' B = s.ite (f β»ΒΉ' B) (1 β»ΒΉ' B) :=
letI := Classical.decPred (Β· β s)
piecewise_preimage s f 1 B
@[to_additive]
lemma mulIndicator_one_preimage (s : Set M) :
t.mulIndicator 1 β»ΒΉ' s β ({Set.univ, β
} : Set (Set Ξ±)) := by
classical
rw [mulIndicator_one', Pi.one_def, Set.preimage_const]
split_ifs <;> simp
@[to_additive]
lemma mulIndicator_const_preimage_eq_union (U : Set Ξ±) (s : Set M) (a : M) [Decidable (a β s)]
[Decidable ((1 : M) β s)] : (U.mulIndicator fun _ => a) β»ΒΉ' s =
(if a β s then U else β
) βͺ if (1 : M) β s then UαΆ else β
:= by
rw [mulIndicator_preimage, Pi.one_def, Set.preimage_const, preimage_const]
split_ifs <;> simp [β compl_eq_univ_diff]
@[to_additive]
lemma mulIndicator_const_preimage (U : Set Ξ±) (s : Set M) (a : M) :
(U.mulIndicator fun _ => a) β»ΒΉ' s β ({Set.univ, U, UαΆ, β
} : Set (Set Ξ±)) := by
classical
rw [mulIndicator_const_preimage_eq_union]
split_ifs <;> simp
@[to_additive]
lemma mulIndicator_preimage_of_notMem (s : Set Ξ±) (f : Ξ± β M) {t : Set M} (ht : (1 : M) β t) :
mulIndicator s f β»ΒΉ' t = f β»ΒΉ' t β© s := by
simp [mulIndicator_preimage, Pi.one_def, Set.preimage_const_of_notMem ht]
@[deprecated (since := "2025-05-23")]
alias indicator_preimage_of_not_mem := indicator_preimage_of_notMem
@[to_additive existing, deprecated (since := "2025-05-23")]
alias mulIndicator_preimage_of_not_mem := mulIndicator_preimage_of_notMem
@[to_additive]
lemma mem_range_mulIndicator {r : M} {s : Set Ξ±} {f : Ξ± β M} :
r β range (mulIndicator s f) β r = 1 β§ s β univ β¨ r β f '' s := by
simp [mulIndicator, ite_eq_iff, exists_or, eq_univ_iff_forall, and_comm, or_comm,
@eq_comm _ r 1]
@[to_additive]
lemma mulIndicator_rel_mulIndicator {r : M β M β Prop} (h1 : r 1 1) (ha : a β s β r (f a) (g a)) :
r (mulIndicator s f a) (mulIndicator s g a) := by
simp only [mulIndicator]
split_ifs with has
exacts [ha has, h1]
lemma indicator_one_preimage [Zero M] (U : Set Ξ±) (s : Set M) :
U.indicator 1 β»ΒΉ' s β ({Set.univ, U, UαΆ, β
} : Set (Set Ξ±)) :=
indicator_const_preimage _ _ 1
end Set
|
AddTorsorBases.lean
|
/-
Copyright (c) 2021 Oliver Nash. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Oliver Nash
-/
import Mathlib.Analysis.Normed.Module.FiniteDimension
import Mathlib.LinearAlgebra.AffineSpace.FiniteDimensional
/-!
# Bases in normed affine spaces.
This file contains results about bases in normed affine spaces.
## Main definitions:
* `continuous_barycentric_coord`
* `isOpenMap_barycentric_coord`
* `AffineBasis.interior_convexHull`
* `IsOpen.exists_subset_affineIndependent_span_eq_top`
* `interior_convexHull_nonempty_iff_affineSpan_eq_top`
-/
assert_not_exists HasFDerivAt
section Barycentric
variable {ΞΉ π E P : Type*} [NontriviallyNormedField π] [CompleteSpace π]
variable [NormedAddCommGroup E] [NormedSpace π E]
variable [MetricSpace P] [NormedAddTorsor E P]
theorem isOpenMap_barycentric_coord [Nontrivial ΞΉ] (b : AffineBasis ΞΉ π P) (i : ΞΉ) :
IsOpenMap (b.coord i) :=
AffineMap.isOpenMap_linear_iff.mp <|
(b.coord i).linear.isOpenMap_of_finiteDimensional <|
(b.coord i).linear_surjective_iff.mpr (b.surjective_coord i)
variable [FiniteDimensional π E] (b : AffineBasis ΞΉ π P)
@[continuity]
theorem continuous_barycentric_coord (i : ΞΉ) : Continuous (b.coord i) :=
(b.coord i).continuous_of_finiteDimensional
end Barycentric
open Set
/-- Given a finite-dimensional normed real vector space, the interior of the convex hull of an
affine basis is the set of points whose barycentric coordinates are strictly positive with respect
to this basis.
TODO Restate this result for affine spaces (instead of vector spaces) once the definition of
convexity is generalised to this setting. -/
theorem AffineBasis.interior_convexHull {ΞΉ E : Type*} [Finite ΞΉ] [NormedAddCommGroup E]
[NormedSpace β E] (b : AffineBasis ΞΉ β E) :
interior (convexHull β (range b)) = {x | β i, 0 < b.coord i x} := by
cases subsingleton_or_nontrivial ΞΉ
Β· -- The zero-dimensional case.
have : range b = univ :=
AffineSubspace.eq_univ_of_subsingleton_span_eq_top (subsingleton_range _) b.tot
simp [this]
Β· -- The positive-dimensional case.
haveI : FiniteDimensional β E := b.finiteDimensional
have : convexHull β (range b) = β i, b.coord i β»ΒΉ' Ici 0 := by
rw [b.convexHull_eq_nonneg_coord, setOf_forall]; rfl
ext
simp only [this, interior_iInter_of_finite, β
IsOpenMap.preimage_interior_eq_interior_preimage (isOpenMap_barycentric_coord b _)
(continuous_barycentric_coord b _),
interior_Ici, mem_iInter, mem_setOf_eq, mem_Ioi, mem_preimage]
variable {V P : Type*} [NormedAddCommGroup V] [NormedSpace β V] [MetricSpace P]
[NormedAddTorsor V P]
open AffineMap
/-- Given a set `s` of affine-independent points belonging to an open set `u`, we may extend `s` to
an affine basis, all of whose elements belong to `u`. -/
theorem IsOpen.exists_between_affineIndependent_span_eq_top {s u : Set P} (hu : IsOpen u)
(hsu : s β u) (hne : s.Nonempty) (h : AffineIndependent β ((β) : s β P)) :
β t : Set P, s β t β§ t β u β§ AffineIndependent β ((β) : t β P) β§ affineSpan β t = β€ := by
obtain β¨q, hqβ© := hne
obtain β¨Ξ΅, Ξ΅0, hΞ΅uβ© := Metric.nhds_basis_closedBall.mem_iff.1 (hu.mem_nhds <| hsu hq)
obtain β¨t, htβ, htβ, htββ© := exists_subset_affineIndependent_affineSpan_eq_top h
let f : P β P := fun y => lineMap q y (Ξ΅ / dist y q)
have hf : β y, f y β u := by
refine fun y => hΞ΅u ?_
simp only [f]
rw [Metric.mem_closedBall, lineMap_apply, dist_vadd_left, norm_smul, Real.norm_eq_abs,
dist_eq_norm_vsub V y q, abs_div, abs_of_pos Ξ΅0, abs_of_nonneg (norm_nonneg _), div_mul_comm]
exact mul_le_of_le_one_left Ξ΅0.le (div_self_le_one _)
have hΞ΅yq : β y β s, Ξ΅ / dist y q β 0 := fun y hy =>
div_ne_zero Ξ΅0.ne' (dist_ne_zero.2 (ne_of_mem_of_not_mem hq hy).symm)
classical
let w : t β βΛ£ := fun p => if hp : (p : P) β s then 1 else Units.mk0 _ (hΞ΅yq (βp) hp)
refine β¨Set.range fun p : t => lineMap q p (w p : β), ?_, ?_, ?_, ?_β©
Β· intro p hp; use β¨p, htβ hpβ©; simp [w, hp]
Β· rintro y β¨β¨p, hpβ©, rflβ©
by_cases hps : p β s <;>
simp only [w, hps, lineMap_apply_one, Units.val_mk0, dif_neg, dif_pos, not_false_iff,
Units.val_one] <;>
[exact hsu hps; exact hf p]
Β· exact (htβ.units_lineMap β¨q, htβ hqβ© w).range
Β· rw [affineSpan_eq_affineSpan_lineMap_units (htβ hq) w, htβ]
theorem IsOpen.exists_subset_affineIndependent_span_eq_top {u : Set P} (hu : IsOpen u)
(hne : u.Nonempty) : β s β u, AffineIndependent β ((β) : s β P) β§ affineSpan β s = β€ := by
rcases hne with β¨x, hxβ©
rcases hu.exists_between_affineIndependent_span_eq_top (singleton_subset_iff.mpr hx)
(singleton_nonempty _) (affineIndependent_of_subsingleton _ _) with β¨s, -, hsu, hsβ©
exact β¨s, hsu, hsβ©
/-- The affine span of a nonempty open set is `β€`. -/
theorem IsOpen.affineSpan_eq_top {u : Set P} (hu : IsOpen u) (hne : u.Nonempty) :
affineSpan β u = β€ :=
let β¨_, hsu, _, hs'β© := hu.exists_subset_affineIndependent_span_eq_top hne
top_unique <| hs' βΈ affineSpan_mono _ hsu
theorem affineSpan_eq_top_of_nonempty_interior {s : Set V}
(hs : (interior <| convexHull β s).Nonempty) : affineSpan β s = β€ :=
top_unique <| isOpen_interior.affineSpan_eq_top hs βΈ
(affineSpan_mono _ interior_subset).trans_eq (affineSpan_convexHull _)
theorem AffineBasis.centroid_mem_interior_convexHull {ΞΉ} [Fintype ΞΉ] (b : AffineBasis ΞΉ β V) :
Finset.univ.centroid β b β interior (convexHull β (range b)) := by
haveI := b.nonempty
simp only [b.interior_convexHull, mem_setOf_eq, b.coord_apply_centroid (Finset.mem_univ _),
inv_pos, Nat.cast_pos, Finset.card_pos, Finset.univ_nonempty, forall_true_iff]
theorem interior_convexHull_nonempty_iff_affineSpan_eq_top [FiniteDimensional β V] {s : Set V} :
(interior (convexHull β s)).Nonempty β affineSpan β s = β€ := by
refine β¨affineSpan_eq_top_of_nonempty_interior, fun h => ?_β©
obtain β¨t, hts, b, hbβ© := AffineBasis.exists_affine_subbasis h
suffices (interior (convexHull β (range b))).Nonempty by
rw [hb, Subtype.range_coe_subtype, setOf_mem_eq] at this
refine this.mono (by gcongr)
lift t to Finset V using b.finite_set
exact β¨_, b.centroid_mem_interior_convexHullβ©
theorem Convex.interior_nonempty_iff_affineSpan_eq_top [FiniteDimensional β V] {s : Set V}
(hs : Convex β s) : (interior s).Nonempty β affineSpan β s = β€ := by
rw [β interior_convexHull_nonempty_iff_affineSpan_eq_top, hs.convexHull_eq]
|
quotient.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 div.
From mathcomp Require Import choice fintype prime finset fingroup morphism.
From mathcomp Require Import automorphism.
(******************************************************************************)
(* This file contains the definitions of: *)
(* coset_of H == the (sub)type of bilateral cosets of H (see below). *)
(* coset H == the canonical projection into coset_of H. *)
(* A / H == the quotient of A by H, that is, the morphic image *)
(* of A by coset H. We do not require H <| A, so in a *)
(* textbook A / H would be written 'N_A(H) * H / H. *)
(* quotm f (nHG : H <| G) == the quotient morphism induced by f, *)
(* mapping G / H onto f @* G / f @* H. *)
(* qisom f (eqHG : H = G) == the identity isomorphism between *)
(* [set: coset_of G] and [set: coset_of H]. *)
(* We also prove the three isomorphism theorems, and counting lemmas for *)
(* morphisms. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Import GroupScope.
Section Cosets.
Variables (gT : finGroupType) (Q A : {set gT}).
(******************************************************************************)
(* Cosets are right cosets of elements in the normaliser. *)
(* We let cosets coerce to GroupSet.sort, so they inherit the group subset *)
(* base group structure. Later we will define a proper group structure on *)
(* cosets, which will then hide the inherited structure once coset_of unifies *)
(* with FinGroup.sort; the coercion to GroupSet.sort will no longer be used. *)
(* Note that for Hx Hy : coset_of H, Hx * Hy : {set gT} can mean either *)
(* set_of_coset (mulg Hx Hy) OR mulg (set_of_coset Hx) (set_of_coset Hy). *)
(* However, since the two terms are actually convertible, we can live with *)
(* this ambiguity. *)
(* We take great care that neither the type coset_of H, nor its Canonical *)
(* finGroupType structure, nor the coset H morphism depend on the actual *)
(* group structure of H. Otherwise, rewriting would be extremely awkward *)
(* because all our equalities are stated at the set level. *)
(* The trick we use is to interpret coset_of A, when A is any set, as the *)
(* type of cosets of the group <<A>> generated by A, in the group A <*> N(A) *)
(* generated by A and its normaliser. This coincides with the type of *)
(* bilateral cosets of A when A is a group. We restrict the domain of coset A *)
(* to 'N(A), so that we get almost all the same conversion equalities as if *)
(* we had forced A to be a group in the first place; the only exception, that *)
(* 1 : coset_of A : {set gT} = <<A>> rather than A, can be handled by genGid. *)
(******************************************************************************)
Notation H := <<A>>.
Definition coset_range := [pred B in rcosets H 'N(A)].
Record coset_of : Type :=
Coset { set_of_coset :> GroupSet.sort gT; _ : coset_range set_of_coset }.
HB.instance Definition _ := [isSub for set_of_coset].
#[hnf] HB.instance Definition _ := [Finite of coset_of by <:].
(* We build a new (canonical) structure of groupType for cosets. *)
(* When A is a group, this is the largest possible quotient 'N(A) / A. *)
Lemma coset_one_proof : coset_range H.
Proof. by apply/rcosetsP; exists (1 : gT); rewrite (group1, mulg1). Qed.
Definition coset_one := Coset coset_one_proof.
Let nNH := subsetP (norm_gen A).
Lemma coset_range_mul (B C : coset_of) : coset_range (B * C).
Proof.
case: B C => _ /= /rcosetsP[x Nx ->] [_ /= /rcosetsP[y Ny ->]].
by apply/rcosetsP; exists (x * y); rewrite !(groupM, rcoset_mul, nNH).
Qed.
Definition coset_mul B C := Coset (coset_range_mul B C).
Lemma coset_range_inv (B : coset_of) : coset_range B^-1.
Proof.
case: B => _ /= /rcosetsP[x Nx ->]; rewrite norm_rlcoset ?nNH // invg_lcoset.
by apply/rcosetsP; exists x^-1; rewrite ?groupV.
Qed.
Definition coset_inv B := Coset (coset_range_inv B).
Lemma coset_mulP : associative coset_mul.
Proof. by move=> B C D; apply: val_inj; rewrite /= mulgA. Qed.
Lemma coset_oneP : left_id coset_one coset_mul.
Proof.
case=> B coB; apply: val_inj => /=; case/rcosetsP: coB => x Hx ->{B}.
by rewrite mulgA mulGid.
Qed.
Lemma coset_invP : left_inverse coset_one coset_inv coset_mul.
Proof.
case=> B coB; apply: val_inj => /=; case/rcosetsP: coB => x Hx ->{B}.
rewrite invg_rcoset -mulgA (mulgA H) mulGid.
by rewrite norm_rlcoset ?nNH // -lcosetM mulVg mul1g.
Qed.
HB.instance Definition _ :=
isMulGroup.Build coset_of coset_mulP coset_oneP coset_invP.
(* Projection of the initial group type over the cosets groupType. *)
Definition coset x : coset_of := insubd (1 : coset_of) (H :* x).
(* This is a primitive lemma -- we'll need to restate it for *)
(* the case where A is a group. *)
Lemma val_coset_prim x : x \in 'N(A) -> coset x :=: H :* x.
Proof.
by move=> Nx; rewrite val_insubd /= mem_rcosets -{1}(mul1g x) mem_mulg.
Qed.
Lemma coset_morphM : {in 'N(A) &, {morph coset : x y / x * y}}.
Proof.
move=> x y Nx Ny; apply: val_inj.
by rewrite /= !val_coset_prim ?groupM //= rcoset_mul ?nNH.
Qed.
Canonical coset_morphism := Morphism coset_morphM.
Lemma ker_coset_prim : 'ker coset = 'N_H(A).
Proof.
apply/setP=> z; rewrite !in_setI andbC 2!inE -val_eqE /=.
case Nz: (z \in 'N(A)); rewrite ?andbF ?val_coset_prim // !andbT.
by apply/eqP/idP=> [<-| Az]; rewrite (rcoset_refl, rcoset_id).
Qed.
Implicit Type xbar : coset_of.
Lemma coset_mem y xbar : y \in xbar -> coset y = xbar.
Proof.
case: xbar => /= Hx NHx Hxy; apply: val_inj=> /=.
case/rcosetsP: NHx (NHx) Hxy => x Nx -> NHx Hxy.
by rewrite val_insubd /= (rcoset_eqP Hxy) NHx.
Qed.
(* coset is an inverse to repr *)
Lemma mem_repr_coset xbar : repr xbar \in xbar.
Proof. by case: xbar => /= _ /rcosetsP[x _ ->]; apply: mem_repr_rcoset. Qed.
Lemma repr_coset1 : repr (1 : coset_of) = 1.
Proof. exact: repr_group. Qed.
Lemma coset_reprK : cancel (fun xbar => repr xbar) coset.
Proof. by move=> xbar; apply: coset_mem (mem_repr_coset xbar). Qed.
(* cosetP is slightly stronger than using repr because we only *)
(* guarantee repr xbar \in 'N(A) when A is a group. *)
Lemma cosetP xbar : {x | x \in 'N(A) & xbar = coset x}.
Proof.
pose x := repr 'N_xbar(A).
have [xbar_x Nx]: x \in xbar /\ x \in 'N(A).
apply/setIP; rewrite {}/x; case: xbar => /= _ /rcosetsP[y Ny ->].
by apply: (mem_repr y); rewrite inE rcoset_refl.
by exists x; last rewrite (coset_mem xbar_x).
Qed.
Lemma coset_id x : x \in A -> coset x = 1.
Proof. by move=> Ax; apply: coset_mem; apply: mem_gen. Qed.
Lemma im_coset : coset @* 'N(A) = setT.
Proof.
by apply/setP=> xbar; case: (cosetP xbar) => x Nx ->; rewrite inE mem_morphim.
Qed.
Lemma sub_im_coset (C : {set coset_of}) : C \subset coset @* 'N(A).
Proof. by rewrite im_coset subsetT. Qed.
Lemma cosetpre_proper C D :
(coset @*^-1 C \proper coset @*^-1 D) = (C \proper D).
Proof. by rewrite morphpre_proper ?sub_im_coset. Qed.
Definition quotient : {set coset_of} := coset @* Q.
Lemma quotientE : quotient = coset @* Q. Proof. by []. Qed.
End Cosets.
Arguments coset_of {gT} H%_g : rename.
Arguments coset {gT} H%_g x%_g : rename.
Arguments quotient {gT} A%_g H%_g : rename.
Arguments coset_reprK {gT H%_g} xbar%_g : rename.
Bind Scope group_scope with coset_of.
Notation "A / H" := (quotient A H) : group_scope.
Section CosetOfGroupTheory.
Variables (gT : finGroupType) (H : {group gT}).
Implicit Types (A B : {set gT}) (G K : {group gT}) (xbar yb : coset_of H).
Implicit Types (C D : {set coset_of H}) (L M : {group coset_of H}).
Canonical quotient_group G A : {group coset_of A} :=
Eval hnf in [group of G / A].
Infix "/" := quotient_group : Group_scope.
Lemma val_coset x : x \in 'N(H) -> coset H x :=: H :* x.
Proof. by move=> Nx; rewrite val_coset_prim // genGid. Qed.
Lemma coset_default x : (x \in 'N(H)) = false -> coset H x = 1.
Proof.
move=> Nx; apply: val_inj.
by rewrite val_insubd /= mem_rcosets /= genGid mulSGid ?normG ?Nx.
Qed.
Lemma coset_norm xbar : xbar \subset 'N(H).
Proof.
case: xbar => /= _ /rcosetsP[x Nx ->].
by rewrite genGid mul_subG ?sub1set ?normG.
Qed.
Lemma ker_coset : 'ker (coset H) = H.
Proof. by rewrite ker_coset_prim genGid (setIidPl _) ?normG. Qed.
Lemma coset_idr x : x \in 'N(H) -> coset H x = 1 -> x \in H.
Proof. by move=> Nx Hx1; rewrite -ker_coset mem_morphpre //= Hx1 set11. Qed.
Lemma repr_coset_norm xbar : repr xbar \in 'N(H).
Proof. exact: subsetP (coset_norm _) _ (mem_repr_coset _). Qed.
Lemma imset_coset G : coset H @: G = G / H.
Proof.
apply/eqP; rewrite eqEsubset andbC imsetS ?subsetIr //=.
apply/subsetP=> _ /imsetP[x Gx ->].
by case Nx: (x \in 'N(H)); rewrite ?(coset_default Nx) ?mem_morphim ?group1.
Qed.
Lemma val_quotient A : val @: (A / H) = rcosets H 'N_A(H).
Proof.
apply/setP=> B; apply/imsetP/rcosetsP=> [[xbar Axbar]|[x /setIP[Ax Nx]]] ->{B}.
case/morphimP: Axbar => x Nx Ax ->{xbar}.
by exists x; [rewrite inE Ax | rewrite /= val_coset].
by exists (coset H x); [apply/morphimP; exists x | rewrite /= val_coset].
Qed.
Lemma card_quotient_subnorm A : #|A / H| = #|'N_A(H) : H|.
Proof. by rewrite -(card_imset _ val_inj) val_quotient. Qed.
Lemma leq_quotient A : #|A / H| <= #|A|.
Proof. exact: leq_morphim. Qed.
Lemma ltn_quotient A : H :!=: 1 -> H \subset A -> #|A / H| < #|A|.
Proof.
by move=> ntH sHA; rewrite ltn_morphim // ker_coset (setIidPr sHA) proper1G.
Qed.
Lemma card_quotient A : A \subset 'N(H) -> #|A / H| = #|A : H|.
Proof. by move=> nHA; rewrite card_quotient_subnorm (setIidPl nHA). Qed.
Lemma divg_normal G : H <| G -> #|G| %/ #|H| = #|G / H|.
Proof. by case/andP=> sHG nHG; rewrite divgS ?card_quotient. Qed.
(* Specializing all the morphisms lemmas that have different assumptions *)
(* (e.g., because 'ker (coset H) = H), or conclusions (e.g., because we use *)
(* A / H rather than coset H @* A). We may want to reevaluate later, and *)
(* eliminate variants that aren't used . *)
(* Variant of morph1; no specialization for other morph lemmas. *)
Lemma coset1 : coset H 1 :=: H.
Proof. by rewrite morph1 /= genGid. Qed.
(* Variant of kerE. *)
Lemma cosetpre1 : coset H @*^-1 1 = H.
Proof. by rewrite -kerE ker_coset. Qed.
(* Variant of morphimEdom; mophimE[sub] covered by imset_coset. *)
(* morph[im|pre]Iim are also covered by im_quotient. *)
Lemma im_quotient : 'N(H) / H = setT.
Proof. exact: im_coset. Qed.
Lemma quotientT : setT / H = setT.
Proof. by rewrite -im_quotient; apply: morphimT. Qed.
(* Variant of morphimIdom. *)
Lemma quotientInorm A : 'N_A(H) / H = A / H.
Proof. by rewrite /quotient setIC morphimIdom. Qed.
Lemma quotient_setIpre A D : (A :&: coset H @*^-1 D) / H = A / H :&: D.
Proof. exact: morphim_setIpre. Qed.
Lemma mem_quotient x G : x \in G -> coset H x \in G / H.
Proof. by move=> Gx; rewrite -imset_coset imset_f. Qed.
Lemma quotientS A B : A \subset B -> A / H \subset B / H.
Proof. exact: morphimS. Qed.
Lemma quotient0 : set0 / H = set0.
Proof. exact: morphim0. Qed.
Lemma quotient_set1 x : x \in 'N(H) -> [set x] / H = [set coset H x].
Proof. exact: morphim_set1. Qed.
Lemma quotient1 : 1 / H = 1.
Proof. exact: morphim1. Qed.
Lemma quotientV A : A^-1 / H = (A / H)^-1.
Proof. exact: morphimV. Qed.
Lemma quotientMl A B : A \subset 'N(H) -> A * B / H = (A / H) * (B / H).
Proof. exact: morphimMl. Qed.
Lemma quotientMr A B : B \subset 'N(H) -> A * B / H = (A / H) * (B / H).
Proof. exact: morphimMr. Qed.
Lemma cosetpreM C D : coset H @*^-1 (C * D) = coset H @*^-1 C * coset H @*^-1 D.
Proof. by rewrite morphpreMl ?sub_im_coset. Qed.
Lemma quotientJ A x : x \in 'N(H) -> A :^ x / H = (A / H) :^ coset H x.
Proof. exact: morphimJ. Qed.
Lemma quotientU A B : (A :|: B) / H = A / H :|: B / H.
Proof. exact: morphimU. Qed.
Lemma quotientI A B : (A :&: B) / H \subset A / H :&: B / H.
Proof. exact: morphimI. Qed.
Lemma quotientY A B :
A \subset 'N(H) -> B \subset 'N(H) -> (A <*> B) / H = (A / H) <*> (B / H).
Proof. exact: morphimY. Qed.
Lemma quotient_homg A : A \subset 'N(H) -> homg (A / H) A.
Proof. exact: morphim_homg. Qed.
Lemma coset_kerl x y : x \in H -> coset H (x * y) = coset H y.
Proof.
move=> Hx; case Ny: (y \in 'N(H)); first by rewrite mkerl ?ker_coset.
by rewrite !coset_default ?groupMl // (subsetP (normG H)).
Qed.
Lemma coset_kerr x y : y \in H -> coset H (x * y) = coset H x.
Proof.
move=> Hy; case Nx: (x \in 'N(H)); first by rewrite mkerr ?ker_coset.
by rewrite !coset_default ?groupMr // (subsetP (normG H)).
Qed.
Lemma rcoset_kercosetP x y :
x \in 'N(H) -> y \in 'N(H) -> reflect (coset H x = coset H y) (x \in H :* y).
Proof. by rewrite -{6}ker_coset; apply: rcoset_kerP. Qed.
Lemma kercoset_rcoset x y :
x \in 'N(H) -> y \in 'N(H) ->
coset H x = coset H y -> exists2 z, z \in H & x = z * y.
Proof. by move=> Nx Ny eqfxy; rewrite -ker_coset; apply: ker_rcoset. Qed.
Lemma quotientGI G A : H \subset G -> (G :&: A) / H = G / H :&: A / H.
Proof. by rewrite -{1}ker_coset; apply: morphimGI. Qed.
Lemma quotientIG A G : H \subset G -> (A :&: G) / H = A / H :&: G / H.
Proof. by rewrite -{1}ker_coset; apply: morphimIG. Qed.
Lemma quotientD A B : A / H :\: B / H \subset (A :\: B) / H.
Proof. exact: morphimD. Qed.
Lemma quotientD1 A : (A / H)^# \subset A^# / H.
Proof. exact: morphimD1. Qed.
Lemma quotientDG A G : H \subset G -> (A :\: G) / H = A / H :\: G / H.
Proof. by rewrite -{1}ker_coset; apply: morphimDG. Qed.
Lemma quotientK A : A \subset 'N(H) -> coset H @*^-1 (A / H) = H * A.
Proof. by rewrite -{8}ker_coset; apply: morphimK. Qed.
Lemma quotientYK G : G \subset 'N(H) -> coset H @*^-1 (G / H) = H <*> G.
Proof. by move=> nHG; rewrite quotientK ?norm_joinEr. Qed.
Lemma quotientGK G : H <| G -> coset H @*^-1 (G / H) = G.
Proof. by case/andP; rewrite -{1}ker_coset; apply: morphimGK. Qed.
Lemma quotient_class x A :
x \in 'N(H) -> A \subset 'N(H) -> x ^: A / H = coset H x ^: (A / H).
Proof. exact: morphim_class. Qed.
Lemma classes_quotient A :
A \subset 'N(H) -> classes (A / H) = [set xA / H | xA in classes A].
Proof. exact: classes_morphim. Qed.
Lemma cosetpre_set1 x :
x \in 'N(H) -> coset H @*^-1 [set coset H x] = H :* x.
Proof. by rewrite -{9}ker_coset; apply: morphpre_set1. Qed.
Lemma cosetpre_set1_coset xbar : coset H @*^-1 [set xbar] = xbar.
Proof. by case: (cosetP xbar) => x Nx ->; rewrite cosetpre_set1 ?val_coset. Qed.
Lemma cosetpreK C : coset H @*^-1 C / H = C.
Proof. by rewrite /quotient morphpreK ?sub_im_coset. Qed.
(* Variant of morhphim_ker *)
Lemma trivg_quotient : H / H = 1.
Proof. by rewrite -[X in X / _]ker_coset /quotient morphim_ker. Qed.
Lemma quotientS1 G : G \subset H -> G / H = 1.
Proof. by move=> sGH; apply/trivgP; rewrite -trivg_quotient quotientS. Qed.
Lemma sub_cosetpre M : H \subset coset H @*^-1 M.
Proof. by rewrite -{1}ker_coset; apply: ker_sub_pre. Qed.
Lemma quotient_proper G K :
H <| G -> H <| K -> (G / H \proper K / H) = (G \proper K).
Proof. by move=> nHG nHK; rewrite -cosetpre_proper ?quotientGK. Qed.
Lemma normal_cosetpre M : H <| coset H @*^-1 M.
Proof. by rewrite -{1}ker_coset; apply: ker_normal_pre. Qed.
Lemma cosetpreSK C D :
(coset H @*^-1 C \subset coset H @*^-1 D) = (C \subset D).
Proof. by rewrite morphpreSK ?sub_im_coset. Qed.
Lemma sub_quotient_pre A C :
A \subset 'N(H) -> (A / H \subset C) = (A \subset coset H @*^-1 C).
Proof. exact: sub_morphim_pre. Qed.
Lemma sub_cosetpre_quo C G :
H <| G -> (coset H @*^-1 C \subset G) = (C \subset G / H).
Proof. by move=> nHG; rewrite -cosetpreSK quotientGK. Qed.
(* Variant of ker_trivg_morphim. *)
Lemma quotient_sub1 A : A \subset 'N(H) -> (A / H \subset [1]) = (A \subset H).
Proof.
by move=> nHA /=; rewrite -[gval H in RHS]ker_coset ker_trivg_morphim nHA.
Qed.
Lemma quotientSK A B :
A \subset 'N(H) -> (A / H \subset B / H) = (A \subset H * B).
Proof. by move=> nHA; rewrite morphimSK ?ker_coset. Qed.
Lemma quotientSGK A G :
A \subset 'N(H) -> H \subset G -> (A / H \subset G / H) = (A \subset G).
Proof. by rewrite -{2}ker_coset; apply: morphimSGK. Qed.
Lemma quotient_injG :
{in [pred G : {group gT} | H <| G] &, injective (fun G => G / H)}.
Proof. by rewrite /normal -{1}ker_coset; apply: morphim_injG. Qed.
Lemma quotient_inj G1 G2 :
H <| G1 -> H <| G2 -> G1 / H = G2 / H -> G1 :=: G2.
Proof. by rewrite /normal -[in mem H]ker_coset; apply: morphim_inj. Qed.
Lemma quotient_neq1 A : H <| A -> (A / H != 1) = (H \proper A).
Proof.
case/andP=> sHA nHA; rewrite /proper sHA -trivg_quotient eqEsubset andbC.
by rewrite quotientS //= quotientSGK.
Qed.
Lemma quotient_gen A : A \subset 'N(H) -> <<A>> / H = <<A / H>>.
Proof. exact: morphim_gen. Qed.
Lemma cosetpre_gen C :
1 \in C -> coset H @*^-1 <<C>> = <<coset H @*^-1 C>>.
Proof. by move=> C1; rewrite morphpre_gen ?sub_im_coset. Qed.
Lemma quotientR A B :
A \subset 'N(H) -> B \subset 'N(H) -> [~: A, B] / H = [~: A / H, B / H].
Proof. exact: morphimR. Qed.
Lemma quotient_norm A : 'N(A) / H \subset 'N(A / H).
Proof. exact: morphim_norm. Qed.
Lemma quotient_norms A B : A \subset 'N(B) -> A / H \subset 'N(B / H).
Proof. exact: morphim_norms. Qed.
Lemma quotient_subnorm A B : 'N_A(B) / H \subset 'N_(A / H)(B / H).
Proof. exact: morphim_subnorm. Qed.
Lemma quotient_normal A B : A <| B -> A / H <| B / H.
Proof. exact: morphim_normal. Qed.
Lemma quotient_cent1 x : 'C[x] / H \subset 'C[coset H x].
Proof.
case Nx: (x \in 'N(H)); first exact: morphim_cent1.
by rewrite coset_default // cent11T subsetT.
Qed.
Lemma quotient_cent1s A x : A \subset 'C[x] -> A / H \subset 'C[coset H x].
Proof.
by move=> sAC; apply: subset_trans (quotientS sAC) (quotient_cent1 x).
Qed.
Lemma quotient_subcent1 A x : 'C_A[x] / H \subset 'C_(A / H)[coset H x].
Proof. exact: subset_trans (quotientI _ _) (setIS _ (quotient_cent1 x)). Qed.
Lemma quotient_cent A : 'C(A) / H \subset 'C(A / H).
Proof. exact: morphim_cent. Qed.
Lemma quotient_cents A B : A \subset 'C(B) -> A / H \subset 'C(B / H).
Proof. exact: morphim_cents. Qed.
Lemma quotient_abelian A : abelian A -> abelian (A / H).
Proof. exact: morphim_abelian. Qed.
Lemma quotient_subcent A B : 'C_A(B) / H \subset 'C_(A / H)(B / H).
Proof. exact: morphim_subcent. Qed.
Lemma norm_quotient_pre A C :
A \subset 'N(H) -> A / H \subset 'N(C) -> A \subset 'N(coset H @*^-1 C).
Proof.
by move/sub_quotient_pre=> -> /subset_trans-> //; apply: morphpre_norm.
Qed.
Lemma cosetpre_normal C D : (coset H @*^-1 C <| coset H @*^-1 D) = (C <| D).
Proof. by rewrite morphpre_normal ?sub_im_coset. Qed.
Lemma quotient_normG G : H <| G -> 'N(G) / H = 'N(G / H).
Proof.
case/andP=> sHG nHG.
by rewrite [_ / _]morphim_normG ?ker_coset // im_coset setTI.
Qed.
Lemma quotient_subnormG A G : H <| G -> 'N_A(G) / H = 'N_(A / H)(G / H).
Proof. by case/andP=> sHG nHG; rewrite -morphim_subnormG ?ker_coset. Qed.
Lemma cosetpre_cent1 x : 'C_('N(H))[x] \subset coset H @*^-1 'C[coset H x].
Proof.
case Nx: (x \in 'N(H)); first by rewrite morphpre_cent1.
by rewrite coset_default // cent11T morphpreT subsetIl.
Qed.
Lemma cosetpre_cent1s C x :
coset H @*^-1 C \subset 'C[x] -> C \subset 'C[coset H x].
Proof.
move=> sC; rewrite -cosetpreSK; apply: subset_trans (cosetpre_cent1 x).
by rewrite subsetI subsetIl.
Qed.
Lemma cosetpre_subcent1 C x :
'C_(coset H @*^-1 C)[x] \subset coset H @*^-1 'C_C[coset H x].
Proof.
by rewrite -morphpreIdom -setIA setICA morphpreI setIS // cosetpre_cent1.
Qed.
Lemma cosetpre_cent A : 'C_('N(H))(A) \subset coset H @*^-1 'C(A / H).
Proof. exact: morphpre_cent. Qed.
Lemma cosetpre_cents A C : coset H @*^-1 C \subset 'C(A) -> C \subset 'C(A / H).
Proof. by apply: morphpre_cents; rewrite ?sub_im_coset. Qed.
Lemma cosetpre_subcent C A :
'C_(coset H @*^-1 C)(A) \subset coset H @*^-1 'C_C(A / H).
Proof. exact: morphpre_subcent. Qed.
Lemma restrm_quotientE G A (nHG : G \subset 'N(H)) :
A \subset G -> restrm nHG (coset H) @* A = A / H.
Proof. exact: restrmEsub. Qed.
Section InverseImage.
Variables (G : {group gT}) (Kbar : {group coset_of H}).
Hypothesis nHG : H <| G.
Variant inv_quotient_spec (P : pred {group gT}) : Prop :=
InvQuotientSpec K of Kbar :=: K / H & H \subset K & P K.
Lemma inv_quotientS :
Kbar \subset G / H -> inv_quotient_spec (fun K => K \subset G).
Proof.
case/andP: nHG => sHG nHG' sKbarG.
have sKdH: Kbar \subset 'N(H) / H by rewrite (subset_trans sKbarG) ?morphimS.
exists (coset H @*^-1 Kbar)%G; first by rewrite cosetpreK.
by rewrite -{1}ker_coset morphpreS ?sub1G.
by rewrite sub_cosetpre_quo.
Qed.
Lemma inv_quotientN : Kbar <| G / H -> inv_quotient_spec (fun K => K <| G).
Proof.
move=> nKbar; case/inv_quotientS: (normal_sub nKbar) => K defKbar sHK sKG.
exists K => //; rewrite defKbar -cosetpre_normal !quotientGK // in nKbar.
exact: normalS nHG.
Qed.
End InverseImage.
Lemma quotientMidr A : A * H / H = A / H.
Proof.
by rewrite [_ /_]morphimMr ?normG //= -!quotientE trivg_quotient mulg1.
Qed.
Lemma quotientMidl A : H * A / H = A / H.
Proof.
by rewrite [_ /_]morphimMl ?normG //= -!quotientE trivg_quotient mul1g.
Qed.
Lemma quotientYidr G : G \subset 'N(H) -> G <*> H / H = G / H.
Proof.
move=> nHG; rewrite -genM_join quotient_gen ?mul_subG ?normG //.
by rewrite quotientMidr genGid.
Qed.
Lemma quotientYidl G : G \subset 'N(H) -> H <*> G / H = G / H.
Proof. by move=> nHG; rewrite joingC quotientYidr. Qed.
Section Injective.
Variables (G : {group gT}).
Hypotheses (nHG : G \subset 'N(H)) (tiHG : H :&: G = 1).
Lemma quotient_isom : isom G (G / H) (restrm nHG (coset H)).
Proof. by apply/isomP; rewrite ker_restrm setIC ker_coset tiHG im_restrm. Qed.
Lemma quotient_isog : isog G (G / H).
Proof. exact: isom_isog quotient_isom. Qed.
End Injective.
End CosetOfGroupTheory.
Notation "A / H" := (quotient_group A H) : Group_scope.
Section Quotient1.
Variables (gT : finGroupType) (A : {set gT}).
Lemma coset1_injm : 'injm (@coset gT 1).
Proof. by rewrite ker_coset /=. Qed.
Lemma quotient1_isom : isom A (A / 1) (coset 1).
Proof. by apply: sub_isom coset1_injm; rewrite ?norms1. Qed.
Lemma quotient1_isog : isog A (A / 1).
Proof. by apply: isom_isog quotient1_isom; apply: norms1. Qed.
End Quotient1.
Section QuotientMorphism.
Variable (gT rT : finGroupType) (G H : {group gT}) (f : {morphism G >-> rT}).
Implicit Types A : {set gT}.
Implicit Types B : {set (coset_of H)}.
Hypotheses (nsHG : H <| G).
Let sHG : H \subset G := normal_sub nsHG.
Let nHG : G \subset 'N(H) := normal_norm nsHG.
Let nfHfG : f @* G \subset 'N(f @* H) := morphim_norms f nHG.
Notation fH := (coset (f @* H) \o f).
Lemma quotm_dom_proof : G \subset 'dom fH.
Proof. by rewrite -sub_morphim_pre. Qed.
Notation fH_G := (restrm quotm_dom_proof fH).
Lemma quotm_ker_proof : 'ker (coset H) \subset 'ker fH_G.
Proof.
by rewrite ker_restrm ker_comp !ker_coset morphpreIdom morphimK ?mulG_subr.
Qed.
Definition quotm := factm quotm_ker_proof nHG.
Canonical quotm_morphism := [morphism G / H of quotm].
Lemma quotmE x : x \in G -> quotm (coset H x) = coset (f @* H) (f x).
Proof. exact: factmE. Qed.
Lemma morphim_quotm A : quotm @* (A / H) = f @* A / f @* H.
Proof. by rewrite morphim_factm [LHS]morphim_restrm morphim_comp morphimIdom. Qed.
Lemma morphpre_quotm Abar : quotm @*^-1 (Abar / f @* H) = f @*^-1 Abar / H.
Proof.
rewrite morphpre_factm morphpre_restrm morphpre_comp /=.
rewrite morphpreIdom -[Abar / _]quotientInorm quotientK ?subsetIr //=.
rewrite morphpreMl ?morphimS // morphimK // [_ * H]normC ?subIset ?nHG //.
rewrite -quotientE -mulgA quotientMidl /= setIC -morphpreIim setIA.
by rewrite (setIidPl nfHfG) morphpreIim -morphpreMl ?sub1G ?mul1g.
Qed.
Lemma ker_quotm : 'ker quotm = 'ker f / H.
Proof. by rewrite -morphpre_quotm /quotient morphim1. Qed.
Lemma injm_quotm : 'injm f -> 'injm quotm.
Proof. by move/trivgP=> /= kf1; rewrite ker_quotm kf1 quotientE morphim1. Qed.
End QuotientMorphism.
Section EqIso.
Variables (gT : finGroupType) (G H : {group gT}).
Hypothesis (eqGH : G :=: H).
Lemma im_qisom_proof : 'N(H) \subset 'N(G). Proof. by rewrite eqGH. Qed.
Lemma qisom_ker_proof : 'ker (coset G) \subset 'ker (coset H).
Proof. by rewrite eqGH. Qed.
Lemma qisom_restr_proof : setT \subset 'N(H) / G.
Proof. by rewrite eqGH im_quotient. Qed.
Definition qisom :=
restrm qisom_restr_proof (factm qisom_ker_proof im_qisom_proof).
Canonical qisom_morphism := Eval hnf in [morphism of qisom].
Lemma qisomE x : qisom (coset G x) = coset H x.
Proof.
case Nx: (x \in 'N(H)); first exact: factmE.
by rewrite !coset_default ?eqGH ?morph1.
Qed.
Lemma val_qisom Gx : val (qisom Gx) = val Gx.
Proof.
by case: (cosetP Gx) => x Nx ->{Gx}; rewrite qisomE /= !val_coset -?eqGH.
Qed.
Lemma morphim_qisom A : qisom @* (A / G) = A / H.
Proof. by rewrite morphim_restrm setTI morphim_factm. Qed.
Lemma morphpre_qisom A : qisom @*^-1 (A / H) = A / G.
Proof.
rewrite morphpre_restrm setTI morphpre_factm eqGH.
by rewrite morphpreK // im_coset subsetT.
Qed.
Lemma injm_qisom : 'injm qisom.
Proof. by rewrite -quotient1 -morphpre_qisom morphpreS ?sub1G. Qed.
Lemma im_qisom : qisom @* setT = setT.
Proof. by rewrite -{2}im_quotient morphim_qisom eqGH im_quotient. Qed.
Lemma qisom_isom : isom setT setT qisom.
Proof. by apply/isomP; rewrite injm_qisom im_qisom. Qed.
Lemma qisom_isog : [set: coset_of G] \isog [set: coset_of H].
Proof. exact: isom_isog qisom_isom. Qed.
Lemma qisom_inj : injective qisom.
Proof. by move=> x y; apply: (injmP injm_qisom); rewrite inE. Qed.
Lemma morphim_qisom_inj : injective (fun Gx => qisom @* Gx).
Proof.
by move=> Gx Gy; apply: injm_morphim_inj; rewrite (injm_qisom, subsetT).
Qed.
End EqIso.
Arguments qisom_inj {gT G H} eqGH [x1 x2].
Arguments morphim_qisom_inj {gT G H} eqGH [x1 x2].
Section FirstIsomorphism.
Variables aT rT : finGroupType.
Lemma first_isom (G : {group aT}) (f : {morphism G >-> rT}) :
{g : {morphism G / 'ker f >-> rT} | 'injm g &
forall A : {set aT}, g @* (A / 'ker f) = f @* A}.
Proof.
have nkG := ker_norm f.
have skk: 'ker (coset ('ker f)) \subset 'ker f by rewrite ker_coset.
exists (factm_morphism skk nkG) => /=; last exact: morphim_factm.
by rewrite ker_factm -quotientE trivg_quotient.
Qed.
Variables (G H : {group aT}) (f : {morphism G >-> rT}).
Hypothesis sHG : H \subset G.
Lemma first_isog : (G / 'ker f) \isog (f @* G).
Proof.
by case: (first_isom f) => g injg im_g; apply/isogP; exists g; rewrite ?im_g.
Qed.
Lemma first_isom_loc : {g : {morphism H / 'ker_H f >-> rT} |
'injm g & forall A : {set aT}, A \subset H -> g @* (A / 'ker_H f) = f @* A}.
Proof.
case: (first_isom (restrm_morphism sHG f)).
rewrite ker_restrm => g injg im_g; exists g => // A sAH.
by rewrite im_g morphim_restrm (setIidPr sAH).
Qed.
Lemma first_isog_loc : (H / 'ker_H f) \isog (f @* H).
Proof.
by case: first_isom_loc => g injg im_g; apply/isogP; exists g; rewrite ?im_g.
Qed.
End FirstIsomorphism.
Section SecondIsomorphism.
Variables (gT : finGroupType) (H K : {group gT}).
Hypothesis nKH : H \subset 'N(K).
Lemma second_isom : {f : {morphism H / (K :&: H) >-> coset_of K} |
'injm f & forall A : {set gT}, A \subset H -> f @* (A / (K :&: H)) = A / K}.
Proof.
have ->: K :&: H = 'ker_H (coset K) by rewrite ker_coset setIC.
exact: first_isom_loc.
Qed.
Lemma second_isog : H / (K :&: H) \isog H / K.
Proof. by rewrite setIC -{1 3}(ker_coset K); apply: first_isog_loc. Qed.
Lemma weak_second_isog : H / (K :&: H) \isog H * K / K.
Proof. by rewrite quotientMidr; apply: second_isog. Qed.
End SecondIsomorphism.
Section ThirdIsomorphism.
Variables (gT : finGroupType) (G H K : {group gT}).
Lemma homg_quotientS (A : {set gT}) :
A \subset 'N(H) -> A \subset 'N(K) -> H \subset K -> A / K \homg A / H.
Proof.
rewrite -!(gen_subG A) /=; set L := <<A>> => nHL nKL sKH.
have sub_ker: 'ker (restrm nHL (coset H)) \subset 'ker (restrm nKL (coset K)).
by rewrite !ker_restrm !ker_coset setIS.
have sAL: A \subset L := subset_gen A; rewrite -(setIidPr sAL).
rewrite -[_ / H](morphim_restrm nHL) -[_ / K](morphim_restrm nKL) /=.
by rewrite -(morphim_factm sub_ker (subxx L)) morphim_homg ?morphimS.
Qed.
Hypothesis sHK : H \subset K.
Hypothesis snHG : H <| G.
Hypothesis snKG : K <| G.
Theorem third_isom : {f : {morphism (G / H) / (K / H) >-> coset_of K} | 'injm f
& forall A : {set gT}, A \subset G -> f @* (A / H / (K / H)) = A / K}.
Proof.
have [[sKG nKG] [sHG nHG]] := (andP snKG, andP snHG).
have sHker: 'ker (coset H) \subset 'ker (restrm nKG (coset K)).
by rewrite ker_restrm !ker_coset subsetI sHG.
have:= first_isom_loc (factm_morphism sHker nHG) (subxx _) => /=.
rewrite ker_factm_loc ker_restrm ker_coset !(setIidPr sKG) /= -!quotientE.
case=> f injf im_f; exists f => // A sAG; rewrite im_f ?morphimS //.
by rewrite morphim_factm morphim_restrm (setIidPr sAG).
Qed.
Theorem third_isog : (G / H / (K / H)) \isog (G / K).
Proof.
by case: third_isom => f inj_f im_f; apply/isogP; exists f; rewrite ?im_f.
Qed.
End ThirdIsomorphism.
Lemma char_from_quotient (gT : finGroupType) (G H K : {group gT}) :
H <| K -> H \char G -> K / H \char G / H -> K \char G.
Proof.
case/andP=> sHK nHK chHG.
have nsHG := char_normal chHG; have [sHG nHG] := andP nsHG.
case/charP; rewrite quotientSGK // => sKG /= chKG.
apply/charP; split=> // f injf Gf; apply/morphim_fixP => //.
rewrite -(quotientSGK _ sHK); last by rewrite -morphimIim Gf subIset ?nHG.
have{chHG} Hf: f @* H = H by case/charP: chHG => _; apply.
set q := quotm_morphism f nsHG; have{injf}: 'injm q by apply: injm_quotm.
have: q @* _ = _ := morphim_quotm _ _ _; move: q; rewrite Hf => q im_q injq.
by rewrite -im_q chKG // im_q Gf.
Qed.
(* Counting lemmas for morphisms. *)
Section CardMorphism.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Implicit Types G H : {group aT}.
Implicit Types L M : {group rT}.
Lemma card_morphim G : #|f @* G| = #|D :&: G : 'ker f|.
Proof.
rewrite -morphimIdom -indexgI -card_quotient; last first.
by rewrite normsI ?normG ?subIset ?ker_norm.
by apply: esym (card_isog _); rewrite first_isog_loc ?subsetIl.
Qed.
Lemma dvdn_morphim G : #|f @* G| %| #|G|.
Proof.
rewrite card_morphim (dvdn_trans (dvdn_indexg _ _)) //.
by rewrite cardSg ?subsetIr.
Qed.
Lemma logn_morphim p G : logn p #|f @* G| <= logn p #|G|.
Proof. by rewrite dvdn_leq_log ?dvdn_morphim. Qed.
Lemma coprime_morphl G p : coprime #|G| p -> coprime #|f @* G| p.
Proof. exact: coprime_dvdl (dvdn_morphim G). Qed.
Lemma coprime_morphr G p : coprime p #|G| -> coprime p #|f @* G|.
Proof. exact: coprime_dvdr (dvdn_morphim G). Qed.
Lemma coprime_morph G H : coprime #|G| #|H| -> coprime #|f @* G| #|f @* H|.
Proof. by move=> coGH; rewrite coprime_morphl // coprime_morphr. Qed.
Lemma index_morphim_ker G H :
H \subset G -> G \subset D ->
(#|f @* G : f @* H| * #|'ker_G f : H|)%N = #|G : H|.
Proof.
move=> sHG sGD; apply/eqP.
rewrite -(eqn_pmul2l (cardG_gt0 (f @* H))) mulnA Lagrange ?morphimS //.
rewrite !card_morphim (setIidPr sGD) (setIidPr (subset_trans sHG sGD)).
rewrite -(eqn_pmul2l (cardG_gt0 ('ker_H f))) /=.
by rewrite -{1}(setIidPr sHG) setIAC mulnCA mulnC mulnA !LagrangeI Lagrange.
Qed.
Lemma index_morphim G H : G :&: H \subset D -> #|f @* G : f @* H| %| #|G : H|.
Proof.
move=> dGH; rewrite -(indexgI G) -(setIidPr dGH) setIA.
apply: dvdn_trans (indexSg (subsetIl _ H) (subsetIr D G)).
rewrite -index_morphim_ker ?subsetIl ?subsetIr ?dvdn_mulr //= morphimIdom.
by rewrite indexgS ?morphimS ?subsetIr.
Qed.
Lemma index_injm G H : 'injm f -> G \subset D -> #|f @* G : f @* H| = #|G : H|.
Proof.
move=> injf dG; rewrite -{2}(setIidPr dG) -(indexgI _ H) /=.
rewrite -index_morphim_ker ?subsetIl ?subsetIr //= setIAC morphimIdom setIC.
rewrite injmI ?subsetIr // indexgI /= morphimIdom setIC ker_injm //.
by rewrite -(indexgI (1 :&: _)) /= -setIA !(setIidPl (sub1G _)) indexgg muln1.
Qed.
Lemma card_morphpre L : L \subset f @* D -> #|f @*^-1 L| = (#|'ker f| * #|L|)%N.
Proof.
move/morphpreK=> {2} <-; rewrite card_morphim morphpreIdom.
by rewrite Lagrange // morphpreS ?sub1G.
Qed.
Lemma index_morphpre L M :
L \subset f @* D -> #|f @*^-1 L : f @*^-1 M| = #|L : M|.
Proof.
move=> dL; rewrite -!divgI -morphpreI /= card_morphpre //.
have: L :&: M \subset f @* D by rewrite subIset ?dL.
by move/card_morphpre->; rewrite divnMl ?cardG_gt0.
Qed.
End CardMorphism.
Lemma card_homg (aT rT : finGroupType) (G : {group aT}) (R : {group rT}) :
G \homg R -> #|G| %| #|R|.
Proof. by case/homgP=> f <-; rewrite card_morphim setIid dvdn_indexg. Qed.
Section CardCosetpre.
Variables (gT : finGroupType) (G H K : {group gT}) (L M : {group coset_of H}).
Lemma dvdn_quotient : #|G / H| %| #|G|.
Proof. exact: dvdn_morphim. Qed.
Lemma index_quotient_ker :
K \subset G -> G \subset 'N(H) ->
(#|G / H : K / H| * #|G :&: H : K|)%N = #|G : K|.
Proof. by rewrite -{5}(ker_coset H); apply: index_morphim_ker. Qed.
Lemma index_quotient : G :&: K \subset 'N(H) -> #|G / H : K / H| %| #|G : K|.
Proof. exact: index_morphim. Qed.
Lemma index_quotient_eq :
G :&: H \subset K -> K \subset G -> G \subset 'N(H) ->
#|G / H : K / H| = #|G : K|.
Proof.
move=> sGH_K sKG sGN; rewrite -index_quotient_ker {sKG sGN}//.
by rewrite -(indexgI _ K) (setIidPl sGH_K) indexgg muln1.
Qed.
Lemma card_cosetpre : #|coset H @*^-1 L| = (#|H| * #|L|)%N.
Proof. by rewrite card_morphpre ?ker_coset ?sub_im_coset. Qed.
Lemma index_cosetpre : #|coset H @*^-1 L : coset H @*^-1 M| = #|L : M|.
Proof. by rewrite index_morphpre ?sub_im_coset. Qed.
End CardCosetpre.
|
LinearLowerBound.lean
|
/-
Copyright (c) 2024 YaΓ«l Dillies, Patrick Luo, Eric Rodriguez. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Patrick Luo, Eric Rodriguez
-/
import Mathlib.Algebra.Group.Action.Pointwise.Finset
import Mathlib.Algebra.Group.Subgroup.Pointwise
import Mathlib.Data.Nat.SuccPred
/-!
# Linear lower bound on the growth of a generating set
This file proves that the growth of a set generating an infinite group is at least linear.
-/
open Subgroup
open scoped Pointwise
namespace Finset
variable {G : Type*} [Group G] [DecidableEq G] {X : Finset G} {n : β}
@[to_additive]
lemma pow_ssubset_pow_succ_of_pow_ne_closure (hXβ : (1 : G) β X) (hX : X.Nontrivial)
(hXclosure : (X ^ n : Set G) β closure (X : Set G)) : X ^ n β X ^ (n + 1) := by
obtain rfl | hn := eq_or_ne n 0
Β· simpa [ssubset_iff_subset_not_subset, hXβ, -Finset.subset_singleton_iff]
using hX.not_subset_singleton
refine (pow_subset_pow_right hXβ <| n.le_add_right _).ssubset_of_ne ?_
contrapose! hXclosure with hXn
rw [β closure_pow (mod_cast hXβ) hn]
wlog hnβ : n = 1
Β· simp +contextual only [pow_one] at this
replace hXn d : X ^ (n + d) = X ^ n := by
induction d with
| zero => rw [add_zero]
| succ d hd =>
rw [pow_add, pow_one] at hXn
rw [β add_assoc, pow_add, pow_one, hd, β hXn]
exact mod_cast this (one_mem_pow hXβ) (hX.pow hn) one_ne_zero
(by simp [hXn, β pow_mul, mul_two]) (by simp)
subst hnβ
simp only [ne_eq, one_ne_zero, not_false_eq_true, Nat.reduceAdd, pow_one] at *
let Xgp : Subgroup G :=
{ carrier := X
mul_mem' := fun {x y} hx hy β¦ by
norm_cast at *
simpa [β hXn, β sq] using mul_mem_mul hx hy
one_mem' := hXβ
inv_mem' := fun {x} hx β¦ by
norm_cast at *
have : x β’ X β X := by
simpa [β hXn, add_assoc, β sq] using smul_finset_subset_mul (t := X) hx
have : x β’ X = X := eq_of_subset_of_card_le this (card_smul_finset ..).ge
rw [β eq_inv_smul_iff] at this
rw [this]
simpa [mem_inv_smul_finset_iff] }
exact subset_closure.antisymm <| (closure_le Xgp).2 subset_rfl
@[to_additive]
lemma pow_right_strictMonoOn (hXβ : 1 β X) (hX : X.Nontrivial) :
StrictMonoOn (fun n β¦ X ^ n) {n | (X ^ (n - 1) : Set G) β closure (X : Set G)} := by
refine strictMonoOn_of_lt_add_one β¨?_β© fun n _ _ hn β¦
pow_ssubset_pow_succ_of_pow_ne_closure hXβ hX hn
rintro - - n hn m β¨-, hmnβ© hm
apply hn
obtain rfl | hmβ := m.eq_zero_or_pos
Β· simp [eq_comm (a := (1 : Set _)), coe_set_eq_one, -Set.subset_singleton_iff,
hX.coe.not_subset_singleton] at hm
Β· calc (X : Set G) ^ (n - 1)
_ = X ^ (n - m) * X ^ (m - 1) := by rw [β pow_add]; congr 1; omega
_ = closure (X : Set G) := by rw [hm, Set.pow_mul_subgroupClosure hX.nonempty.to_set]
@[to_additive]
lemma pow_right_strictMono (hXβ : 1 β X) (hXclosure : (closure (X : Set G) : Set G).Infinite) :
StrictMono fun n β¦ X ^ n := by
obtain rfl | hX := eq_singleton_or_nontrivial hXβ
Β· simp [closure_singleton_one] at hXclosure
have h n : (X ^ (n - 1) : Set G) β closure (X : Set G) :=
fun h β¦ by simp [β h, β coe_pow] at hXclosure
simpa [h] using pow_right_strictMonoOn hXβ hX
/-- The growth of a set generating an infinite group is at least linear. -/
@[to_additive /-- The growth of a set generating an infinite group is at least linear. -/]
lemma add_one_le_card_pow (hXβ : 1 β X) (hXclosure : (closure (X : Set G) : Set G).Infinite) :
β n, n + 1 β€ #(X ^ n)
| 0 => by simp
| n + 1 => (add_one_le_card_pow hXβ hXclosure _).trans_lt <| card_lt_card <|
pow_right_strictMono hXβ (by simp [hXclosure]) n.lt_succ_self
end Finset
|
ssrnum.v
|
From mathcomp Require Export orderedzmod.
From mathcomp Require Export numdomain.
From mathcomp Require Export numfield.
Module Num.
Export orderedzmod.Num.
Export numdomain.Num.
Export numfield.Num.
Module Theory.
Export orderedzmod.Num.Theory.
Export numdomain.Num.Theory.
Export numfield.Num.Theory.
End Theory.
Module Def.
Export orderedzmod.Num.Def.
Export numdomain.Num.Def.
Export numfield.Num.Def.
End Def.
Module ExtraDef.
#[deprecated(since="mathcomp 2.5.0", note="Use Num.Def.sqrtr instead.")]
Notation sqrtr := numfield.Num.Def.sqrtr.
End ExtraDef.
End Num.
|
Imo2024Q1.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.Algebra.BigOperators.Intervals
import Mathlib.Algebra.BigOperators.Ring.Finset
import Mathlib.Algebra.Order.BigOperators.Group.LocallyFinite
import Mathlib.Algebra.Order.ToIntervalMod
import Mathlib.Data.Real.Archimedean
import Mathlib.Tactic.Peel
import Mathlib.Tactic.Recall
/-!
# IMO 2024 Q1
Determine all real numbers $\alpha$ such that, for every positive integer $n$, the integer
\[
\lfloor \alpha \rfloor + \lfloor 2\alpha \rfloor + \cdots + \lfloor n\alpha \rfloor
\]
is a multiple of~$n$.
We follow Solution 3 from the
[official solutions](https://www.imo2024.uk/s/IMO-2024-Paper-1-Solutions.pdf).
First reducing modulo 2, any answer that is not a multiple of 2 is inductively shown to be
contained in a decreasing sequence of intervals, with empty intersection.
-/
open Finset
namespace Imo2024Q1
/-- The condition of the problem. -/
def Condition (Ξ± : β) : Prop := (β n : β, 0 < n β (n : β€) β£ β i β Finset.Icc 1 n, βi * Ξ±β)
/-- This is to be determined by the solver of the original problem. -/
def solutionSet : Set β := {Ξ± : β | β m : β€, Ξ± = 2 * m}
lemma condition_two_mul_int (m : β€) : Condition (2 * m) := by
rintro n -
suffices (n : β€) β£ β i β Finset.Icc 0 n, β((i * (2 * m) : β€) : β)β by
rw [β insert_Icc_add_one_left_eq_Icc n.zero_le, sum_insert_zero (by simp)] at this
exact_mod_cast this
simp_rw [Int.floor_intCast, β sum_mul, β Ico_succ_right_eq_Icc, β range_eq_Ico, β mul_assoc]
apply dvd_mul_of_dvd_left
rw [β Nat.cast_sum, β Nat.cast_ofNat (n := 2), β Nat.cast_mul, Finset.sum_range_id_mul_two]
simp
lemma condition_sub_two_mul_int_iff {Ξ± : β} (m : β€) : Condition (Ξ± - 2 * m) β Condition Ξ± := by
peel with n hn
apply dvd_iff_dvd_of_dvd_sub
simp_rw [β Finset.sum_sub_distrib, mul_sub]
norm_cast
simp_rw [Int.floor_sub_intCast, sub_sub_cancel_left]
convert condition_two_mul_int (-m) n hn
norm_cast
rw [Int.floor_intCast]
simp
lemma condition_toIcoMod_iff {Ξ± : β} :
Condition (toIcoMod (by simp : (0 : β) < 2) 0 Ξ±) β Condition Ξ± := by
rw [toIcoMod, zsmul_eq_mul, mul_comm, condition_sub_two_mul_int_iff]
namespace Condition
variable {Ξ± : β} (hc : Condition Ξ±)
include hc
lemma mem_Ico_one_of_mem_Ioo (h : Ξ± β Set.Ioo 0 2) : Ξ± β Set.Ico 1 2 := by
rcases h with β¨h0, h2β©
refine β¨?_, h2β©
by_contra! hn
have hr : 1 < βΞ±β»ΒΉββ := by
rw [Nat.lt_ceil]
exact_mod_cast (one_lt_invβ h0).2 hn
apply hr.ne'
suffices βΞ±β»ΒΉββ = (1 : β€) from mod_cast this
apply Int.eq_one_of_dvd_one (Int.zero_le_ofNat _)
convert hc βΞ±β»ΒΉββ (zero_lt_one.trans hr)
rw [β Finset.add_sum_Ico_eq_sum_Icc hr.le]
convert (add_zero _).symm
Β· rw [Int.floor_eq_iff]
constructor
Β· rw [Int.cast_one]
calc 1 β€ Ξ±β»ΒΉ * Ξ± := by simp [h0.ne']
_ β€ βΞ±β»ΒΉββ * Ξ± := by gcongr; exact Nat.le_ceil Ξ±β»ΒΉ
Β· calc βΞ±β»ΒΉββ * Ξ±
_ < (Ξ±β»ΒΉ + 1) * Ξ± := by gcongr; exact Nat.ceil_lt_add_one (inv_nonneg.2 h0.le)
_ = 1 + Ξ± := by field_simp [h0.ne']
_ β€ (1 : β) + 1 := by gcongr; norm_cast
Β· apply Finset.sum_eq_zero
intro x hx
rw [Int.floor_eq_zero_iff]
refine β¨by positivity, ?_β©
rw [Finset.mem_Ico, Nat.lt_ceil] at hx
calc x * Ξ± < Ξ±β»ΒΉ * Ξ± := by gcongr; exact hx.2
_ = 1 := by simp [h0.ne']
lemma mem_Ico_n_of_mem_Ioo (h : Ξ± β Set.Ioo 0 2) {n : β} (hn : 0 < n) :
Ξ± β Set.Ico ((2 * n - 1) / n : β) 2 := by
suffices β i β Finset.Icc 1 n, βi * Ξ±β = n ^ 2 β§ Ξ± β Set.Ico ((2 * n - 1) / n : β) 2 from this.2
induction n, hn using Nat.le_induction with
| base =>
obtain β¨h1, h2β© := hc.mem_Ico_one_of_mem_Ioo h
simp only [Finset.Icc_self, Finset.sum_singleton, Nat.cast_one, one_mul, one_pow,
Int.floor_eq_iff, Int.cast_one, mul_one, div_one, Set.mem_Ico, tsub_le_iff_right]
exact β¨β¨h1, by linarithβ©, by linarith, h2β©
| succ k kpos hk =>
rcases hk with β¨hks, hkl, hk2β©
have hs : (β i β Finset.Icc 1 (k + 1), βi * Ξ±β) =
β(k + 1 : β) * Ξ±β + ((k : β) : β€) ^ 2 := by
have hn11 : k + 1 β Finset.Icc 1 k := by
rw [Finset.mem_Icc]
omega
rw [β insert_Icc_right_eq_Icc_add_one (Nat.le_add_left 1 k), sum_insert hn11, hks]
specialize hc (k + 1) k.succ_pos
rw [hs] at hc β’
have hkl' : 2 * k β€ β(k + 1 : β) * Ξ±β := by
rw [Int.le_floor]
calc ((2 * k : β€) : β) = ((2 * k : β€) : β) + 0 := (add_zero _).symm
_ β€ ((2 * k : β€) : β) + (k - 1) / k := by gcongr; norm_cast; positivity
_ = (k + 1 : β) * ((2 * (k : β) - 1) / ((k : β) : β)) := by field_simp; ring
_ β€ (k + 1 : β) * Ξ± := by gcongr
have hk2' : β(k + 1 : β) * Ξ±β < (k + 1 : β) * 2 := by
rw [Int.floor_lt]
push_cast
gcongr
have hk' : β(k + 1 : β) * Ξ±β = 2 * k + 1 := by
by_contra
rw [show β(k + 1 : β) * Ξ±β = 2 * k by omega] at hc
have hc' : ((k + 1 : β) : β€) β£ ((k + 1 : β) : β€) * ((k + 1 : β) : β€) - 1 := by
convert hc using 1
push_cast
ring
rw [dvd_sub_right (dvd_mul_right _ _), β isUnit_iff_dvd_one, Int.isUnit_iff] at hc'
omega
rw [hk']
refine β¨?_, ?_, h.2β©
Β· push_cast
ring
Β· rw [Int.floor_eq_iff] at hk'
rw [div_le_iffβ (by norm_cast; omega), mul_comm Ξ±]
convert hk'.1
push_cast
ring
end Condition
lemma not_condition_of_mem_Ioo {Ξ± : β} (h : Ξ± β Set.Ioo 0 2) : Β¬Condition Ξ± := by
intro hc
let n : β := β(2 - Ξ±)β»ΒΉββ + 1
have hn : 0 < n := by omega
have hna := (hc.mem_Ico_n_of_mem_Ioo h hn).1
rcases h with β¨-, h2β©
have hna' : 2 - (n : β)β»ΒΉ β€ Ξ± := by
convert hna using 1
field_simp
rw [sub_eq_add_neg, β le_sub_iff_add_le', neg_le, neg_sub] at hna'
rw [le_inv_commβ (by linarith) (mod_cast hn), β not_lt] at hna'
apply hna'
exact_mod_cast Nat.lt_floor_add_one (_ : β)
lemma condition_iff_of_mem_Ico {Ξ± : β} (h : Ξ± β Set.Ico 0 2) : Condition Ξ± β Ξ± = 0 := by
constructor
Β· intro hc
cases Set.eq_left_or_mem_Ioo_of_mem_Ico h with
| inl h => exact h
| inr ho => exact False.elim (not_condition_of_mem_Ioo ho hc)
Β· rintro rfl
convert condition_two_mul_int 0
norm_num
recall Imo2024Q1.Condition (Ξ± : β) := (β n : β, 0 < n β (n : β€) β£ β i β Finset.Icc 1 n, βi * Ξ±β)
recall Imo2024Q1.solutionSet := {Ξ± : β | β m : β€, Ξ± = 2 * m}
theorem result (Ξ± : β) : Condition Ξ± β Ξ± β solutionSet := by
refine β¨fun h β¦ ?_, ?_β©
Β· rw [β condition_toIcoMod_iff, condition_iff_of_mem_Ico (toIcoMod_mem_Ico' _ _),
β AddCommGroup.modEq_iff_toIcoMod_eq_left, AddCommGroup.ModEq] at h
simp_rw [sub_zero] at h
rcases h with β¨m, rflβ©
rw [zsmul_eq_mul, mul_comm]
simp [solutionSet]
Β· rintro β¨m, rflβ©
exact condition_two_mul_int m
end Imo2024Q1
|
Defs.lean
|
/-
Copyright (c) 2018 Kenny Lau. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kenny Lau, Joey van Langen, Casper Putz
-/
import Mathlib.Data.Nat.Cast.Basic
import Mathlib.Data.Nat.Find
import Mathlib.Data.Nat.Prime.Defs
import Mathlib.Data.Int.Cast.Basic
import Mathlib.Order.Lattice
/-!
# Characteristic of semirings
## Main definitions
* `CharP R p` expresses that the ring (additive monoid with one) `R` has characteristic `p`
* `ringChar`: the characteristic of a ring
* `ExpChar R p` expresses that the ring (additive monoid with one) `R` has
exponential characteristic `p` (which is `1` if `R` has characteristic 0, and `p` if it has
prime characteristic `p`)
-/
assert_not_exists Field Finset OrderHom
variable (R : Type*)
namespace CharP
section AddMonoidWithOne
variable [AddMonoidWithOne R] (p : β)
/-- The generator of the kernel of the unique homomorphism β β R for a semiring R.
*Warning*: for a semiring `R`, `CharP R 0` and `CharZero R` need not coincide.
* `CharP R 0` asks that only `0 : β` maps to `0 : R` under the map `β β R`;
* `CharZero R` requires an injection `β βͺ R`.
For instance, endowing `{0, 1}` with addition given by `max` (i.e. `1` is absorbing), shows that
`CharZero {0, 1}` does not hold and yet `CharP {0, 1} 0` does.
This example is formalized in `Counterexamples/CharPZeroNeCharZero.lean`.
-/
@[mk_iff]
class _root_.CharP (R : Type*) [AddMonoidWithOne R] (p : outParam β) : Prop where
cast_eq_zero_iff (R p) : β x : β, (x : R) = 0 β p β£ x
variable [CharP R p] {a b : β}
@[deprecated CharP.cast_eq_zero_iff (since := "2025-04-03")]
lemma cast_eq_zero_iff' (R : Type*) [AddMonoidWithOne R] (p : β) [CharP R p] (a : β) :
(a : R) = 0 β p β£ a := cast_eq_zero_iff R p a
lemma _root_.CharP.ofNat_eq_zero' (p : β) [CharP R p]
(a : β) [a.AtLeastTwo] (h : p β£ a) :
(ofNat(a) : R) = 0 := by
rwa [β CharP.cast_eq_zero_iff R p] at h
variable {R} in
lemma congr {q : β} (h : p = q) : CharP R q := h βΈ βΉCharP R pβΊ
@[simp] lemma cast_eq_zero : (p : R) = 0 := (cast_eq_zero_iff R p p).2 dvd_rfl
lemma cast_eq_mod (k : β) : (k : R) = (k % p : β) :=
have (a : β) : ((p * a : β) : R) = 0 := by
rw [CharP.cast_eq_zero_iff R p]
exact Nat.dvd_mul_right p a
calc
(k : R) = β(k % p + p * (k / p)) := by rw [Nat.mod_add_div]
_ = β(k % p) := by simp [this]
lemma cast_eq_iff_mod_eq [IsLeftCancelAdd R] : (a:R) = (b:R) β a % p = b % p := by
wlog hle : a β€ b
Β· simpa only [eq_comm] using (this _ _ (lt_of_not_ge hle).le)
obtain β¨c, rflβ© := Nat.exists_eq_add_of_le hle
rw [Nat.cast_add, left_eq_add, CharP.cast_eq_zero_iff R p]
constructor
Β· simp +contextual [Nat.add_mod, Nat.dvd_iff_mod_eq_zero]
intro h
have := Nat.sub_mod_eq_zero_of_mod_eq h.symm
simpa [Nat.dvd_iff_mod_eq_zero] using this
-- TODO: This lemma needs to be `@[simp]` for confluence in the presence of `CharP.cast_eq_zero` and
-- `Nat.cast_ofNat`, but with `no_index` on its entire LHS, it matches literally every expression so
-- is too expensive. If https://github.com/leanprover/lean4/issues/2867 is fixed in a performant way, this can be made `@[simp]`.
--
-- @[simp]
lemma ofNat_eq_zero [p.AtLeastTwo] : (ofNat(p) : R) = 0 := cast_eq_zero R p
lemma eq {p q : β} (hp : CharP R p) (hq : CharP R q) : p = q :=
Nat.dvd_antisymm ((cast_eq_zero_iff (self := hp) R p q).1 (@cast_eq_zero _ _ _ hq))
((cast_eq_zero_iff (self := hq) R q p).1 (@cast_eq_zero _ _ _ hp))
instance ofCharZero [CharZero R] : CharP R 0 where
cast_eq_zero_iff x := by rw [zero_dvd_iff, β Nat.cast_zero, Nat.cast_inj]
end AddMonoidWithOne
section AddGroupWithOne
variable [AddGroupWithOne R] (p : β) [CharP R p] {a b : β€}
lemma intCast_eq_zero_iff (a : β€) : (a : R) = 0 β (p : β€) β£ a := by
rcases lt_trichotomy a 0 with (h | rfl | h)
Β· rw [β neg_eq_zero, β Int.cast_neg, β Int.dvd_neg]
lift -a to β using Int.neg_nonneg.mpr (le_of_lt h) with b
rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast]
Β· simp only [Int.cast_zero, Int.dvd_zero]
Β· lift a to β using le_of_lt h with b
rw [Int.cast_natCast, CharP.cast_eq_zero_iff R p, Int.natCast_dvd_natCast]
lemma charP_to_charZero [CharP R 0] : CharZero R :=
charZero_of_inj_zero fun n h0 => eq_zero_of_zero_dvd ((cast_eq_zero_iff R 0 n).mp h0)
lemma charP_zero_iff_charZero : CharP R 0 β CharZero R :=
β¨fun _ β¦ charP_to_charZero R, fun _ β¦ ofCharZero Rβ©
end AddGroupWithOne
section NonAssocSemiring
variable [NonAssocSemiring R]
lemma Β«existsΒ» : β p, CharP R p :=
letI := Classical.decEq R
by_cases
(fun H : β p : β, (p : R) = 0 β p = 0 =>
β¨0, β¨fun x => by rw [zero_dvd_iff]; exact β¨H x, by rintro rfl; simpβ©β©β©)
fun H =>
β¨Nat.find (not_forall.1 H),
β¨fun x =>
β¨fun H1 =>
Nat.dvd_of_mod_eq_zero
(by_contradiction fun H2 =>
Nat.find_min (not_forall.1 H)
(Nat.mod_lt x <|
Nat.pos_of_ne_zero <| not_of_not_imp <| Nat.find_spec (not_forall.1 H))
(not_imp_of_and_not
β¨by
rwa [β Nat.mod_add_div x (Nat.find (not_forall.1 H)), Nat.cast_add,
Nat.cast_mul,
of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)),
zero_mul, add_zero] at H1,
H2β©)),
fun H1 => by
rw [β Nat.mul_div_cancel' H1, Nat.cast_mul,
of_not_not (not_not_of_not_imp <| Nat.find_spec (not_forall.1 H)),
zero_mul]β©β©β©
lemma existsUnique : β! p, CharP R p :=
let β¨c, Hβ© := CharP.exists R
β¨c, H, fun _y H2 => CharP.eq R H2 Hβ©
end NonAssocSemiring
end CharP
/-- Noncomputable function that outputs the unique characteristic of a semiring. -/
noncomputable def ringChar [NonAssocSemiring R] : β := Classical.choose (CharP.existsUnique R)
namespace ringChar
variable [NonAssocSemiring R]
lemma spec : β x : β, (x : R) = 0 β ringChar R β£ x := by
letI : CharP R (ringChar R) := (Classical.choose_spec (CharP.existsUnique R)).1
exact CharP.cast_eq_zero_iff R (ringChar R)
lemma eq (p : β) [C : CharP R p] : ringChar R = p :=
((Classical.choose_spec (CharP.existsUnique R)).2 p C).symm
instance (priority := low) charP : CharP R (ringChar R) :=
β¨spec Rβ©
variable {R}
lemma of_eq {p : β} (h : ringChar R = p) : CharP R p :=
CharP.congr (ringChar R) h
lemma eq_iff {p : β} : ringChar R = p β CharP R p :=
β¨of_eq, @eq R _ pβ©
lemma dvd {x : β} (hx : (x : R) = 0) : ringChar R β£ x :=
(spec R x).1 hx
@[simp]
lemma eq_zero [CharZero R] : ringChar R = 0 :=
eq R 0
lemma Nat.cast_ringChar : (ringChar R : R) = 0 := by rw [ringChar.spec]
end ringChar
lemma CharP.neg_one_ne_one [AddGroupWithOne R] (p : β) [CharP R p] [Fact (2 < p)] :
(-1 : R) β (1 : R) := by
rw [ne_comm, β sub_ne_zero, sub_neg_eq_add, one_add_one_eq_two, β Nat.cast_two, Ne,
CharP.cast_eq_zero_iff R p 2]
exact fun h β¦ (Fact.out : 2 < p).not_ge <| Nat.le_of_dvd Nat.zero_lt_two h
namespace CharP
section
variable [NonAssocRing R]
lemma ringChar_zero_iff_CharZero : ringChar R = 0 β CharZero R := by
rw [ringChar.eq_iff, charP_zero_iff_charZero]
end
section Semiring
variable [NonAssocSemiring R]
lemma char_ne_one [Nontrivial R] (p : β) [hc : CharP R p] : p β 1 := fun hp : p = 1 =>
have : (1 : R) = 0 := by simpa using (cast_eq_zero_iff R p 1).mpr (hp βΈ dvd_refl p)
absurd this one_ne_zero
section NoZeroDivisors
variable [NoZeroDivisors R]
lemma char_is_prime_of_two_le (p : β) [CharP R p] (hp : 2 β€ p) : Nat.Prime p :=
suffices β (d) (_ : d β£ p), d = 1 β¨ d = p from Nat.prime_def.mpr β¨hp, thisβ©
fun (d : β) (hdvd : β e, p = d * e) =>
let β¨e, hmulβ© := hdvd
have : (p : R) = 0 := (cast_eq_zero_iff R p p).mpr (dvd_refl p)
have : (d : R) * e = 0 := @Nat.cast_mul R _ d e βΈ hmul βΈ this
Or.elim (eq_zero_or_eq_zero_of_mul_eq_zero this)
(fun hd : (d : R) = 0 =>
have : p β£ d := (cast_eq_zero_iff R p d).mp hd
show d = 1 β¨ d = p from Or.inr (this.antisymm' β¨e, hmulβ©))
fun he : (e : R) = 0 =>
have : p β£ e := (cast_eq_zero_iff R p e).mp he
have : e β£ p := dvd_of_mul_left_eq d (Eq.symm hmul)
have : e = p := βΉe β£ pβΊ.antisymm βΉp β£ eβΊ
have hβ : 0 < p := by grind
have : d * p = 1 * p := by grind
show d = 1 β¨ d = p from Or.inl (mul_right_cancelβ hβ.ne' this)
section Nontrivial
variable [Nontrivial R]
lemma char_is_prime_or_zero (p : β) [hc : CharP R p] : Nat.Prime p β¨ p = 0 :=
match p, hc with
| 0, _ => Or.inr rfl
| 1, hc => absurd (Eq.refl (1 : β)) (@char_ne_one R _ _ (1 : β) hc)
| m + 2, hc => Or.inl (@char_is_prime_of_two_le R _ _ (m + 2) hc (Nat.le_add_left 2 m))
/-- The characteristic is prime if it is non-zero. -/
lemma char_prime_of_ne_zero {p : β} [CharP R p] (hp : p β 0) : p.Prime :=
(CharP.char_is_prime_or_zero R p).resolve_right hp
lemma exists' (R : Type*) [NonAssocRing R] [NoZeroDivisors R] [Nontrivial R] :
CharZero R β¨ β p : β, Fact p.Prime β§ CharP R p := by
obtain β¨p, hcharβ© := CharP.exists R
rcases char_is_prime_or_zero R p with h | rfl
exacts [Or.inr β¨p, Fact.mk h, hcharβ©, Or.inl (charP_to_charZero R)]
lemma char_is_prime_of_pos (p : β) [NeZero p] [CharP R p] : Fact p.Prime :=
β¨(CharP.char_is_prime_or_zero R _).resolve_right <| NeZero.ne pβ©
end Nontrivial
end NoZeroDivisors
end Semiring
section NonAssocSemiring
variable {R} [NonAssocSemiring R]
-- This lemma is not an instance, to make sure that trying to prove `Ξ±` is a subsingleton does
-- not try to find a ring structure on `Ξ±`, which can be expensive.
lemma CharOne.subsingleton [CharP R 1] : Subsingleton R :=
Subsingleton.intro <|
suffices β r : R, r = 0 from fun a b => show a = b by rw [this a, this b]
fun r =>
calc
r = 1 * r := by rw [one_mul]
_ = (1 : β) * r := by rw [Nat.cast_one]
_ = 0 * r := by rw [CharP.cast_eq_zero]
_ = 0 := by rw [zero_mul]
lemma false_of_nontrivial_of_char_one [Nontrivial R] [CharP R 1] : False := by
have : Subsingleton R := CharOne.subsingleton
exact false_of_nontrivial_of_subsingleton R
lemma ringChar_ne_one [Nontrivial R] : ringChar R β 1 := by
intro h
apply zero_ne_one' R
symm
rw [β Nat.cast_one, ringChar.spec, h]
lemma nontrivial_of_char_ne_one {v : β} (hv : v β 1) [hr : CharP R v] : Nontrivial R :=
β¨β¨(1 : β), 0, fun h =>
hv <| by rwa [CharP.cast_eq_zero_iff _ v, Nat.dvd_one] at hβ©β©
end NonAssocSemiring
end CharP
namespace NeZero
variable [AddMonoidWithOne R] {r : R} {n p : β}
lemma of_not_dvd [CharP R p] (h : Β¬p β£ n) : NeZero (n : R) :=
β¨(CharP.cast_eq_zero_iff R p n).not.mpr hβ©
lemma not_char_dvd (p : β) [CharP R p] (k : β) [h : NeZero (k : R)] : Β¬p β£ k := by
rwa [β CharP.cast_eq_zero_iff R p k, β Ne, β neZero_iff]
end NeZero
/-!
### Exponential characteristic
This section defines the exponential characteristic, which is defined to be 1 for a ring with
characteristic 0 and the same as the ordinary characteristic, if the ordinary characteristic is
prime. This concept is useful to simplify some theorem statements.
This file establishes a few basic results relating it to the (ordinary characteristic).
The definition is stated for a semiring, but the actual results are for nontrivial rings
(as far as exponential characteristic one is concerned), respectively a ring without zero-divisors
(for prime characteristic).
-/
section AddMonoidWithOne
variable [AddMonoidWithOne R]
/-- The definition of the exponential characteristic of a semiring. -/
class inductive ExpChar : β β Prop
| zero [CharZero R] : ExpChar 1
| prime {q : β} (hprime : q.Prime) [hchar : CharP R q] : ExpChar q
instance expChar_prime (p) [CharP R p] [Fact p.Prime] : ExpChar R p := ExpChar.prime Fact.out
instance expChar_one [CharZero R] : ExpChar R 1 := ExpChar.zero
lemma expChar_ne_zero (p : β) [hR : ExpChar R p] : p β 0 := by
cases hR
Β· exact one_ne_zero
Β· exact βΉp.PrimeβΊ.ne_zero
variable {R} in
/-- The exponential characteristic is unique. -/
lemma ExpChar.eq {p q : β} (hp : ExpChar R p) (hq : ExpChar R q) : p = q := by
rcases hp with β¨hpβ© | β¨hp'β©
Β· rcases hq with hq | hq'
exacts [rfl, False.elim (Nat.not_prime_zero (CharP.eq R βΉ_βΊ (CharP.ofCharZero R) βΈ hq'))]
Β· rcases hq with hq | hq'
exacts [False.elim (Nat.not_prime_zero (CharP.eq R βΉ_βΊ (CharP.ofCharZero R) βΈ hp')),
CharP.eq R βΉ_βΊ βΉ_βΊ]
lemma ExpChar.congr {p : β} (q : β) [hq : ExpChar R q] (h : q = p) : ExpChar R p := h βΈ hq
/-- The exponential characteristic is one if the characteristic is zero. -/
lemma expChar_one_of_char_zero (q : β) [hp : CharP R 0] [hq : ExpChar R q] : q = 1 := by
rcases hq with q | hq_prime
Β· rfl
Β· exact False.elim <| hq_prime.ne_zero <| βΉCharP R qβΊ.eq R hp
/-- The characteristic equals the exponential characteristic iff the former is prime. -/
lemma char_eq_expChar_iff (p q : β) [hp : CharP R p] [hq : ExpChar R q] : p = q β p.Prime := by
rcases hq with q | hq_prime
Β· rw [(CharP.eq R hp (.ofCharZero R) : p = 0)]
decide
Β· exact β¨fun hpq => hpq.symm βΈ hq_prime, fun _ => CharP.eq R hp βΉCharP R qβΊβ©
/-- The exponential characteristic is a prime number or one.
See also `CharP.char_is_prime_or_zero`. -/
lemma expChar_is_prime_or_one (q : β) [hq : ExpChar R q] : Nat.Prime q β¨ q = 1 := by
cases hq with
| zero => exact .inr rfl
| prime hp => exact .inl hp
/-- The exponential characteristic is positive. -/
lemma expChar_pos (q : β) [ExpChar R q] : 0 < q := by
rcases expChar_is_prime_or_one R q with h | rfl
exacts [Nat.Prime.pos h, Nat.one_pos]
/-- Any power of the exponential characteristic is positive. -/
lemma expChar_pow_pos (q : β) [ExpChar R q] (n : β) : 0 < q ^ n :=
Nat.pow_pos (expChar_pos R q)
end AddMonoidWithOne
section NonAssocSemiring
variable [NonAssocSemiring R]
/-- Noncomputable function that outputs the unique exponential characteristic of a semiring. -/
noncomputable def ringExpChar : β := max (ringChar R) 1
lemma ringExpChar.eq (q : β) [h : ExpChar R q] : ringExpChar R = q := by
rcases h with _ | h
Β· haveI := CharP.ofCharZero R
rw [ringExpChar, ringChar.eq R 0]; rfl
rw [ringExpChar, ringChar.eq R q]
exact Nat.max_eq_left h.one_lt.le
@[simp] lemma ringExpChar.eq_one [CharZero R] : ringExpChar R = 1 := by
rw [ringExpChar, ringChar.eq_zero, max_eq_right (Nat.zero_le _)]
section Nontrivial
variable [Nontrivial R]
/-- The exponential characteristic is one if the characteristic is zero. -/
lemma char_zero_of_expChar_one (p : β) [hp : CharP R p] [hq : ExpChar R 1] : p = 0 := by
cases hq
Β· exact CharP.eq R hp (.ofCharZero R)
Β· exact False.elim (CharP.char_ne_one R 1 rfl)
-- This could be an instance, but there are no `ExpChar R 1` instances in mathlib.
/-- The characteristic is zero if the exponential characteristic is one. -/
lemma charZero_of_expChar_one' [hq : ExpChar R 1] : CharZero R := by
cases hq
Β· assumption
Β· exact False.elim (CharP.char_ne_one R 1 rfl)
/-- The exponential characteristic is one iff the characteristic is zero. -/
lemma expChar_one_iff_char_zero (p q : β) [CharP R p] [ExpChar R q] : q = 1 β p = 0 := by
constructor
Β· rintro rfl
exact char_zero_of_expChar_one R p
Β· rintro rfl
exact expChar_one_of_char_zero R q
end Nontrivial
end NonAssocSemiring
lemma ExpChar.exists [Ring R] [IsDomain R] : β q, ExpChar R q := by
obtain _ | β¨p, β¨hpβ©, _β© := CharP.exists' R
exacts [β¨1, .zeroβ©, β¨p, .prime hpβ©]
lemma ExpChar.exists_unique [Ring R] [IsDomain R] : β! q, ExpChar R q :=
let β¨q, Hβ© := ExpChar.exists R
β¨q, H, fun _ H2 β¦ ExpChar.eq H2 Hβ©
instance ringExpChar.expChar [Ring R] [IsDomain R] : ExpChar R (ringExpChar R) := by
obtain β¨q, _β© := ExpChar.exists R
rwa [ringExpChar.eq R q]
variable {R} in
lemma ringExpChar.of_eq [Ring R] [IsDomain R] {q : β} (h : ringExpChar R = q) : ExpChar R q :=
h βΈ ringExpChar.expChar R
variable {R} in
lemma ringExpChar.eq_iff [Ring R] [IsDomain R] {q : β} : ringExpChar R = q β ExpChar R q :=
β¨ringExpChar.of_eq, fun _ β¦ ringExpChar.eq R qβ©
|
Balance.lean
|
/-
Copyright (c) 2023 YaΓ«l Dillies, Bhavik Mehta. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies, Bhavik Mehta
-/
import Mathlib.Algebra.BigOperators.Expect
/-!
# Balancing a function
This file defines the balancing of a function `f`, defined as `f` minus its average.
This is the unique function `g` such that `f a - f b = g a - g b` for all `a` and `b`, and
`β a, g a = 0`. This is particularly useful in Fourier analysis as `f` and `g` then have the same
Fourier transform, except in the `0`-th frequency where the Fourier transform of `g` vanishes.
-/
open Finset Function
open scoped BigOperators
variable {ΞΉ H F G : Type*}
namespace Fintype
section AddCommGroup
variable [Fintype ΞΉ] [AddCommGroup G] [Module ββ₯0 G] [AddCommGroup H] [Module ββ₯0 H]
/-- The balancing of a function, namely the function minus its average. -/
def balance (f : ΞΉ β G) : ΞΉ β G := f - Function.const _ (πΌ y, f y)
lemma balance_apply (f : ΞΉ β G) (x : ΞΉ) : balance f x = f x - πΌ y, f y := rfl
@[simp] lemma balance_zero : balance (0 : ΞΉ β G) = 0 := by simp [balance]
@[simp] lemma balance_add (f g : ΞΉ β G) : balance (f + g) = balance f + balance g := by
simp only [balance, expect_add_distrib, β const_add, add_sub_add_comm, Pi.add_apply]
@[simp] lemma balance_sub (f g : ΞΉ β G) : balance (f - g) = balance f - balance g := by
simp only [balance, expect_sub_distrib, const_sub, sub_sub_sub_comm, Pi.sub_apply]
@[simp] lemma balance_neg (f : ΞΉ β G) : balance (-f) = -balance f := by
simp only [balance, expect_neg_distrib, const_neg, neg_sub', Pi.neg_apply]
@[simp] lemma sum_balance (f : ΞΉ β G) : β x, balance f x = 0 := by
cases isEmpty_or_nonempty ΞΉ <;> simp [balance_apply]
@[simp] lemma expect_balance (f : ΞΉ β G) : πΌ x, balance f x = 0 := by simp [expect]
@[simp] lemma balance_idem (f : ΞΉ β G) : balance (balance f) = balance f := by
cases isEmpty_or_nonempty ΞΉ <;> ext x <;> simp [balance, expect_sub_distrib, univ_nonempty]
@[simp] lemma map_balance [FunLike F G H] [LinearMapClass F ββ₯0 G H] (g : F) (f : ΞΉ β G) (a : ΞΉ) :
g (balance f a) = balance (g β f) a := by simp [balance, map_expect]
end AddCommGroup
end Fintype
|
Basic.lean
|
/-
Copyright (c) 2021 YaΓ«l Dillies. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: YaΓ«l Dillies
-/
import Mathlib.Order.ConditionallyCompleteLattice.Basic
import Mathlib.Order.Cover
import Mathlib.Order.Iterate
/-!
# Successor and predecessor
This file defines successor and predecessor orders. `succ a`, the successor of an element `a : Ξ±` is
the least element greater than `a`. `pred a` is the greatest element less than `a`. Typical examples
include `β`, `β€`, `β+`, `Fin n`, but also `ENat`, the lexicographic order of a successor/predecessor
order...
## Typeclasses
* `SuccOrder`: Order equipped with a sensible successor function.
* `PredOrder`: Order equipped with a sensible predecessor function.
## Implementation notes
Maximal elements don't have a sensible successor. Thus the naΓ―ve typeclass
```lean
class NaiveSuccOrder (Ξ± : Type*) [Preorder Ξ±] where
(succ : Ξ± β Ξ±)
(succ_le_iff : β {a b}, succ a β€ b β a < b)
(lt_succ_iff : β {a b}, a < succ b β a β€ b)
```
can't apply to an `OrderTop` because plugging in `a = b = β€` into either of `succ_le_iff` and
`lt_succ_iff` yields `β€ < β€` (or more generally `m < m` for a maximal element `m`).
The solution taken here is to remove the implications `β€ β <` and instead require that `a < succ a`
for all non maximal elements (enforced by the combination of `le_succ` and the contrapositive of
`max_of_succ_le`).
The stricter condition of every element having a sensible successor can be obtained through the
combination of `SuccOrder Ξ±` and `NoMaxOrder Ξ±`.
-/
open Function OrderDual Set
variable {Ξ± Ξ² : Type*}
/-- Order equipped with a sensible successor function. -/
@[ext]
class SuccOrder (Ξ± : Type*) [Preorder Ξ±] where
/-- Successor function -/
succ : Ξ± β Ξ±
/-- Proof of basic ordering with respect to `succ` -/
le_succ : β a, a β€ succ a
/-- Proof of interaction between `succ` and maximal element -/
max_of_succ_le {a} : succ a β€ a β IsMax a
/-- Proof that `succ a` is the least element greater than `a` -/
succ_le_of_lt {a b} : a < b β succ a β€ b
/-- Order equipped with a sensible predecessor function. -/
@[ext]
class PredOrder (Ξ± : Type*) [Preorder Ξ±] where
/-- Predecessor function -/
pred : Ξ± β Ξ±
/-- Proof of basic ordering with respect to `pred` -/
pred_le : β a, pred a β€ a
/-- Proof of interaction between `pred` and minimal element -/
min_of_le_pred {a} : a β€ pred a β IsMin a
/-- Proof that `pred b` is the greatest element less than `b` -/
le_pred_of_lt {a b} : a < b β a β€ pred b
instance [Preorder Ξ±] [SuccOrder Ξ±] :
PredOrder Ξ±α΅α΅ where
pred := toDual β SuccOrder.succ β ofDual
pred_le := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
SuccOrder.le_succ, implies_true]
min_of_le_pred h := by apply SuccOrder.max_of_succ_le h
le_pred_of_lt := by intro a b h; exact SuccOrder.succ_le_of_lt h
instance [Preorder Ξ±] [PredOrder Ξ±] :
SuccOrder Ξ±α΅α΅ where
succ := toDual β PredOrder.pred β ofDual
le_succ := by
simp only [comp, OrderDual.forall, ofDual_toDual, toDual_le_toDual,
PredOrder.pred_le, implies_true]
max_of_succ_le h := by apply PredOrder.min_of_le_pred h
succ_le_of_lt := by intro a b h; exact PredOrder.le_pred_of_lt h
section Preorder
variable [Preorder Ξ±]
/-- A constructor for `SuccOrder Ξ±` usable when `Ξ±` has no maximal element. -/
def SuccOrder.ofSuccLeIff (succ : Ξ± β Ξ±) (hsucc_le_iff : β {a b}, succ a β€ b β a < b) :
SuccOrder Ξ± :=
{ succ
le_succ := fun _ => (hsucc_le_iff.1 le_rfl).le
max_of_succ_le := fun ha => (lt_irrefl _ <| hsucc_le_iff.1 ha).elim
succ_le_of_lt := fun h => hsucc_le_iff.2 h }
/-- A constructor for `PredOrder Ξ±` usable when `Ξ±` has no minimal element. -/
def PredOrder.ofLePredIff (pred : Ξ± β Ξ±) (hle_pred_iff : β {a b}, a β€ pred b β a < b) :
PredOrder Ξ± :=
{ pred
pred_le := fun _ => (hle_pred_iff.1 le_rfl).le
min_of_le_pred := fun ha => (lt_irrefl _ <| hle_pred_iff.1 ha).elim
le_pred_of_lt := fun h => hle_pred_iff.2 h }
end Preorder
section LinearOrder
variable [LinearOrder Ξ±]
/-- A constructor for `SuccOrder Ξ±` for `Ξ±` a linear order. -/
@[simps]
def SuccOrder.ofCore (succ : Ξ± β Ξ±) (hn : β {a}, Β¬IsMax a β β b, a < b β succ a β€ b)
(hm : β a, IsMax a β succ a = a) : SuccOrder Ξ± :=
{ succ
succ_le_of_lt := fun {a b} =>
by_cases (fun h hab => (hm a h).symm βΈ hab.le) fun h => (hn h b).mp
le_succ := fun a =>
by_cases (fun h => (hm a h).symm.le) fun h => le_of_lt <| by simpa using (hn h a).not
max_of_succ_le := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
/-- A constructor for `PredOrder Ξ±` for `Ξ±` a linear order. -/
@[simps]
def PredOrder.ofCore (pred : Ξ± β Ξ±)
(hn : β {a}, Β¬IsMin a β β b, b β€ pred a β b < a) (hm : β a, IsMin a β pred a = a) :
PredOrder Ξ± :=
{ pred
le_pred_of_lt := fun {a b} =>
by_cases (fun h hab => (hm b h).symm βΈ hab.le) fun h => (hn h a).mpr
pred_le := fun a =>
by_cases (fun h => (hm a h).le) fun h => le_of_lt <| by simpa using (hn h a).not
min_of_le_pred := fun {a} => not_imp_not.mp fun h => by simpa using (hn h a).not }
variable (Ξ±)
open Classical in
/-- A well-order is a `SuccOrder`. -/
noncomputable def SuccOrder.ofLinearWellFoundedLT [WellFoundedLT Ξ±] : SuccOrder Ξ± :=
ofCore (fun a β¦ if h : (Ioi a).Nonempty then wellFounded_lt.min _ h else a)
(fun ha _ β¦ by
rw [not_isMax_iff] at ha
simp_rw [Set.Nonempty, mem_Ioi, dif_pos ha]
exact β¨(wellFounded_lt.min_le Β· ha), lt_of_lt_of_le (wellFounded_lt.min_mem _ ha)β©)
fun _ ha β¦ dif_neg (not_not_intro ha <| not_isMax_iff.mpr Β·)
/-- A linear order with well-founded greater-than relation is a `PredOrder`. -/
noncomputable def PredOrder.ofLinearWellFoundedGT (Ξ±) [LinearOrder Ξ±] [WellFoundedGT Ξ±] :
PredOrder Ξ± := letI := SuccOrder.ofLinearWellFoundedLT Ξ±α΅α΅; inferInstanceAs (PredOrder Ξ±α΅α΅α΅α΅)
end LinearOrder
/-! ### Successor order -/
namespace Order
section Preorder
variable [Preorder Ξ±] [SuccOrder Ξ±] {a b : Ξ±}
/-- The successor of an element. If `a` is not maximal, then `succ a` is the least element greater
than `a`. If `a` is maximal, then `succ a = a`. -/
def succ : Ξ± β Ξ± :=
SuccOrder.succ
theorem le_succ : β a : Ξ±, a β€ succ a :=
SuccOrder.le_succ
theorem max_of_succ_le {a : Ξ±} : succ a β€ a β IsMax a :=
SuccOrder.max_of_succ_le
theorem succ_le_of_lt {a b : Ξ±} : a < b β succ a β€ b :=
SuccOrder.succ_le_of_lt
alias _root_.LT.lt.succ_le := succ_le_of_lt
@[simp]
theorem succ_le_iff_isMax : succ a β€ a β IsMax a :=
β¨max_of_succ_le, fun h => h <| le_succ _β©
alias β¨_root_.IsMax.of_succ_le, _root_.IsMax.succ_leβ© := succ_le_iff_isMax
@[simp]
theorem lt_succ_iff_not_isMax : a < succ a β Β¬IsMax a :=
β¨not_isMax_of_lt, fun ha => (le_succ a).lt_of_not_ge fun h => ha <| max_of_succ_le hβ©
alias β¨_, lt_succ_of_not_isMaxβ© := lt_succ_iff_not_isMax
theorem wcovBy_succ (a : Ξ±) : a β©Ώ succ a :=
β¨le_succ a, fun _ hb => (succ_le_of_lt hb).not_gtβ©
theorem covBy_succ_of_not_isMax (h : Β¬IsMax a) : a β succ a :=
(wcovBy_succ a).covBy_of_lt <| lt_succ_of_not_isMax h
theorem lt_succ_of_le_of_not_isMax (hab : b β€ a) (ha : Β¬IsMax a) : b < succ a :=
hab.trans_lt <| lt_succ_of_not_isMax ha
theorem succ_le_iff_of_not_isMax (ha : Β¬IsMax a) : succ a β€ b β a < b :=
β¨(lt_succ_of_not_isMax ha).trans_le, succ_le_of_ltβ©
lemma succ_lt_succ_of_not_isMax (h : a < b) (hb : Β¬ IsMax b) : succ a < succ b :=
lt_succ_of_le_of_not_isMax (succ_le_of_lt h) hb
@[simp, mono, gcongr]
theorem succ_le_succ (h : a β€ b) : succ a β€ succ b := by
by_cases hb : IsMax b
Β· by_cases hba : b β€ a
Β· exact (hb <| hba.trans <| le_succ _).trans (le_succ _)
Β· exact succ_le_of_lt ((h.lt_of_not_ge hba).trans_le <| le_succ b)
Β· rw [succ_le_iff_of_not_isMax fun ha => hb <| ha.mono h]
apply lt_succ_of_le_of_not_isMax h hb
theorem succ_mono : Monotone (succ : Ξ± β Ξ±) := fun _ _ => succ_le_succ
/-- See also `Order.succ_eq_of_covBy`. -/
lemma le_succ_of_wcovBy (h : a β©Ώ b) : b β€ succ a := by
obtain hab | β¨-, hbaβ© := h.covBy_or_le_and_le
Β· by_contra hba
exact h.2 (lt_succ_of_not_isMax hab.lt.not_isMax) <| hab.lt.succ_le.lt_of_not_ge hba
Β· exact hba.trans (le_succ _)
alias _root_.WCovBy.le_succ := le_succ_of_wcovBy
theorem le_succ_iterate (k : β) (x : Ξ±) : x β€ succ^[k] x :=
id_le_iterate_of_id_le le_succ _ _
theorem isMax_iterate_succ_of_eq_of_lt {n m : β} (h_eq : succ^[n] a = succ^[m] a)
(h_lt : n < m) : IsMax (succ^[n] a) := by
refine max_of_succ_le (le_trans ?_ h_eq.symm.le)
rw [β iterate_succ_apply' succ]
have h_le : n + 1 β€ m := Nat.succ_le_of_lt h_lt
exact Monotone.monotone_iterate_of_le_map succ_mono (le_succ a) h_le
theorem isMax_iterate_succ_of_eq_of_ne {n m : β} (h_eq : succ^[n] a = succ^[m] a)
(h_ne : n β m) : IsMax (succ^[n] a) := by
rcases le_total n m with h | h
Β· exact isMax_iterate_succ_of_eq_of_lt h_eq (lt_of_le_of_ne h h_ne)
Β· rw [h_eq]
exact isMax_iterate_succ_of_eq_of_lt h_eq.symm (lt_of_le_of_ne h h_ne.symm)
theorem Iic_subset_Iio_succ_of_not_isMax (ha : Β¬IsMax a) : Iic a β Iio (succ a) :=
fun _ => (lt_succ_of_le_of_not_isMax Β· ha)
theorem Ici_succ_of_not_isMax (ha : Β¬IsMax a) : Ici (succ a) = Ioi a :=
Set.ext fun _ => succ_le_iff_of_not_isMax ha
theorem Icc_subset_Ico_succ_right_of_not_isMax (hb : Β¬IsMax b) : Icc a b β Ico a (succ b) := by
rw [β Ici_inter_Iio, β Ici_inter_Iic]
gcongr
intro _ h
apply lt_succ_of_le_of_not_isMax h hb
theorem Ioc_subset_Ioo_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ioc a b β Ioo a (succ b) := by
rw [β Ioi_inter_Iio, β Ioi_inter_Iic]
gcongr
intro _ h
apply Iic_subset_Iio_succ_of_not_isMax hb h
theorem Icc_succ_left_of_not_isMax (ha : Β¬IsMax a) : Icc (succ a) b = Ioc a b := by
rw [β Ici_inter_Iic, Ici_succ_of_not_isMax ha, Ioi_inter_Iic]
theorem Ico_succ_left_of_not_isMax (ha : Β¬IsMax a) : Ico (succ a) b = Ioo a b := by
rw [β Ici_inter_Iio, Ici_succ_of_not_isMax ha, Ioi_inter_Iio]
section NoMaxOrder
variable [NoMaxOrder Ξ±]
theorem lt_succ (a : Ξ±) : a < succ a :=
lt_succ_of_not_isMax <| not_isMax a
@[simp]
theorem lt_succ_of_le : a β€ b β a < succ b :=
(lt_succ_of_le_of_not_isMax Β· <| not_isMax b)
@[simp]
theorem succ_le_iff : succ a β€ b β a < b :=
succ_le_iff_of_not_isMax <| not_isMax a
@[gcongr] theorem succ_lt_succ (hab : a < b) : succ a < succ b := by simp [hab]
theorem succ_strictMono : StrictMono (succ : Ξ± β Ξ±) := fun _ _ => succ_lt_succ
theorem covBy_succ (a : Ξ±) : a β succ a :=
covBy_succ_of_not_isMax <| not_isMax a
theorem Iic_subset_Iio_succ (a : Ξ±) : Iic a β Iio (succ a) := by simp
@[simp]
theorem Ici_succ (a : Ξ±) : Ici (succ a) = Ioi a :=
Ici_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Icc_subset_Ico_succ_right (a b : Ξ±) : Icc a b β Ico a (succ b) :=
Icc_subset_Ico_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Ioc_subset_Ioo_succ_right (a b : Ξ±) : Ioc a b β Ioo a (succ b) :=
Ioc_subset_Ioo_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem Icc_succ_left (a b : Ξ±) : Icc (succ a) b = Ioc a b :=
Icc_succ_left_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_left (a b : Ξ±) : Ico (succ a) b = Ioo a b :=
Ico_succ_left_of_not_isMax <| not_isMax _
end NoMaxOrder
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [SuccOrder Ξ±] {a b : Ξ±}
@[simp]
theorem succ_eq_iff_isMax : succ a = a β IsMax a :=
β¨fun h => max_of_succ_le h.le, fun h => h.eq_of_ge <| le_succ _β©
alias β¨_, _root_.IsMax.succ_eqβ© := succ_eq_iff_isMax
lemma le_iff_eq_or_succ_le : a β€ b β a = b β¨ succ a β€ b := by
by_cases ha : IsMax a
Β· simpa [ha.succ_eq] using le_of_eq
Β· rw [succ_le_iff_of_not_isMax ha, le_iff_eq_or_lt]
theorem le_le_succ_iff : a β€ b β§ b β€ succ a β b = a β¨ b = succ a := by
refine
β¨fun h =>
or_iff_not_imp_left.2 fun hba : b β a =>
h.2.antisymm (succ_le_of_lt <| h.1.lt_of_ne <| hba.symm),
?_β©
rintro (rfl | rfl)
Β· exact β¨le_rfl, le_succ bβ©
Β· exact β¨le_succ a, le_rflβ©
/-- See also `Order.le_succ_of_wcovBy`. -/
lemma succ_eq_of_covBy (h : a β b) : succ a = b := (succ_le_of_lt h.lt).antisymm h.wcovBy.le_succ
alias _root_.CovBy.succ_eq := succ_eq_of_covBy
theorem _root_.OrderIso.map_succ [PartialOrder Ξ²] [SuccOrder Ξ²] (f : Ξ± βo Ξ²) (a : Ξ±) :
f (succ a) = succ (f a) := by
by_cases h : IsMax a
Β· rw [h.succ_eq, (f.isMax_apply.2 h).succ_eq]
Β· exact (f.map_covBy.2 <| covBy_succ_of_not_isMax h).succ_eq.symm
section NoMaxOrder
variable [NoMaxOrder Ξ±]
theorem succ_eq_iff_covBy : succ a = b β a β b :=
β¨by rintro rfl; exact covBy_succ _, CovBy.succ_eqβ©
end NoMaxOrder
section OrderTop
variable [OrderTop Ξ±]
@[simp]
theorem succ_top : succ (β€ : Ξ±) = β€ := by
rw [succ_eq_iff_isMax, isMax_iff_eq_top]
theorem succ_le_iff_eq_top : succ a β€ a β a = β€ :=
succ_le_iff_isMax.trans isMax_iff_eq_top
theorem lt_succ_iff_ne_top : a < succ a β a β β€ :=
lt_succ_iff_not_isMax.trans not_isMax_iff_ne_top
end OrderTop
section OrderBot
variable [OrderBot Ξ±] [Nontrivial Ξ±]
theorem bot_lt_succ (a : Ξ±) : β₯ < succ a :=
(lt_succ_of_not_isMax not_isMax_bot).trans_le <| succ_mono bot_le
theorem succ_ne_bot (a : Ξ±) : succ a β β₯ :=
(bot_lt_succ a).ne'
end OrderBot
end PartialOrder
section LinearOrder
variable [LinearOrder Ξ±] [SuccOrder Ξ±] {a b : Ξ±}
theorem le_of_lt_succ {a b : Ξ±} : a < succ b β a β€ b := fun h β¦ by
by_contra! nh
exact (h.trans_le (succ_le_of_lt nh)).false
theorem lt_succ_iff_of_not_isMax (ha : Β¬IsMax a) : b < succ a β b β€ a :=
β¨le_of_lt_succ, fun h => h.trans_lt <| lt_succ_of_not_isMax haβ©
theorem succ_lt_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) :
succ a < succ b β a < b := by
rw [lt_succ_iff_of_not_isMax hb, succ_le_iff_of_not_isMax ha]
theorem succ_le_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) :
succ a β€ succ b β a β€ b := by
rw [succ_le_iff_of_not_isMax ha, lt_succ_iff_of_not_isMax hb]
theorem Iio_succ_of_not_isMax (ha : Β¬IsMax a) : Iio (succ a) = Iic a :=
Set.ext fun _ => lt_succ_iff_of_not_isMax ha
theorem Ico_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ico a (succ b) = Icc a b := by
rw [β Ici_inter_Iio, Iio_succ_of_not_isMax hb, Ici_inter_Iic]
theorem Ioo_succ_right_of_not_isMax (hb : Β¬IsMax b) : Ioo a (succ b) = Ioc a b := by
rw [β Ioi_inter_Iio, Iio_succ_of_not_isMax hb, Ioi_inter_Iic]
theorem succ_eq_succ_iff_of_not_isMax (ha : Β¬IsMax a) (hb : Β¬IsMax b) :
succ a = succ b β a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, succ_le_succ_iff_of_not_isMax ha hb,
succ_lt_succ_iff_of_not_isMax ha hb]
theorem le_succ_iff_eq_or_le : a β€ succ b β a = succ b β¨ a β€ b := by
by_cases hb : IsMax b
Β· rw [hb.succ_eq, or_iff_right_of_imp le_of_eq]
Β· rw [β lt_succ_iff_of_not_isMax hb, le_iff_eq_or_lt]
theorem lt_succ_iff_eq_or_lt_of_not_isMax (hb : Β¬IsMax b) : a < succ b β a = b β¨ a < b :=
(lt_succ_iff_of_not_isMax hb).trans le_iff_eq_or_lt
theorem not_isMin_succ [Nontrivial Ξ±] (a : Ξ±) : Β¬ IsMin (succ a) := by
obtain ha | ha := (le_succ a).eq_or_lt
Β· exact (ha βΈ succ_eq_iff_isMax.1 ha.symm).not_isMin
Β· exact not_isMin_of_lt ha
theorem Iic_succ (a : Ξ±) : Iic (succ a) = insert (succ a) (Iic a) :=
ext fun _ => le_succ_iff_eq_or_le
theorem Icc_succ_right (h : a β€ succ b) : Icc a (succ b) = insert (succ b) (Icc a b) := by
simp_rw [β Ici_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ici.2 h)]
theorem Ioc_succ_right (h : a < succ b) : Ioc a (succ b) = insert (succ b) (Ioc a b) := by
simp_rw [β Ioi_inter_Iic, Iic_succ, inter_insert_of_mem (mem_Ioi.2 h)]
theorem Iio_succ_eq_insert_of_not_isMax (h : Β¬IsMax a) : Iio (succ a) = insert a (Iio a) :=
ext fun _ => lt_succ_iff_eq_or_lt_of_not_isMax h
theorem Ico_succ_right_eq_insert_of_not_isMax (hβ : a β€ b) (hβ : Β¬IsMax b) :
Ico a (succ b) = insert b (Ico a b) := by
simp_rw [β Iio_inter_Ici, Iio_succ_eq_insert_of_not_isMax hβ, insert_inter_of_mem (mem_Ici.2 hβ)]
theorem Ioo_succ_right_eq_insert_of_not_isMax (hβ : a < b) (hβ : Β¬IsMax b) :
Ioo a (succ b) = insert b (Ioo a b) := by
simp_rw [β Iio_inter_Ioi, Iio_succ_eq_insert_of_not_isMax hβ, insert_inter_of_mem (mem_Ioi.2 hβ)]
section NoMaxOrder
variable [NoMaxOrder Ξ±]
@[simp]
theorem lt_succ_iff : a < succ b β a β€ b :=
lt_succ_iff_of_not_isMax <| not_isMax b
theorem succ_le_succ_iff : succ a β€ succ b β a β€ b := by simp
theorem succ_lt_succ_iff : succ a < succ b β a < b := by simp
alias β¨le_of_succ_le_succ, _β© := succ_le_succ_iff
alias β¨lt_of_succ_lt_succ, _β© := succ_lt_succ_iff
-- TODO: prove for a succ-archimedean non-linear order with bottom
@[simp]
theorem Iio_succ (a : Ξ±) : Iio (succ a) = Iic a :=
Iio_succ_of_not_isMax <| not_isMax _
@[simp]
theorem Ico_succ_right (a b : Ξ±) : Ico a (succ b) = Icc a b :=
Ico_succ_right_of_not_isMax <| not_isMax _
-- TODO: prove for a succ-archimedean non-linear order
@[simp]
theorem Ioo_succ_right (a b : Ξ±) : Ioo a (succ b) = Ioc a b :=
Ioo_succ_right_of_not_isMax <| not_isMax _
@[simp]
theorem succ_eq_succ_iff : succ a = succ b β a = b :=
succ_eq_succ_iff_of_not_isMax (not_isMax a) (not_isMax b)
theorem succ_injective : Injective (succ : Ξ± β Ξ±) := fun _ _ => succ_eq_succ_iff.1
theorem succ_ne_succ_iff : succ a β succ b β a β b :=
succ_injective.ne_iff
alias β¨_, succ_ne_succβ© := succ_ne_succ_iff
theorem lt_succ_iff_eq_or_lt : a < succ b β a = b β¨ a < b :=
lt_succ_iff.trans le_iff_eq_or_lt
theorem Iio_succ_eq_insert (a : Ξ±) : Iio (succ a) = insert a (Iio a) :=
Iio_succ_eq_insert_of_not_isMax <| not_isMax a
theorem Ico_succ_right_eq_insert (h : a β€ b) : Ico a (succ b) = insert b (Ico a b) :=
Ico_succ_right_eq_insert_of_not_isMax h <| not_isMax b
theorem Ioo_succ_right_eq_insert (h : a < b) : Ioo a (succ b) = insert b (Ioo a b) :=
Ioo_succ_right_eq_insert_of_not_isMax h <| not_isMax b
@[simp]
theorem Ioo_eq_empty_iff_le_succ : Ioo a b = β
β b β€ succ a := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· contrapose! h
exact β¨succ a, lt_succ_iff_not_isMax.mpr (not_isMax a), hβ©
Β· ext x
suffices a < x β b β€ x by simpa
exact fun hx β¦ le_of_lt_succ <| lt_of_le_of_lt h <| succ_strictMono hx
end NoMaxOrder
section OrderBot
variable [OrderBot Ξ±]
theorem lt_succ_bot_iff [NoMaxOrder Ξ±] : a < succ β₯ β a = β₯ := by rw [lt_succ_iff, le_bot_iff]
theorem le_succ_bot_iff : a β€ succ β₯ β a = β₯ β¨ a = succ β₯ := by
rw [le_succ_iff_eq_or_le, le_bot_iff, or_comm]
end OrderBot
end LinearOrder
/-- There is at most one way to define the successors in a `PartialOrder`. -/
instance [PartialOrder Ξ±] : Subsingleton (SuccOrder Ξ±) :=
β¨by
intro hβ hβ
ext a
by_cases ha : IsMax a
Β· exact (@IsMax.succ_eq _ _ hβ _ ha).trans ha.succ_eq.symm
Β· exact @CovBy.succ_eq _ _ hβ _ _ (covBy_succ_of_not_isMax ha)β©
theorem succ_eq_sInf [CompleteLattice Ξ±] [SuccOrder Ξ±] (a : Ξ±) :
succ a = sInf (Set.Ioi a) := by
apply (le_sInf fun b => succ_le_of_lt).antisymm
obtain rfl | ha := eq_or_ne a β€
Β· rw [succ_top]
exact le_top
Β· exact sInf_le (lt_succ_iff_ne_top.2 ha)
theorem succ_eq_iInf [CompleteLattice Ξ±] [SuccOrder Ξ±] (a : Ξ±) : succ a = β¨
b > a, b := by
rw [succ_eq_sInf, iInf_subtype', iInf, Subtype.range_coe_subtype, Ioi]
theorem succ_eq_csInf [ConditionallyCompleteLattice Ξ±] [SuccOrder Ξ±] [NoMaxOrder Ξ±] (a : Ξ±) :
succ a = sInf (Set.Ioi a) := by
apply (le_csInf nonempty_Ioi fun b => succ_le_of_lt).antisymm
exact csInf_le β¨a, fun b => le_of_ltβ© <| lt_succ a
/-! ### Predecessor order -/
section Preorder
variable [Preorder Ξ±] [PredOrder Ξ±] {a b : Ξ±}
/-- The predecessor of an element. If `a` is not minimal, then `pred a` is the greatest element less
than `a`. If `a` is minimal, then `pred a = a`. -/
def pred : Ξ± β Ξ± :=
PredOrder.pred
theorem pred_le : β a : Ξ±, pred a β€ a :=
PredOrder.pred_le
theorem min_of_le_pred {a : Ξ±} : a β€ pred a β IsMin a :=
PredOrder.min_of_le_pred
theorem le_pred_of_lt {a b : Ξ±} : a < b β a β€ pred b :=
PredOrder.le_pred_of_lt
alias _root_.LT.lt.le_pred := le_pred_of_lt
@[simp]
theorem le_pred_iff_isMin : a β€ pred a β IsMin a :=
β¨min_of_le_pred, fun h => h <| pred_le _β©
alias β¨_root_.IsMin.of_le_pred, _root_.IsMin.le_predβ© := le_pred_iff_isMin
@[simp]
theorem pred_lt_iff_not_isMin : pred a < a β Β¬IsMin a :=
β¨not_isMin_of_lt, fun ha => (pred_le a).lt_of_not_ge fun h => ha <| min_of_le_pred hβ©
alias β¨_, pred_lt_of_not_isMinβ© := pred_lt_iff_not_isMin
theorem pred_wcovBy (a : Ξ±) : pred a β©Ώ a :=
β¨pred_le a, fun _ hb nh => (le_pred_of_lt nh).not_gt hbβ©
theorem pred_covBy_of_not_isMin (h : Β¬IsMin a) : pred a β a :=
(pred_wcovBy a).covBy_of_lt <| pred_lt_of_not_isMin h
theorem pred_lt_of_not_isMin_of_le (ha : Β¬IsMin a) : a β€ b β pred a < b :=
(pred_lt_of_not_isMin ha).trans_le
theorem le_pred_iff_of_not_isMin (ha : Β¬IsMin a) : b β€ pred a β b < a :=
β¨fun h => h.trans_lt <| pred_lt_of_not_isMin ha, le_pred_of_ltβ©
lemma pred_lt_pred_of_not_isMin (h : a < b) (ha : Β¬ IsMin a) : pred a < pred b :=
pred_lt_of_not_isMin_of_le ha <| le_pred_of_lt h
theorem pred_le_pred_of_not_isMin_of_le (ha : Β¬IsMin a) (hb : Β¬IsMin b) :
a β€ b β pred a β€ pred b := by
rw [le_pred_iff_of_not_isMin hb]
apply pred_lt_of_not_isMin_of_le ha
@[simp, mono, gcongr]
theorem pred_le_pred {a b : Ξ±} (h : a β€ b) : pred a β€ pred b :=
succ_le_succ h.dual
theorem pred_mono : Monotone (pred : Ξ± β Ξ±) := fun _ _ => pred_le_pred
/-- See also `Order.pred_eq_of_covBy`. -/
lemma pred_le_of_wcovBy (h : a β©Ώ b) : pred b β€ a := by
obtain hab | β¨-, hbaβ© := h.covBy_or_le_and_le
Β· by_contra hba
exact h.2 (hab.lt.le_pred.lt_of_not_ge hba) (pred_lt_of_not_isMin hab.lt.not_isMin)
Β· exact (pred_le _).trans hba
alias _root_.WCovBy.pred_le := pred_le_of_wcovBy
theorem pred_iterate_le (k : β) (x : Ξ±) : pred^[k] x β€ x := by
conv_rhs => rw [(by simp only [Function.iterate_id, id] : x = id^[k] x)]
exact Monotone.iterate_le_of_le pred_mono pred_le k x
theorem isMin_iterate_pred_of_eq_of_lt {n m : β} (h_eq : pred^[n] a = pred^[m] a)
(h_lt : n < m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_lt Ξ±α΅α΅ _ _ _ _ _ h_eq h_lt
theorem isMin_iterate_pred_of_eq_of_ne {n m : β} (h_eq : pred^[n] a = pred^[m] a)
(h_ne : n β m) : IsMin (pred^[n] a) :=
@isMax_iterate_succ_of_eq_of_ne Ξ±α΅α΅ _ _ _ _ _ h_eq h_ne
theorem Ici_subset_Ioi_pred_of_not_isMin (ha : Β¬IsMin a) : Ici a β Ioi (pred a) :=
fun _ β¦ pred_lt_of_not_isMin_of_le ha
theorem Iic_pred_of_not_isMin (ha : Β¬IsMin a) : Iic (pred a) = Iio a :=
Set.ext fun _ => le_pred_iff_of_not_isMin ha
theorem Icc_subset_Ioc_pred_left_of_not_isMin (ha : Β¬IsMin a) : Icc a b β Ioc (pred a) b := by
rw [β Ioi_inter_Iic, β Ici_inter_Iic]
gcongr
apply Ici_subset_Ioi_pred_of_not_isMin ha
theorem Ico_subset_Ioo_pred_left_of_not_isMin (ha : Β¬IsMin a) : Ico a b β Ioo (pred a) b := by
rw [β Ioi_inter_Iio, β Ici_inter_Iio]
gcongr
apply Ici_subset_Ioi_pred_of_not_isMin ha
theorem Icc_pred_right_of_not_isMin (ha : Β¬IsMin b) : Icc a (pred b) = Ico a b := by
rw [β Ici_inter_Iic, Iic_pred_of_not_isMin ha, Ici_inter_Iio]
theorem Ioc_pred_right_of_not_isMin (ha : Β¬IsMin b) : Ioc a (pred b) = Ioo a b := by
rw [β Ioi_inter_Iic, Iic_pred_of_not_isMin ha, Ioi_inter_Iio]
section NoMinOrder
variable [NoMinOrder Ξ±]
theorem pred_lt (a : Ξ±) : pred a < a :=
pred_lt_of_not_isMin <| not_isMin a
@[simp]
theorem pred_lt_of_le : a β€ b β pred a < b :=
pred_lt_of_not_isMin_of_le <| not_isMin a
@[simp]
theorem le_pred_iff : a β€ pred b β a < b :=
le_pred_iff_of_not_isMin <| not_isMin b
theorem pred_le_pred_of_le : a β€ b β pred a β€ pred b := by intro; simp_all
theorem pred_lt_pred : a < b β pred a < pred b := by intro; simp_all
theorem pred_strictMono : StrictMono (pred : Ξ± β Ξ±) := fun _ _ => pred_lt_pred
theorem pred_covBy (a : Ξ±) : pred a β a :=
pred_covBy_of_not_isMin <| not_isMin a
theorem Ici_subset_Ioi_pred (a : Ξ±) : Ici a β Ioi (pred a) := by simp
@[simp]
theorem Iic_pred (a : Ξ±) : Iic (pred a) = Iio a :=
Iic_pred_of_not_isMin <| not_isMin a
@[simp]
theorem Icc_subset_Ioc_pred_left (a b : Ξ±) : Icc a b β Ioc (pred a) b :=
Icc_subset_Ioc_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Ico_subset_Ioo_pred_left (a b : Ξ±) : Ico a b β Ioo (pred a) b :=
Ico_subset_Ioo_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem Icc_pred_right (a b : Ξ±) : Icc a (pred b) = Ico a b :=
Icc_pred_right_of_not_isMin <| not_isMin _
@[simp]
theorem Ioc_pred_right (a b : Ξ±) : Ioc a (pred b) = Ioo a b :=
Ioc_pred_right_of_not_isMin <| not_isMin _
end NoMinOrder
end Preorder
section PartialOrder
variable [PartialOrder Ξ±] [PredOrder Ξ±] {a b : Ξ±}
@[simp]
theorem pred_eq_iff_isMin : pred a = a β IsMin a :=
β¨fun h => min_of_le_pred h.ge, fun h => h.eq_of_le <| pred_le _β©
alias β¨_, _root_.IsMin.pred_eqβ© := pred_eq_iff_isMin
lemma le_iff_eq_or_le_pred : a β€ b β a = b β¨ a β€ pred b := by
by_cases hb : IsMin b
Β· simpa [hb.pred_eq] using le_of_eq
Β· rw [le_pred_iff_of_not_isMin hb, le_iff_eq_or_lt]
theorem pred_le_le_iff {a b : Ξ±} : pred a β€ b β§ b β€ a β b = a β¨ b = pred a := by
refine
β¨fun h =>
or_iff_not_imp_left.2 fun hba : b β a => (le_pred_of_lt <| h.2.lt_of_ne hba).antisymm h.1, ?_β©
rintro (rfl | rfl)
Β· exact β¨pred_le b, le_rflβ©
Β· exact β¨le_rfl, pred_le aβ©
/-- See also `Order.pred_le_of_wcovBy`. -/
lemma pred_eq_of_covBy (h : a β b) : pred b = a := h.wcovBy.pred_le.antisymm (le_pred_of_lt h.lt)
alias _root_.CovBy.pred_eq := pred_eq_of_covBy
theorem _root_.OrderIso.map_pred {Ξ² : Type*} [PartialOrder Ξ²] [PredOrder Ξ²] (f : Ξ± βo Ξ²) (a : Ξ±) :
f (pred a) = pred (f a) :=
f.dual.map_succ a
section NoMinOrder
variable [NoMinOrder Ξ±]
theorem pred_eq_iff_covBy : pred b = a β a β b :=
β¨by
rintro rfl
exact pred_covBy _, CovBy.pred_eqβ©
end NoMinOrder
section OrderBot
variable [OrderBot Ξ±]
@[simp]
theorem pred_bot : pred (β₯ : Ξ±) = β₯ :=
isMin_bot.pred_eq
theorem le_pred_iff_eq_bot : a β€ pred a β a = β₯ :=
@succ_le_iff_eq_top Ξ±α΅α΅ _ _ _ _
theorem pred_lt_iff_ne_bot : pred a < a β a β β₯ :=
@lt_succ_iff_ne_top Ξ±α΅α΅ _ _ _ _
end OrderBot
section OrderTop
variable [OrderTop Ξ±] [Nontrivial Ξ±]
theorem pred_lt_top (a : Ξ±) : pred a < β€ :=
(pred_mono le_top).trans_lt <| pred_lt_of_not_isMin not_isMin_top
theorem pred_ne_top (a : Ξ±) : pred a β β€ :=
(pred_lt_top a).ne
end OrderTop
end PartialOrder
section LinearOrder
variable [LinearOrder Ξ±] [PredOrder Ξ±] {a b : Ξ±}
theorem le_of_pred_lt {a b : Ξ±} : pred a < b β a β€ b := fun h β¦ by
by_contra! nh
exact le_pred_of_lt nh |>.trans_lt h |>.false
theorem pred_lt_iff_of_not_isMin (ha : Β¬IsMin a) : pred a < b β a β€ b :=
β¨le_of_pred_lt, (pred_lt_of_not_isMin ha).trans_leβ©
theorem pred_lt_pred_iff_of_not_isMin (ha : Β¬IsMin a) (hb : Β¬IsMin b) :
pred a < pred b β a < b := by
rw [pred_lt_iff_of_not_isMin ha, le_pred_iff_of_not_isMin hb]
theorem pred_le_pred_iff_of_not_isMin (ha : Β¬IsMin a) (hb : Β¬IsMin b) :
pred a β€ pred b β a β€ b := by
rw [le_pred_iff_of_not_isMin hb, pred_lt_iff_of_not_isMin ha]
theorem Ioi_pred_of_not_isMin (ha : Β¬IsMin a) : Ioi (pred a) = Ici a :=
Set.ext fun _ => pred_lt_iff_of_not_isMin ha
theorem Ioc_pred_left_of_not_isMin (ha : Β¬IsMin a) : Ioc (pred a) b = Icc a b := by
rw [β Ioi_inter_Iic, Ioi_pred_of_not_isMin ha, Ici_inter_Iic]
theorem Ioo_pred_left_of_not_isMin (ha : Β¬IsMin a) : Ioo (pred a) b = Ico a b := by
rw [β Ioi_inter_Iio, Ioi_pred_of_not_isMin ha, Ici_inter_Iio]
theorem pred_eq_pred_iff_of_not_isMin (ha : Β¬IsMin a) (hb : Β¬IsMin b) :
pred a = pred b β a = b := by
rw [eq_iff_le_not_lt, eq_iff_le_not_lt, pred_le_pred_iff_of_not_isMin ha hb,
pred_lt_pred_iff_of_not_isMin ha hb]
theorem pred_le_iff_eq_or_le : pred a β€ b β b = pred a β¨ a β€ b := by
by_cases ha : IsMin a
Β· rw [ha.pred_eq, or_iff_right_of_imp ge_of_eq]
Β· rw [β pred_lt_iff_of_not_isMin ha, le_iff_eq_or_lt, eq_comm]
theorem pred_lt_iff_eq_or_lt_of_not_isMin (ha : Β¬IsMin a) : pred a < b β a = b β¨ a < b :=
(pred_lt_iff_of_not_isMin ha).trans le_iff_eq_or_lt
theorem not_isMax_pred [Nontrivial Ξ±] (a : Ξ±) : Β¬ IsMax (pred a) :=
not_isMin_succ (Ξ± := Ξ±α΅α΅) a
theorem Ici_pred (a : Ξ±) : Ici (pred a) = insert (pred a) (Ici a) :=
ext fun _ => pred_le_iff_eq_or_le
theorem Ioi_pred_eq_insert_of_not_isMin (ha : Β¬IsMin a) : Ioi (pred a) = insert a (Ioi a) := by
ext x; simp only [insert, mem_setOf, @eq_comm _ x a, mem_Ioi, Set.insert]
exact pred_lt_iff_eq_or_lt_of_not_isMin ha
theorem Icc_pred_left (h : pred a β€ b) : Icc (pred a) b = insert (pred a) (Icc a b) := by
simp_rw [β Ici_inter_Iic, Ici_pred, insert_inter_of_mem (mem_Iic.2 h)]
theorem Ico_pred_left (h : pred a < b) : Ico (pred a) b = insert (pred a) (Ico a b) := by
simp_rw [β Ici_inter_Iio, Ici_pred, insert_inter_of_mem (mem_Iio.2 h)]
section NoMinOrder
variable [NoMinOrder Ξ±]
@[simp]
theorem pred_lt_iff : pred a < b β a β€ b :=
pred_lt_iff_of_not_isMin <| not_isMin a
theorem pred_le_pred_iff : pred a β€ pred b β a β€ b := by simp
theorem pred_lt_pred_iff : pred a < pred b β a < b := by simp
alias β¨le_of_pred_le_pred, _β© := pred_le_pred_iff
alias β¨lt_of_pred_lt_pred, _β© := pred_lt_pred_iff
-- TODO: prove for a pred-archimedean non-linear order with top
@[simp]
theorem Ioi_pred (a : Ξ±) : Ioi (pred a) = Ici a :=
Ioi_pred_of_not_isMin <| not_isMin a
@[simp]
theorem Ioc_pred_left (a b : Ξ±) : Ioc (pred a) b = Icc a b :=
Ioc_pred_left_of_not_isMin <| not_isMin _
-- TODO: prove for a pred-archimedean non-linear order
@[simp]
theorem Ioo_pred_left (a b : Ξ±) : Ioo (pred a) b = Ico a b :=
Ioo_pred_left_of_not_isMin <| not_isMin _
@[simp]
theorem pred_eq_pred_iff : pred a = pred b β a = b := by
simp_rw [eq_iff_le_not_lt, pred_le_pred_iff, pred_lt_pred_iff]
theorem pred_injective : Injective (pred : Ξ± β Ξ±) := fun _ _ => pred_eq_pred_iff.1
theorem pred_ne_pred_iff : pred a β pred b β a β b :=
pred_injective.ne_iff
alias β¨_, pred_ne_predβ© := pred_ne_pred_iff
theorem pred_lt_iff_eq_or_lt : pred a < b β a = b β¨ a < b :=
pred_lt_iff.trans le_iff_eq_or_lt
theorem Ioi_pred_eq_insert (a : Ξ±) : Ioi (pred a) = insert a (Ioi a) :=
ext fun _ => pred_lt_iff_eq_or_lt.trans <| or_congr_left eq_comm
theorem Ico_pred_right_eq_insert (h : a β€ b) : Ioc (pred a) b = insert a (Ioc a b) := by
simp_rw [β Ioi_inter_Iic, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iic.2 h)]
theorem Ioo_pred_right_eq_insert (h : a < b) : Ioo (pred a) b = insert a (Ioo a b) := by
simp_rw [β Ioi_inter_Iio, Ioi_pred_eq_insert, insert_inter_of_mem (mem_Iio.2 h)]
@[simp]
theorem Ioo_eq_empty_iff_pred_le : Ioo a b = β
β pred b β€ a := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· contrapose! h
exact β¨pred b, h, pred_lt_iff_not_isMin.mpr (not_isMin b)β©
Β· ext x
suffices a < x β b β€ x by simpa
exact fun hx β¦ le_of_pred_lt <| lt_of_le_of_lt h hx
end NoMinOrder
section OrderTop
variable [OrderTop Ξ±]
theorem pred_top_lt_iff [NoMinOrder Ξ±] : pred β€ < a β a = β€ :=
@lt_succ_bot_iff Ξ±α΅α΅ _ _ _ _ _
theorem pred_top_le_iff : pred β€ β€ a β a = β€ β¨ a = pred β€ :=
@le_succ_bot_iff Ξ±α΅α΅ _ _ _ _
end OrderTop
end LinearOrder
/-- There is at most one way to define the predecessors in a `PartialOrder`. -/
instance [PartialOrder Ξ±] : Subsingleton (PredOrder Ξ±) :=
β¨by
intro hβ hβ
ext a
by_cases ha : IsMin a
Β· exact (@IsMin.pred_eq _ _ hβ _ ha).trans ha.pred_eq.symm
Β· exact @CovBy.pred_eq _ _ hβ _ _ (pred_covBy_of_not_isMin ha)β©
theorem pred_eq_sSup [CompleteLattice Ξ±] [PredOrder Ξ±] :
β a : Ξ±, pred a = sSup (Set.Iio a) :=
succ_eq_sInf (Ξ± := Ξ±α΅α΅)
theorem pred_eq_iSup [CompleteLattice Ξ±] [PredOrder Ξ±] (a : Ξ±) : pred a = β¨ b < a, b :=
succ_eq_iInf (Ξ± := Ξ±α΅α΅) a
theorem pred_eq_csSup [ConditionallyCompleteLattice Ξ±] [PredOrder Ξ±] [NoMinOrder Ξ±] (a : Ξ±) :
pred a = sSup (Set.Iio a) :=
succ_eq_csInf (Ξ± := Ξ±α΅α΅) a
/-! ### Successor-predecessor orders -/
section SuccPredOrder
section Preorder
variable [Preorder Ξ±] [SuccOrder Ξ±] [PredOrder Ξ±] {a b : Ξ±}
lemma le_succ_pred (a : Ξ±) : a β€ succ (pred a) := (pred_wcovBy _).le_succ
lemma pred_succ_le (a : Ξ±) : pred (succ a) β€ a := (wcovBy_succ _).pred_le
lemma pred_le_iff_le_succ : pred a β€ b β a β€ succ b where
mp hab := (le_succ_pred _).trans (succ_mono hab)
mpr hab := (pred_mono hab).trans (pred_succ_le _)
lemma gc_pred_succ : GaloisConnection (pred : Ξ± β Ξ±) succ := fun _ _ β¦ pred_le_iff_le_succ
end Preorder
variable [PartialOrder Ξ±] [SuccOrder Ξ±] [PredOrder Ξ±] {a : Ξ±}
@[simp]
theorem succ_pred_of_not_isMin (h : Β¬IsMin a) : succ (pred a) = a :=
CovBy.succ_eq (pred_covBy_of_not_isMin h)
@[simp]
theorem pred_succ_of_not_isMax (h : Β¬IsMax a) : pred (succ a) = a :=
CovBy.pred_eq (covBy_succ_of_not_isMax h)
theorem succ_pred [NoMinOrder Ξ±] (a : Ξ±) : succ (pred a) = a :=
CovBy.succ_eq (pred_covBy _)
theorem pred_succ [NoMaxOrder Ξ±] (a : Ξ±) : pred (succ a) = a :=
CovBy.pred_eq (covBy_succ _)
theorem pred_succ_iterate_of_not_isMax (i : Ξ±) (n : β) (hin : Β¬IsMax (succ^[n - 1] i)) :
pred^[n] (succ^[n] i) = i := by
induction n with
| zero => simp only [Function.iterate_zero, id]
| succ n hn =>
rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hin
have h_not_max : Β¬IsMax (succ^[n - 1] i) := by
rcases n with - | n
Β· simpa using hin
rw [Nat.succ_sub_succ_eq_sub, Nat.sub_zero] at hn β’
have h_sub_le : succ^[n] i β€ succ^[n.succ] i := by
rw [Function.iterate_succ']
exact le_succ _
refine fun h_max => hin fun j hj => ?_
have hj_le : j β€ succ^[n] i := h_max (h_sub_le.trans hj)
exact hj_le.trans h_sub_le
rw [Function.iterate_succ, Function.iterate_succ']
simp only [Function.comp_apply]
rw [pred_succ_of_not_isMax hin]
exact hn h_not_max
theorem succ_pred_iterate_of_not_isMin (i : Ξ±) (n : β) (hin : Β¬IsMin (pred^[n - 1] i)) :
succ^[n] (pred^[n] i) = i :=
@pred_succ_iterate_of_not_isMax Ξ±α΅α΅ _ _ _ i n hin
end SuccPredOrder
end Order
open Order
/-! ### `WithBot`, `WithTop`
Adding a greatest/least element to a `SuccOrder` or to a `PredOrder`.
As far as successors and predecessors are concerned, there are four ways to add a bottom or top
element to an order:
* Adding a `β€` to an `OrderTop`: Preserves `succ` and `pred`.
* Adding a `β€` to a `NoMaxOrder`: Preserves `succ`. Never preserves `pred`.
* Adding a `β₯` to an `OrderBot`: Preserves `succ` and `pred`.
* Adding a `β₯` to a `NoMinOrder`: Preserves `pred`. Never preserves `succ`.
where "preserves `(succ/pred)`" means
`(Succ/Pred)Order Ξ± β (Succ/Pred)Order ((WithTop/WithBot) Ξ±)`.
-/
namespace WithTop
/-! #### Adding a `β€` to an `OrderTop` -/
section Succ
variable [PartialOrder Ξ±] [SuccOrder Ξ±] [β a : Ξ±, Decidable (succ a = a)]
instance : SuccOrder (WithTop Ξ±) where
succ a :=
match a with
| β€ => β€
| Option.some a => ite (succ a = a) β€ (some (succ a))
le_succ a := by
obtain - | a := a
Β· exact le_top
change _ β€ ite _ _ _
split_ifs
Β· exact le_top
Β· exact coe_le_coe.2 (le_succ a)
max_of_succ_le {a} ha := by
cases a
Β· exact isMax_top
dsimp only at ha
split_ifs at ha with ha'
Β· exact (not_top_le_coe _ ha).elim
Β· rw [coe_le_coe, succ_le_iff_isMax, β succ_eq_iff_isMax] at ha
exact (ha' ha).elim
succ_le_of_lt {a b} h := by
cases b
Β· exact le_top
cases a
Β· exact (not_top_lt h).elim
rw [coe_lt_coe] at h
change ite _ _ _ β€ _
split_ifs with ha
Β· rw [succ_eq_iff_isMax] at ha
exact (ha.not_lt h).elim
Β· exact coe_le_coe.2 (succ_le_of_lt h)
@[simp]
theorem succ_coe_of_isMax {a : Ξ±} (h : IsMax a) : succ βa = (β€ : WithTop Ξ±) :=
dif_pos (succ_eq_iff_isMax.2 h)
theorem succ_coe_of_not_isMax {a : Ξ±} (h : Β¬ IsMax a) : succ (βa : WithTop Ξ±) = β(succ a) :=
dif_neg (succ_eq_iff_isMax.not.2 h)
@[simp]
theorem succ_coe [NoMaxOrder Ξ±] {a : Ξ±} : succ (βa : WithTop Ξ±) = β(succ a) :=
succ_coe_of_not_isMax <| not_isMax a
end Succ
section Pred
variable [Preorder Ξ±] [OrderTop Ξ±] [PredOrder Ξ±]
instance : PredOrder (WithTop Ξ±) where
pred a :=
match a with
| β€ => some β€
| Option.some a => some (pred a)
pred_le a :=
match a with
| β€ => le_top
| Option.some a => coe_le_coe.2 (pred_le a)
min_of_le_pred {a} ha := by
cases a
Β· exact ((coe_lt_top (β€ : Ξ±)).not_ge ha).elim
Β· exact (min_of_le_pred <| coe_le_coe.1 ha).withTop
le_pred_of_lt {a b} h := by
cases a
Β· exact (le_top.not_gt h).elim
cases b
Β· exact coe_le_coe.2 le_top
exact coe_le_coe.2 (le_pred_of_lt <| coe_lt_coe.1 h)
/-- Not to be confused with `WithTop.pred_bot`, which is about `WithTop.pred`. -/
@[simp] lemma orderPred_top : pred (β€ : WithTop Ξ±) = β(β€ : Ξ±) := rfl
/-- Not to be confused with `WithTop.pred_coe`, which is about `WithTop.pred`. -/
@[simp] lemma orderPred_coe (a : Ξ±) : pred (βa : WithTop Ξ±) = β(pred a) := rfl
@[simp]
theorem pred_untop :
β (a : WithTop Ξ±) (ha : a β β€),
pred (a.untop ha) = (pred a).untop (by induction a <;> simp)
| β€, ha => (ha rfl).elim
| (a : Ξ±), _ => rfl
end Pred
section Pred
variable [Preorder Ξ±] [NoMaxOrder Ξ±]
instance [hΞ± : Nonempty Ξ±] : IsEmpty (PredOrder (WithTop Ξ±)) :=
β¨by
intro
cases h : pred (β€ : WithTop Ξ±) with
| top => exact hΞ±.elim fun a => (min_of_le_pred h.ge).not_lt <| coe_lt_top a
| coe a =>
obtain β¨c, hcβ© := exists_gt a
rw [β coe_lt_coe, β h] at hc
exact (le_pred_of_lt (coe_lt_top c)).not_gt hcβ©
end Pred
end WithTop
namespace WithBot
/-! #### Adding a `β₯` to an `OrderBot` -/
section Succ
variable [Preorder Ξ±] [OrderBot Ξ±] [SuccOrder Ξ±]
instance : SuccOrder (WithBot Ξ±) where
succ a :=
match a with
| β₯ => some β₯
| Option.some a => some (succ a)
le_succ a :=
match a with
| β₯ => bot_le
| Option.some a => coe_le_coe.2 (le_succ a)
max_of_succ_le {a} ha := by
cases a
Β· exact ((bot_lt_coe (β₯ : Ξ±)).not_ge ha).elim
Β· exact (max_of_succ_le <| coe_le_coe.1 ha).withBot
succ_le_of_lt {a b} h := by
cases b
Β· exact (not_lt_bot h).elim
cases a
Β· exact coe_le_coe.2 bot_le
Β· exact coe_le_coe.2 (succ_le_of_lt <| coe_lt_coe.1 h)
/-- Not to be confused with `WithBot.succ_bot`, which is about `WithBot.succ`. -/
@[simp] lemma orderSucc_bot : succ (β₯ : WithBot Ξ±) = β(β₯ : Ξ±) := rfl
/-- Not to be confused with `WithBot.succ_coe`, which is about `WithBot.succ`. -/
@[simp] lemma orderSucc_coe (a : Ξ±) : succ (βa : WithBot Ξ±) = β(succ a) := rfl
@[simp]
theorem succ_unbot :
β (a : WithBot Ξ±) (ha : a β β₯),
succ (a.unbot ha) = (succ a).unbot (by induction a <;> simp)
| β₯, ha => (ha rfl).elim
| (a : Ξ±), _ => rfl
end Succ
section Pred
variable [PartialOrder Ξ±] [PredOrder Ξ±] [β a : Ξ±, Decidable (pred a = a)]
instance : PredOrder (WithBot Ξ±) where
pred a :=
match a with
| β₯ => β₯
| Option.some a => ite (pred a = a) β₯ (some (pred a))
pred_le a := by
obtain - | a := a
Β· exact bot_le
change ite _ _ _ β€ _
split_ifs
Β· exact bot_le
Β· exact coe_le_coe.2 (pred_le a)
min_of_le_pred {a} ha := by
cases a with
| bot => exact isMin_bot
| coe a =>
dsimp only at ha
split_ifs at ha with ha'
Β· exact (not_coe_le_bot _ ha).elim
Β· rw [coe_le_coe, le_pred_iff_isMin, β pred_eq_iff_isMin] at ha
exact (ha' ha).elim
le_pred_of_lt {a b} h := by
cases a
Β· exact bot_le
cases b
Β· exact (not_lt_bot h).elim
rw [coe_lt_coe] at h
change _ β€ ite _ _ _
split_ifs with hb
Β· rw [pred_eq_iff_isMin] at hb
exact (hb.not_lt h).elim
Β· exact coe_le_coe.2 (le_pred_of_lt h)
@[simp]
theorem pred_coe_of_isMin {a : Ξ±} (h : IsMin a) : pred βa = (β₯ : WithBot Ξ±) :=
dif_pos (pred_eq_iff_isMin.2 h)
theorem pred_coe_of_not_isMin {a : Ξ±} (h : Β¬ IsMin a) : pred (βa : WithBot Ξ±) = β(pred a) :=
dif_neg (pred_eq_iff_isMin.not.2 h)
theorem pred_coe [NoMinOrder Ξ±] {a : Ξ±} : pred (βa : WithBot Ξ±) = β(pred a) :=
pred_coe_of_not_isMin <| not_isMin a
end Pred
/-! #### Adding a `β₯` to a `NoMinOrder` -/
section Succ
variable [Preorder Ξ±] [NoMinOrder Ξ±]
instance [hΞ± : Nonempty Ξ±] : IsEmpty (SuccOrder (WithBot Ξ±)) :=
β¨by
intro
cases h : succ (β₯ : WithBot Ξ±) with
| bot => exact hΞ±.elim fun a => (max_of_succ_le h.le).not_lt <| bot_lt_coe a
| coe a =>
obtain β¨c, hcβ© := exists_lt a
rw [β coe_lt_coe, β h] at hc
exact (succ_le_of_lt (bot_lt_coe _)).not_gt hcβ©
end Succ
end WithBot
section OrderIso
variable {X Y : Type*} [Preorder X] [Preorder Y]
-- See note [reducible non instances]
/-- `SuccOrder` transfers across equivalences between orders. -/
protected abbrev SuccOrder.ofOrderIso [SuccOrder X] (f : X βo Y) : SuccOrder Y where
succ y := f (succ (f.symm y))
le_succ y := by rw [β map_inv_le_iff f]; exact le_succ (f.symm y)
max_of_succ_le h := by
rw [β f.symm.isMax_apply]
refine max_of_succ_le ?_
simp [f.le_symm_apply, h]
succ_le_of_lt h := by rw [β le_map_inv_iff]; exact succ_le_of_lt (by simp [h])
-- See note [reducible non instances]
/-- `PredOrder` transfers across equivalences between orders. -/
protected abbrev PredOrder.ofOrderIso [PredOrder X] (f : X βo Y) :
PredOrder Y where
pred y := f (pred (f.symm y))
pred_le y := by rw [β le_map_inv_iff f]; exact pred_le (f.symm y)
min_of_le_pred h := by
rw [β f.symm.isMin_apply]
refine min_of_le_pred ?_
simp [f.symm_apply_le, h]
le_pred_of_lt h := by rw [β map_inv_le_iff]; exact le_pred_of_lt (by simp [h])
end OrderIso
section OrdConnected
variable {Ξ± : Type*} [PartialOrder Ξ±] {s : Set Ξ±} [s.OrdConnected]
open scoped Classical in
noncomputable instance Set.OrdConnected.predOrder [PredOrder Ξ±] :
PredOrder s where
pred x := if h : Order.pred x.1 β s then β¨Order.pred x.1, hβ© else x
pred_le := fun β¨x, hxβ© β¦ by dsimp; split <;> simp_all [Order.pred_le]
min_of_le_pred := @fun β¨x, hxβ© h β¦ by
dsimp at h
split_ifs at h with h'
Β· simp only [Subtype.mk_le_mk, Order.le_pred_iff_isMin] at h
rintro β¨y, _β© hy
simp [h hy]
Β· rintro β¨y, hyβ© h
rcases h.lt_or_eq with h | h
Β· simp only [Subtype.mk_lt_mk] at h
have := h.le_pred
absurd h'
apply out' hy hx
simp [this, Order.pred_le]
Β· simp [h]
le_pred_of_lt := @fun β¨b, hbβ© β¨c, hcβ© h β¦ by
rw [Subtype.mk_lt_mk] at h
dsimp only
split
Β· exact h.le_pred
Β· exact h.le
@[simp, norm_cast]
lemma coe_pred_of_mem [PredOrder Ξ±] {a : s} (h : pred a.1 β s) :
(pred a).1 = pred βa := by classical
change Subtype.val (dite ..) = _
simp [h]
lemma isMin_of_pred_notMem [PredOrder Ξ±] {a : s} (h : pred βa β s) : IsMin a := by classical
rw [β pred_eq_iff_isMin]
change dite .. = _
simp [h]
@[deprecated (since := "2025-05-23")]
alias isMin_of_not_pred_mem := isMin_of_pred_notMem
lemma pred_notMem_iff_isMin [PredOrder Ξ±] [NoMinOrder Ξ±] {a : s} :
pred βa β s β IsMin a where
mp := isMin_of_pred_notMem
mpr h nh := by
replace h := congr($h.pred_eq.1)
rw [coe_pred_of_mem nh] at h
simp at h
@[deprecated (since := "2025-05-23")]
alias not_pred_mem_iff_isMin := pred_notMem_iff_isMin
noncomputable instance Set.OrdConnected.succOrder [SuccOrder Ξ±] :
SuccOrder s :=
letI : PredOrder sα΅α΅ := inferInstanceAs (PredOrder (OrderDual.ofDual β»ΒΉ' s))
inferInstanceAs (SuccOrder sα΅α΅α΅α΅)
@[simp, norm_cast]
lemma coe_succ_of_mem [SuccOrder Ξ±] {a : s} (h : succ βa β s) :
(succ a).1 = succ βa := by classical
change Subtype.val (dite ..) = _
split_ifs <;> trivial
lemma isMax_of_succ_notMem [SuccOrder Ξ±] {a : s} (h : succ βa β s) : IsMax a := by
classical
rw [β succ_eq_iff_isMax]
change dite .. = _
split_ifs <;> trivial
@[deprecated (since := "2025-05-23")]
alias isMax_of_not_succ_mem := isMax_of_succ_notMem
lemma succ_notMem_iff_isMax [SuccOrder Ξ±] [NoMaxOrder Ξ±] {a : s} :
succ βa β s β IsMax a where
mp := isMax_of_succ_notMem
mpr h nh := by
replace h := congr($h.succ_eq.1)
rw [coe_succ_of_mem nh] at h
simp at h
@[deprecated (since := "2025-05-23")]
alias not_succ_mem_iff_isMax := succ_notMem_iff_isMax
end OrdConnected
|
Slice.lean
|
import Mathlib.Tactic.CategoryTheory.Slice
open CategoryTheory
variable (C : Type) [Category C] (X Y Z W U : C)
variable (fβ fβ : X βΆ Y) (g gβ gβ : Y βΆ Z) (h : Z βΆ W) (l : W βΆ U)
set_option linter.unusedTactic false in
example (hyp : fβ β« gβ = fβ β« gβ) : fβ β« gβ β« h β« l = (fβ β« gβ) β« (h β« l) := by
conv =>
rhs
slice 2 3
show fβ β« gβ β« h β« l = fβ β« (gβ β« h) β« l
conv =>
lhs
slice 1 2
rw [hyp]
show ((fβ β« gβ) β« h) β« l = fβ β« (gβ β« h) β« l
conv =>
lhs
slice 2 3
example (hyp : fβ β« gβ = fβ β« gβ) : fβ β« gβ β« h β« l = (fβ β« gβ) β« (h β« l) := by
slice_lhs 1 2 => { rw [hyp] }; slice_rhs 1 2 => skip
example (hβ : fβ = fβ) : fβ β« g β« h β« l = ((fβ β« g) β« h) β« l := by
slice_lhs 1 1 => rw [hβ]
example (hβ : fβ = fβ) : ((fβ β« g) β« h) β« l = fβ β« g β« h β« l := by
slice_rhs 1 1 => rw [hβ]
|
all_solvable.v
|
From mathcomp Require Export abelian.
From mathcomp Require Export alt.
From mathcomp Require Export burnside_app.
From mathcomp Require Export center.
From mathcomp Require Export commutator.
From mathcomp Require Export cyclic.
From mathcomp Require Export extraspecial.
From mathcomp Require Export extremal.
From mathcomp Require Export finmodule.
From mathcomp Require Export frobenius.
From mathcomp Require Export gfunctor.
From mathcomp Require Export gseries.
From mathcomp Require Export hall.
From mathcomp Require Export jordanholder.
From mathcomp Require Export maximal.
From mathcomp Require Export nilpotent.
From mathcomp Require Export pgroup.
From mathcomp Require Export primitive_action.
From mathcomp Require Export sylow.
|
galois.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 ssralg poly.
From mathcomp Require Import polydiv finset fingroup morphism quotient perm.
From mathcomp Require Import action zmodp cyclic matrix mxalgebra vector.
From mathcomp Require Import falgebra fieldext separable.
(******************************************************************************)
(* Basic Galois field theory *)
(* *)
(* This file defines: *)
(* splittingFieldFor K p E <-> E is the smallest field over K that splits p *)
(* into linear factors *)
(* kHom K E f <=> f : 'End(L) is a ring morphism on E and fixes K *)
(* kAut K E f <=> f : 'End(L) is a kHom K E and f @: E == E *)
(* kHomExtend E f x y == a kHom K <<E; x>> that extends f and maps x to y, *)
(* when f \is a kHom K E and root (minPoly E x) y *)
(* splittingFieldType F == the interface type of splitting field extensions *)
(* of F, that is, extensions generated by all the *)
(* algebraic roots of some polynomial, or, *)
(* equivalently, normal field extensions of F *)
(* The HB class is called SplittingField. *)
(* splitting_field_axiom F L == the axiom stating that L is a splitting field *)
(* gal_of E == the group_type of automorphisms of E over the *)
(* base field F *)
(* 'Gal(E / K) == the group of automorphisms of E that fix K *)
(* fixedField s == the field fixed by the set of automorphisms s *)
(* fixedField set0 = E when set0 : {set: gal_of E} *)
(* normalField K E <=> E is invariant for every 'Gal(L / K) for every L *)
(* galois K E <=> E is a normal and separable field extension of K *)
(* galTrace K E a == \sum_(f in 'Gal(E / K)) (f a) *)
(* galNorm K E a == \prod_(f in 'Gal(E / K)) (f a) *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Reserved Notation "''Gal' ( A / B )"
(A at level 35, format "''Gal' ( A / B )").
Import GroupScope GRing.Theory.
Local Open Scope ring_scope.
Section SplittingFieldFor.
Variables (F : fieldType) (L : fieldExtType F).
Definition splittingFieldFor (U : {vspace L}) (p : {poly L}) (V : {vspace L}) :=
exists2 rs, p %= \prod_(z <- rs) ('X - z%:P) & <<U & rs>>%VS = V.
Lemma splittingFieldForS (K M E : {subfield L}) p :
(K <= M)%VS -> (M <= E)%VS ->
splittingFieldFor K p E -> splittingFieldFor M p E.
Proof.
move=> sKM sKE [rs Dp genL]; exists rs => //; apply/eqP.
rewrite eqEsubv -[in X in _ && (X <= _)%VS]genL adjoin_seqSl // andbT.
by apply/Fadjoin_seqP; split; rewrite // -genL; apply: seqv_sub_adjoin.
Qed.
End SplittingFieldFor.
Section kHom.
Variables (F : fieldType) (L : fieldExtType F).
Implicit Types (U V : {vspace L}) (K E : {subfield L}) (f g : 'End(L)).
Definition kHom U V f := ahom_in V f && (U <= fixedSpace f)%VS.
Lemma kHomP_tmp {K V f} :
reflect [/\ {in K, forall x, f x = x} &
{in V &, forall x y, f (x * y) = f x * f y}]
(kHom K V f).
Proof.
apply: (iffP andP) => [[/ahom_inP[fM _] /subvP idKf] | [idKf fM]].
by split=> // x /idKf/fixedSpaceP.
split; last by apply/subvP=> x /idKf/fixedSpaceP.
by apply/ahom_inP; split=> //; rewrite idKf ?mem1v.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `kHomP_tmp` instead")]
Lemma kHomP {K V f} :
reflect [/\ {in V &, forall x y, f (x * y) = f x * f y} &
{in K, forall x, f x = x}]
(kHom K V f).
Proof. by apply: (iffP kHomP_tmp) => [][]. Qed.
Lemma kAHomP {U V} {f : 'AEnd(L)} :
reflect {in U, forall x, f x = x} (kHom U V f).
Proof. by rewrite /kHom ahomWin; apply: fixedSpacesP. Qed.
Lemma kHom1 U V : kHom U V \1.
Proof. by apply/kAHomP => u _; rewrite lfunE. Qed.
Lemma k1HomE V f : kHom 1 V f = ahom_in V f.
Proof. by apply: andb_idr => /ahom_inP[_ f1]; apply/fixedSpaceP. Qed.
Lemma kHom_monoid_morphism (f : 'End(L)) :
reflect (monoid_morphism f) (kHom 1 {:L} f).
Proof. by rewrite k1HomE; apply: ahomP_tmp. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `kHom_monoid_morphism` instead")]
Lemma kHom_lrmorphism (f : 'End(L)) : reflect (multiplicative f) (kHom 1 {:L} f).
Proof. #[warning="-deprecated-since-mathcomp-2.5.0"] by rewrite k1HomE; apply: ahomP. Qed.
(* Lemma kHom_lrmorphism (f : 'End(L)) : reflect (lrmorphism f) (kHom 1 {:L} f). *)
(* Proof. by rewrite k1HomE; apply: ahomP. Qed. *)
Lemma k1AHom V (f : 'AEnd(L)) : kHom 1 V f.
Proof. by rewrite k1HomE ahomWin. Qed.
Lemma kHom_poly_id K E f p :
kHom K E f -> p \is a polyOver K -> map_poly f p = p.
Proof.
by case/kHomP_tmp=> idKf _ /polyOverP Kp; apply/polyP=> i; rewrite coef_map /= idKf.
Qed.
Lemma kHomSl U1 U2 V f : (U1 <= U2)%VS -> kHom U2 V f -> kHom U1 V f.
Proof. by rewrite /kHom => sU12 /andP[-> /(subv_trans sU12)]. Qed.
Lemma kHomSr K V1 V2 f : (V1 <= V2)%VS -> kHom K V2 f -> kHom K V1 f.
Proof. by move/subvP=> sV12 /kHomP_tmp[idKf /(sub_in2 sV12)fM]; apply/kHomP_tmp. Qed.
Lemma kHomS K1 K2 V1 V2 f :
(K1 <= K2)%VS -> (V1 <= V2)%VS -> kHom K2 V2 f -> kHom K1 V1 f.
Proof. by move=> sK12 sV12 /(kHomSl sK12)/(kHomSr sV12). Qed.
Lemma kHom_eq K E f g :
(K <= E)%VS -> {in E, f =1 g} -> kHom K E f = kHom K E g.
Proof.
move/subvP=> sKE eq_fg; wlog suffices: f g eq_fg / kHom K E f -> kHom K E g.
by move=> IH; apply/idP/idP; apply: IH => x /eq_fg.
case/kHomP_tmp=> idKf fM; apply/kHomP_tmp.
by split=> [x Kx | x y Ex Ey]; rewrite -!eq_fg ?fM ?rpredM // ?idKf ?sKE.
Qed.
Lemma kHom_inv K E f : kHom K E f -> {in E, {morph f : x / x^-1}}.
Proof.
case/kHomP_tmp=> idKf fM x Ex.
have [-> | nz_x] := eqVneq x 0; first by rewrite linear0 invr0 linear0.
have fxV: f x * f x^-1 = 1 by rewrite -fM ?rpredV ?divff // idKf ?mem1v.
have Ufx: f x \is a GRing.unit by apply/unitrPr; exists (f x^-1).
by apply: (mulrI Ufx); rewrite divrr.
Qed.
Lemma kHom_dim K E f : kHom K E f -> \dim (f @: E) = \dim E.
Proof.
move=> homKf; have [idKf fM] := kHomP_tmp homKf.
apply/limg_dim_eq/eqP; rewrite -subv0; apply/subvP=> v.
rewrite memv_cap memv0 memv_ker => /andP[Ev]; apply: contraLR => nz_v.
by rewrite -unitfE unitrE -(kHom_inv homKf) // -fM ?rpredV ?divff ?idKf ?mem1v.
Qed.
Section kHomMorphism.
Variables (K E : {subfield L}) (f : 'End(L)).
Let kHomf : subvs_of E -> L := f \o vsval.
Lemma kHom_is_zmod_morphism : kHom K E f -> zmod_morphism kHomf.
Proof. by case/kHomP_tmp => idKf fM; apply: raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_zmod_morphism` instead")]
Definition kHom_is_additive := kHom_is_zmod_morphism.
Lemma kHom_is_monoid_morphism : kHom K E f -> monoid_morphism kHomf.
Proof.
case/kHomP_tmp=> idKf fM; rewrite /kHomf.
by split=> [|a b] /=; [rewrite algid1 idKf // mem1v | rewrite /= fM ?subvsP].
Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `kHom_is_monoid_morphism` instead")]
Definition kHom_is_multiplicative :=
(fun p => (p.1, p.2)) \o kHom_is_monoid_morphism.
Variable (homKEf : kHom K E f).
HB.instance Definition _ :=
@GRing.isZmodMorphism.Build _ _ kHomf (kHom_is_zmod_morphism homKEf).
HB.instance Definition _ :=
@GRing.isMonoidMorphism.Build _ _ kHomf (kHom_is_monoid_morphism homKEf).
Definition kHom_rmorphism := Eval hnf in (kHomf : {rmorphism _ -> _}).
End kHomMorphism.
Lemma kHom_horner K E f p x :
kHom K E f -> p \is a polyOver E -> x \in E -> f p.[x] = (map_poly f p).[f x].
Proof.
move=> homKf /polyOver_subvs[{}p -> Ex]; pose fRM := kHom_rmorphism homKf.
by rewrite (horner_map _ _ (Subvs Ex)) -[f _](horner_map fRM) map_poly_comp.
Qed.
Lemma kHom_root K E f p x :
kHom K E f -> p \is a polyOver E -> x \in E -> root p x ->
root (map_poly f p) (f x).
Proof.
by move/kHom_horner=> homKf Ep Ex /rootP px0; rewrite /root -homKf ?px0 ?raddf0.
Qed.
Lemma kHom_root_id K E f p x :
(K <= E)%VS -> kHom K E f -> p \is a polyOver K -> x \in E -> root p x ->
root p (f x).
Proof.
move=> sKE homKf Kp Ex /(kHom_root homKf (polyOverSv sKE Kp) Ex).
by rewrite (kHom_poly_id homKf).
Qed.
Section kHomExtend.
Variables (K E : {subfield L}) (f : 'End(L)) (x y : L).
Let kHomf z := (map_poly f (Fadjoin_poly E x z)).[y].
Fact kHomExtend_zmod_morphism_subproof : zmod_morphism kHomf.
Proof. by move=> a b; rewrite /kHomf 2!raddfB hornerD hornerN. Qed.
Fact kHomExtend_scalable_subproof : scalable kHomf.
Proof.
move=> k a; rewrite /kHomf linearZ /= -[RHS]mulr_algl -hornerZ; congr _.[_].
by apply/polyP => i; rewrite !(coefZ, coef_map) /= !mulr_algl linearZ.
Qed.
HB.instance Definition _ := @GRing.isZmodMorphism.Build _ _ kHomf
kHomExtend_zmod_morphism_subproof.
HB.instance Definition _ := @GRing.isScalable.Build _ _ _ _ kHomf
kHomExtend_scalable_subproof.
Let kHomExtendLinear := Eval hnf in (kHomf : {linear _ -> _}).
Definition kHomExtend := linfun kHomExtendLinear.
Lemma kHomExtendE z : kHomExtend z = (map_poly f (Fadjoin_poly E x z)).[y].
Proof. by rewrite lfunE. Qed.
Hypotheses (sKE : (K <= E)%VS) (homKf : kHom K E f).
Local Notation Px := (minPoly E x).
Hypothesis fPx_y_0 : root (map_poly f Px) y.
Lemma kHomExtend_id z : z \in E -> kHomExtend z = f z.
Proof. by move=> Ez; rewrite kHomExtendE Fadjoin_polyC ?map_polyC ?hornerC. Qed.
Lemma kHomExtend_val : kHomExtend x = y.
Proof.
have fX: map_poly f 'X = 'X by rewrite (kHom_poly_id homKf) ?polyOverX.
have [Ex | E'x] := boolP (x \in E); last first.
by rewrite kHomExtendE Fadjoin_polyX // fX hornerX.
have:= fPx_y_0; rewrite (minPoly_XsubC Ex) raddfB /= map_polyC fX root_XsubC /=.
by rewrite (kHomExtend_id Ex) => /eqP->.
Qed.
Lemma kHomExtend_poly p :
p \in polyOver E -> kHomExtend p.[x] = (map_poly f p).[y].
Proof.
move=> Ep; rewrite kHomExtendE (Fadjoin_poly_mod x) //.
rewrite (divp_eq (map_poly f p) (map_poly f Px)).
rewrite !hornerE (rootP fPx_y_0) mulr0 add0r.
have [p1 ->] := polyOver_subvs Ep.
have [Px1 ->] := polyOver_subvs (minPolyOver E x).
by rewrite -map_modp -!map_poly_comp (map_modp (kHom_rmorphism homKf)).
Qed.
Lemma kHomExtendP : kHom K <<E; x>> kHomExtend.
Proof.
have [idKf fM] := kHomP_tmp homKf.
apply/kHomP_tmp; split=> [z Kz|]; first by rewrite kHomExtend_id ?(subvP sKE) ?idKf.
move=> _ _ /Fadjoin_polyP[p Ep ->] /Fadjoin_polyP[q Eq ->].
rewrite -hornerM !kHomExtend_poly ?rpredM // -hornerM; congr _.[_].
apply/polyP=> i; rewrite coef_map !coefM /= linear_sum /=.
by apply: eq_bigr => j _; rewrite !coef_map /= fM ?(polyOverP _).
Qed.
End kHomExtend.
Definition kAut U V f := kHom U V f && (f @: V == V)%VS.
Lemma kAutE K E f : kAut K E f = kHom K E f && (f @: E <= E)%VS.
Proof.
apply/andP/andP=> [[-> /eqP->] // | [homKf EfE]].
by rewrite eqEdim EfE /= (kHom_dim homKf).
Qed.
Lemma kAutS U1 U2 V f : (U1 <= U2)%VS -> kAut U2 V f -> kAut U1 V f.
Proof. by move=> sU12 /andP[/(kHomSl sU12)homU1f EfE]; apply/andP. Qed.
Lemma kHom_kAut_sub K E f : kAut K E f -> kHom K E f. Proof. by case/andP. Qed.
Lemma kAut_eq K E (f g : 'End(L)) :
(K <= E)%VS -> {in E, f =1 g} -> kAut K E f = kAut K E g.
Proof.
by move=> sKE eq_fg; rewrite !kAutE (kHom_eq sKE eq_fg) (eq_in_limg eq_fg).
Qed.
Lemma kAutfE K f : kAut K {:L} f = kHom K {:L} f.
Proof. by rewrite kAutE subvf andbT. Qed.
Lemma kAut1E E (f : 'AEnd(L)) : kAut 1 E f = (f @: E <= E)%VS.
Proof. by rewrite kAutE k1AHom. Qed.
Lemma kAutf_lker0 K f : kHom K {:L} f -> lker f == 0%VS.
Proof.
move/(kHomSl (sub1v _))/kHom_monoid_morphism => fM.
pose fmM := GRing.isMonoidMorphism.Build _ _ _ fM.
pose fRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun f) fmM.
by apply/lker0P; apply: (fmorph_inj fRM).
Qed.
Lemma inv_kHomf K f : kHom K {:L} f -> kHom K {:L} f^-1.
Proof.
move=> homKf; have [[idKf fM] kerf0] := (kHomP_tmp homKf, kAutf_lker0 homKf).
have f1K: cancel f^-1%VF f by apply: lker0_lfunVK.
apply/kHomP_tmp; split=> [x Kx | x y _ _]; apply: (lker0P kerf0).
by rewrite f1K idKf.
by rewrite fM ?memvf ?{1}f1K.
Qed.
Lemma inv_is_ahom (f : 'AEnd(L)) : ahom_in {:L} f^-1.
Proof.
have /ahomP_tmp/kHom_monoid_morphism hom1f := valP f.
exact/ahomP_tmp/kHom_monoid_morphism/inv_kHomf.
Qed.
Canonical inv_ahom (f : 'AEnd(L)) : 'AEnd(L) := AHom (inv_is_ahom f).
Notation "f ^-1" := (inv_ahom f) : lrfun_scope.
Lemma comp_kHom_img K E f g :
kHom K (g @: E) f -> kHom K E g -> kHom K E (f \o g).
Proof.
move=> /kHomP_tmp[idKf fM] /kHomP_tmp[idKg gM]; apply/kHomP_tmp; split=> [x Kx | x y Ex Ey].
by rewrite lfunE /= idKg ?idKf.
by rewrite !lfunE /= gM // fM ?memv_img.
Qed.
Lemma comp_kHom K E f g : kHom K {:L} f -> kHom K E g -> kHom K E (f \o g).
Proof. by move/(kHomSr (subvf (g @: E))); apply: comp_kHom_img. Qed.
Lemma kHom_extends K E f p U :
(K <= E)%VS -> kHom K E f ->
p \is a polyOver K -> splittingFieldFor E p U ->
{g | kHom K U g & {in E, f =1 g}}.
Proof.
move=> sKE homEf Kp /sig2_eqW[rs Dp <-{U}].
set r := rs; have rs_r: all [in rs] r by apply/allP.
elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in E f sKE homEf *.
by exists f; rewrite ?Fadjoin_nil.
set Ez := <<E; z>>%AS; pose fpEz := map_poly f (minPoly E z).
suffices{IHr} /sigW[y fpEz_y]: exists y, root fpEz y.
have homEz_fz: kHom K Ez (kHomExtend E f z y) by apply: kHomExtendP.
have sKEz: (K <= Ez)%VS := subv_trans sKE (subv_adjoin E z).
have [g homGg Dg] := IHr rs_r _ _ sKEz homEz_fz.
exists g => [|x Ex]; first by rewrite adjoin_cons.
by rewrite -Dg ?subvP_adjoin // kHomExtend_id.
have [m DfpEz]: {m | fpEz %= \prod_(w <- mask m rs) ('X - w%:P)}.
apply: dvdp_prod_XsubC; rewrite -(eqp_dvdr _ Dp) -(kHom_poly_id homEf Kp).
have /polyOver_subvs[q Dq] := polyOverSv sKE Kp.
have /polyOver_subvs[qz Dqz] := minPolyOver E z.
rewrite /fpEz Dq Dqz -2?{1}map_poly_comp (dvdp_map (kHom_rmorphism homEf)).
rewrite -(dvdp_map (@vsval _ _ E)) -Dqz -Dq.
by rewrite minPoly_dvdp ?(polyOverSv sKE) // (eqp_root Dp) root_prod_XsubC.
exists (mask m rs)`_0; rewrite (eqp_root DfpEz) root_prod_XsubC mem_nth //.
rewrite -ltnS -(size_prod_XsubC _ id) -(eqp_size DfpEz).
rewrite size_poly_eq -?lead_coefE ?size_minPoly // (monicP (monic_minPoly E z)).
by have [idKf _] := kHomP_tmp homEf; rewrite idKf ?mem1v ?oner_eq0.
Qed.
End kHom.
Notation "f ^-1" := (inv_ahom f) : lrfun_scope.
#[warning="-deprecated-since-mathcomp-2.5.0"]
Arguments kHomP {F L K V f}.
Arguments kHomP_tmp {F L K V f}.
Arguments kAHomP {F L U V f}.
#[warning="-deprecated-since-mathcomp-2.5.0"]
Arguments kHom_lrmorphism {F L f}.
Arguments kHom_monoid_morphism {F L f}.
Definition splitting_field_axiom (F : fieldType) (L : fieldExtType F) :=
exists2 p : {poly L}, p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}.
HB.mixin Record FieldExt_isSplittingField (F : fieldType) L of FieldExt F L := {
splittingFieldP_subproof : splitting_field_axiom L
}.
#[mathcomp(axiom="splitting_field_axiom"), short(type="splittingFieldType")]
HB.structure Definition SplittingField F :=
{ T of FieldExt_isSplittingField F T & FieldExt F T }.
Module SplittingFieldExports.
Bind Scope ring_scope with SplittingField.sort.
End SplittingFieldExports.
HB.export SplittingFieldExports.
Lemma normal_field_splitting (F : fieldType) (L : fieldExtType F) :
(forall (K : {subfield L}) x,
exists r, minPoly K x == \prod_(y <- r) ('X - y%:P)) ->
SplittingField.axiom L.
Proof.
move=> normalL; pose r i := sval (sigW (normalL 1%AS (tnth (vbasis {:L}) i))).
have sz_r i: size (r i) <= \dim {:L}.
rewrite -ltnS -(size_prod_XsubC _ id) /r; case: sigW => _ /= /eqP <-.
rewrite size_minPoly ltnS; move: (tnth _ _) => x.
by rewrite adjoin_degreeE dimv1 divn1 dimvS // subvf.
pose mkf (z : L) := 'X - z%:P.
exists (\prod_i \prod_(j < \dim {:L} | j < size (r i)) mkf (r i)`_j).
apply: rpred_prod => i _; rewrite big_ord_narrow /= /r; case: sigW => rs /=.
by rewrite (big_nth 0) big_mkord => /eqP <- {rs}; apply: minPolyOver.
rewrite pair_big_dep /= -big_filter -(big_map _ xpredT mkf).
set rF := map _ _; exists rF; first exact: eqpxx.
apply/eqP; rewrite eqEsubv subvf -(span_basis (vbasisP {:L})).
apply/span_subvP=> _ /tnthP[i ->]; set x := tnth _ i.
have /tnthP[j ->]: x \in in_tuple (r i).
by rewrite -root_prod_XsubC /r; case: sigW => _ /=/eqP<-; apply: root_minPoly.
apply/seqv_sub_adjoin/mapP; rewrite (tnth_nth 0).
exists (i, widen_ord (sz_r i) j) => //.
by rewrite mem_filter /= ltn_ord mem_index_enum.
Qed.
HB.factory Record FieldExt_isNormalSplittingField
(F : fieldType) L of FieldExt F L := {
normal_field_splitting_axiom : forall (K : {subfield L}) x,
exists r, minPoly K x == \prod_(y <- r) ('X - y%:P)
}.
HB.builders Context F L of FieldExt_isNormalSplittingField F L.
HB.instance Definition _ := FieldExt_isSplittingField.Build F L
(normal_field_splitting normal_field_splitting_axiom).
HB.end.
Fact regular_splittingAxiom (F : fieldType) : SplittingField.axiom F^o.
Proof.
exists 1; first exact: rpred1.
by exists [::]; [rewrite big_nil eqpxx | rewrite Fadjoin_nil regular_fullv].
Qed.
HB.instance Definition _ (F : fieldType) :=
FieldExt_isSplittingField.Build F F^o (regular_splittingAxiom F).
Section SplittingFieldTheory.
Variables (F : fieldType) (L : splittingFieldType F).
Implicit Types (U V W : {vspace L}).
Implicit Types (K M E : {subfield L}).
Lemma splittingFieldP : SplittingField.axiom L.
Proof. exact: splittingFieldP_subproof. Qed.
Lemma splittingPoly :
{p : {poly L} | p \is a polyOver 1%VS & splittingFieldFor 1 p {:L}}.
Proof.
pose factF p s := (p \is a polyOver 1%VS) && (p %= \prod_(z <- s) ('X - z%:P)).
suffices [[p rs] /andP[]]: {ps | factF F L ps.1 ps.2 & <<1 & ps.2>> = {:L}}%VS.
by exists p; last exists rs.
apply: sig2_eqW; have [p F0p [rs splitLp genLrs]] := splittingFieldP.
by exists (p, rs); rewrite // /factF F0p splitLp.
Qed.
Fact fieldOver_splitting E : SplittingField.axiom (fieldOver E).
Proof.
have [p Fp [r Dp defL]] := splittingFieldP; exists p.
apply/polyOverP=> j; rewrite trivial_fieldOver.
by rewrite (subvP (sub1v E)) ?(polyOverP Fp).
exists r => //; apply/vspaceP=> x; rewrite memvf.
have [L0 [_ _ defL0]] := @aspaceOverP _ _ E <<1 & r : seq (fieldOver E)>>.
rewrite defL0; have: x \in <<1 & r>>%VS by rewrite defL (@memvf _ L).
apply: subvP; apply/Fadjoin_seqP; rewrite -memvE -defL0 mem1v.
by split=> // y r_y; rewrite -defL0 seqv_sub_adjoin.
Qed.
HB.instance Definition _ E := FieldExt_isSplittingField.Build
(subvs_of E) (fieldOver E) (fieldOver_splitting E).
Lemma enum_AEnd : {kAutL : seq 'AEnd(L) | forall f, f \in kAutL}.
Proof.
pose isAutL (s : seq 'AEnd(L)) (f : 'AEnd(L)) := kHom 1 {:L} f = (f \in s).
suffices [kAutL in_kAutL] : {kAutL : seq 'AEnd(L) | forall f, isAutL kAutL f}.
by exists kAutL => f; rewrite -in_kAutL k1AHom.
have [p Kp /sig2_eqW[rs Dp defL]] := splittingPoly.
do [rewrite {}/isAutL -(erefl (asval 1)); set r := rs; set E := 1%AS] in defL *.
have [sKE rs_r]: (1 <= E)%VS /\ all [in rs] r by split; last apply/allP.
elim: r rs_r => [_|z r IHr /=/andP[rs_z rs_r]] /= in (E) sKE defL *.
rewrite Fadjoin_nil in defL; exists [tuple \1%AF] => f; rewrite defL inE.
apply/idP/eqP=> [/kAHomP f1 | ->]; last exact: kHom1.
by apply/val_inj/lfunP=> x; rewrite id_lfunE f1 ?memvf.
do [set Ez := <<E; z>>%VS; rewrite adjoin_cons] in defL.
have sEEz: (E <= Ez)%VS := subv_adjoin E z; have sKEz := subv_trans sKE sEEz.
have{IHr} [homEz DhomEz] := IHr rs_r _ sKEz defL.
have Ep: p \in polyOver E := polyOverSv sKE Kp.
have{rs_z} pz0: root p z by rewrite (eqp_root Dp) root_prod_XsubC.
pose pEz := minPoly E z; pose n := \dim_E Ez.
have{pz0} [rz DpEz]: {rz : n.-tuple L | pEz %= \prod_(w <- rz) ('X - w%:P)}.
have /dvdp_prod_XsubC[m DpEz]: pEz %| \prod_(w <- rs) ('X - w%:P).
by rewrite -(eqp_dvdr _ Dp) minPoly_dvdp ?(polyOverSv sKE).
suffices sz_rz: size (mask m rs) == n by exists (Tuple sz_rz).
rewrite -[n]adjoin_degreeE -eqSS -size_minPoly.
by rewrite (eqp_size DpEz) size_prod_XsubC.
have fEz i (y := tnth rz i): {f : 'AEnd(L) | kHom E {:L} f & f z = y}.
have homEfz: kHom E Ez (kHomExtend E \1 z y).
rewrite kHomExtendP ?kHom1 // lfun1_poly.
by rewrite (eqp_root DpEz) -/rz root_prod_XsubC mem_tnth.
have splitFp: splittingFieldFor Ez p {:L}.
exists rs => //; apply/eqP; rewrite eqEsubv subvf -defL adjoin_seqSr //.
exact/allP.
have [f homLf Df] := kHom_extends sEEz homEfz Ep splitFp.
have [ahomf _] := andP homLf; exists (AHom ahomf) => //.
rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 E E)) // lfun1_poly.
by rewrite (eqp_root DpEz) root_prod_XsubC mem_tnth.
exists [seq (s2val (fEz i) \o f)%AF| i <- enum 'I_n, f <- homEz] => f.
apply/idP/allpairsP => [homLf | [[i g] [_ Hg ->]] /=]; last first.
by case: (fEz i) => fi /= /comp_kHom->; rewrite ?(kHomSl sEEz) ?DhomEz.
have /tnthP[i Dfz]: f z \in rz.
rewrite memtE /= -root_prod_XsubC -(eqp_root DpEz).
by rewrite (kHom_root_id _ homLf) ?memvf ?subvf ?minPolyOver ?root_minPoly.
case Dfi: (fEz i) => [fi homLfi fi_z]; have kerfi0 := kAutf_lker0 homLfi.
set fj := (fi ^-1 \o f)%AF; suffices Hfj : fj \in homEz.
exists (i, fj) => //=; rewrite mem_enum inE Hfj; split => //.
by apply/val_inj; rewrite {}Dfi /= (lker0_compVKf kerfi0).
rewrite -DhomEz; apply/kAHomP => _ /Fadjoin_polyP[q Eq ->].
have homLfj: kHom E {:L} fj := comp_kHom (inv_kHomf homLfi) homLf.
have /kHom_monoid_morphism fjM := kHomSl (sub1v _) homLfj.
pose fjmM := GRing.isMonoidMorphism.Build _ _ _ fjM.
pose fjRM : {rmorphism _ -> _} := HB.pack (fun_of_lfun fj) fjmM.
rewrite -[fj _](horner_map fjRM) (kHom_poly_id homLfj) //=.
by rewrite (@lfunE _ _ L) /= Dfz -fi_z lker0_lfunK.
Qed.
Lemma splitting_field_normal K x :
exists r, minPoly K x == \prod_(y <- r) ('X - y%:P).
Proof.
pose q1 := minPoly 1 x; pose fx_root q (f : 'AEnd(L)) := root q (f x).
have [[p F0p splitLp] [autL DautL]] := (splittingFieldP, enum_AEnd).
suffices{K} autL_px q: q != 0 -> q %| q1 -> size q > 1 -> has (fx_root q) autL.
set q := minPoly K x; have: q \is monic := monic_minPoly K x.
have: q %| q1 by rewrite minPolyS // sub1v.
have [d] := ubnP (size q); elim: d q => // d IHd q leqd q_dv_q1 mon_q.
have nz_q: q != 0 := monic_neq0 mon_q.
have [|q_gt1|q_1] := ltngtP (size q) 1; last first; last by rewrite polySpred.
by exists nil; rewrite big_nil -eqp_monic ?monic1 // -size_poly_eq1 q_1.
have /hasP[f autLf /factor_theorem[q2 Dq]] := autL_px q nz_q q_dv_q1 q_gt1.
have mon_q2: q2 \is monic by rewrite -(monicMr _ (monicXsubC (f x))) -Dq.
rewrite Dq size_monicM -?size_poly_eq0 ?size_XsubC ?addn2 //= ltnS in leqd.
have q2_dv_q1: q2 %| q1 by rewrite (dvdp_trans _ q_dv_q1) // Dq dvdp_mulr.
rewrite Dq; have [r /eqP->] := IHd q2 leqd q2_dv_q1 mon_q2.
by exists (f x :: r); rewrite big_cons mulrC.
have [d] := ubnP (size q); elim: d q => // d IHd q leqd nz_q q_dv_q1 q_gt1.
without loss{d leqd IHd nz_q q_gt1} irr_q: q q_dv_q1 / irreducible_poly q.
move=> IHq; apply: wlog_neg => not_autLx_q; apply: IHq => //.
split=> // q2 q2_neq1 q2_dv_q; rewrite -dvdp_size_eqp // eqn_leq dvdp_leq //=.
rewrite leqNgt; apply: contra not_autLx_q => ltq2q.
have nz_q2: q2 != 0 by apply: contraTneq q2_dv_q => ->; rewrite dvd0p.
have{q2_neq1} q2_gt1: size q2 > 1 by rewrite neq_ltn polySpred in q2_neq1 *.
have{leqd ltq2q} ltq2d: size q2 < d by apply: leq_trans ltq2q _.
apply: sub_has (IHd _ ltq2d nz_q2 (dvdp_trans q2_dv_q q_dv_q1) q2_gt1) => f.
by rewrite /fx_root !root_factor_theorem => /dvdp_trans->.
have{irr_q} [Lz [inLz [z qz0]]]: {Lz : fieldExtType F &
{inLz : 'AHom(L, Lz) & {z : Lz | root (map_poly inLz q) z}}}.
- have [Lz0 _ [z qz0 defLz]] := irredp_FAdjoin irr_q.
pose Lz : fieldExtType _ := baseFieldType Lz0.
pose inLz : {rmorphism L -> Lz} := in_alg Lz0.
have inLzL_linear: linear (locked inLz).
by move=> a u v; rewrite -[in LHS]mulr_algl rmorphD rmorphM -lock mulr_algl.
pose inLzLlM := GRing.isLinear.Build _ _ _ _ _ inLzL_linear.
pose inLzLL : {linear _ -> _} := HB.pack (locked inLz : _ -> _) inLzLlM.
have ihLzZ: ahom_in {:L} (linfun inLzLL).
by apply/ahom_inP; split=> [u v|]; rewrite !lfunE (rmorphM, rmorph1).
exists Lz, (AHom ihLzZ), z; congr (root _ z): qz0.
by apply: eq_map_poly => y; rewrite lfunE /= -lock.
pose imL := [aspace of limg inLz]; pose pz := map_poly inLz p.
have in_imL u: inLz u \in imL by rewrite memv_img ?memvf.
have F0pz: pz \is a polyOver 1%VS.
apply/polyOverP=> i; rewrite -(aimg1 inLz) coef_map /= memv_img //.
exact: (polyOverP F0p).
have{splitLp} splitLpz: splittingFieldFor 1 pz imL.
have [r def_p defL] := splitLp; exists (map inLz r) => [|{def_p}].
move: def_p; rewrite -(eqp_map inLz) rmorph_prod.
rewrite big_map; congr (_ %= _); apply: eq_big => //= y _.
by rewrite rmorphB /= map_polyX map_polyC.
apply/eqP; rewrite eqEsubv /= -{2}defL {defL}; apply/andP; split.
by apply/Fadjoin_seqP; rewrite sub1v; split=> // _ /mapP[y r_y ->].
elim/last_ind: r => [|r y IHr] /=; first by rewrite !Fadjoin_nil aimg1.
rewrite map_rcons !adjoin_rcons /=.
apply/subvP=> _ /memv_imgP[_ /Fadjoin_polyP[p1 r_p1 ->] ->].
rewrite -horner_map /= mempx_Fadjoin //=; apply/polyOverP=> i.
by rewrite coef_map (subvP IHr) //= memv_img ?(polyOverP r_p1).
have [f homLf fxz]: exists2 f : 'End(Lz), kHom 1 imL f & f (inLz x) = z.
pose q1z := minPoly 1 (inLz x).
have Dq1z: map_poly inLz q1 %| q1z.
have F0q1z i: exists a, q1z`_i = a%:A by apply/vlineP/polyOverP/minPolyOver.
have [q2 Dq2]: exists q2, q1z = map_poly inLz q2.
exists (\poly_(i < size q1z) (sval (sig_eqW (F0q1z i)))%:A).
rewrite -{1}[q1z]coefK; apply/polyP=> i; rewrite coef_map !{1}coef_poly.
by case: sig_eqW => a; case: ifP; rewrite /= ?rmorph0 ?rmorph_alg.
rewrite Dq2 dvdp_map minPoly_dvdp //.
apply/polyOverP=> i; have[a] := F0q1z i.
rewrite -(rmorph_alg inLz) Dq2 coef_map /= => /fmorph_inj->.
exact/rpredZ/mem1v.
by rewrite -(fmorph_root inLz) -Dq2 root_minPoly.
have q1z_z: root q1z z.
rewrite !root_factor_theorem in qz0 *.
by apply: dvdp_trans qz0 (dvdp_trans _ Dq1z); rewrite dvdp_map.
have map1q1z_z: root (map_poly \1%VF q1z) z.
by rewrite map_poly_id => // ? _; rewrite lfunE.
pose f0 := kHomExtend 1 \1 (inLz x) z.
have{map1q1z_z} hom_f0 : kHom 1 <<1; inLz x>> f0.
by apply: kHomExtendP map1q1z_z => //; apply: kHom1.
have{} splitLpz: splittingFieldFor <<1; inLz x>> pz imL.
have [r def_pz defLz] := splitLpz; exists r => //.
apply/eqP; rewrite eqEsubv -{2}defLz adjoin_seqSl ?sub1v // andbT.
apply/Fadjoin_seqP; split; last first.
by rewrite /= -[limg _]defLz; apply: seqv_sub_adjoin.
by apply/FadjoinP/andP; rewrite sub1v memv_img ?memvf.
have [f homLzf Df] := kHom_extends (sub1v _) hom_f0 F0pz splitLpz.
have [-> | x'z] := eqVneq (inLz x) z.
by exists \1%VF; rewrite ?lfunE ?kHom1.
exists f => //; rewrite -Df ?memv_adjoin ?(kHomExtend_val (kHom1 1 1)) //.
by rewrite lfun1_poly.
pose f1 := (inLz^-1 \o f \o inLz)%VF; have /kHomP_tmp[fFid fM] := homLf.
have Df1 u: inLz (f1 u) = f (inLz u).
rewrite !comp_lfunE limg_lfunVK //= -[limg _]/(asval imL).
have [r def_pz defLz] := splitLpz; set r1 := r.
have: inLz u \in <<1 & r1>>%VS by rewrite defLz.
have: all [in r] r1 by apply/allP.
elim/last_ind: r1 {u}(inLz u) => [|r1 y IHr1] u.
by rewrite Fadjoin_nil => _ Fu; rewrite fFid // (subvP (sub1v _)).
rewrite all_rcons adjoin_rcons => /andP[rr1 ry] /Fadjoin_polyP[pu r1pu ->].
rewrite (kHom_horner homLf) -defLz; last exact: seqv_sub_adjoin; last first.
by apply: polyOverS r1pu; apply/subvP/adjoin_seqSr/allP.
apply: rpred_horner.
by apply/polyOverP=> i; rewrite coef_map /= defLz IHr1 ?(polyOverP r1pu).
rewrite seqv_sub_adjoin // -root_prod_XsubC -(eqp_root def_pz).
rewrite (kHom_root_id _ homLf) ?sub1v //.
by rewrite -defLz seqv_sub_adjoin.
by rewrite (eqp_root def_pz) root_prod_XsubC.
suffices f1_is_ahom : ahom_in {:L} f1.
apply/hasP; exists (AHom f1_is_ahom); first exact: DautL.
by rewrite /fx_root -(fmorph_root inLz) /= Df1 fxz.
apply/ahom_inP; split=> [a b _ _|]; apply: (fmorph_inj inLz).
by rewrite rmorphM /= !Df1 rmorphM fM ?in_imL.
by rewrite /= Df1 /= fFid ?rmorph1 ?mem1v.
Qed.
Lemma kHom_to_AEnd K E f : kHom K E f -> {g : 'AEnd(L) | {in E, f =1 val g}}.
Proof.
move=> homKf; have{homKf} [homFf sFE] := (kHomSl (sub1v K) homKf, sub1v E).
have [p Fp /(splittingFieldForS sFE (subvf E))splitLp] := splittingPoly.
have [g0 homLg0 eq_fg] := kHom_extends sFE homFf Fp splitLp.
by apply: exist (Sub g0 _) _ => //; apply/ahomP_tmp/kHom_monoid_morphism.
Qed.
End SplittingFieldTheory.
(* Hide the finGroup structure on 'AEnd(L) in a module so that we can control *)
(* when it is exported. Most people will want to use the finGroup structure *)
(* on 'Gal(E / K) and will not need this module. *)
Module Import AEnd_FinGroup.
Section AEnd_FinGroup.
Variables (F : fieldType) (L : splittingFieldType F).
Implicit Types (U V W : {vspace L}) (K M E : {subfield L}).
Definition inAEnd f := SeqSub (svalP (enum_AEnd L) f).
Fact inAEndK : cancel inAEnd val. Proof. by []. Qed.
HB.instance Definition _ := Countable.copy 'AEnd(L) (can_type inAEndK).
HB.instance Definition _ := isFinite.Build 'AEnd(L)
(pcan_enumP (can_pcan inAEndK)).
(* the group operation is the categorical composition operation *)
Definition comp_AEnd (f g : 'AEnd(L)) : 'AEnd(L) := (g \o f)%AF.
Fact comp_AEndA : associative comp_AEnd.
Proof. by move=> f g h; apply: val_inj; symmetry; apply: comp_lfunA. Qed.
Fact comp_AEnd1l : left_id \1%AF comp_AEnd.
Proof. by move=> f; apply/val_inj/comp_lfun1r. Qed.
Fact comp_AEndK : left_inverse \1%AF (@inv_ahom _ L) comp_AEnd.
Proof. by move=> f; apply/val_inj; rewrite /= lker0_compfV ?AEnd_lker0. Qed.
HB.instance Definition _:= isMulGroup.Build 'AEnd(L)
comp_AEndA comp_AEnd1l comp_AEndK.
Definition kAEnd U V := [set f : 'AEnd(L) | kAut U V f].
Definition kAEndf U := kAEnd U {:L}.
Lemma kAEnd_group_set K E : group_set (kAEnd K E).
Proof.
apply/group_setP; split=> [|f g]; first by rewrite inE /kAut kHom1 lim1g eqxx.
rewrite !inE !kAutE => /andP[homKf EfE] /andP[/(kHomSr EfE)homKg EgE].
by rewrite (comp_kHom_img homKg homKf) limg_comp (subv_trans _ EgE) ?limgS.
Qed.
Canonical kAEnd_group K E := group (kAEnd_group_set K E).
Canonical kAEndf_group K := [group of kAEndf K].
Lemma kAEnd_norm K E : kAEnd K E \subset 'N(kAEndf E)%g.
Proof.
apply/subsetP=> x; rewrite -groupV 2!in_set => /andP[_ /eqP ExE].
apply/subsetP=> _ /imsetP[y homEy ->]; rewrite !in_set !kAutfE in homEy *.
apply/kAHomP=> u Eu; have idEy := kAHomP homEy; rewrite -ExE in idEy.
rewrite !(@lfunE _ _ L) /= (@lfunE _ _ L) /= idEy ?memv_img //.
by rewrite lker0_lfunVK ?AEnd_lker0.
Qed.
Lemma mem_kAut_coset K E (g : 'AEnd(L)) :
kAut K E g -> g \in coset (kAEndf E) g.
Proof.
move=> autEg; rewrite val_coset ?rcoset_refl //.
by rewrite (subsetP (kAEnd_norm K E)) // inE.
Qed.
Lemma aut_mem_eqP E (x y : coset_of (kAEndf E)) f g :
f \in x -> g \in y -> reflect {in E, f =1 g} (x == y).
Proof.
move=> x_f y_g; rewrite -(coset_mem x_f) -(coset_mem y_g).
have [Nf Ng] := (subsetP (coset_norm x) f x_f, subsetP (coset_norm y) g y_g).
rewrite (sameP eqP (rcoset_kercosetP Nf Ng)) mem_rcoset inE kAutfE.
apply: (iffP kAHomP) => idEfg u Eu.
by rewrite -(mulgKV g f) lfunE /= idEfg.
by rewrite (@lfunE _ _ L) /= idEfg // lker0_lfunK ?AEnd_lker0.
Qed.
End AEnd_FinGroup.
End AEnd_FinGroup.
Section GaloisTheory.
Variables (F : fieldType) (L : splittingFieldType F).
Implicit Types (U V W : {vspace L}).
Implicit Types (K M E : {subfield L}).
(* We take Galois automorphisms for a subfield E to be automorphisms of the *)
(* full field {:L} that operate in E taken modulo those that fix E pointwise. *)
(* The type of Galois automorphisms of E is then the subtype of elements of *)
(* the quotient kAEnd 1 E / kAEndf E, which we encapsulate in a specific *)
(* wrapper to ensure stability of the gal_repr coercion insertion. *)
Section gal_of_Definition.
Variable V : {vspace L}.
(* The <<_>>, which becomes redundant when V is a {subfield L}, ensures that *)
(* the argument of [subg _] is syntactically a group. *)
Inductive gal_of := Gal of [subg kAEnd_group 1 <<V>> / kAEndf (agenv V)].
Definition gal (f : 'AEnd(L)) := Gal (subg _ (coset _ f)).
Definition gal_sgval x := let: Gal u := x in u.
Fact gal_sgvalK : cancel gal_sgval Gal. Proof. by case. Qed.
Let gal_sgval_inj := can_inj gal_sgvalK.
HB.instance Definition _ := Countable.copy gal_of (can_type gal_sgvalK).
HB.instance Definition _ := isFinite.Build gal_of
(pcan_enumP (can_pcan gal_sgvalK)).
Definition gal_one := Gal 1%g.
Definition gal_inv x := Gal (gal_sgval x)^-1.
Definition gal_mul x y := Gal (gal_sgval x * gal_sgval y).
Fact gal_oneP : left_id gal_one gal_mul.
Proof. by move=> x; apply/gal_sgval_inj/mul1g. Qed.
Fact gal_invP : left_inverse gal_one gal_inv gal_mul.
Proof. by move=> x; apply/gal_sgval_inj/mulVg. Qed.
Fact gal_mulP : associative gal_mul.
Proof. by move=> x y z; apply/gal_sgval_inj/mulgA. Qed.
HB.instance Definition _ := isMulGroup.Build gal_of gal_mulP gal_oneP gal_invP.
Coercion gal_repr u : 'AEnd(L) := repr (sgval (gal_sgval u)).
Fact gal_is_morphism : {in kAEnd 1 (agenv V) &, {morph gal : x y / x * y}%g}.
Proof.
move=> f g /= autEa autEb; congr (Gal _).
by rewrite !morphM ?mem_morphim // (subsetP (kAEnd_norm 1 _)).
Qed.
Canonical gal_morphism := Morphism gal_is_morphism.
Lemma gal_reprK : cancel gal_repr gal.
Proof. by case=> x; rewrite /gal coset_reprK sgvalK. Qed.
Lemma gal_repr_inj : injective gal_repr.
Proof. exact: can_inj gal_reprK. Qed.
Lemma gal_AEnd x : gal_repr x \in kAEnd 1 (agenv V).
Proof.
rewrite /gal_repr; case/gal_sgval: x => _ /=/morphimP[g Ng autEg ->].
rewrite val_coset //=; case: repr_rcosetP => f; rewrite groupMr // !inE kAut1E.
by rewrite kAutE -andbA => /and3P[_ /fixedSpace_limg-> _].
Qed.
End gal_of_Definition.
Prenex Implicits gal_repr.
Lemma gal_eqP E {x y : gal_of E} : reflect {in E, x =1 y} (x == y).
Proof.
by rewrite -{1}(subfield_closed E); apply: aut_mem_eqP; apply: mem_repr_coset.
Qed.
Lemma galK E (f : 'AEnd(L)) : (f @: E <= E)%VS -> {in E, gal E f =1 f}.
Proof.
rewrite -kAut1E -{1 2}(subfield_closed E) => autEf.
apply: (aut_mem_eqP (mem_repr_coset _) _ (eqxx _)).
by rewrite subgK /= ?(mem_kAut_coset autEf) // ?mem_quotient ?inE.
Qed.
Lemma eq_galP E (f g : 'AEnd(L)) :
(f @: E <= E)%VS -> (g @: E <= E)%VS ->
reflect {in E, f =1 g} (gal E f == gal E g).
Proof.
move=> EfE EgE.
by apply: (iffP gal_eqP) => Dfg a Ea; have:= Dfg a Ea; rewrite !{1}galK.
Qed.
Lemma limg_gal E (x : gal_of E) : (x @: E)%VS = E.
Proof. by have:= gal_AEnd x; rewrite inE subfield_closed => /andP[_ /eqP]. Qed.
Lemma memv_gal E (x : gal_of E) a : a \in E -> x a \in E.
Proof. by move/(memv_img x); rewrite limg_gal. Qed.
Lemma gal_id E a : (1 : gal_of E)%g a = a.
Proof. by rewrite /gal_repr repr_coset1 id_lfunE. Qed.
Lemma galM E (x y : gal_of E) a : a \in E -> (x * y)%g a = y (x a).
Proof.
rewrite /= -comp_lfunE; apply/eq_galP; rewrite ?limg_comp ?limg_gal //.
by rewrite morphM /= ?gal_reprK ?gal_AEnd.
Qed.
Lemma galV E (x : gal_of E) : {in E, (x^-1)%g =1 x^-1%VF}.
Proof.
move=> a Ea; apply: canRL (lker0_lfunK (AEnd_lker0 _)) _.
by rewrite -galM // mulVg gal_id.
Qed.
(* Standard mathematical notation for 'Gal(E / K) puts the larger field first.*)
Definition galoisG V U := gal V @* <<kAEnd (U :&: V) V>>.
Local Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope.
Canonical galoisG_group E U := Eval hnf in [group of (galoisG E U)].
Local Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope.
Section Automorphism.
Lemma gal_cap U V : 'Gal(V / U) = 'Gal(V / U :&: V).
Proof. by rewrite /galoisG -capvA capvv. Qed.
Lemma gal_kAut K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kAut K E x.
Proof.
move=> sKE; apply/morphimP/idP=> /= [[g EgE KautEg ->{x}] | KautEx].
rewrite genGid !inE kAut1E /= subfield_closed (capv_idPl sKE) in KautEg EgE.
by apply: etrans KautEg; apply/(kAut_eq sKE); apply: galK.
exists (x : 'AEnd(L)); rewrite ?gal_reprK ?gal_AEnd //.
by rewrite (capv_idPl sKE) mem_gen ?inE.
Qed.
Lemma gal_kHom K E x : (K <= E)%VS -> (x \in 'Gal(E / K)) = kHom K E x.
Proof. by move/gal_kAut->; rewrite /kAut limg_gal eqxx andbT. Qed.
Lemma kAut_to_gal K E f :
kAut K E f -> {x : gal_of E | x \in 'Gal(E / K) & {in E, f =1 x}}.
Proof.
case/andP=> homKf EfE; have [g Df] := kHom_to_AEnd homKf.
have{homKf EfE} autEg: kAut (K :&: E) E g.
rewrite /kAut -(kHom_eq (capvSr _ _) Df) (kHomSl (capvSl _ _) homKf) /=.
by rewrite -(eq_in_limg Df).
have FautEg := kAutS (sub1v _) autEg.
exists (gal E g) => [|a Ea]; last by rewrite {f}Df // galK // -kAut1E.
by rewrite mem_morphim /= ?subfield_closed ?genGid ?inE.
Qed.
Lemma fixed_gal K E x a :
(K <= E)%VS -> x \in 'Gal(E / K) -> a \in K -> x a = a.
Proof. by move/gal_kHom=> -> /kAHomP idKx /idKx. Qed.
Lemma fixedPoly_gal K E x p :
(K <= E)%VS -> x \in 'Gal(E / K) -> p \is a polyOver K -> map_poly x p = p.
Proof.
move=> sKE galEKx /polyOverP Kp; apply/polyP => i.
by rewrite coef_map /= (fixed_gal sKE).
Qed.
Lemma root_minPoly_gal K E x a :
(K <= E)%VS -> x \in 'Gal(E / K) -> a \in E -> root (minPoly K a) (x a).
Proof.
move=> sKE galEKx Ea; have homKx: kHom K E x by rewrite -gal_kHom.
have K_Pa := minPolyOver K a; rewrite -[minPoly K a](fixedPoly_gal _ galEKx) //.
by rewrite (kHom_root homKx) ?root_minPoly // (polyOverS (subvP sKE)).
Qed.
End Automorphism.
Lemma gal_adjoin_eq K a x y :
x \in 'Gal(<<K; a>> / K) -> y \in 'Gal(<<K; a>> / K) ->
(x == y) = (x a == y a).
Proof.
move=> galKa_x galKa_y; apply/idP/eqP=> [/eqP-> // | eq_xy_a].
apply/gal_eqP => _ /Fadjoin_polyP[p Kp ->].
by rewrite -!horner_map !(fixedPoly_gal (subv_adjoin K a)) //= eq_xy_a.
Qed.
Lemma galS K M E : (K <= M)%VS -> 'Gal(E / M) \subset 'Gal(E / K).
Proof.
rewrite gal_cap (gal_cap K E) => sKM; apply/subsetP=> x.
by rewrite !gal_kAut ?capvSr //; apply: kAutS; apply: capvS.
Qed.
Lemma gal_conjg K E x : 'Gal(E / K) :^ x = 'Gal(E / x @: K).
Proof.
without loss sKE: K / (K <= E)%VS.
move=> IH_K; rewrite gal_cap {}IH_K ?capvSr //.
transitivity 'Gal(E / x @: K :&: x @: E); last by rewrite limg_gal -gal_cap.
congr 'Gal(E / _); apply/eqP; rewrite eqEsubv limg_cap; apply/subvP=> a.
rewrite memv_cap => /andP[/memv_imgP[b Kb ->] /memv_imgP[c Ec] eq_bc].
by rewrite memv_img // memv_cap Kb (lker0P (AEnd_lker0 _) _ _ eq_bc).
wlog suffices IHx: x K sKE / 'Gal(E / K) :^ x \subset 'Gal(E / x @: K).
apply/eqP; rewrite eqEsubset IHx // -sub_conjgV (subset_trans (IHx _ _ _)) //.
by apply/subvP=> _ /memv_imgP[a Ka ->]; rewrite memv_gal ?(subvP sKE).
rewrite -limg_comp (etrans (eq_in_limg _) (lim1g _)) // => a /(subvP sKE)Ka.
by rewrite !(@lfunE _ _ L) /= -galM // mulgV gal_id.
apply/subsetP=> _ /imsetP[y galEy ->]; rewrite gal_cap gal_kHom ?capvSr //=.
apply/kAHomP=> _ /memv_capP[/memv_imgP[a Ka ->] _]; have Ea := subvP sKE a Ka.
by rewrite -galM // -conjgC galM // (fixed_gal sKE galEy).
Qed.
Definition fixedField V (A : {set gal_of V}) :=
(V :&: \bigcap_(x in A) fixedSpace x)%VS.
Lemma fixedFieldP E {A : {set gal_of E}} a :
a \in E -> reflect (forall x, x \in A -> x a = a) (a \in fixedField A).
Proof.
by rewrite memv_cap => ->; apply: (iffP subv_bigcapP) => cAa x /cAa/fixedSpaceP.
Qed.
Lemma mem_fixedFieldP E (A : {set gal_of E}) a :
a \in fixedField A -> a \in E /\ (forall x, x \in A -> x a = a).
Proof.
by move=> fixAa; have [Ea _] := memv_capP fixAa; have:= fixedFieldP Ea fixAa.
Qed.
Fact fixedField_is_aspace E (A : {set gal_of E}) : is_aspace (fixedField A).
Proof.
rewrite /fixedField; elim/big_rec: _ {1}E => [|x K _ IH_K] M.
exact: (valP (M :&: _)%AS).
by rewrite capvA IH_K.
Qed.
Canonical fixedField_aspace E A : {subfield L} :=
ASpace (@fixedField_is_aspace E A).
Lemma fixedField_bound E (A : {set gal_of E}) : (fixedField A <= E)%VS.
Proof. exact: capvSl. Qed.
Lemma fixedFieldS E (A B : {set gal_of E}) :
A \subset B -> (fixedField B <= fixedField A)%VS.
Proof.
move/subsetP=> sAB; apply/subvP => a /mem_fixedFieldP[Ea cBa].
by apply/fixedFieldP; last apply: sub_in1 cBa.
Qed.
Lemma galois_connection_subv K E :
(K <= E)%VS -> (K <= fixedField ('Gal(E / K)))%VS.
Proof.
move=> sKE; apply/subvP => a Ka; have Ea := subvP sKE a Ka.
by apply/fixedFieldP=> // x galEx; apply: (fixed_gal sKE).
Qed.
Lemma galois_connection_subset E (A : {set gal_of E}):
A \subset 'Gal(E / fixedField A).
Proof.
apply/subsetP => x Ax; rewrite gal_kAut ?capvSl // kAutE limg_gal subvv andbT.
by apply/kAHomP=> a /mem_fixedFieldP[_ ->].
Qed.
Lemma galois_connection K E (A : {set gal_of E}):
(K <= E)%VS -> (A \subset 'Gal(E / K)) = (K <= fixedField A)%VS.
Proof.
move=> sKE; apply/idP/idP => [/fixedFieldS | /(galS E)].
exact/subv_trans/galois_connection_subv.
exact/subset_trans/galois_connection_subset.
Qed.
Definition galTrace U V a := \sum_(x in 'Gal(V / U)) (x a).
Definition galNorm U V a := \prod_(x in 'Gal(V / U)) (x a).
Section TraceAndNormMorphism.
Variables U V : {vspace L}.
Fact galTrace_is_zmod_morphism : zmod_morphism (galTrace U V).
Proof.
by move=> a b /=; rewrite -sumrB; apply: eq_bigr => x _; rewrite rmorphB.
Qed.
#[deprecated(since="mathcomp 2.5.0", note="use `galTrace_is_zmod_morphism` instead")]
Definition galTrace_is_additive := galTrace_is_zmod_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build L L (galTrace U V)
galTrace_is_zmod_morphism.
Lemma galNorm1 : galNorm U V 1 = 1.
Proof. by apply: big1 => x _; rewrite rmorph1. Qed.
Lemma galNormM : {morph galNorm U V : a b / a * b}.
Proof.
by move=> a b /=; rewrite -big_split; apply: eq_bigr => x _; rewrite rmorphM.
Qed.
Lemma galNormV : {morph galNorm U V : a / a^-1}.
Proof.
by move=> a /=; rewrite -prodfV; apply: eq_bigr => x _; rewrite fmorphV.
Qed.
Lemma galNormX n : {morph galNorm U V : a / a ^+ n}.
Proof.
move=> a; elim: n => [|n IHn]; first exact: galNorm1.
by rewrite !exprS galNormM IHn.
Qed.
Lemma galNorm_prod (I : Type) (r : seq I) (P : pred I) (B : I -> L) :
galNorm U V (\prod_(i <- r | P i) B i)
= \prod_(i <- r | P i) galNorm U V (B i).
Proof. exact: (big_morph _ galNormM galNorm1). Qed.
Lemma galNorm0 : galNorm U V 0 = 0.
Proof. by rewrite /galNorm (bigD1 1%g) ?group1 // rmorph0 /= mul0r. Qed.
Lemma galNorm_eq0 a : (galNorm U V a == 0) = (a == 0).
Proof.
apply/idP/eqP=> [/prodf_eq0[x _] | ->]; last by rewrite galNorm0.
by rewrite fmorph_eq0 => /eqP.
Qed.
End TraceAndNormMorphism.
Section TraceAndNormField.
Variables K E : {subfield L}.
Lemma galTrace_fixedField a :
a \in E -> galTrace K E a \in fixedField 'Gal(E / K).
Proof.
move=> Ea; apply/fixedFieldP=> [|x galEx].
by apply: rpred_sum => x _; apply: memv_gal.
rewrite {2}/galTrace (reindex_acts 'R _ galEx) ?astabsR //=.
by rewrite rmorph_sum; apply: eq_bigr => y _; rewrite galM ?lfunE.
Qed.
Lemma galTrace_gal a x :
a \in E -> x \in 'Gal(E / K) -> galTrace K E (x a) = galTrace K E a.
Proof.
move=> Ea galEx; rewrite {2}/galTrace (reindex_inj (mulgI x)).
by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE.
Qed.
Lemma galNorm_fixedField a :
a \in E -> galNorm K E a \in fixedField 'Gal(E / K).
Proof.
move=> Ea; apply/fixedFieldP=> [|x galEx].
by apply: rpred_prod => x _; apply: memv_gal.
rewrite {2}/galNorm (reindex_acts 'R _ galEx) ?astabsR //=.
by rewrite rmorph_prod; apply: eq_bigr => y _; rewrite galM ?lfunE.
Qed.
Lemma galNorm_gal a x :
a \in E -> x \in 'Gal(E / K) -> galNorm K E (x a) = galNorm K E a.
Proof.
move=> Ea galEx; rewrite {2}/galNorm (reindex_inj (mulgI x)).
by apply: eq_big => [b | b _]; rewrite ?groupMl // galM ?lfunE.
Qed.
End TraceAndNormField.
Definition normalField U V := [forall x in kAEndf U, x @: V == V]%VS.
Lemma normalField_kAut K M E f :
(K <= M <= E)%VS -> normalField K M -> kAut K E f -> kAut K M f.
Proof.
case/andP=> sKM sME nKM /kAut_to_gal[x galEx /(sub_in1 (subvP sME))Df].
have sKE := subv_trans sKM sME; rewrite gal_kHom // in galEx.
rewrite (kAut_eq sKM Df) /kAut (kHomSr sME) //= (forall_inP nKM) // inE.
by rewrite kAutfE; apply/kAHomP; apply: (kAHomP galEx).
Qed.
Lemma normalFieldP K E :
reflect {in E, forall a, exists2 r,
all [in E] r & minPoly K a = \prod_(b <- r) ('X - b%:P)}
(normalField K E).
Proof.
apply: (iffP eqfun_inP) => [nKE a Ea | nKE x]; last first.
rewrite inE kAutfE => homKx; suffices: kAut K E x by case/andP=> _ /eqP.
rewrite kAutE (kHomSr (subvf E)) //=; apply/subvP=> _ /memv_imgP[a Ea ->].
have [r /allP/=srE splitEa] := nKE a Ea.
rewrite srE // -root_prod_XsubC -splitEa.
by rewrite -(kHom_poly_id homKx (minPolyOver K a)) fmorph_root root_minPoly.
have [r /eqP splitKa] := splitting_field_normal K a.
exists r => //; apply/allP => b; rewrite -root_prod_XsubC -splitKa => pKa_b_0.
pose y := kHomExtend K \1 a b; have [hom1K lf1p] := (kHom1 K K, lfun1_poly).
have homKy: kHom K <<K; a>> y by apply/kHomExtendP; rewrite ?lf1p.
have [[g Dy] [idKy _]] := (kHom_to_AEnd homKy, kHomP_tmp homKy).
have <-: g a = b by rewrite -Dy ?memv_adjoin // (kHomExtend_val hom1K) ?lf1p.
suffices /nKE <-: g \in kAEndf K by apply: memv_img.
by rewrite inE kAutfE; apply/kAHomP=> c Kc; rewrite -Dy ?subvP_adjoin ?idKy.
Qed.
Lemma normalFieldf K : normalField K {:L}.
Proof.
apply/normalFieldP=> a _; have [r /eqP->] := splitting_field_normal K a.
by exists r => //; apply/allP=> b; rewrite /= memvf.
Qed.
Lemma normalFieldS K M E : (K <= M)%VS -> normalField K E -> normalField M E.
Proof.
move=> sKM /normalFieldP nKE; apply/normalFieldP=> a Ea.
have [r /allP Er splitKa] := nKE a Ea.
have /dvdp_prod_XsubC[m splitMa]: minPoly M a %| \prod_(b <- r) ('X - b%:P).
by rewrite -splitKa minPolyS.
exists (mask m r); first by apply/allP=> b /mem_mask/Er.
by apply/eqP; rewrite -eqp_monic ?monic_prod_XsubC ?monic_minPoly.
Qed.
Lemma splitting_normalField E K :
(K <= E)%VS ->
reflect (exists2 p, p \is a polyOver K & splittingFieldFor K p E)
(normalField K E).
Proof.
move=> sKE; apply: (iffP idP) => [nKE| [p Kp [rs Dp defE]]]; last first.
apply/forall_inP=> g /[!(inE, kAutE)] /andP[homKg _].
rewrite -dimv_leqif_eq ?limg_dim_eq ?(eqP (AEnd_lker0 g)) ?capv0 //.
rewrite -defE aimg_adjoin_seq; have [_ /fixedSpace_limg->] := andP homKg.
apply/adjoin_seqSr=> _ /mapP[a rs_a ->].
rewrite -!root_prod_XsubC -!(eqp_root Dp) in rs_a *.
by apply: kHom_root_id homKg Kp _ rs_a; rewrite ?subvf ?memvf.
pose splitK a r := minPoly K a = \prod_(b <- r) ('X - b%:P).
have{nKE} rK_ a: {r | a \in E -> all [in E] r /\ splitK a r}.
case Ea: (a \in E); last by exists [::].
by have /sig2_eqW[r] := normalFieldP _ _ nKE a Ea; exists r.
have sXE := basis_mem (vbasisP E); set X : seq L := vbasis E in sXE.
exists (\prod_(a <- X) minPoly K a).
by apply: rpred_prod => a _; apply: minPolyOver.
exists (flatten [seq (sval (rK_ a)) | a <- X]).
move/allP: sXE; elim: X => [|a X IHX]; first by rewrite !big_nil eqpxx.
rewrite big_cons /= big_cat /= => /andP[Ea sXE].
by case: (rK_ a) => /= r [] // _ <-; apply/eqp_mull/IHX.
apply/eqP; rewrite eqEsubv; apply/andP; split.
apply/Fadjoin_seqP; split=> // b /flatten_mapP[a /sXE Ea].
by apply/allP; case: rK_ => r /= [].
rewrite -{1}(span_basis (vbasisP E)); apply/span_subvP=> a Xa.
apply/seqv_sub_adjoin/flatten_mapP; exists a => //; rewrite -root_prod_XsubC.
by case: rK_ => /= r [| _ <-]; rewrite ?sXE ?root_minPoly.
Qed.
Lemma kHom_to_gal K M E f :
(K <= M <= E)%VS -> normalField K E -> kHom K M f ->
{x | x \in 'Gal(E / K) & {in M, f =1 x}}.
Proof.
case/andP=> /subvP sKM /subvP sME nKE KhomMf.
have [[g Df] [idKf _]] := (kHom_to_AEnd KhomMf, kHomP_tmp KhomMf).
suffices /kAut_to_gal[x galEx Dg]: kAut K E g.
by exists x => //= a Ma; rewrite Df // Dg ?sME.
have homKg: kHom K {:L} g by apply/kAHomP=> a Ka; rewrite -Df ?sKM ?idKf.
by rewrite /kAut (kHomSr (subvf _)) // (forall_inP nKE) // inE kAutfE.
Qed.
Lemma normalField_root_minPoly K E a b :
(K <= E)%VS -> normalField K E -> a \in E -> root (minPoly K a) b ->
exists2 x, x \in 'Gal(E / K) & x a = b.
Proof.
move=> sKE nKE Ea pKa_b_0; pose f := kHomExtend K \1 a b.
have homKa_f: kHom K <<K; a>> f.
by apply: kHomExtendP; rewrite ?kHom1 ?lfun1_poly.
have sK_Ka_E: (K <= <<K; a>> <= E)%VS.
by rewrite subv_adjoin; apply/FadjoinP; rewrite sKE Ea.
have [x galEx Df] := kHom_to_gal sK_Ka_E nKE homKa_f; exists x => //.
by rewrite -Df ?memv_adjoin // (kHomExtend_val (kHom1 K K)) ?lfun1_poly.
Qed.
Arguments normalFieldP {K E}.
Lemma normalField_factors K E :
(K <= E)%VS ->
reflect {in E, forall a, exists2 r : seq (gal_of E),
r \subset 'Gal(E / K)
& minPoly K a = \prod_(x <- r) ('X - (x a)%:P)}
(normalField K E).
Proof.
move=> sKE; apply: (iffP idP) => [nKE a Ea | nKE]; last first.
apply/normalFieldP=> a Ea; have [r _ ->] := nKE a Ea.
exists [seq x a | x : gal_of E <- r]; last by rewrite big_map.
by rewrite all_map; apply/allP=> b _; apply: memv_gal.
have [r Er splitKa] := normalFieldP nKE a Ea.
pose f b := [pick x in 'Gal(E / K) | x a == b].
exists (pmap f r).
apply/subsetP=> x; rewrite mem_pmap /f => /mapP[b _].
by case: (pickP _) => // c /andP[galEc _] [->].
rewrite splitKa; have{splitKa}: all (root (minPoly K a)) r.
by apply/allP => b; rewrite splitKa root_prod_XsubC.
elim: r Er => /= [|b r IHr]; first by rewrite !big_nil.
case/andP=> Eb Er /andP[pKa_b_0 /(IHr Er){Er}IHr].
have [x galE /eqP xa_b] := normalField_root_minPoly sKE nKE Ea pKa_b_0.
rewrite /(f b); case: (pickP _) => [y /andP[_ /eqP<-]|/(_ x)/andP[]//].
by rewrite !big_cons IHr.
Qed.
Definition galois U V := [&& (U <= V)%VS, separable U V & normalField U V].
Lemma galoisS K M E : (K <= M <= E)%VS -> galois K E -> galois M E.
Proof.
case/andP=> sKM sME /and3P[_ sepUV nUV].
by rewrite /galois sME (separableSl sKM) ?(normalFieldS sKM).
Qed.
Lemma galois_dim K E : galois K E -> \dim_K E = #|'Gal(E / K)|.
Proof.
case/and3P=> sKE /eq_adjoin_separable_generator-> // nKE.
set a := separable_generator K E in nKE *.
have [r /allP/=Er splitKa] := normalFieldP nKE a (memv_adjoin K a).
rewrite (dim_sup_field (subv_adjoin K a)) mulnK ?adim_gt0 //.
apply/eqP; rewrite -eqSS -adjoin_degreeE -size_minPoly splitKa size_prod_XsubC.
set n := size r; rewrite eqSS -[n]card_ord.
have x_ (i : 'I_n): {x | x \in 'Gal(<<K; a>> / K) & x a = r`_i}.
apply/sig2_eqW/normalField_root_minPoly; rewrite ?subv_adjoin ?memv_adjoin //.
by rewrite splitKa root_prod_XsubC mem_nth.
have /card_image <-: injective (fun i => s2val (x_ i)).
move=> i j /eqP; case: (x_ i) (x_ j) => y /= galEy Dya [z /= galEx Dza].
rewrite gal_adjoin_eq // Dya Dza nth_uniq // => [/(i =P j)//|].
by rewrite -separable_prod_XsubC -splitKa; apply: separable_generatorP.
apply/eqP/eq_card=> x; apply/codomP/idP=> [[i ->] | galEx]; first by case: x_.
have /(nthP 0) [i ltin Dxa]: x a \in r.
rewrite -root_prod_XsubC -splitKa.
by rewrite root_minPoly_gal ?memv_adjoin ?subv_adjoin.
exists (Ordinal ltin); apply/esym/eqP.
by case: x_ => y /= galEy /eqP; rewrite Dxa gal_adjoin_eq.
Qed.
Lemma galois_factors K E :
(K <= E)%VS ->
reflect {in E, forall a, exists r, let r_a := [seq x a | x : gal_of E <- r] in
[/\ r \subset 'Gal(E / K), uniq r_a
& minPoly K a = \prod_(b <- r_a) ('X - b%:P)]}
(galois K E).
Proof.
move=> sKE; apply: (iffP and3P) => [[_ sepKE nKE] a Ea | galKE].
have [r galEr splitEa] := normalField_factors sKE nKE a Ea.
exists r; rewrite /= -separable_prod_XsubC !big_map -splitEa.
by split=> //; apply: separableP Ea.
split=> //.
apply/separableP => a /galKE[r [_ Ur_a splitKa]].
by rewrite /separable_element splitKa separable_prod_XsubC.
apply/(normalField_factors sKE)=> a /galKE[r [galEr _ ->]].
by rewrite big_map; exists r.
Qed.
Lemma splitting_galoisField K E :
reflect (exists p, [/\ p \is a polyOver K, separable_poly p
& splittingFieldFor K p E])
(galois K E).
Proof.
apply: (iffP and3P) => [[sKE sepKE nKE]|[p [Kp sep_p [r Dp defE]]]].
rewrite (eq_adjoin_separable_generator sepKE) // in nKE *.
set a := separable_generator K E in nKE *; exists (minPoly K a).
split; first 1 [exact: minPolyOver | exact/separable_generatorP].
have [r /= /allP Er splitKa] := normalFieldP nKE a (memv_adjoin _ _).
exists r; first by rewrite splitKa eqpxx.
apply/eqP; rewrite eqEsubv; apply/andP; split.
by apply/Fadjoin_seqP; split => //; apply: subv_adjoin.
apply/FadjoinP; split; first exact: subv_adjoin_seq.
by rewrite seqv_sub_adjoin // -root_prod_XsubC -splitKa root_minPoly.
have sKE: (K <= E)%VS by rewrite -defE subv_adjoin_seq.
split=> //; last by apply/splitting_normalField=> //; exists p; last exists r.
rewrite -defE; apply/separable_Fadjoin_seq/allP=> a r_a.
by apply/separable_elementP; exists p; rewrite (eqp_root Dp) root_prod_XsubC.
Qed.
Lemma galois_fixedField K E :
reflect (fixedField 'Gal(E / K) = K) (galois K E).
Proof.
apply: (iffP idP) => [/and3P[sKE /separableP sepKE nKE] | fixedKE].
apply/eqP; rewrite eqEsubv galois_connection_subv ?andbT //.
apply/subvP=> a /mem_fixedFieldP[Ea fixEa]; rewrite -adjoin_deg_eq1.
have [r /allP Er splitKa] := normalFieldP nKE a Ea.
rewrite -eqSS -size_minPoly splitKa size_prod_XsubC eqSS -[1]/(size [:: a]).
have Ur: uniq r by rewrite -separable_prod_XsubC -splitKa; apply: sepKE.
rewrite -uniq_size_uniq {Ur}// => b; rewrite inE -root_prod_XsubC -splitKa.
apply/eqP/idP=> [-> | pKa_b_0]; first exact: root_minPoly.
by have [x /fixEa-> ->] := normalField_root_minPoly sKE nKE Ea pKa_b_0.
have sKE: (K <= E)%VS by rewrite -fixedKE capvSl.
apply/galois_factors=> // a Ea.
pose r_pKa := [seq x a | x : gal_of E in 'Gal(E / K)].
have /fin_all_exists2[x_ galEx_ Dx_a] (b : seq_sub r_pKa) := imageP (valP b).
exists (codom x_); rewrite -map_comp; set r := map _ _.
have r_xa x: x \in 'Gal(E / K) -> x a \in r.
move=> galEx; have r_pKa_xa: x a \in r_pKa by apply/imageP; exists x.
by rewrite [x a](Dx_a (SeqSub r_pKa_xa)); apply: codom_f.
have Ur: uniq r by apply/injectiveP=> b c /=; rewrite -!Dx_a => /val_inj.
split=> //; first by apply/subsetP=> _ /codomP[b ->].
apply/eqP; rewrite -eqp_monic ?monic_minPoly ?monic_prod_XsubC //.
apply/andP; split; last first.
rewrite uniq_roots_dvdp ?uniq_rootsE // all_map.
by apply/allP=> b _ /=; rewrite root_minPoly_gal.
apply: minPoly_dvdp; last by rewrite root_prod_XsubC -(gal_id E a) r_xa ?group1.
rewrite -fixedKE; apply/polyOverP => i; apply/fixedFieldP=> [|x galEx].
rewrite (polyOverP _) // big_map rpred_prod // => b _.
by rewrite polyOverXsubC memv_gal.
rewrite -coef_map rmorph_prod; congr (_ : {poly _})`_i.
symmetry; rewrite (perm_big (map x r)) /= ?(big_map x).
by apply: eq_bigr => b _; rewrite rmorphB /= map_polyX map_polyC.
have Uxr: uniq (map x r) by rewrite map_inj_uniq //; apply: fmorph_inj.
have /uniq_min_size: {subset map x r <= r}.
by rewrite -map_comp => _ /codomP[b ->] /=; rewrite -galM // r_xa ?groupM.
by rewrite (size_map x) perm_sym; case=> // _ /uniq_perm->.
Qed.
Lemma mem_galTrace K E a : galois K E -> a \in E -> galTrace K E a \in K.
Proof. by move/galois_fixedField => {2}<- /galTrace_fixedField. Qed.
Lemma mem_galNorm K E a : galois K E -> a \in E -> galNorm K E a \in K.
Proof. by move/galois_fixedField=> {2}<- /galNorm_fixedField. Qed.
Lemma gal_independent_contra E (P : pred (gal_of E)) (c_ : gal_of E -> L) x :
P x -> c_ x != 0 ->
exists2 a, a \in E & \sum_(y | P y) c_ y * y a != 0.
Proof.
have [n] := ubnP #|P|; elim: n c_ x P => // n IHn c_ x P lePn Px nz_cx.
rewrite ltnS (cardD1x Px) in lePn; move/IHn: lePn => {n IHn}/=IH_P.
have [/eqfun_inP c_Px'_0 | ] := boolP [forall (y | P y && (y != x)), c_ y == 0].
exists 1; rewrite ?mem1v // (bigD1 x Px) /= rmorph1 mulr1.
by rewrite big1 ?addr0 // => y /c_Px'_0->; rewrite mul0r.
case/forall_inPn => y Px'y nz_cy.
have [Py /gal_eqP/eqlfun_inP/subvPn[a Ea]] := andP Px'y.
rewrite memv_ker !lfun_simp => nz_yxa; pose d_ y := c_ y * (y a - x a).
have /IH_P[//|b Eb nz_sumb]: d_ y != 0 by rewrite mulf_neq0.
have [sumb_0|] := eqVneq (\sum_(z | P z) c_ z * z b) 0; last by exists b.
exists (a * b); first exact: rpredM.
rewrite -subr_eq0 -[z in _ - z](mulr0 (x a)) -[in z in _ - z]sumb_0.
rewrite mulr_sumr -sumrB (bigD1 x Px) rmorphM /= mulrCA subrr add0r.
congr (_ != 0): nz_sumb; apply: eq_bigr => z _.
by rewrite mulrCA rmorphM -mulrBr -mulrBl mulrA.
Qed.
Lemma gal_independent E (P : pred (gal_of E)) (c_ : gal_of E -> L) :
(forall a, a \in E -> \sum_(x | P x) c_ x * x a = 0) ->
(forall x, P x -> c_ x = 0).
Proof.
move=> sum_cP_0 x Px; apply/eqP/idPn=> /(gal_independent_contra Px)[a Ea].
by rewrite sum_cP_0 ?eqxx.
Qed.
Lemma Hilbert's_theorem_90 K E x a :
generator 'Gal(E / K) x -> a \in E ->
reflect (exists2 b, b \in E /\ b != 0 & a = b / x b) (galNorm K E a == 1).
Proof.
move/(_ =P <[x]>)=> DgalE Ea.
have galEx: x \in 'Gal(E / K) by rewrite DgalE cycle_id.
apply: (iffP eqP) => [normEa1 | [b [Eb nzb] ->]]; last first.
by rewrite galNormM galNormV galNorm_gal // mulfV // galNorm_eq0.
have [x1 | ntx] := eqVneq x 1%g.
exists 1; first by rewrite mem1v oner_neq0.
by rewrite -{1}normEa1 /galNorm DgalE x1 cycle1 big_set1 !gal_id divr1.
pose c_ y := \prod_(i < invm (injm_Zpm x) y) (x ^+ i)%g a.
have nz_c1: c_ 1%g != 0 by rewrite /c_ morph1 big_ord0 oner_neq0.
have [d] := @gal_independent_contra _ [in 'Gal(E / K)] _ _ (group1 _) nz_c1.
set b := \sum_(y in _) _ => Ed nz_b; exists b.
split=> //; apply: rpred_sum => y galEy.
by apply: rpredM; first apply: rpred_prod => i _; apply: memv_gal.
apply: canRL (mulfK _) _; first by rewrite fmorph_eq0.
rewrite rmorph_sum mulr_sumr [b](reindex_acts 'R _ galEx) ?astabsR //=.
apply: eq_bigr => y galEy; rewrite galM // rmorphM mulrA; congr (_ * _).
have /morphimP[/= i _ _ ->] /=: y \in Zpm @* Zp #[x] by rewrite im_Zpm -DgalE.
have <-: Zpm (i + 1) = (Zpm i * x)%g by rewrite morphM ?mem_Zp ?order_gt1.
rewrite /c_ !invmE ?mem_Zp ?order_gt1 //= addn1; set n := _.+2.
transitivity (\prod_(j < i.+1) (x ^+ j)%g a).
rewrite big_ord_recl gal_id rmorph_prod; congr (_ * _).
by apply: eq_bigr => j _; rewrite expgSr galM ?lfunE.
have [/modn_small->//||->] := ltngtP i.+1 n; first by rewrite ltnNge ltn_ord.
rewrite modnn big_ord0; apply: etrans normEa1; rewrite /galNorm DgalE -im_Zpm.
rewrite morphimEdom big_imset /=; last exact/injmP/injm_Zpm.
by apply: eq_bigl => j /=; rewrite mem_Zp ?order_gt1.
Qed.
Section Matrix.
Variable (E : {subfield L}) (A : {set gal_of E}).
Let K := fixedField A.
Lemma gal_matrix :
{w : #|A|.-tuple L | {subset w <= E} /\ 0 \notin w &
[/\ \matrix_(i, j < #|A|) enum_val i (tnth w j) \in unitmx,
directv (\sum_i K * <[tnth w i]>) &
group_set A -> (\sum_i K * <[tnth w i]>)%VS = E] }.
Proof.
pose nzE (w : #|A|.-tuple L) := {subset w <= E} /\ 0 \notin w.
pose M w := \matrix_(i, j < #|A|) nth 1%g (enum A) i (tnth w j).
have [w [Ew nzw] uM]: {w : #|A|.-tuple L | nzE w & M w \in unitmx}.
rewrite {}/nzE {}/M cardE; have: uniq (enum A) := enum_uniq _.
elim: (enum A) => [|x s IHs] Uxs.
by exists [tuple]; rewrite // flatmx0 -(flatmx0 1%:M) unitmx1.
have [s'x Us]: x \notin s /\ uniq s by apply/andP.
have{IHs} [w [Ew nzw] uM] := IHs Us; set M := \matrix_(i, j) _ in uM.
pose a := \row_i x (tnth w i) *m invmx M.
pose c_ y := oapp (a 0) (-1) (insub (index y s)).
have cx_n1 : c_ x = -1 by rewrite /c_ insubN ?index_mem.
have nz_cx : c_ x != 0 by rewrite cx_n1 oppr_eq0 oner_neq0.
have Px: [pred y in x :: s] x := mem_head x s.
have{Px nz_cx} /sig2W[w0 Ew0 nzS] := gal_independent_contra Px nz_cx.
exists [tuple of cons w0 w].
split; first by apply/allP; rewrite /= Ew0; apply/allP.
rewrite inE negb_or (contraNneq _ nzS) // => <-.
by rewrite big1 // => y _; rewrite rmorph0 mulr0.
rewrite unitmxE -[\det _]mul1r; set M1 := \matrix_(i, j < 1 + size s) _.
have <-: \det (block_mx 1 (- a) 0 1%:M) = 1 by rewrite det_ublock !det1 mulr1.
rewrite -det_mulmx -[M1]submxK mulmx_block !mul0mx !mul1mx !add0r !mulNmx.
have ->: drsubmx M1 = M by apply/matrixP => i j; rewrite !mxE !(tnth_nth 0).
have ->: ursubmx M1 - a *m M = 0.
by apply/rowP=> i; rewrite mulmxKV // !mxE !(tnth_nth 0) subrr.
rewrite det_lblock unitrM andbC -(unitmxE M) uM unitfE -oppr_eq0.
congr (_ != 0): nzS; rewrite [_ - _]mx11_scalar det_scalar !mxE opprB /=.
rewrite -big_uniq // big_cons /= cx_n1 mulN1r addrC; congr (_ + _).
rewrite (big_nth 1%g) big_mkord; apply: eq_bigr => j _.
by rewrite /c_ index_uniq // valK; congr (_ * _); rewrite !mxE.
exists w => [//|]; split=> [||gA].
- by congr (_ \in unitmx): uM; apply/matrixP=> i j; rewrite !mxE -enum_val_nth.
- apply/directv_sum_independent=> kw_ Kw_kw sum_kw_0 j _.
have /fin_all_exists2[k_ Kk_ Dk_] i := memv_cosetP (Kw_kw i isT).
pose kv := \col_i k_ i.
transitivity (kv j 0 * tnth w j); first by rewrite !mxE.
suffices{j}/(canRL (mulKmx uM))->: M w *m kv = 0 by rewrite mulmx0 mxE mul0r.
apply/colP=> i /[!mxE]; pose Ai := nth 1%g (enum A) i.
transitivity (Ai (\sum_j kw_ j)); last by rewrite sum_kw_0 rmorph0.
rewrite rmorph_sum; apply: eq_bigr => j _; rewrite !mxE /= -/Ai.
rewrite Dk_ mulrC rmorphM /=; congr (_ * _).
by have /mem_fixedFieldP[_ -> //] := Kk_ j; rewrite -mem_enum mem_nth -?cardE.
pose G := group gA; have G_1 := group1 G; pose iG := enum_rank_in G_1.
apply/eqP; rewrite eqEsubv; apply/andP; split.
apply/subv_sumP=> i _; apply: subv_trans (asubv _).
by rewrite prodvS ?capvSl // -memvE Ew ?mem_tnth.
apply/subvP=> w0 Ew0; apply/memv_sumP.
pose wv := \col_(i < #|A|) enum_val i w0; pose v := invmx (M w) *m wv.
exists (fun i => tnth w i * v i 0) => [i _|]; last first.
transitivity (wv (iG 1%g) 0); first by rewrite mxE enum_rankK_in ?gal_id.
rewrite -[wv](mulKVmx uM) -/v mxE; apply: eq_bigr => i _.
by congr (_ * _); rewrite !mxE -enum_val_nth enum_rankK_in ?gal_id.
rewrite mulrC memv_mul ?memv_line //; apply/fixedFieldP=> [|x Gx].
rewrite mxE rpred_sum // => j _; rewrite !mxE rpredM //; last exact: memv_gal.
have E_M k l: M w k l \in E by rewrite mxE memv_gal // Ew ?mem_tnth.
have Edet n (N : 'M_n) (E_N : forall i j, N i j \in E): \det N \in E.
by apply: rpred_sum => sigma _; rewrite rpredMsign rpred_prod.
rewrite /invmx uM 2!mxE mulrC rpred_div ?Edet //.
by rewrite rpredMsign Edet // => k l; rewrite 2!mxE.
suffices{i} {2}<-: map_mx x v = v by rewrite [map_mx x v i 0]mxE.
have uMx: map_mx x (M w) \in unitmx by rewrite map_unitmx.
rewrite map_mxM map_invmx /=; apply: canLR {uMx}(mulKmx uMx) _.
apply/colP=> i /[!mxE]; pose ix := iG (enum_val i * x)%g.
have Dix b: b \in E -> enum_val ix b = x (enum_val i b).
by move=> Eb; rewrite enum_rankK_in ?groupM ?enum_valP // galM ?lfunE.
transitivity ((M w *m v) ix 0); first by rewrite mulKVmx // mxE Dix.
rewrite mxE; apply: eq_bigr => j _; congr (_ * _).
by rewrite !mxE -!enum_val_nth Dix // ?Ew ?mem_tnth.
Qed.
End Matrix.
Lemma dim_fixedField E (G : {group gal_of E}) : #|G| = \dim_(fixedField G) E.
Proof.
have [w [_ nzw] [_ Edirect /(_ (groupP G))defE]] := gal_matrix G.
set n := #|G|; set m := \dim (fixedField G); rewrite -defE (directvP Edirect).
rewrite -[n]card_ord -(@mulnK #|'I_n| m) ?adim_gt0 //= -sum_nat_const.
congr (_ %/ _)%N; apply: eq_bigr => i _.
by rewrite dim_cosetv ?(memPn nzw) ?mem_tnth.
Qed.
Lemma dim_fixed_galois K E (G : {group gal_of E}) :
galois K E -> G \subset 'Gal(E / K) ->
\dim_K (fixedField G) = #|'Gal(E / K) : G|.
Proof.
move=> galE sGgal; have [sFE _ _] := and3P galE; apply/eqP.
rewrite -divgS // eqn_div ?cardSg // dim_fixedField -galois_dim //.
by rewrite mulnC muln_divA ?divnK ?field_dimS ?capvSl -?galois_connection.
Qed.
Lemma gal_fixedField E (G : {group gal_of E}): 'Gal(E / fixedField G) = G.
Proof.
apply/esym/eqP; rewrite eqEcard galois_connection_subset /= (dim_fixedField G).
rewrite galois_dim //; apply/galois_fixedField/eqP.
rewrite eqEsubv galois_connection_subv ?capvSl //.
by rewrite fixedFieldS ?galois_connection_subset.
Qed.
Lemma gal_generated E (A : {set gal_of E}) : 'Gal(E / fixedField A) = <<A>>.
Proof.
apply/eqP; rewrite eqEsubset gen_subG galois_connection_subset.
by rewrite -[<<A>>]gal_fixedField galS // fixedFieldS // subset_gen.
Qed.
Lemma fixedField_galois E (A : {set gal_of E}): galois (fixedField A) E.
Proof.
have: galois (fixedField <<A>>) E.
by apply/galois_fixedField; rewrite gal_fixedField.
by apply: galoisS; rewrite capvSl fixedFieldS // subset_gen.
Qed.
Section FundamentalTheoremOfGaloisTheory.
Variables E K : {subfield L}.
Hypothesis galKE : galois K E.
Section IntermediateField.
Variable M : {subfield L}.
Hypothesis (sKME : (K <= M <= E)%VS) (nKM : normalField K M).
Lemma normalField_galois : galois K M.
Proof.
have [[sKM sME] [_ sepKE nKE]] := (andP sKME, and3P galKE).
by rewrite /galois sKM (separableSr sME).
Qed.
Definition normalField_cast (x : gal_of E) : gal_of M := gal M x.
Lemma normalField_cast_eq x :
x \in 'Gal(E / K) -> {in M, normalField_cast x =1 x}.
Proof.
have [sKM sME] := andP sKME; have sKE := subv_trans sKM sME.
rewrite gal_kAut // => /(normalField_kAut sKME nKM).
by rewrite kAutE => /andP[_ /galK].
Qed.
Lemma normalField_castM :
{in 'Gal(E / K) &, {morph normalField_cast : x y / (x * y)%g}}.
Proof.
move=> x y galEx galEy /=; apply/eqP/gal_eqP => a Ma.
have Ea: a \in E by have [_ /subvP->] := andP sKME.
rewrite normalField_cast_eq ?groupM ?galM //=.
by rewrite normalField_cast_eq ?memv_gal // normalField_cast_eq.
Qed.
Canonical normalField_cast_morphism := Morphism normalField_castM.
Lemma normalField_ker : 'ker normalField_cast = 'Gal(E / M).
Proof.
have [sKM sME] := andP sKME.
apply/setP=> x; apply/idP/idP=> [kerMx | galEMx].
rewrite gal_kHom //; apply/kAHomP=> a Ma.
by rewrite -normalField_cast_eq ?(dom_ker kerMx) // (mker kerMx) gal_id.
have galEM: x \in 'Gal(E / K) := subsetP (galS E sKM) x galEMx.
apply/kerP=> //; apply/eqP/gal_eqP=> a Ma.
by rewrite normalField_cast_eq // gal_id (fixed_gal sME).
Qed.
Lemma normalField_normal : 'Gal(E / M) <| 'Gal(E / K).
Proof. by rewrite -normalField_ker ker_normal. Qed.
Lemma normalField_img : normalField_cast @* 'Gal(E / K) = 'Gal(M / K).
Proof.
have [[sKM sME] [sKE _ nKE]] := (andP sKME, and3P galKE).
apply/setP=> x; apply/idP/idP=> [/morphimP[{}x galEx _ ->] | galMx].
rewrite gal_kHom //; apply/kAHomP=> a Ka; have Ma := subvP sKM a Ka.
by rewrite normalField_cast_eq // (fixed_gal sKE).
have /(kHom_to_gal sKME nKE)[y galEy eq_xy]: kHom K M x by rewrite -gal_kHom.
apply/morphimP; exists y => //; apply/eqP/gal_eqP => a Ha.
by rewrite normalField_cast_eq // eq_xy.
Qed.
Lemma normalField_isom :
{f : {morphism ('Gal(E / K) / 'Gal(E / M)) >-> gal_of M} |
isom ('Gal(E / K) / 'Gal (E / M)) 'Gal(M / K) f
& (forall A, f @* (A / 'Gal(E / M)) = normalField_cast @* A)
/\ {in 'Gal(E / K) & M, forall x, f (coset 'Gal (E / M) x) =1 x} }%g.
Proof.
have:= first_isom normalField_cast_morphism; rewrite normalField_ker.
case=> f injf Df; exists f; first by apply/isomP; rewrite Df normalField_img.
split=> [//|x a galEx /normalField_cast_eq<- //]; congr ((_ : gal_of M) a).
apply: set1_inj; rewrite -!morphim_set1 ?mem_quotient ?Df //.
by rewrite (subsetP (normal_norm normalField_normal)).
Qed.
Lemma normalField_isog : 'Gal(E / K) / 'Gal(E / M) \isog 'Gal(M / K).
Proof. by rewrite -normalField_ker -normalField_img first_isog. Qed.
End IntermediateField.
Section IntermediateGroup.
Variable G : {group gal_of E}.
Hypothesis nsGgalE : G <| 'Gal(E / K).
Lemma normal_fixedField_galois : galois K (fixedField G).
Proof.
have [[sKE sepKE nKE] [sGgal nGgal]] := (and3P galKE, andP nsGgalE).
rewrite /galois -(galois_connection _ sKE) sGgal.
rewrite (separableSr _ sepKE) ?capvSl //; apply/forall_inP=> f autKf.
rewrite eqEdim limg_dim_eq ?(eqP (AEnd_lker0 _)) ?capv0 // leqnn andbT.
apply/subvP => _ /memv_imgP[a /mem_fixedFieldP[Ea cGa] ->].
have /kAut_to_gal[x galEx -> //]: kAut K E f.
rewrite /kAut (forall_inP nKE) // andbT; apply/kAHomP.
by move: autKf; rewrite inE kAutfE => /kHomP_tmp[].
apply/fixedFieldP=> [|y Gy]; first exact: memv_gal.
by rewrite -galM // conjgCV galM //= cGa // memJ_norm ?groupV ?(subsetP nGgal).
Qed.
End IntermediateGroup.
End FundamentalTheoremOfGaloisTheory.
End GaloisTheory.
Prenex Implicits gal_repr gal gal_reprK.
Arguments gal_repr_inj {F L V} [x1 x2].
Notation "''Gal' ( V / U )" := (galoisG V U) : group_scope.
Notation "''Gal' ( V / U )" := (galoisG_group V U) : Group_scope.
Arguments fixedFieldP {F L E A a}.
Arguments normalFieldP {F L K E}.
Arguments splitting_galoisField {F L K E}.
Arguments galois_fixedField {F L K E}.
|
Resolution.lean
|
/-
Copyright (c) 2022 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston
-/
import Mathlib.RepresentationTheory.Homological.Resolution
deprecated_module (since := "2025-06-14")
|
Symmetric.lean
|
/-
Copyright (c) 2020 Kim Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Kevin Buzzard, Kim Morrison, Jakob von Raumer
-/
import Mathlib.CategoryTheory.Monoidal.Braided.Basic
import Mathlib.Algebra.Category.ModuleCat.Monoidal.Basic
/-!
# The symmetric monoidal structure on `Module R`.
-/
universe v w x u
open CategoryTheory MonoidalCategory
namespace ModuleCat
variable {R : Type u} [CommRing R]
/-- (implementation) the braiding for R-modules -/
def braiding (M N : ModuleCat.{u} R) : M β N β
N β M :=
LinearEquiv.toModuleIso (TensorProduct.comm R M N)
namespace MonoidalCategory
@[simp]
theorem braiding_naturality {Xβ Xβ Yβ Yβ : ModuleCat.{u} R} (f : Xβ βΆ Yβ) (g : Xβ βΆ Yβ) :
(f ββ g) β« (Yβ.braiding Yβ).hom = (Xβ.braiding Xβ).hom β« (g ββ f) := by
ext : 1
apply TensorProduct.ext'
intro x y
rfl
@[simp]
theorem braiding_naturality_left {X Y : ModuleCat R} (f : X βΆ Y) (Z : ModuleCat R) :
f β· Z β« (braiding Y Z).hom = (braiding X Z).hom β« Z β f := by
simp_rw [β id_tensorHom]
apply braiding_naturality
@[simp]
theorem braiding_naturality_right (X : ModuleCat R) {Y Z : ModuleCat R} (f : Y βΆ Z) :
X β f β« (braiding X Z).hom = (braiding X Y).hom β« f β· X := by
simp_rw [β id_tensorHom]
apply braiding_naturality
@[simp]
theorem hexagon_forward (X Y Z : ModuleCat.{u} R) :
(Ξ±_ X Y Z).hom β« (braiding X _).hom β« (Ξ±_ Y Z X).hom =
(braiding X Y).hom β· Z β« (Ξ±_ Y X Z).hom β« Y β (braiding X Z).hom := by
ext : 1
apply TensorProduct.ext_threefold
intro x y z
rfl
@[simp]
theorem hexagon_reverse (X Y Z : ModuleCat.{u} R) :
(Ξ±_ X Y Z).inv β« (braiding _ Z).hom β« (Ξ±_ Z X Y).inv =
X β (Y.braiding Z).hom β« (Ξ±_ X Z Y).inv β« (X.braiding Z).hom β· Y := by
apply (cancel_epi (Ξ±_ X Y Z).hom).1
ext : 1
apply TensorProduct.ext_threefold
intro x y z
rfl
attribute [local ext] TensorProduct.ext
/-- The symmetric monoidal structure on `Module R`. -/
instance symmetricCategory : SymmetricCategory (ModuleCat.{u} R) where
braiding := braiding
braiding_naturality_left := braiding_naturality_left
braiding_naturality_right := braiding_naturality_right
hexagon_forward := hexagon_forward
hexagon_reverse := hexagon_reverse
-- Porting note: this proof was automatic in Lean3
-- now `aesop` is applying `ModuleCat.ext` in favour of `TensorProduct.ext`.
symmetry _ _ := by
ext : 1
apply TensorProduct.ext'
cat_disch
@[simp]
theorem braiding_hom_apply {M N : ModuleCat.{u} R} (m : M) (n : N) :
((Ξ²_ M N).hom : M β N βΆ N β M) (m ββ n) = n ββ m :=
rfl
@[simp]
theorem braiding_inv_apply {M N : ModuleCat.{u} R} (m : M) (n : N) :
((Ξ²_ M N).inv : N β M βΆ M β N) (n ββ m) = m ββ n :=
rfl
theorem tensorΞΌ_eq_tensorTensorTensorComm {A B C D : ModuleCat R} :
tensorΞΌ A B C D = ofHom (TensorProduct.tensorTensorTensorComm R A B C D).toLinearMap :=
ModuleCat.hom_ext <| TensorProduct.ext <| TensorProduct.ext <| LinearMap.extβ fun _ _ =>
TensorProduct.ext <| LinearMap.extβ fun _ _ => rfl
@[simp]
theorem tensorΞΌ_apply
{A B C D : ModuleCat R} (x : A) (y : B) (z : C) (w : D) :
tensorΞΌ A B C D ((x ββ y) ββ (z ββ w)) = (x ββ z) ββ (y ββ w) := rfl
end MonoidalCategory
end ModuleCat
|
MonoidAlgebra.lean
|
/-
Copyright (c) 2025 Amelia Livingston. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Amelia Livingston, YaΓ«l Dillies, MichaΕ MrugaΕa
-/
import Mathlib.RingTheory.Bialgebra.Hom
import Mathlib.RingTheory.Coalgebra.MonoidAlgebra
/-!
# The bialgebra structure on monoid algebras
Given a monoid `M`, a commutative semiring `R` and an `R`-bialgebra `A`, this file collects results
about the `R`-bialgebra instance on `A[M]` inherited from the corresponding structure on its
coefficients, building upon results in `Mathlib/RingTheory/Coalgebra/MonoidAlgebra.lean` about the
coalgebra structure.
## Main definitions
* `(Add)MonoidAlgebra.instBialgebra`: the `R`-bialgebra structure on `A[M]` when `M` is an (add)
monoid and `A` is an `R`-bialgebra.
* `LaurentPolynomial.instBialgebra`: the `R`-bialgebra structure on the Laurent polynomials
`A[T;Tβ»ΒΉ]` when `A` is an `R`-bialgebra.
-/
noncomputable section
open Bialgebra
variable {R A M N O : Type*}
namespace MonoidAlgebra
variable [CommSemiring R] [Semiring A] [Bialgebra R A] [Monoid M] [Monoid N] [Monoid O]
variable (R A M) in
instance instBialgebra : Bialgebra R (MonoidAlgebra A M) where
counit_one := by simp only [one_def, counit_single, Bialgebra.counit_one]
mul_comprβ_counit := by ext; simp
comul_one := by
simp only [one_def, comul_single, Bialgebra.comul_one, Algebra.TensorProduct.one_def,
TensorProduct.map_tmul, lsingle_apply]
mul_comprβ_comul := by
ext a b c d
simp only [Function.comp_apply, LinearMap.coe_comp, LinearMap.comprβ_apply,
LinearMap.mul_apply', single_mul_single, comul_single, Bialgebra.comul_mul,
β (Coalgebra.Repr.arbitrary R b).eq, β (Coalgebra.Repr.arbitrary R d).eq, Finset.sum_mul_sum,
Algebra.TensorProduct.tmul_mul_tmul, map_sum, TensorProduct.map_tmul, lsingle_apply,
LinearMap.complββ_apply, LinearMap.coeFn_sum, Finset.sum_apply,
Finset.sum_comm (s := (Coalgebra.Repr.arbitrary R b).index)]
-- TODO: Generalise to `MonoidAlgebra A M ββc[R] MonoidAlgebra A N` under `Bialgebra R A`
variable (R) in
/-- If `f : M β N` is a monoid hom, then `MonoidAlgebra.mapDomain f` is a bialgebra hom between
their monoid algebras. -/
@[simps!]
noncomputable def mapDomainBialgHom (f : M β* N) : MonoidAlgebra R M ββc[R] MonoidAlgebra R N :=
.ofAlgHom (mapDomainAlgHom R R f) (by ext; simp) (by ext; simp)
@[simp] lemma mapDomainBialgHom_id : mapDomainBialgHom R (.id M) = .id _ _ := by ext; simp
@[simp]
lemma mapDomainBialgHom_comp (f : N β* O) (g : M β* N) :
mapDomainBialgHom R (f.comp g) = (mapDomainBialgHom R f).comp (mapDomainBialgHom R g) := by
ext; simp [Finsupp.mapDomain_comp]
lemma mapDomainBialgHom_mapDomainBialgHom (f : N β* O) (g : M β* N) (x : MonoidAlgebra R M) :
mapDomainBialgHom R f (mapDomainBialgHom R g x) = mapDomainBialgHom R (f.comp g) x := by
ext; simp
end MonoidAlgebra
namespace AddMonoidAlgebra
variable [CommSemiring R] [Semiring A] [Bialgebra R A] [AddMonoid M] [AddMonoid N] [AddMonoid O]
variable (R A M) in
instance instBialgebra : Bialgebra R A[M] where
counit_one := by simp only [one_def, counit_single, Bialgebra.counit_one]
mul_comprβ_counit := by ext; simp [single_mul_single]
comul_one := by
simp only [one_def, comul_single, Bialgebra.comul_one, Algebra.TensorProduct.one_def,
TensorProduct.map_tmul, lsingle_apply]
mul_comprβ_comul := by
ext a b c d
simp only [Function.comp_apply, LinearMap.coe_comp, LinearMap.comprβ_apply,
LinearMap.mul_apply', single_mul_single, comul_single, Bialgebra.comul_mul,
β (Coalgebra.Repr.arbitrary R b).eq, β (Coalgebra.Repr.arbitrary R d).eq, Finset.sum_mul_sum,
Algebra.TensorProduct.tmul_mul_tmul, map_sum, TensorProduct.map_tmul, lsingle_apply,
LinearMap.complββ_apply, LinearMap.coeFn_sum, Finset.sum_apply,
Finset.sum_comm (s := (Coalgebra.Repr.arbitrary R b).index)]
-- TODO: Generalise to `A[M] ββc[R] A[N]` under `Bialgebra R A`
variable (R) in
/-- If `f : M β N` is a monoid hom, then `AddMonoidAlgebra.mapDomain f` is a bialgebra hom between
their monoid algebras. -/
@[simps]
noncomputable def mapDomainBialgHom (f : M β+ N) : R[M] ββc[R] R[N] where
__ := mapDomainAlgHom R R f
map_smul' m x := by simp
counit_comp := by ext; simp
map_comp_comul := by ext; simp
@[simp] lemma mapDomainBialgHom_id : mapDomainBialgHom R (.id M) = .id _ _ := by ext; simp
@[simp]
lemma mapDomainBialgHom_comp (f : N β+ O) (g : M β+ N) :
mapDomainBialgHom R (f.comp g) = (mapDomainBialgHom R f).comp (mapDomainBialgHom R g) := by
ext; simp
lemma mapDomainBialgHom_mapDomainBialgHom (f : N β+ O) (g : M β+ N) (x : R[M]) :
mapDomainBialgHom R f (mapDomainBialgHom R g x) = mapDomainBialgHom R (f.comp g) x := by
ext; simp
end AddMonoidAlgebra
namespace LaurentPolynomial
open AddMonoidAlgebra
variable {R : Type*} [CommSemiring R] {A : Type*} [Semiring A] [Bialgebra R A]
instance instBialgebra : Bialgebra R A[T;Tβ»ΒΉ] :=
inferInstanceAs <| Bialgebra R A[β€]
@[simp]
theorem comul_T (n : β€) :
Coalgebra.comul (R := R) (T n : A[T;Tβ»ΒΉ]) = T n ββ[R] T n := by
simp [T, -single_eq_C_mul_T, Algebra.TensorProduct.one_def]
@[simp]
theorem counit_T (n : β€) :
Coalgebra.counit (R := R) (T n : A[T;Tβ»ΒΉ]) = 1 := by
simp [T, -single_eq_C_mul_T]
end LaurentPolynomial
|
Spread.lean
|
/-
Copyright (c) 2021 Gabriel Ebner. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Gabriel Ebner
-/
import Mathlib.Init
import Lean.Elab.Binders
/-!
# Macro for spread syntax (`__ := instSomething`) in structures.
-/
open Lean Parser.Term Macro
/-
This adds support for structure instance spread syntax.
```lean
instance : Foo Ξ± where
__ := instSomething -- include fields from `instSomething`
example : Foo Ξ± := {
__ := instSomething -- include fields from `instSomething`
}
```
-/
/--
Mathlib extension to preserve old behavior of structure instances.
We need to be able to `let` some implementation details that are still local instances.
Normally implementation detail fvars are not local instances,
but we need them to be implementation details so that `simp` will see them as "reducible" fvars.
-/
syntax (name := letImplDetailStx) "let_impl_detail " ident " := " term "; " term : term
open Lean Elab Term Meta
@[term_elab letImplDetailStx, inherit_doc letImplDetailStx]
def elabLetImplDetail : TermElab := fun stx expectedType? =>
match stx with
| `(let_impl_detail $id := $valStx; $body) => do
let val β elabTerm valStx none
let type β inferType val
trace[Elab.let.decl] "{id.getId} : {type} := {val}"
let result β
withLetDecl id.getId (kind := .default) type val fun x => do
addLocalVarInfo id x
let lctx β getLCtx
let lctx := lctx.modifyLocalDecl x.fvarId! fun decl => decl.setKind .implDetail
withLCtx lctx (β getLocalInstances) do
let body β elabTermEnsuringType body expectedType?
let body β instantiateMVars body
mkLetFVars #[x] body (usedLetOnly := false)
pure result
| _ => throwUnsupportedSyntax
macro_rules
| `({ $[$srcs,* with]? $[$fields],* $[: $ty?]? }) => show MacroM Term from do
let mut spreads := #[]
let mut newFields := #[]
for field in fields do
match field.1 with
| `(structInstField| $name:ident := $arg) =>
if name.getId.eraseMacroScopes == `__ then do
spreads := spreads.push arg
else
newFields := newFields.push field
| _ =>
throwUnsupported
if spreads.isEmpty then throwUnsupported
let spreadData β withFreshMacroScope <| spreads.mapIdxM fun i spread => do
let n := Name.num `__spread i
return (mkIdent <| β Macro.addMacroScope n, spread)
let srcs := (srcs.map (Β·.getElems)).getD {} ++ spreadData.map Prod.fst
let body β `({ $srcs,* with $[$newFields],* $[: $ty?]? })
spreadData.foldrM (init := body) fun (id, val) body => `(let_impl_detail $id := $val; $body)
|
DiscreteValuativeRel.lean
|
/-
Copyright (c) 2025 Yakov Pechersky. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yakov Pechersky
-/
import Mathlib.Algebra.GroupWithZero.Range
import Mathlib.GroupTheory.ArchimedeanDensely
import Mathlib.RingTheory.Valuation.RankOne
/-!
# Discrete Valuative Relations
Discrete valuative relations have a maximal element less than one in the value group.
In the rank-one case, this is equivalent to the value group being isomorphic to `β€α΅β°`.
-/
namespace ValuativeRel
variable {R : Type*} [CommRing R] [ValuativeRel R]
open WithZero
lemma nonempty_orderIso_withZeroMul_int_iff :
Nonempty (ValueGroupWithZero R β*o β€α΅β°) β
IsDiscrete R β§ IsNontrivial R β§ MulArchimedean (ValueGroupWithZero R) := by
constructor
Β· rintro β¨eβ©
let x := e.symm (exp (-1))
have hx0 : x β 0 := by simp [x]
have hx1 : x < 1 := by simp [- exp_neg, x, β lt_map_inv_iff, β exp_zero]
refine β¨β¨x, hx1, fun y hy β¦ ?_β©, β¨x, hx0, hx1.neβ©, .comap e.toMonoidHom e.strictMonoβ©
rcases eq_or_ne y 0 with rfl | hy0
Β· simp
Β· rw [β map_one e.symm, β map_inv_lt_iff, β log_lt_log (by simp [hy0]) (by simp)] at hy
rw [β map_inv_le_iff, β log_le_log (by simp [hy0]) (by simp)]
simp only [OrderMonoidIso.equivLike_inv_eq_symm, OrderMonoidIso.symm_symm, log_one,
log_exp] at hy β’
linarith
Β· rintro β¨hD, hN, hMβ©
rw [isNontrivial_iff_nontrivial_units] at hN
rw [LinearOrderedCommGroupWithZero.discrete_iff_not_denselyOrdered]
intro H
obtain β¨x, hx, hx'β© := hD.has_maximal_element
obtain β¨y, hy, hy'β© := exists_between hx
exact hy.not_ge (hx' y hy')
lemma IsDiscrete.of_compatible_withZeroMulInt (v : Valuation R β€α΅β°) [v.Compatible] :
IsDiscrete R := by
have : IsRankLeOne R := .of_compatible_mulArchimedean v
by_cases h : IsNontrivial R
Β· by_cases H : DenselyOrdered (ValueGroupWithZero R)
Β· exfalso
refine (MonoidWithZeroHom.range_nontrivial (ValueGroupWithZero.embed v)).not_subsingleton ?_
rw [β WithZero.denselyOrdered_set_iff_subsingleton]
exact (ValueGroupWithZero.embed_strictMono v).denselyOrdered_range
Β· rw [isNontrivial_iff_nontrivial_units] at h
rw [β LinearOrderedCommGroupWithZero.discrete_iff_not_denselyOrdered] at H
rw [nonempty_orderIso_withZeroMul_int_iff] at H
exact H.left
Β· rw [isNontrivial_iff_nontrivial_units, not_nontrivial_iff_subsingleton] at h
refine β¨β¨0, zero_lt_one, fun y hy β¦ ?_β©β©
contrapose! hy
have : 1 = Units.mk0 y hy.ne' := Subsingleton.elim _ _
exact Units.val_le_val.mpr this.le
end ValuativeRel
|
Pushforward.lean
|
/-
Copyright (c) 2024 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.Algebra.Category.ModuleCat.Presheaf.ChangeOfRings
/-!
# Pushforward of presheaves of modules
If `F : C β₯€ D`, the precomposition `F.op β _` induces a functor from presheaves
over `D` to presheaves over `C`. When `R : Dα΅α΅ β₯€ RingCat`, we define the
induced functor `pushforwardβ : PresheafOfModules.{v} R β₯€ PresheafOfModules.{v} (F.op β R)`
on presheaves of modules.
In case we have a morphism of presheaves of rings `S βΆ F.op β R`, we also construct
a functor `pushforward : PresheafOfModules.{v} R β₯€ PresheafOfModules.{v} S`.
-/
universe v vβ vβ uβ uβ u
open CategoryTheory
variable {C : Type uβ} [Category.{vβ} C] {D : Type uβ} [Category.{vβ} D]
namespace PresheafOfModules
variable (F : C β₯€ D)
/-- Implementation of `pushforwardβ`. -/
@[simps]
def pushforwardβ_obj (R : Dα΅α΅ β₯€ RingCat.{u}) (M : PresheafOfModules R) :
PresheafOfModules (F.op β R) :=
{ obj X := ModuleCat.of _ (M.obj (F.op.obj X))
map {X Y} f := M.map (F.op.map f)
map_id X := by
refine ModuleCat.hom_ext
-- Work around an instance diamond for `restrictScalarsId'`
(@LinearMap.ext _ _ _ _ _ _ _ _ (_) (_) _ _ _ (fun x => ?_))
exact (M.congr_map_apply (F.op.map_id X) x).trans (by simp)
map_comp := fun f g β¦ by
refine ModuleCat.hom_ext
-- Work around an instance diamond for `restrictScalarsId'`
(@LinearMap.ext _ _ _ _ _ _ _ _ (_) (_) _ _ _ (fun x => ?_))
exact (M.congr_map_apply (F.op.map_comp f g) x).trans (by simp) }
/-- The pushforward functor on presheaves of modules for a functor `F : C β₯€ D` and
`R : Dα΅α΅ β₯€ RingCat`. On the underlying presheaves of abelian groups, it is induced
by the precomposition with `F.op`. -/
def pushforwardβ (R : Dα΅α΅ β₯€ RingCat.{u}) :
PresheafOfModules.{v} R β₯€ PresheafOfModules.{v} (F.op β R) where
obj M := pushforwardβ_obj F R M
map {Mβ Mβ} Ο := { app X := Ο.app _ }
/-- The pushforward of presheaves of modules commutes with the forgetful functor
to presheaves of abelian groups. -/
noncomputable def pushforwardβCompToPresheaf (R : Dα΅α΅ β₯€ RingCat.{u}) :
pushforwardβ.{v} F R β toPresheaf _ β
toPresheaf _ β (Functor.whiskeringLeft _ _ _).obj F.op :=
Iso.refl _
variable {F}
variable {R : Dα΅α΅ β₯€ RingCat.{u}} {S : Cα΅α΅ β₯€ RingCat.{u}} (Ο : S βΆ F.op β R)
attribute [local simp] pushforwardβ in
/-- The pushforward functor `PresheafOfModules R β₯€ PresheafOfModules S` induced by
a morphism of presheaves of rings `S βΆ F.op β R`. -/
@[simps! obj_obj]
noncomputable def pushforward : PresheafOfModules.{v} R β₯€ PresheafOfModules.{v} S :=
pushforwardβ F R β restrictScalars Ο
/-- The pushforward of presheaves of modules commutes with the forgetful functor
to presheaves of abelian groups. -/
noncomputable def pushforwardCompToPresheaf :
pushforward.{v} Ο β toPresheaf _ β
toPresheaf _ β (Functor.whiskeringLeft _ _ _).obj F.op :=
Iso.refl _
lemma pushforward_obj_map_apply (M : PresheafOfModules.{v} R) {X Y : Cα΅α΅} (f : X βΆ Y)
(m : (ModuleCat.restrictScalars (Ο.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
(((pushforward Ο).obj M).map f).hom m = M.map (F.map f.unop).op m := rfl
/-- `@[simp]`-normal form of `pushforward_obj_map_apply`. -/
@[simp]
lemma pushforward_obj_map_apply' (M : PresheafOfModules.{v} R) {X Y : Cα΅α΅} (f : X βΆ Y)
(m : (ModuleCat.restrictScalars (Ο.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
DFunLike.coe
(F := β((ModuleCat.restrictScalars _).obj _) ββ[_]
β((ModuleCat.restrictScalars (S.map f).hom).obj ((ModuleCat.restrictScalars _).obj _)))
(((pushforward Ο).obj M).map f).hom m = M.map (F.map f.unop).op m := rfl
lemma pushforward_map_app_apply {M N : PresheafOfModules.{v} R} (Ξ± : M βΆ N) (X : Cα΅α΅)
(m : (ModuleCat.restrictScalars (Ο.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
(((pushforward Ο).map Ξ±).app X).hom m = Ξ±.app (Opposite.op (F.obj X.unop)) m := rfl
/-- `@[simp]`-normal form of `pushforward_map_app_apply`. -/
@[simp]
lemma pushforward_map_app_apply' {M N : PresheafOfModules.{v} R} (Ξ± : M βΆ N) (X : Cα΅α΅)
(m : (ModuleCat.restrictScalars (Ο.app X).hom).obj (M.obj (Opposite.op (F.obj X.unop)))) :
DFunLike.coe
(F := β((ModuleCat.restrictScalars _).obj _) ββ[_] β((ModuleCat.restrictScalars _).obj _))
(((pushforward Ο).map Ξ±).app X).hom m = Ξ±.app (Opposite.op (F.obj X.unop)) m := rfl
end PresheafOfModules
|
IsCardinalForSmallObjectArgument.lean
|
/-
Copyright (c) 2025 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.CategoryTheory.SmallObject.Construction
import Mathlib.CategoryTheory.SmallObject.TransfiniteIteration
import Mathlib.CategoryTheory.SmallObject.TransfiniteCompositionLifting
import Mathlib.CategoryTheory.MorphismProperty.IsSmall
import Mathlib.AlgebraicTopology.RelativeCellComplex.Basic
import Mathlib.SetTheory.Cardinal.Regular
/-!
# Cardinals that are suitable for the small object argument
In this file, given a class of morphisms `I : MorphismProperty C` and
a regular cardinal `ΞΊ : Cardinal.{w}`, we define a typeclass
`IsCardinalForSmallObjectArgument I ΞΊ` which requires certain
smallness properties (`I` is `w`-small, `C` is locally `w`-small),
the existence of certain colimits (pushouts, coproducts of size `w`,
and the condition `HasIterationOfShape ΞΊ.ord.toType C` about the
existence of colimits indexed by limit ordinal smaller than or equal
to `ΞΊ.ord`), and the technical assumption that if `A` is the
a morphism in `I`, then the functor `Hom(A, _)` should commute
with the filtering colimits corresponding to relative
`I`-cell complexes. (This last condition shall hold when `ΞΊ`
is the successor of an infinite cardinal `c` such that all these objects `A` are `c`-presentable,
see `Mathlib/CategoryTheory/Presentable/Basic.lean`.)
Given `I : MorphismProperty C`, we shall say that `I` permits
the small object argument if there exists `ΞΊ` such that
`IsCardinalForSmallObjectArgument I ΞΊ` holds. See the file
`Mathlib/CategoryTheory/SmallObject/Basic.lean` for the definition of this typeclass
`HasSmallObjectArgument` and an outline of the proof.
## Main results
Assuming `IsCardinalForSmallObjectArgument I ΞΊ`, any morphism `f : X βΆ Y`
is factored as `ΞΉObj I ΞΊ f β« ΟObj I ΞΊ f = f`. It is shown that `ΞΉObj I ΞΊ f`
is a relative `I`-cell complex (see `SmallObject.relativeCellComplexΞΉObj`)
and that `ΟObj I ΞΊ f` has the right lifting property with respect to `I`
(see `SmallObject.rlp_ΟObj`). This construction is obtained by
iterating to the power `ΞΊ.ord.toType` the functor `Arrow C β₯€ Arrow C` defined
in the file `Mathlib/CategoryTheory/SmallObject/Construction.lean`.
This factorization is functorial in `f`
and gives the property `HasFunctorialFactorization I.rlp.llp I.rlp`.
Finally, the lemma `llp_rlp_of_isCardinalForSmallObjectArgument`
(and its primed version) shows that the morphisms in `I.rlp.llp` are exactly
the retracts of the transfinite compositions (of shape `ΞΊ.ord.toType`) of
pushouts of coproducts of morphisms in `I`.
## References
- https://ncatlab.org/nlab/show/small+object+argument
-/
universe w v v' u u'
namespace CategoryTheory
open Category HomotopicalAlgebra Limits SmallObject
variable {C : Type u} [Category.{v} C] (I : MorphismProperty C)
namespace MorphismProperty
/-- Given `I : MorphismProperty C` and a regular cardinal `ΞΊ : Cardinal.{w}`,
this property asserts the technical conditions which allow to proceed
to the small object argument by doing a construction by transfinite
induction indexed by the well ordered type `ΞΊ.ord.toType`. -/
class IsCardinalForSmallObjectArgument (ΞΊ : Cardinal.{w}) [Fact ΞΊ.IsRegular]
[OrderBot ΞΊ.ord.toType] : Prop where
isSmall : IsSmall.{w} I := by infer_instance
locallySmall : LocallySmall.{w} C := by infer_instance
hasPushouts : HasPushouts C := by infer_instance
hasCoproducts : HasCoproducts.{w} C := by infer_instance
hasIterationOfShape : HasIterationOfShape ΞΊ.ord.toType C := by infer_instance
preservesColimit {A B X Y : C} (i : A βΆ B) (_ : I i) (f : X βΆ Y)
(hf : RelativeCellComplex.{w} (fun (_ : ΞΊ.ord.toType) β¦ I.homFamily) f) :
PreservesColimit hf.F (coyoneda.obj (Opposite.op A))
end MorphismProperty
namespace SmallObject
open MorphismProperty
variable (ΞΊ : Cardinal.{w}) [Fact ΞΊ.IsRegular] [OrderBot ΞΊ.ord.toType]
[I.IsCardinalForSmallObjectArgument ΞΊ]
include I ΞΊ
lemma isSmall : IsSmall.{w} I :=
IsCardinalForSmallObjectArgument.isSmall ΞΊ
lemma locallySmall : LocallySmall.{w} C :=
IsCardinalForSmallObjectArgument.locallySmall I ΞΊ
lemma hasIterationOfShape : HasIterationOfShape ΞΊ.ord.toType C :=
IsCardinalForSmallObjectArgument.hasIterationOfShape I
lemma hasPushouts : HasPushouts C :=
IsCardinalForSmallObjectArgument.hasPushouts I ΞΊ
lemma hasCoproducts : HasCoproducts.{w} C :=
IsCardinalForSmallObjectArgument.hasCoproducts I ΞΊ
lemma preservesColimit {A B X Y : C} (i : A βΆ B) (hi : I i) (f : X βΆ Y)
(hf : RelativeCellComplex.{w} (fun (_ : ΞΊ.ord.toType) β¦ I.homFamily) f) :
PreservesColimit hf.F (coyoneda.obj (Opposite.op A)) :=
IsCardinalForSmallObjectArgument.preservesColimit i hi f hf
lemma hasColimitsOfShape_discrete (X Y : C) (p : X βΆ Y) :
HasColimitsOfShape
(Discrete (FunctorObjIndex I.homFamily p)) C := by
haveI := locallySmall I ΞΊ
haveI := isSmall I ΞΊ
haveI := hasCoproducts I ΞΊ
exact hasColimitsOfShape_of_equivalence
(Discrete.equivalence (equivShrink.{w} _)).symm
/-- The successor structure on `Arrow C β₯€ Arrow C` corresponding
to the iterations of the natural transformation
`Ξ΅ : π (Arrow C) βΆ SmallObject.functor I.homFamily`
(see the file `SmallObject.Construction`). -/
noncomputable def succStruct : SuccStruct (Arrow C β₯€ Arrow C) :=
haveI := hasColimitsOfShape_discrete I ΞΊ
haveI := hasPushouts I ΞΊ
SuccStruct.ofNatTrans (Ξ΅ I.homFamily)
/-- For the successor structure `succStruct I ΞΊ` on `Arrow C β₯€ Arrow C`,
the morphism from an object to its successor induces
morphisms in `C` which consists in attaching `I`-cells. -/
noncomputable def attachCellsOfSuccStructProp
{F G : Arrow C β₯€ Arrow C} {Ο : F βΆ G}
(h : (succStruct I ΞΊ).prop Ο) (f : Arrow C) :
AttachCells.{w} I.homFamily (Ο.app f).left :=
haveI := locallySmall I ΞΊ
haveI := isSmall I ΞΊ
haveI := hasColimitsOfShape_discrete I ΞΊ
haveI := hasPushouts I ΞΊ
AttachCells.ofArrowIso (attachCellsΞΉFunctorObjOfSmall _ _)
((Functor.mapArrow ((evaluation _ _).obj f β
Arrow.leftFunc)).mapIso h.arrowIso.symm)
/-- The class of morphisms in `Arrow C` which on the left side are
pushouts of coproducts of morphisms in `I`, and which are
isomorphisms on the right side. -/
def propArrow : MorphismProperty (Arrow C) := fun _ _ f β¦
(coproducts.{w} I).pushouts f.left β§ (isomorphisms C) f.right
lemma succStruct_prop_le_propArrow :
(succStruct I ΞΊ).prop β€ (propArrow.{w} I).functorCategory (Arrow C) := by
haveI := locallySmall I ΞΊ
haveI := isSmall I ΞΊ
haveI := hasColimitsOfShape_discrete I ΞΊ
haveI := hasPushouts I ΞΊ
intro _ _ _ β¨Fβ© f
constructor
Β· nth_rw 1 [β I.ofHoms_homFamily]
apply pushouts_mk _ (functorObj_isPushout I.homFamily (F.obj f).hom)
exact coproducts_of_small _ _ (colimitsOfShape_colimMap _ (by rintro β¨jβ©; constructor))
Β· rw [MorphismProperty.isomorphisms.iff]
dsimp [succStruct]
infer_instance
/-- The functor `ΞΊ.ord.toType β₯€ Arrow C β₯€ Arrow C` corresponding to the
iterations of the successor structure `succStruct I ΞΊ`. -/
noncomputable def iterationFunctor : ΞΊ.ord.toType β₯€ Arrow C β₯€ Arrow C :=
haveI := hasIterationOfShape I ΞΊ
(succStruct I ΞΊ).iterationFunctor ΞΊ.ord.toType
/-- The colimit of `iterationFunctor I ΞΊ`. -/
noncomputable def iteration : Arrow C β₯€ Arrow C :=
haveI := hasIterationOfShape I ΞΊ
(succStruct I ΞΊ).iteration ΞΊ.ord.toType
/-- The natural "inclusion" `π (Arrow C) βΆ iteration I ΞΊ`. -/
noncomputable def ΞΉIteration : π _ βΆ iteration I ΞΊ :=
haveI := hasIterationOfShape I ΞΊ
(succStruct I ΞΊ).ΞΉIteration ΞΊ.ord.toType
/-- The morphism `ΞΉIteration I ΞΊ` is a transfinite composition of shape
`ΞΊ.ord.toType` of morphisms satisfying `(succStruct I ΞΊ).prop`. -/
noncomputable def transfiniteCompositionOfShapeSuccStructPropΞΉIteration :
(succStruct I ΞΊ).prop.TransfiniteCompositionOfShape ΞΊ.ord.toType (ΞΉIteration I ΞΊ) :=
haveI := hasIterationOfShape I ΞΊ
(succStruct I ΞΊ).transfiniteCompositionOfShapeΞΉIteration ΞΊ.ord.toType
@[simp]
lemma transfiniteCompositionOfShapeSuccStructPropΞΉIteration_F :
(transfiniteCompositionOfShapeSuccStructPropΞΉIteration I ΞΊ).F =
iterationFunctor I ΞΊ :=
rfl
/-- For any `f : Arrow C`, the map `((ΞΉIteration I ΞΊ).app f).right` is
a transfinite composition of isomorphisms. -/
noncomputable def transfiniteCompositionOfShapeΞΉIterationAppRight (f : Arrow C) :
(isomorphisms C).TransfiniteCompositionOfShape ΞΊ.ord.toType
((ΞΉIteration I ΞΊ).app f).right :=
haveI := hasIterationOfShape I ΞΊ
let h := transfiniteCompositionOfShapeSuccStructPropΞΉIteration I ΞΊ
{ toTransfiniteCompositionOfShape :=
h.toTransfiniteCompositionOfShape.map ((evaluation _ _).obj f β Arrow.rightFunc)
map_mem j hj := ((succStruct_prop_le_propArrow I ΞΊ _ (h.map_mem j hj)) f).2 }
instance (f : Arrow C) : IsIso ((ΞΉIteration I ΞΊ).app f).right :=
(transfiniteCompositionOfShapeΞΉIterationAppRight I ΞΊ f).isIso
instance {jβ jβ : ΞΊ.ord.toType} (Ο : jβ βΆ jβ) (f : Arrow C) :
IsIso (((iterationFunctor I ΞΊ).map Ο).app f).right :=
inferInstanceAs (IsIso ((transfiniteCompositionOfShapeΞΉIterationAppRight I ΞΊ f).F.map Ο))
/-- For any `f : Arrow C`, the object `((iteration I ΞΊ).obj f).right`
identifies to `f.right`. -/
@[simps! hom]
noncomputable def iterationObjRightIso (f : Arrow C) :
f.right β
((iteration I ΞΊ).obj f).right :=
asIso ((ΞΉIteration I ΞΊ).app f).right
/-- For any `f : Arrow C` and `j : ΞΊ.ord.toType`, the object
`(((iterationFunctor I ΞΊ).obj j).obj f).right` identifies to `f.right`. -/
noncomputable def iterationFunctorObjObjRightIso (f : Arrow C) (j : ΞΊ.ord.toType) :
(((iterationFunctor I ΞΊ).obj j).obj f).right β
f.right :=
asIso ((transfiniteCompositionOfShapeΞΉIterationAppRight I ΞΊ f).incl.app j) βͺβ«
(iterationObjRightIso I ΞΊ f).symm
@[reassoc (attr := simp)]
lemma iterationFunctorObjObjRightIso_ΞΉIteration_app_right (f : Arrow C) (j : ΞΊ.ord.toType) :
(iterationFunctorObjObjRightIso I ΞΊ f j).hom β« ((ΞΉIteration I ΞΊ).app f).right =
(transfiniteCompositionOfShapeΞΉIterationAppRight I ΞΊ f).incl.app j := by
simp [iterationFunctorObjObjRightIso, iterationObjRightIso]
lemma prop_iterationFunctor_map_succ (j : ΞΊ.ord.toType) :
(succStruct I ΞΊ).prop ((iterationFunctor I ΞΊ).map (homOfLE (Order.le_succ j))) := by
have := hasIterationOfShape I ΞΊ
have := Cardinal.noMaxOrder (Fact.elim inferInstance : ΞΊ.IsRegular).aleph0_le
exact (succStruct I ΞΊ).prop_iterationFunctor_map_succ j (not_isMax j)
/-- For any `f : Arrow C` and `j : ΞΊ.ord.toType`, the morphism
`((iterationFunctor I ΞΊ).map (homOfLE (Order.le_succ j))).app f` identifies
to a morphism given by `SmallObject.Ξ΅ I.homFamily`. -/
noncomputable def iterationFunctorMapSuccAppArrowIso (f : Arrow C) (j : ΞΊ.ord.toType) :
letI := hasColimitsOfShape_discrete I ΞΊ
letI := hasPushouts I ΞΊ
Arrow.mk (((iterationFunctor I ΞΊ).map (homOfLE (Order.le_succ j))).app f) β
(Ξ΅ I.homFamily).app (((iterationFunctor I ΞΊ).obj j).obj f) :=
have := hasIterationOfShape I ΞΊ
have := Cardinal.noMaxOrder (Fact.elim inferInstance : ΞΊ.IsRegular).aleph0_le
Arrow.isoMk (Iso.refl _)
(((evaluation _ _).obj f).mapIso
((succStruct I ΞΊ).iterationFunctorObjSuccIso j (not_isMax j))) (by
have this := NatTrans.congr_app ((succStruct I ΞΊ).iterationFunctor_map_succ j (not_isMax j)) f
dsimp at this
dsimp [iterationFunctor]
rw [id_comp, this, assoc, Iso.inv_hom_id_app, comp_id]
dsimp [succStruct])
@[simp]
lemma iterationFunctorMapSuccAppArrowIso_hom_left (f : Arrow C) (j : ΞΊ.ord.toType) :
(iterationFunctorMapSuccAppArrowIso I ΞΊ f j).hom.left = π _ := rfl
@[reassoc (attr := simp)]
lemma iterationFunctorMapSuccAppArrowIso_hom_right_right_comp
(f : Arrow C) (j : ΞΊ.ord.toType) :
(iterationFunctorMapSuccAppArrowIso I ΞΊ f j).hom.right.right β«
(((iterationFunctor I ΞΊ).map (homOfLE (Order.le_succ j))).app f).right = π _ := by
have := Arrow.rightFunc.congr_map ((iterationFunctorMapSuccAppArrowIso I ΞΊ f j).hom.w)
dsimp at this β’
rw [β cancel_epi (((iterationFunctor I ΞΊ).map (homOfLE (Order.le_succ j))).app f).right,
β reassoc_of% this, comp_id]
section
variable {X Y : C} (f : X βΆ Y)
/-- The intermediate object in the factorization given by the
small object argument. -/
noncomputable def obj : C := ((iteration I ΞΊ).obj (Arrow.mk f)).left
/-- The "inclusion" morphism in the factorization given by
the the small object argument. -/
noncomputable def ΞΉObj : X βΆ obj I ΞΊ f := ((ΞΉIteration I ΞΊ).app (Arrow.mk f)).left
/-- The "projection" morphism in the factorization given by
the the small object argument. -/
noncomputable def ΟObj : obj I ΞΊ f βΆ Y :=
((iteration I ΞΊ).obj (Arrow.mk f)).hom β« inv ((ΞΉIteration I ΞΊ).app f).right
@[reassoc (attr := simp)]
lemma ΟObj_ΞΉIteration_app_right :
ΟObj I ΞΊ f β« ((ΞΉIteration I ΞΊ).app f).right =
((iteration I ΞΊ).obj (Arrow.mk f)).hom := by simp [ΟObj]
@[reassoc (attr := simp)]
lemma ΞΉObj_ΟObj : ΞΉObj I ΞΊ f β« ΟObj I ΞΊ f = f := by
simp [ΞΉObj, ΟObj]
/-- The morphism `ΞΉObj I ΞΊ f` is a relative `I`-cell complex. -/
noncomputable def relativeCellComplexΞΉObj :
RelativeCellComplex.{w} (fun (_ : ΞΊ.ord.toType) β¦ I.homFamily)
(ΞΉObj I ΞΊ f) := by
have := hasIterationOfShape I ΞΊ
let h := transfiniteCompositionOfShapeSuccStructPropΞΉIteration I ΞΊ
exact
{ toTransfiniteCompositionOfShape :=
h.toTransfiniteCompositionOfShape.map ((evaluation _ _).obj f β Arrow.leftFunc)
attachCells j hj :=
attachCellsOfSuccStructProp I ΞΊ (h.map_mem j hj) f }
lemma transfiniteCompositionsOfShape_ΞΉObj :
(coproducts.{w} I).pushouts.transfiniteCompositionsOfShape ΞΊ.ord.toType
(ΞΉObj I ΞΊ f) :=
β¨((relativeCellComplexΞΉObj I ΞΊ f).transfiniteCompositionOfShape).ofLE
(by simp)β©
lemma llp_rlp_ΞΉObj : I.rlp.llp (ΞΉObj I ΞΊ f) := by
apply I.transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp ΞΊ.ord.toType
apply transfiniteCompositionsOfShape_ΞΉObj
/-- When `ΞΉObj I ΞΊ f` is considered as a relative `I`-cell complex,
the object at the `j`th step is obtained by applying the construction
`SmallObject.functorObj`. -/
noncomputable def relativeCellComplexΞΉObjFObjSuccIso (j : ΞΊ.ord.toType) :
letI := hasColimitsOfShape_discrete I ΞΊ
letI := hasPushouts I ΞΊ
(relativeCellComplexΞΉObj I ΞΊ f).F.obj (Order.succ j) β
functorObj I.homFamily (((iterationFunctor I ΞΊ).obj j).obj (Arrow.mk f)).hom :=
(Arrow.rightFunc β Arrow.leftFunc).mapIso
(iterationFunctorMapSuccAppArrowIso I ΞΊ f j)
lemma ΞΉFunctorObj_eq (j : ΞΊ.ord.toType) :
letI := hasColimitsOfShape_discrete I ΞΊ
letI := hasPushouts I ΞΊ
ΞΉFunctorObj I.homFamily (((iterationFunctor I ΞΊ).obj j).obj (Arrow.mk f)).hom =
(relativeCellComplexΞΉObj I ΞΊ f).F.map (homOfLE (Order.le_succ j)) β«
(relativeCellComplexΞΉObjFObjSuccIso I ΞΊ f j).hom := by
simpa using Arrow.leftFunc.congr_map (iterationFunctorMapSuccAppArrowIso I ΞΊ f j).hom.w
lemma ΟFunctorObj_eq (j : ΞΊ.ord.toType) :
letI := hasColimitsOfShape_discrete I ΞΊ
letI := hasPushouts I ΞΊ
ΟFunctorObj I.homFamily (((iterationFunctor I ΞΊ).obj j).obj (Arrow.mk f)).hom =
(relativeCellComplexΞΉObjFObjSuccIso I ΞΊ f j).inv β«
(relativeCellComplexΞΉObj I ΞΊ f).incl.app (Order.succ j) β«
ΟObj I ΞΊ f β« (iterationFunctorObjObjRightIso I ΞΊ (Arrow.mk f) j).inv := by
have hβ := (iterationFunctorMapSuccAppArrowIso I ΞΊ f j).hom.right.w
have hβ := (transfiniteCompositionOfShapeSuccStructPropΞΉIteration I ΞΊ).incl.naturality
(homOfLE (Order.le_succ j))
dsimp at hβ hβ
rw [comp_id] at hβ
rw [β cancel_mono (iterationFunctorObjObjRightIso I ΞΊ (Arrow.mk f) j).hom,
β cancel_mono ((ΞΉIteration I ΞΊ).app f).right, assoc, assoc, assoc, assoc, assoc,
Iso.inv_hom_id_assoc, ΟObj_ΞΉIteration_app_right,
iterationFunctorObjObjRightIso_ΞΉIteration_app_right,
β cancel_epi (relativeCellComplexΞΉObjFObjSuccIso I ΞΊ f j).hom, Iso.hom_inv_id_assoc]
dsimp [relativeCellComplexΞΉObjFObjSuccIso,
relativeCellComplexΞΉObj, transfiniteCompositionOfShapeΞΉIterationAppRight]
simp only [reassoc_of% hβ, comp_id, comp_id, Arrow.w_mk_right, β hβ,
NatTrans.comp_app, Arrow.comp_right,
iterationFunctorMapSuccAppArrowIso_hom_right_right_comp_assoc]
lemma hasRightLiftingProperty_ΟObj {A B : C} (i : A βΆ B) (hi : I i) (f : X βΆ Y) :
HasLiftingProperty i (ΟObj I ΞΊ f) := β¨by
haveI := hasColimitsOfShape_discrete I ΞΊ
haveI := hasPushouts I ΞΊ
haveI := preservesColimit I ΞΊ i hi _ (relativeCellComplexΞΉObj I ΞΊ f)
intro g b sq
obtain β¨j, t, htβ© := Types.jointly_surjective _
(isColimitOfPreserves (coyoneda.obj (Opposite.op A))
(relativeCellComplexΞΉObj I ΞΊ f).isColimit) g
dsimp at g b sq t ht
obtain β¨l, hlβ, hlββ© := ΞΉFunctorObj_extension' I.homFamily
((relativeCellComplexΞΉObj I ΞΊ f).incl.app j β« ΟObj I ΞΊ f)
((relativeCellComplexΞΉObj I ΞΊ f).F.map (homOfLE (Order.le_succ j)))
((relativeCellComplexΞΉObj I ΞΊ f).incl.app (Order.succ j) β« ΟObj I ΞΊ f) (by simp) (Iso.refl _)
(iterationFunctorObjObjRightIso I ΞΊ (Arrow.mk f) j).symm
(relativeCellComplexΞΉObjFObjSuccIso I ΞΊ f j)
(by dsimp; rw [ΞΉFunctorObj_eq, id_comp])
(by dsimp; rw [ΟFunctorObj_eq, assoc, Iso.hom_inv_id_assoc])
(i := β¨i, hiβ©) t b (by rw [reassoc_of% ht, sq.w]; dsimp)
dsimp at hlβ
exact β¨β¨{
l := l β« (relativeCellComplexΞΉObj I ΞΊ f).incl.app (Order.succ j)
fac_left := by simp [reassoc_of% hlβ, β ht]
fac_right := by rw [assoc, hlβ]
}β©β©β©
lemma rlp_ΟObj : I.rlp (ΟObj I ΞΊ f) :=
fun _ _ _ hi β¦ hasRightLiftingProperty_ΟObj _ _ _ hi _
end
/-- The functoriality of the intermediate object in the
factorization of the small object argument. -/
noncomputable def objMap {f g : Arrow C} (Ο : f βΆ g) : obj I ΞΊ f.hom βΆ obj I ΞΊ g.hom :=
((iteration I ΞΊ).map Ο).left
@[simp]
lemma objMap_id (f : Arrow C) : objMap I ΞΊ (π f) = π _ := by
simp only [objMap, Functor.map_id]
rfl
@[reassoc, simp]
lemma objMap_comp {f g h : Arrow C} (Ο : f βΆ g) (Ο : g βΆ h) :
objMap I ΞΊ (Ο β« Ο) = objMap I ΞΊ Ο β« objMap I ΞΊ Ο := by
simp only [objMap, Functor.map_comp]
rfl
@[reassoc (attr := simp)]
lemma ΞΉObj_naturality {f g : Arrow C} (Ο : f βΆ g) :
ΞΉObj I ΞΊ f.hom β« objMap I ΞΊ Ο = Ο.left β« ΞΉObj I ΞΊ g.hom :=
Arrow.leftFunc.congr_map ((ΞΉIteration I ΞΊ).naturality Ο).symm
@[reassoc (attr := simp)]
lemma ΟObj_naturality {f g : Arrow C} (Ο : f βΆ g) :
objMap I ΞΊ Ο β« ΟObj I ΞΊ g.hom = ΟObj I ΞΊ f.hom β« Ο.right := by
let eβ := asIso ((ΞΉIteration I ΞΊ).app (Arrow.mk f.hom)).right
let eβ := asIso ((ΞΉIteration I ΞΊ).app (Arrow.mk g.hom)).right
change _ β« _ β« eβ.inv = (_ β« eβ.inv) β« _
have hβ := ((iteration I ΞΊ).map Ο).w =β« eβ.inv
have hβ : Ο.right β« eβ.hom = eβ.hom β« ((iteration I ΞΊ).map Ο).right :=
((Functor.whiskerRight (ΞΉIteration I ΞΊ) Arrow.rightFunc).naturality Ο)
dsimp at hβ
rw [assoc] at hβ
apply hβ.trans
simp only [β cancel_mono eβ.hom, assoc, eβ.inv_hom_id, hβ, eβ.inv_hom_id_assoc]
rw [β assoc]
apply comp_id
/-- The functorial factorization `ΞΉObj I ΞΊ f β« ΟObj I ΞΊ f.hom = f`
with `ΞΉObj I ΞΊ f` in `I.rlp.llp` and `ΟObj I ΞΊ f.hom` in `I.rlp`. -/
@[simps]
noncomputable def functorialFactorizationData :
FunctorialFactorizationData I.rlp.llp I.rlp where
Z :=
{ obj f := obj I ΞΊ f.hom
map Ο := objMap I ΞΊ Ο }
i := { app f := ΞΉObj I ΞΊ f.hom }
p := { app f := ΟObj I ΞΊ f.hom }
hi f := llp_rlp_ΞΉObj I ΞΊ f.hom
hp f := rlp_ΟObj I ΞΊ f.hom
lemma hasFunctorialFactorization :
HasFunctorialFactorization I.rlp.llp I.rlp where
nonempty_functorialFactorizationData :=
β¨functorialFactorizationData I ΞΊβ©
/-- If `ΞΊ` is a suitable cardinal for the small object argument for `I : MorphismProperty C`,
then the class `I.rlp.llp` is exactly the class of morphisms that are retracts
of transfinite compositions (of shape `ΞΊ.ord.toType`) of pushouts of coproducts
of maps in `I`. -/
lemma llp_rlp_of_isCardinalForSmallObjectArgument' :
I.rlp.llp = (transfiniteCompositionsOfShape
(coproducts.{w} I).pushouts ΞΊ.ord.toType).retracts := by
refine le_antisymm ?_
(retracts_transfiniteCompositionsOfShape_pushouts_coproducts_le_llp_rlp I ΞΊ.ord.toType)
intro X Y f hf
have sq : CommSq (ΞΉObj I ΞΊ f) f (ΟObj I ΞΊ f) (π _) := β¨by simpβ©
have := hf _ (rlp_ΟObj I ΞΊ f)
refine β¨_, _, _, ?_, transfiniteCompositionsOfShape_ΞΉObj I ΞΊ fβ©
exact
{ i := Arrow.homMk (π _) sq.lift
r := Arrow.homMk (π _) (ΟObj I ΞΊ f) }
/-- If `ΞΊ` is a suitable cardinal for the small object argument for `I : MorphismProperty C`,
then the class `I.rlp.llp` is exactly the class of morphisms that are retracts
of transfinite compositions of pushouts of coproducts of maps in `I`. -/
lemma llp_rlp_of_isCardinalForSmallObjectArgument :
I.rlp.llp =
(transfiniteCompositions.{w} (coproducts.{w} I).pushouts).retracts := by
refine le_antisymm ?_
(retracts_transfiniteComposition_pushouts_coproducts_le_llp_rlp I)
rw [llp_rlp_of_isCardinalForSmallObjectArgument' I ΞΊ]
apply retracts_monotone
apply transfiniteCompositionsOfShape_le_transfiniteCompositions
end SmallObject
end CategoryTheory
|
DiscreteTopologyNonDiscreteUniformity.lean
|
/-
Copyright (c) 2024 Filippo A. E. Nuccio. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Filippo A. E. Nuccio
-/
import Mathlib.Analysis.SpecificLimits.Basic
import Mathlib.Order.Interval.Set.Basic
import Mathlib.Topology.MetricSpace.Pseudo.Defs
import Mathlib.Topology.MetricSpace.Cauchy
import Mathlib.Topology.UniformSpace.Cauchy
/-!
# Discrete uniformities and discrete topology
Exactly as different metrics can induce equivalent topologies on a space, it is possible that
different uniform structures (a notion that generalises that of a metric structure) induce the same
topology on a space. In this file we are concerned in particular with the *discrete topology*,
formalised using the class `DiscreteTopology`, and the *discrete uniformity*, that is the bottom
element of the lattice of uniformities on a type (see `bot_uniformity`).
The theorem `discreteTopology_of_discrete_uniformity` shows that the topology induced by the
discrete uniformity is the discrete one, but it is well-known that the converse might not hold in
general, along the lines of the above discussion. We explicitly produce a metric and a uniform
structure on a space (on `β`, actually) that are not discrete, yet induce the discrete topology.
To check that a certain uniformity is not discrete, recall that once a type `Ξ±` is endowed with a
uniformity, it is possible to speak about `Cauchy` filters on `a` and it is quite easy to see that
if the uniformity on `a` is the discrete one, a filter is Cauchy if and only if it coincides with
the principal filter `π {x}` (see `Filter.principal`) for some `x : Ξ±`. This is the
declaration `UniformSpace.DiscreteUnif.eq_const_of_cauchy` in Mathlib.
A special case of this result is the intuitive observation that a sequence `a : β β β` can be a
Cauchy sequence if and only if it is eventually constant: when claiming this equivalence, one is
implicitly endowing `β` with the metric inherited from `β`, that induces the discrete uniformity
on `β`. Hence, the intuition suggesting that a Cauchy sequence, whose
terms are "closer and closer to each other", valued in `β` must be eventually constant for
*topological* reasons, namely the fact that `β` is a discrete topological space, is *wrong* in the
sense that the reason is intrinsically "metric". In particular, if a non-constant sequence (like
the identity `id : β β β` is Cauchy, then the uniformity is certainly *not discrete*.
## The counterexamples
We produce two counterexamples: in the first section `Metric` we construct a metric and in the
second section `SetPointUniformity` we construct a uniformity, explicitly as a filter on `β Γ β`.
They basically coincide, and the difference of the examples lies in their flavours.
### The metric
We begin by defining a metric on `β` (see `dist_def`) that
1. Induces the discrete topology, as proven in `TopIsDiscrete`;
2. Is not the discrete metric, in particular because the identity is a Cauchy sequence, as proven
in `idIsCauchy`
The definition is simply `dist m n = |2 ^ (- n : β€) - 2 ^ (- m : β€)|`, and I am grateful to
Anatole Dedecker for his suggestion.
### The set-point theoretic uniformity
A uniformity on `β` is a filter on `β Γ β` satisfying some properties: we define a sequence of
subsets `fundamentalEntourage n : (Set β Γ β)` (indexed by `n : β`) and we observe it satisfies the
condition needed to be a basis of a filter: moreover, the filter generated by this basis satisfies
the condition for being a uniformity, and this is the uniformity we put on `β`.
For each `n`, the set `fundamentalEntourage n : Set (β Γ β)` consists of the `n+1` points
`{(0,0),(1,1)...(n,n)}` on the diagonal; together with the half plane `{(x,y) | n β€ x β§ n β€ y}`
That this collection can be used as a filter basis is proven in the definition `counterBasis` and
that the filter `counterBasis.filterBasis` is a uniformity is proven in the definition
`counterCoreUniformity`.
This induces the discrete topology, as proven in `TopIsDiscrete` and the `atTop` filter is Cauchy
(see `atTopIsCauchy`): that this specializes to the statement that the identity sequence
`id : β β β` is Cauchy is proven in `idIsCauchy`.
## Implementation details
Since most of the statements evolve around membership of explicit natural numbers (framed by some
inequality) to explicit subsets, many proofs are easily closed by `aesop` or `omega` or `linarith`.
### References
* [N. Bourbaki, *General Topology*, Chapter II][bourbaki1966]
-/
open Set Function Filter Metric
/- We remove the "usual" instances of (discrete) topological space and of (discrete) uniform space
from `β`. -/
attribute [-instance] instTopologicalSpaceNat instUniformSpaceNat
section Metric
noncomputable local instance : PseudoMetricSpace β where
dist := fun n m β¦ |2 ^ (- n : β€) - 2 ^ (- m : β€)|
dist_self := by simp only [zpow_neg, zpow_natCast, sub_self, abs_zero, implies_true]
dist_comm := fun _ _ β¦ abs_sub_comm ..
dist_triangle := fun _ _ _ β¦ abs_sub_le ..
@[simp]
lemma dist_def {n m : β} : dist n m = |2 ^ (-n : β€) - 2 ^ (-m : β€)| := rfl
lemma Int.eq_of_pow_sub_le {d : β} {m n : β€} (hd1 : 1 < d)
(h : |(d : β) ^ (-m) - d ^ (-n)| < d ^ (-n - 1)) : m = n := by
have hd0 : 0 < d := one_pos.trans hd1
replace h : |(1 : β) - d ^ (n - m)| < (d : β)β»ΒΉ := by
rw [β mul_lt_mul_iff_of_pos_left (a := (d : β) ^ (-n)) (zpow_pos _ _),
β abs_of_nonneg (a := (d : β) ^ (-n)) (le_of_lt <| zpow_pos _ _), β abs_mul, mul_sub, mul_one,
β zpow_addβ <| Nat.cast_ne_zero.mpr (ne_of_gt hd0), sub_eq_add_neg (b := m),
neg_add_cancel_left, β abs_neg, neg_sub,
abs_of_nonneg (a := (d : β) ^ (-n)) (le_of_lt <| zpow_pos _ _), β zpow_neg_one,
β zpow_addβ <| Nat.cast_ne_zero.mpr (ne_of_gt hd0), β sub_eq_add_neg]
exact h
all_goals exact Nat.cast_pos'.mpr hd0
by_cases H : (m : β€) β€ n
Β· obtain β¨a, haβ© := Int.eq_ofNat_of_zero_le (sub_nonneg.mpr H)
rw [ha, β mul_lt_mul_iff_of_pos_left (a := (d : β)) <| Nat.cast_pos'.mpr hd0,
mul_inv_cancelβ <| Nat.cast_ne_zero.mpr (ne_of_gt hd0),
β abs_of_nonneg (a := (d : β)) <| Nat.cast_nonneg' d, β abs_mul,
show |(d : β) * (1 - |(d : β)| ^ (a : β€))| = |(d : β€) * (1 - |(d : β€)| ^ a)| by norm_cast,
β Int.cast_one (R := β), Int.cast_lt, Int.abs_lt_one_iff, Int.mul_eq_zero,
sub_eq_zero, eq_comm (a := 1), pow_eq_one_iff_cases] at h
simp only [Nat.cast_eq_zero, ne_of_gt hd0, Nat.abs_cast, Nat.cast_eq_one, ne_of_gt hd1,
Int.reduceNeg, reduceCtorEq, false_and, or_self, or_false, false_or] at h
rwa [h, Nat.cast_zero, sub_eq_zero, eq_comm] at ha
Β· have h1 : (d : β) ^ (n - m) β€ 1 - (d : β)β»ΒΉ := calc
(d : β) ^ (n - m) β€ (d : β)β»ΒΉ := by
rw [β zpow_neg_one]
apply zpow_right_monoβ <| Nat.one_le_cast.mpr hd0
linarith
_ β€ 1 - (d : β)β»ΒΉ := by
rw [inv_eq_one_div, one_sub_div <| Nat.cast_ne_zero.mpr (ne_of_gt hd0),
div_le_div_iff_of_pos_right <| Nat.cast_pos'.mpr hd0, le_sub_iff_add_le]
norm_cast
linarith [sub_lt_of_abs_sub_lt_right (a := (1 : β)) (b := d ^ (n - m)) (c := dβ»ΒΉ) h]
lemma ball_eq_singleton {n : β} : Metric.ball n ((2 : β) ^ (-n - 1 : β€)) = {n} := by
ext m
constructor
Β· zify [zpow_natCast, mem_ball, dist_def, mem_singleton_iff]
apply Int.eq_of_pow_sub_le one_lt_two
Β· intro H
rw [H, mem_ball, dist_self]
apply zpow_pos two_pos
theorem TopIsDiscrete : DiscreteTopology β := by
apply singletons_open_iff_discrete.mp
intro
simpa only [β ball_eq_singleton] using isOpen_ball
lemma idIsCauchy : CauchySeq (id : β β β) := by
rw [Metric.cauchySeq_iff]
refine fun Ξ΅ β¦ Metric.cauchySeq_iff.mp
(@cauchySeq_of_le_geometric_two β _ 1 (fun n β¦ 2 ^(-n : β€)) fun n β¦ le_of_eq ?_) Ξ΅
simp only [Nat.cast_add, Nat.cast_one, neg_add_rev, Int.reduceNeg, one_div]
rw [Real.dist_eq, zpow_add' <| Or.intro_left _ two_ne_zero]
calc
|2 ^ (- n : β€) - 2 ^ (-1 : β€) * 2 ^ (- n : β€)|
_ = |(1 - (2 : β)β»ΒΉ) * 2 ^ (- n : β€)| := by rw [β one_sub_mul, zpow_neg_one]
_ = |2β»ΒΉ * 2 ^ (-(n : β€))| := by congr; rw [inv_eq_one_div 2, sub_half 1]
_ = 2β»ΒΉ / 2 ^ n := by rw [zpow_neg, abs_mul, abs_inv, abs_inv, inv_eq_one_div,
Nat.abs_ofNat, one_div, zpow_natCast, abs_pow, β div_eq_mul_inv, Nat.abs_ofNat]
end Metric
section SetPointUniformity
/- As the `instance PseudoMetricSpace β` declared in the previous section was local, `β` has no
topology at this point. We are going to define a non-discrete uniform structure (just using the
filter-based definition), that will endow it with a topology that we will eventually show to be
discrete. -/
/-- The fundamental entourages (index by `n : β`) used to construct a basis of the uniformity: for
each `n`, the set `fundamentalEntourage n : Set (β Γ β)` consists of the `n+1` points
`{(0,0),(1,1)...(n,n)}` on the diagonal; together with the half plane `{(x,y) | n β€ x β§ n β€ y}`. -/
def fundamentalEntourage (n : β) : Set (β Γ β) :=
(β i : Icc 0 n, {((i : β), (i : β))}) βͺ Set.Ici (n , n)
@[simp]
lemma fundamentalEntourage_ext (t : β) (T : Set (β Γ β)) : fundamentalEntourage t = T β
T = (β i : Icc 0 t, {((i : β), (i : β))}) βͺ Set.Ici (t , t) := by
simpa only [fundamentalEntourage] using eq_comm
lemma mem_range_fundamentalEntourage (S : Set (β Γ β)) :
S β (range fundamentalEntourage) β β n, fundamentalEntourage n = S := by
simp only [Set.mem_range, Eq.symm]
lemma mem_fundamentalEntourage (n : β) (P : β Γ β) : P β fundamentalEntourage n β
(n β€ P.1 β§ n β€ P.2) β¨ (P.1 = P.2) := by
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· simp only [fundamentalEntourage, iUnion_singleton_eq_range, mem_union, mem_range,
Subtype.exists, mem_Icc, zero_le, true_and, exists_prop', nonempty_prop, mem_Ici] at h
rcases h with h | h
Β· apply Or.inr
rw [((h.choose_spec).2).symm]
Β· exact Or.inl h
Β· simp only [iUnion_singleton_eq_range, mem_union, mem_range, Subtype.exists, mem_Icc, zero_le,
true_and, exists_prop', nonempty_prop, mem_Ici, fundamentalEntourage]
rcases h with h | h
Β· exact Or.inr h
Β· cases le_total n P.1 with
| inl h_le => exact Or.inr β¨h_le, h βΈ h_leβ©
| inr h_le => exact Or.inl β¨P.1, β¨h_le, congrArg _ hβ©β©
/-- The collection `fundamentalEntourage` satisfies the axioms to be a basis for a filter on
`β Γ β` and gives rise to a term in the relevant type. -/
def counterBasis : FilterBasis (β Γ β) where
sets := range fundamentalEntourage
nonempty := range_nonempty _
inter_sets := by
intro S T hS hT
obtain β¨s, hsβ© := hS
obtain β¨t, htβ© := hT
simp only [mem_range, subset_inter_iff, exists_exists_eq_and, fundamentalEntourage]
use max t s
refine β¨fun β¨P1, P2β© hP β¦ ?_, fun β¨P1, P2β© hP β¦ ?_β© <;> rcases hP with h | h
Β· simp only [iUnion_singleton_eq_range, mem_range, Prod.mk.injEq, Subtype.exists,
exists_and_left, exists_eq_left] at h
simpa only [β hs, mem_fundamentalEntourage] using Or.inr h.2
Β· simpa only [β hs, mem_fundamentalEntourage] using Or.inl
β¨le_trans (by omega) h.1, le_trans (by omega) h.2β©
Β· simp only [iUnion_singleton_eq_range, mem_range, Prod.mk.injEq, Subtype.exists,
exists_and_left, exists_eq_left] at h
simpa only [β ht, mem_fundamentalEntourage] using Or.inr h.2
Β· simp only [mem_Ici, Prod.mk_le_mk] at h
simpa only [β ht, mem_fundamentalEntourage] using Or.inl β¨le_trans
(by omega) h.1, le_trans (by omega) h.2β©
@[simp]
lemma mem_counterBasis_iff (S : Set (β Γ β)) :
S β counterBasis β S β range fundamentalEntourage := by
dsimp [counterBasis]
rfl
/-- The "crude" uniform structure, without topology, simply as a the filter generated by `Basis`
and satisfying the axioms for being a uniformity. We later extract the topology `counterTopology`
generated by it and bundle `counterCoreUniformity` and `counterTopology` in a uniform structure
on `β`, proving in passing that `counterTopology = β₯`. -/
def counterCoreUniformity : UniformSpace.Core β := by
apply UniformSpace.Core.mkOfBasis counterBasis <;>
intro S hS
Β· obtain β¨n, hnβ© := hS
simp only [fundamentalEntourage_ext, iUnion_singleton_eq_range] at hn
simp only [hn, mem_union, mem_range, Prod.mk.injEq, and_self, Subtype.exists, mem_Icc, zero_le,
true_and, exists_prop', nonempty_prop, exists_eq_right, mem_Ici, Prod.mk_le_mk]
omega
Β· refine β¨S, hS, ?_β©
obtain β¨n, hnβ© := hS
simp only [fundamentalEntourage_ext, iUnion_singleton_eq_range] at hn
simp only [hn, preimage_union, union_subset_iff]
constructor
Β· apply subset_union_of_subset_left (subset_of_eq _)
aesop
Β· apply subset_union_of_subset_right (subset_of_eq _)
aesop
Β· refine β¨S, hS, ?_β©
obtain β¨n, hnβ© := hS
simp only [fundamentalEntourage_ext, iUnion_singleton_eq_range] at hn
simp only [hn]
rintro β¨P1, P2β© β¨m, h1, h2β©
simp only [mem_union, mem_range, Prod.mk.injEq, Subtype.exists, mem_Icc, zero_le, true_and,
exists_and_left, exists_prop', nonempty_prop, exists_eq_left, mem_Ici, Prod.mk_le_mk] at h1 h2
aesop
/-- The topology on `β` induced by the "crude" uniformity -/
instance counterTopology : TopologicalSpace β := counterCoreUniformity.toTopologicalSpace
/-- The uniform structure on `β` bundling together the "crude" uniformity and the topology -/
instance counterUniformity : UniformSpace β := UniformSpace.ofCore counterCoreUniformity
lemma HasBasis_counterUniformity :
(uniformity β).HasBasis (fun _ β¦ True) fundamentalEntourage := by
change counterCoreUniformity.uniformity.HasBasis (fun _ β¦ True) fundamentalEntourage
simp only [Filter.hasBasis_iff, true_and]
intro T
refine β¨fun β¨s, β¨β¨r, hrβ©, hsβ©β© β¦ β¨r, subset_of_eq_of_subset hr hsβ© , fun β¨n, hnβ© β¦ ?_β©
exact (@FilterBasis.mem_filter_iff _ counterBasis T).mpr β¨fundamentalEntourage n, by simp, hnβ©
/-- A proof that the topology on `β` induced by the "crude" uniformity `counterCoreUniformity`
(or by `counterUniformity` tout-court, since they are `defeq`) is discrete -/
theorem TopIsDiscrete' : DiscreteTopology β := by
rw [discreteTopology_iff_nhds]
intro n
rw [nhds_eq_comap_uniformity']
apply Filter.ext
intro S
simp only [Filter.mem_comap, Filter.mem_pure]
have := @Filter.HasBasis.mem_uniformity_iff _ _ _ _ _ HasBasis_counterUniformity
refine β¨fun h β¦ ?_, fun h β¦ ?_β©
Β· simp_rw [this] at h
obtain β¨T, β¨β¨i, β¨-, h1β©β©, h2β©β© := h
apply h2 (h1 _ _ _)
rw [mem_fundamentalEntourage]
aesop
Β· refine β¨fundamentalEntourage (n + 1), ?_, ?_β©
Β· change fundamentalEntourage (n + 1) β counterCoreUniformity.uniformity
exact @Filter.HasBasis.mem_of_mem (β Γ β) β counterCoreUniformity.uniformity (fun _ β¦ True)
fundamentalEntourage (n + 1) HasBasis_counterUniformity trivial
Β· simp only [preimage_subset_iff, mem_fundamentalEntourage, add_le_iff_nonpos_right,
nonpos_iff_eq_zero, one_ne_zero, and_false, false_or]
exact fun _ a β¦ mem_of_eq_of_mem a h
/- With respect to the above uniformity, the `atTop` filter is Cauchy; in particular, it is not of
the form `π {x}` for any `x`, although the topology is discrete. This implies in passing that this
uniformity is not discrete. -/
lemma atTopIsCauchy : Cauchy (atTop : Filter β) := by
rw [HasBasis_counterUniformity.cauchy_iff]
refine β¨atTop_neBot, fun i _ β¦ ?_β©
simp_rw [mem_fundamentalEntourage, mem_atTop_sets, ge_iff_le]
exact β¨Ici i, β¨β¨i, fun _ hb β¦ hbβ©, fun _ hx _ hy β¦ Or.inl β¨hx, hyβ©β©β©
/-- We find the same result about the identity map found in `idIsCauchy`, without using any metric
structure. -/
lemma idIsCauchy' : CauchySeq (id : β β _) := β¨map_neBot, cauchy_iff_le.mp atTopIsCauchyβ©
end SetPointUniformity
|
NewtonIdentities.lean
|
/-
Copyright (c) 2023 Michael Lee. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Michael Lee
-/
import Mathlib.Algebra.Algebra.Subalgebra.Basic
import Mathlib.Algebra.MvPolynomial.CommRing
import Mathlib.Algebra.MvPolynomial.Rename
import Mathlib.Data.Fintype.Basic
import Mathlib.RingTheory.MvPolynomial.Symmetric.Defs
/-!
# Newton's Identities
This file defines `MvPolynomial` power sums as a means of implementing Newton's identities. The
combinatorial proof, due to Zeilberger, defines for `k : β` a subset `pairs` of
`(range k).powerset Γ range k` and a map `pairMap` such that `pairMap` is an involution on `pairs`,
and a map `weight` which identifies elements of `pairs` with the terms of the summation in Newton's
identities and which satisfies `weight β pairMap = -weight`. The result therefore follows neatly
from an identity implemented in mathlib as `Finset.sum_involution`. Namely, we use
`Finset.sum_involution` to show that `β t β pairs Ο k, weight Ο R k t = 0`. We then identify
`(-1) ^ k * k * esymm Ο R k` with the terms of the weight sum for which `t.fst` has
cardinality `k`, and `(-1) ^ i * esymm Ο R i * psum Ο R (k - i)` with the terms of the weight sum
for which `t.fst` has cardinality `i` for `i < k` , and we thereby derive the main result
`(-1) ^ k * k * esymm Ο R k + β i β range k, (-1) ^ i * esymm Ο R i * psum Ο R (k - i) = 0` (or
rather, two equivalent forms which provide direct definitions for `esymm` and `psum` in lower-degree
terms).
## Main declarations
* `MvPolynomial.mul_esymm_eq_sum`: a recurrence relation for the `k`th elementary
symmetric polynomial in terms of lower-degree elementary symmetric polynomials and power sums.
* `MvPolynomial.psum_eq_mul_esymm_sub_sum`: a recurrence relation for the degree-`k` power sum
in terms of lower-degree elementary symmetric polynomials and power sums.
## References
See [zeilberger1984] for the combinatorial proof of Newton's identities.
-/
open Equiv (Perm)
open MvPolynomial
noncomputable section
namespace MvPolynomial
open Finset Nat
namespace NewtonIdentities
variable (Ο : Type*) (R : Type*) [CommRing R]
section DecidableEq
variable [DecidableEq Ο]
private def pairMap (t : Finset Ο Γ Ο) : Finset Ο Γ Ο :=
if h : t.snd β t.fst then (t.fst.erase t.snd, t.snd) else (t.fst.cons t.snd h, t.snd)
private lemma pairMap_ne_self (t : Finset Ο Γ Ο) : pairMap Ο t β t := by
rw [pairMap]
split_ifs with h1
all_goals by_contra ht; rw [β ht] at h1; simp_all
private lemma pairMap_of_snd_mem_fst {t : Finset Ο Γ Ο} (h : t.snd β t.fst) :
pairMap Ο t = (t.fst.erase t.snd, t.snd) := by
simp [pairMap, h]
private lemma pairMap_of_snd_notMem_fst {t : Finset Ο Γ Ο} (h : t.snd β t.fst) :
pairMap Ο t = (t.fst.cons t.snd h, t.snd) := by
simp [pairMap, h]
@[deprecated (since := "2025-05-24")] alias pairMap_of_snd_nmem_fst := pairMap_of_snd_notMem_fst
@[simp]
private theorem pairMap_involutive : (pairMap Ο).Involutive := by
intro t
rw [pairMap, pairMap]
split_ifs with h1 h2 h3
Β· simp at h2
Β· simp [insert_erase h1]
Β· simp_all
Β· simp at h3
variable [Fintype Ο]
private def pairs (k : β) : Finset (Finset Ο Γ Ο) :=
{t | #t.1 β€ k β§ (#t.1 = k β t.snd β t.fst)}
@[simp]
private lemma mem_pairs (k : β) (t : Finset Ο Γ Ο) :
t β pairs Ο k β #t.1 β€ k β§ (#t.1 = k β t.snd β t.fst) := by
simp [pairs]
private def weight (k : β) (t : Finset Ο Γ Ο) : MvPolynomial Ο R :=
(-1) ^ #t.1 * ((β a β t.fst, X a) * X t.snd ^ (k - #t.1))
private theorem pairMap_mem_pairs {k : β} (t : Finset Ο Γ Ο) (h : t β pairs Ο k) :
pairMap Ο t β pairs Ο k := by
rw [mem_pairs] at h β’
rcases (em (t.snd β t.fst)) with h1 | h1
Β· rw [pairMap_of_snd_mem_fst Ο h1]
simp only [h1, implies_true, and_true] at h
simp only [card_erase_of_mem h1, tsub_le_iff_right, mem_erase, ne_eq, h1]
refine β¨le_step h, ?_β©
by_contra h2
simp only [not_true_eq_false, and_true, not_forall, not_false_eq_true, exists_prop] at h2
rw [β h2] at h
exact not_le_of_gt (sub_lt (card_pos.mpr β¨t.snd, h1β©) zero_lt_one) h
Β· rw [pairMap_of_snd_notMem_fst Ο h1]
simp only [h1] at h
simp only [card_cons, mem_cons, true_or, implies_true, and_true]
exact (le_iff_eq_or_lt.mp h.left).resolve_left h.right
private theorem weight_add_weight_pairMap {k : β} (t : Finset Ο Γ Ο) (h : t β pairs Ο k) :
weight Ο R k t + weight Ο R k (pairMap Ο t) = 0 := by
rw [weight, weight]
rw [mem_pairs] at h
have h2 (n : β) : -(-1 : MvPolynomial Ο R) ^ n = (-1) ^ (n + 1) := by
rw [β neg_one_mul ((-1 : MvPolynomial Ο R) ^ n), pow_add, pow_one, mul_comm]
rcases (em (t.snd β t.fst)) with h1 | h1
Β· rw [pairMap_of_snd_mem_fst Ο h1]
simp only [β prod_erase_mul t.fst (fun j β¦ (X j : MvPolynomial Ο R)) h1,
mul_assoc (β a β erase t.fst t.snd, X a), card_erase_of_mem h1]
nth_rewrite 1 [β pow_one (X t.snd)]
simp only [β pow_add, add_comm]
have h3 : 1 β€ #t.1 := lt_iff_add_one_le.mp (card_pos.mpr β¨t.snd, h1β©)
rw [β tsub_tsub_assoc h.left h3, β neg_neg ((-1 : MvPolynomial Ο R) ^ (#t.1 - 1)),
h2 (#t.1 - 1), Nat.sub_add_cancel h3]
simp
Β· rw [pairMap_of_snd_notMem_fst Ο h1]
simp only [mul_comm, mul_assoc (β a β t.fst, X a), card_cons, prod_cons]
nth_rewrite 2 [β pow_one (X t.snd)]
simp only [β pow_add, β Nat.add_sub_assoc (Nat.lt_of_le_of_ne h.left (mt h.right h1)), add_comm,
Nat.succ_eq_add_one, Nat.add_sub_add_right]
rw [β neg_neg ((-1 : MvPolynomial Ο R) ^ #t.1), h2]
simp
private theorem weight_sum (k : β) : β t β pairs Ο k, weight Ο R k t = 0 :=
sum_involution (fun t _ β¦ pairMap Ο t) (weight_add_weight_pairMap Ο R)
(fun t _ β¦ (fun _ β¦ pairMap_ne_self Ο t)) (pairMap_mem_pairs Ο)
(fun t _ β¦ pairMap_involutive Ο t)
private theorem sum_filter_pairs_eq_sum_powersetCard_sum (k : β)
(f : Finset Ο Γ Ο β MvPolynomial Ο R) :
β t β pairs Ο k with #t.1 = k, f t = β A β powersetCard k univ, β j β A, f (A, j) := by
apply sum_finset_product
aesop
private theorem sum_filter_pairs_eq_sum_powersetCard_mem_filter_antidiagonal_sum (k : β) (a : β Γ β)
(ha : a β {a β antidiagonal k | a.fst < k}) (f : Finset Ο Γ Ο β MvPolynomial Ο R) :
β t β pairs Ο k with #t.1 = a.1, f t = β A β powersetCard a.1 univ, β j, f (A, j) := by
apply sum_finset_product
simp only [mem_filter, mem_powersetCard_univ, mem_univ, and_true, and_iff_right_iff_imp]
rintro p hp
have : #p.fst β€ k := by apply le_of_lt; aesop
aesop
private lemma filter_pairs_lt (k : β) :
(pairs Ο k).filter (fun (s, _) β¦ #s < k) =
(range k).disjiUnion (powersetCard Β· univ) ((pairwise_disjoint_powersetCard _).set_pairwise _)
ΓΛ’ univ := by ext; aesop (add unsafe le_of_lt)
private theorem sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum (k : β)
(f : Finset Ο Γ Ο β MvPolynomial Ο R) :
β t β pairs Ο k with #t.1 < k, f t =
β a β antidiagonal k with a.fst < k, β A β powersetCard a.fst univ, β j, f (A, j) := by
rw [filter_pairs_lt, sum_product, sum_disjiUnion]
refine sum_nbij' (fun n β¦ (n, k - n)) Prod.fst ?_ ?_ ?_ ?_ ?_ <;>
simp +contextual [@eq_comm _ _ k, le_of_lt]
private theorem disjoint_filter_pairs_lt_filter_pairs_eq (k : β) :
Disjoint {t β pairs Ο k | #t.1 < k} {t β pairs Ο k | #t.1 = k} := by
rw [disjoint_filter]
exact fun _ _ h1 h2 β¦ lt_irrefl _ (h2.symm.subst h1)
private theorem disjUnion_filter_pairs_eq_pairs (k : β) :
disjUnion {t β pairs Ο k | #t.1 < k} {t β pairs Ο k | #t.1 = k}
(disjoint_filter_pairs_lt_filter_pairs_eq Ο k) = pairs Ο k := by
simp only [Finset.ext_iff]
grind [Finset.disjUnion_eq_union, MvPolynomial.NewtonIdentities.pairs]
end DecidableEq
variable [Fintype Ο]
private theorem esymm_summand_to_weight (k : β) (A : Finset Ο) (h : A β powersetCard k univ) :
β j β A, weight Ο R k (A, j) = k * (-1) ^ k * (β i β A, X i : MvPolynomial Ο R) := by
simp [weight, mem_powersetCard_univ.mp h, mul_assoc]
private theorem esymm_to_weight [DecidableEq Ο] (k : β) : k * esymm Ο R k =
(-1) ^ k * β t β pairs Ο k with #t.1 = k, weight Ο R k t := by
rw [esymm, sum_filter_pairs_eq_sum_powersetCard_sum Ο R k (fun t β¦ weight Ο R k t),
sum_congr rfl (esymm_summand_to_weight Ο R k), mul_comm (k : MvPolynomial Ο R) ((-1) ^ k),
β mul_sum, β mul_assoc, β mul_assoc, β pow_add, Even.neg_one_pow β¨k, rflβ©, one_mul]
private theorem esymm_mul_psum_summand_to_weight (k : β) (a : β Γ β) (ha : a β antidiagonal k) :
β A β powersetCard a.fst univ, β j, weight Ο R k (A, j) =
(-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd := by
simp only [esymm, psum, weight, β mul_assoc, mul_sum]
rw [sum_comm]
refine sum_congr rfl fun x _ β¦ ?_
rw [sum_mul]
refine sum_congr rfl fun s hs β¦ ?_
rw [mem_powersetCard_univ.mp hs, β mem_antidiagonal.mp ha, add_sub_self_left]
private theorem esymm_mul_psum_to_weight [DecidableEq Ο] (k : β) :
β a β antidiagonal k with a.fst < k, (-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd =
β t β pairs Ο k with #t.1 < k, weight Ο R k t := by
rw [β sum_congr rfl (fun a ha β¦ esymm_mul_psum_summand_to_weight Ο R k a (mem_filter.mp ha).left),
sum_filter_pairs_eq_sum_filter_antidiagonal_powersetCard_sum Ο R k]
end NewtonIdentities
variable (Ο : Type*) [Fintype Ο] (R : Type*) [CommRing R]
/-- **Newton's identities** give a recurrence relation for the kth elementary symmetric polynomial
in terms of lower degree elementary symmetric polynomials and power sums. -/
theorem mul_esymm_eq_sum (k : β) :
k * esymm Ο R k = (-1) ^ (k + 1) *
β a β antidiagonal k with a.1 < k, (-1) ^ a.1 * esymm Ο R a.1 * psum Ο R a.2 := by
classical
rw [NewtonIdentities.esymm_to_weight Ο R k, NewtonIdentities.esymm_mul_psum_to_weight Ο R k,
eq_comm, β sub_eq_zero, sub_eq_add_neg, neg_mul_eq_neg_mul,
neg_eq_neg_one_mul ((-1 : MvPolynomial Ο R) ^ k)]
nth_rw 2 [β pow_one (-1 : MvPolynomial Ο R)]
rw [β pow_add, add_comm 1 k, β left_distrib,
β sum_disjUnion (NewtonIdentities.disjoint_filter_pairs_lt_filter_pairs_eq Ο k),
NewtonIdentities.disjUnion_filter_pairs_eq_pairs Ο k, NewtonIdentities.weight_sum Ο R k,
neg_one_pow_mul_eq_zero_iff.mpr rfl]
theorem sum_antidiagonal_card_esymm_psum_eq_zero :
β a β antidiagonal (Fintype.card Ο), (-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd = 0 := by
let k := Fintype.card Ο
suffices (-1 : MvPolynomial Ο R) ^ (k + 1) *
β a β antidiagonal k, (-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd = 0 by
simpa using this
simp [k, β sum_filter_add_sum_filter_not (antidiagonal k) (fun a β¦ a.fst < k),
β mul_esymm_eq_sum, mul_add, β mul_assoc, β pow_add, mul_comm βk (esymm Ο R k)]
/-- A version of Newton's identities which may be more useful in the case that we know the values of
the elementary symmetric polynomials and would like to calculate the values of the power sums. -/
theorem psum_eq_mul_esymm_sub_sum (k : β) (h : 0 < k) :
psum Ο R k = (-1) ^ (k + 1) * k * esymm Ο R k -
β a β antidiagonal k with a.1 β Set.Ioo 0 k, (-1) ^ a.fst * esymm Ο R a.1 * psum Ο R a.2 := by
simp only [Set.Ioo, Set.mem_setOf_eq, and_comm]
have hesymm := mul_esymm_eq_sum Ο R k
rw [β (sum_filter_add_sum_filter_not {a β antidiagonal k | a.fst < k}
(fun a β¦ 0 < a.fst) (fun a β¦ (-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd))] at hesymm
have sub_both_sides := congrArg (Β· - (-1 : MvPolynomial Ο R) ^ (k + 1) *
β a β {a β antidiagonal k | a.fst < k} with 0 < a.fst,
(-1) ^ a.fst * esymm Ο R a.fst * psum Ο R a.snd) hesymm
simp only [left_distrib, add_sub_cancel_left] at sub_both_sides
have sub_both_sides := congrArg ((-1 : MvPolynomial Ο R) ^ (k + 1) * Β·) sub_both_sides
simp only [mul_sub_left_distrib, β mul_assoc, β pow_add, Even.neg_one_pow β¨k + 1, rflβ©, one_mul,
filter_filter (fun a : β Γ β β¦ a.fst < k) (fun a β¦ Β¬0 < a.fst)]
at sub_both_sides
have : {a β antidiagonal k | a.fst < k β§ Β¬0 < a.fst} = {(0, k)} := by
ext a
rw [mem_filter, mem_antidiagonal, mem_singleton]
refine β¨?_, by rintro rfl; omegaβ©
rintro β¨ha, β¨_, ha0β©β©
rw [β ha, Nat.eq_zero_of_not_pos ha0, zero_add, β Nat.eq_zero_of_not_pos ha0]
rw [this, sum_singleton] at sub_both_sides
simp only [_root_.pow_zero, esymm_zero, mul_one, one_mul, filter_filter] at sub_both_sides
exact sub_both_sides.symm
end MvPolynomial
|
NoetherianSpace.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.Topology.Homeomorph.Lemmas
import Mathlib.Topology.Sets.Closeds
/-!
# Noetherian space
A Noetherian space is a topological space that satisfies any of the following equivalent conditions:
- `WellFounded ((Β· > Β·) : TopologicalSpace.Opens Ξ± β TopologicalSpace.Opens Ξ± β Prop)`
- `WellFounded ((Β· < Β·) : TopologicalSpace.Closeds Ξ± β TopologicalSpace.Closeds Ξ± β Prop)`
- `β s : Set Ξ±, IsCompact s`
- `β s : TopologicalSpace.Opens Ξ±, IsCompact s`
The first is chosen as the definition, and the equivalence is shown in
`TopologicalSpace.noetherianSpace_TFAE`.
Many examples of noetherian spaces come from algebraic topology. For example, the underlying space
of a noetherian scheme (e.g., the spectrum of a noetherian ring) is noetherian.
## Main Results
- `TopologicalSpace.NoetherianSpace.set`: Every subspace of a noetherian space is noetherian.
- `TopologicalSpace.NoetherianSpace.isCompact`: Every set in a noetherian space is a compact set.
- `TopologicalSpace.noetherianSpace_TFAE`: Describes the equivalent definitions of noetherian
spaces.
- `TopologicalSpace.NoetherianSpace.range`: The image of a noetherian space under a continuous map
is noetherian.
- `TopologicalSpace.NoetherianSpace.iUnion`: The finite union of noetherian spaces is noetherian.
- `TopologicalSpace.NoetherianSpace.discrete`: A noetherian and Hausdorff space is discrete.
- `TopologicalSpace.NoetherianSpace.exists_finset_irreducible`: Every closed subset of a noetherian
space is a finite union of irreducible closed subsets.
- `TopologicalSpace.NoetherianSpace.finite_irreducibleComponents`: The number of irreducible
components of a noetherian space is finite.
-/
open Topology
variable (Ξ± Ξ² : Type*) [TopologicalSpace Ξ±] [TopologicalSpace Ξ²]
namespace TopologicalSpace
/-- Type class for noetherian spaces. It is defined to be spaces whose open sets satisfies ACC. -/
abbrev NoetherianSpace : Prop := WellFoundedGT (Opens Ξ±)
theorem noetherianSpace_iff_opens : NoetherianSpace Ξ± β β s : Opens Ξ±, IsCompact (s : Set Ξ±) := by
rw [NoetherianSpace, CompleteLattice.wellFoundedGT_iff_isSupFiniteCompact,
CompleteLattice.isSupFiniteCompact_iff_all_elements_compact]
exact forall_congr' Opens.isCompactElement_iff
instance (priority := 100) NoetherianSpace.compactSpace [h : NoetherianSpace Ξ±] : CompactSpace Ξ± :=
β¨(noetherianSpace_iff_opens Ξ±).mp h β€β©
variable {Ξ± Ξ²}
/-- In a Noetherian space, all sets are compact. -/
protected theorem NoetherianSpace.isCompact [NoetherianSpace Ξ±] (s : Set Ξ±) : IsCompact s := by
refine isCompact_iff_finite_subcover.2 fun U hUo hs => ?_
rcases ((noetherianSpace_iff_opens Ξ±).mp βΉ_βΊ β¨β i, U i, isOpen_iUnion hUoβ©).elim_finite_subcover U
hUo Set.Subset.rfl with β¨t, htβ©
exact β¨t, hs.trans htβ©
protected theorem _root_.Topology.IsInducing.noetherianSpace [NoetherianSpace Ξ±] {i : Ξ² β Ξ±}
(hi : IsInducing i) : NoetherianSpace Ξ² :=
(noetherianSpace_iff_opens _).2 fun _ => hi.isCompact_iff.2 (NoetherianSpace.isCompact _)
@[stacks 0052 "(1)"]
instance NoetherianSpace.set [NoetherianSpace Ξ±] (s : Set Ξ±) : NoetherianSpace s :=
IsInducing.subtypeVal.noetherianSpace
variable (Ξ±) in
open List in
theorem noetherianSpace_TFAE :
TFAE [NoetherianSpace Ξ±,
WellFoundedLT (Closeds Ξ±),
β s : Set Ξ±, IsCompact s,
β s : Opens Ξ±, IsCompact (s : Set Ξ±)] := by
tfae_have 1 β 2 := by
simp_rw [isWellFounded_iff]
exact Opens.compl_bijective.2.wellFounded_iff (@OrderIso.compl (Set Ξ±)).lt_iff_lt.symm
tfae_have 1 β 4 := noetherianSpace_iff_opens Ξ±
tfae_have 1 β 3 := @NoetherianSpace.isCompact Ξ± _
tfae_have 3 β 4 := fun h s => h s
tfae_finish
theorem noetherianSpace_iff_isCompact : NoetherianSpace Ξ± β β s : Set Ξ±, IsCompact s :=
(noetherianSpace_TFAE Ξ±).out 0 2
instance [NoetherianSpace Ξ±] : WellFoundedLT (Closeds Ξ±) :=
Iff.mp ((noetherianSpace_TFAE Ξ±).out 0 1) βΉ_βΊ
instance {Ξ±} : NoetherianSpace (CofiniteTopology Ξ±) := by
simp only [noetherianSpace_iff_isCompact, isCompact_iff_ultrafilter_le_nhds,
CofiniteTopology.nhds_eq, Ultrafilter.le_sup_iff, Filter.le_principal_iff]
intro s f hs
rcases f.le_cofinite_or_eq_pure with (hf | β¨a, rflβ©)
Β· rcases Filter.nonempty_of_mem hs with β¨a, haβ©
exact β¨a, ha, Or.inr hfβ©
Β· exact β¨a, hs, Or.inl le_rflβ©
theorem noetherianSpace_of_surjective [NoetherianSpace Ξ±] (f : Ξ± β Ξ²) (hf : Continuous f)
(hf' : Function.Surjective f) : NoetherianSpace Ξ² :=
noetherianSpace_iff_isCompact.2 <| (Set.image_surjective.mpr hf').forall.2 fun s =>
(NoetherianSpace.isCompact s).image hf
theorem noetherianSpace_iff_of_homeomorph (f : Ξ± ββ Ξ²) : NoetherianSpace Ξ± β NoetherianSpace Ξ² :=
β¨fun _ => noetherianSpace_of_surjective f f.continuous f.surjective,
fun _ => noetherianSpace_of_surjective f.symm f.symm.continuous f.symm.surjectiveβ©
theorem NoetherianSpace.range [NoetherianSpace Ξ±] (f : Ξ± β Ξ²) (hf : Continuous f) :
NoetherianSpace (Set.range f) :=
noetherianSpace_of_surjective (Set.rangeFactorization f) (hf.subtype_mk _)
Set.surjective_onto_range
theorem noetherianSpace_set_iff (s : Set Ξ±) :
NoetherianSpace s β β t, t β s β IsCompact t := by
simp only [noetherianSpace_iff_isCompact, IsEmbedding.subtypeVal.isCompact_iff,
Subtype.forall_set_subtype]
@[simp]
theorem noetherian_univ_iff : NoetherianSpace (Set.univ : Set Ξ±) β NoetherianSpace Ξ± :=
noetherianSpace_iff_of_homeomorph (Homeomorph.Set.univ Ξ±)
theorem NoetherianSpace.iUnion {ΞΉ : Type*} (f : ΞΉ β Set Ξ±) [Finite ΞΉ]
[hf : β i, NoetherianSpace (f i)] : NoetherianSpace (β i, f i) := by
simp_rw [noetherianSpace_set_iff] at hf β’
intro t ht
rw [β Set.inter_eq_left.mpr ht, Set.inter_iUnion]
exact isCompact_iUnion fun i => hf i _ Set.inter_subset_right
-- This is not an instance since it makes a loop with `t2_space_discrete`.
theorem NoetherianSpace.discrete [NoetherianSpace Ξ±] [T2Space Ξ±] : DiscreteTopology Ξ± :=
β¨eq_bot_iff.mpr fun _ _ => isClosed_compl_iff.mp (NoetherianSpace.isCompact _).isClosedβ©
attribute [local instance] NoetherianSpace.discrete
/-- Spaces that are both Noetherian and Hausdorff are finite. -/
theorem NoetherianSpace.finite [NoetherianSpace Ξ±] [T2Space Ξ±] : Finite Ξ± :=
Finite.of_finite_univ (NoetherianSpace.isCompact Set.univ).finite_of_discrete
instance (priority := 100) Finite.to_noetherianSpace [Finite Ξ±] : NoetherianSpace Ξ± :=
β¨Finite.wellFounded_of_trans_of_irrefl _β©
/-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/
theorem NoetherianSpace.exists_finite_set_closeds_irreducible [NoetherianSpace Ξ±] (s : Closeds Ξ±) :
β S : Set (Closeds Ξ±), S.Finite β§ (β t β S, IsIrreducible (t : Set Ξ±)) β§ s = sSup S := by
apply wellFounded_lt.induction s; clear s
intro s H
rcases eq_or_ne s β₯ with rfl | hβ
Β· use β
; simp
Β· by_cases hβ : IsPreirreducible (s : Set Ξ±)
Β· replace hβ : IsIrreducible (s : Set Ξ±) := β¨Closeds.coe_nonempty.2 hβ, hββ©
use {s}; simp [hβ]
Β· simp only [isPreirreducible_iff_isClosed_union_isClosed, not_forall, not_or] at hβ
obtain β¨zβ, zβ, hzβ, hzβ, h, hzβ', hzβ'β© := hβ
lift zβ to Closeds Ξ± using hzβ
lift zβ to Closeds Ξ± using hzβ
rcases H (s β zβ) (inf_lt_left.2 hzβ') with β¨Sβ, hSfβ, hSβ, hββ©
rcases H (s β zβ) (inf_lt_left.2 hzβ') with β¨Sβ, hSfβ, hSβ, hββ©
refine β¨Sβ βͺ Sβ, hSfβ.union hSfβ, Set.union_subset_iff.2 β¨hSβ, hSββ©, ?_β©
rwa [sSup_union, β hβ, β hβ, β inf_sup_left, left_eq_inf]
/-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/
theorem NoetherianSpace.exists_finite_set_isClosed_irreducible [NoetherianSpace Ξ±]
{s : Set Ξ±} (hs : IsClosed s) : β S : Set (Set Ξ±), S.Finite β§
(β t β S, IsClosed t) β§ (β t β S, IsIrreducible t) β§ s = ββ S := by
lift s to Closeds Ξ± using hs
rcases NoetherianSpace.exists_finite_set_closeds_irreducible s with β¨S, hSf, hS, rflβ©
refine β¨(β) '' S, hSf.image _, Set.forall_mem_image.2 fun S _ β¦ S.2, Set.forall_mem_image.2 hS,
?_β©
lift S to Finset (Closeds Ξ±) using hSf
simp [β Finset.sup_id_eq_sSup, Closeds.coe_finset_sup]
/-- In a Noetherian space, every closed set is a finite union of irreducible closed sets. -/
theorem NoetherianSpace.exists_finset_irreducible [NoetherianSpace Ξ±] (s : Closeds Ξ±) :
β S : Finset (Closeds Ξ±), (β k : S, IsIrreducible (k : Set Ξ±)) β§ s = S.sup id := by
simpa [Set.exists_finite_iff_finset, Finset.sup_id_eq_sSup]
using NoetherianSpace.exists_finite_set_closeds_irreducible s
@[stacks 0052 "(2)"]
theorem NoetherianSpace.finite_irreducibleComponents [NoetherianSpace Ξ±] :
(irreducibleComponents Ξ±).Finite := by
obtain β¨S : Set (Set Ξ±), hSf, hSc, hSi, hSUβ© :=
NoetherianSpace.exists_finite_set_isClosed_irreducible isClosed_univ (Ξ± := Ξ±)
refine hSf.subset fun s hs => ?_
lift S to Finset (Set Ξ±) using hSf
rcases isIrreducible_iff_sUnion_isClosed.1 hs.1 S hSc (hSU βΈ Set.subset_univ _) with β¨t, htS, htβ©
rwa [ht.antisymm (hs.2 (hSi _ htS) ht)]
@[stacks 0052 "(3)"]
theorem NoetherianSpace.exists_open_ne_empty_le_irreducibleComponent [NoetherianSpace Ξ±]
(Z : Set Ξ±) (H : Z β irreducibleComponents Ξ±) :
β o : Set Ξ±, IsOpen o β§ o β β
β§ o β€ Z := by
classical
let ΞΉ : Set (Set Ξ±) := irreducibleComponents Ξ± \ {Z}
have hΞΉ : ΞΉ.Finite := NoetherianSpace.finite_irreducibleComponents.subset Set.diff_subset
have hΞΉ' : Finite ΞΉ := by rwa [Set.finite_coe_iff]
let U := Z \ β (x : ΞΉ), x
have hU0 : U β β
:= fun r β¦ by
obtain β¨Z', hZ'β© := isIrreducible_iff_sUnion_isClosed.mp H.1 hΞΉ.toFinset
(fun z hz β¦ by
simp only [Set.Finite.mem_toFinset] at hz
exact isClosed_of_mem_irreducibleComponents _ hz.1)
(by
rw [Set.Finite.coe_toFinset, Set.sUnion_eq_iUnion]
rw [Set.diff_eq_empty] at r
exact r)
simp only [Set.Finite.mem_toFinset] at hZ'
exact hZ'.1.2 <| le_antisymm (H.2 hZ'.1.1.1 hZ'.2) hZ'.2
have hU1 : U = (β (x : ΞΉ), x.1) αΆ := by
rw [Set.compl_eq_univ_diff]
refine le_antisymm (Set.diff_subset_diff le_top <| subset_refl _) ?_
rw [β Set.compl_eq_univ_diff]
refine Set.compl_subset_iff_union.mpr (le_antisymm le_top ?_)
rw [Set.union_comm, β Set.sUnion_eq_iUnion, β Set.sUnion_insert]
rintro a -
by_cases h : a β U
Β· exact β¨U, Set.mem_insert _ _, hβ©
Β· rw [Set.mem_diff, Decidable.not_and_iff_not_or_not, not_not, Set.mem_iUnion] at h
rcases h with (h|β¨i, hiβ©)
Β· refine β¨irreducibleComponent a, Or.inr ?_, mem_irreducibleComponentβ©
simp only [ΞΉ, Set.mem_diff, Set.mem_singleton_iff]
refine β¨irreducibleComponent_mem_irreducibleComponents _, ?_β©
rintro rfl
exact h mem_irreducibleComponent
Β· exact β¨i, Or.inr i.2, hiβ©
refine β¨U, hU1 βΈ isOpen_compl_iff.mpr ?_, hU0, sdiff_leβ©
exact isClosed_iUnion_of_finite fun i β¦ isClosed_of_mem_irreducibleComponents i.1 i.2.1
end TopologicalSpace
|
archimedean.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrfun ssrbool eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop order ssralg poly ssrnum ssrint.
(******************************************************************************)
(* Archimedean structures *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* This file defines some numeric structures extended with the Archimedean *)
(* axiom. To use this file, insert "Import Num.Theory." and optionally *)
(* "Import Num.Def." before your scripts as in the ssrnum library. *)
(* The modules provided by this library subsume those from ssrnum. *)
(* *)
(* This file defines the following structures: *)
(* *)
(* archiNumDomainType == numDomainType with the Archimedean axiom *)
(* The HB class is called ArchiNumDomain. *)
(* archiNumFieldType == numFieldType with the Archimedean axiom *)
(* The HB class is called ArchiNumField. *)
(* archiClosedFieldType == closedFieldType with the Archimedean axiom *)
(* The HB class is called ArchiClosedField. *)
(* archiRealDomainType == realDomainType with the Archimedean axiom *)
(* The HB class is called ArchiRealDomain. *)
(* archiRealFieldType == realFieldType with the Archimedean axiom *)
(* The HB class is called ArchiRealField. *)
(* archiRcfType == rcfType with the Archimedean axiom *)
(* The HB class is called ArchiRealClosedField. *)
(* *)
(* Over these structures, we have the following operations: *)
(* x \is a Num.int <=> x is an integer, i.e., x = m%:~R for some m : int *)
(* x \is a Num.nat <=> x is a natural number, i.e., x = m%:R for some m : nat*)
(* Num.floor x == the m : int such that m%:~R <= x < (m + 1)%:~R *)
(* when x \is a Num.real, otherwise 0%Z *)
(* Num.ceil x == the m : int such that (m - 1)%:~R < x <= m%:~R *)
(* when x \is a Num.real, otherwise 0%Z *)
(* Num.truncn x == the n : nat such that n%:R <= x < n.+1%:R *)
(* when 0 <= n, otherwise 0%N *)
(* Num.bound x == an upper bound for x, i.e., an n such that `|x| < n%:R *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Local Open Scope ring_scope.
Import Order.TTheory GRing.Theory Num.Theory.
Module Num.
Import Num.Def.
HB.mixin Record NumDomain_hasFloorCeilTruncn R of Num.NumDomain R := {
floor : R -> int;
ceil : R -> int;
truncn : R -> nat;
int_num_subdef : pred R;
nat_num_subdef : pred R;
floor_subproof :
forall x,
if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R
else floor x == 0;
ceil_subproof : forall x, ceil x = - floor (- x);
truncn_subproof : forall x, truncn x = if floor x is Posz n then n else 0;
int_num_subproof : forall x, reflect (exists n, x = n%:~R) (int_num_subdef x);
nat_num_subproof : forall x, reflect (exists n, x = n%:R) (nat_num_subdef x);
}.
#[short(type="archiNumDomainType")]
HB.structure Definition ArchiNumDomain :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.NumDomain R }.
Module ArchiNumDomainExports.
Bind Scope ring_scope with ArchiNumDomain.sort.
End ArchiNumDomainExports.
HB.export ArchiNumDomainExports.
#[short(type="archiNumFieldType")]
HB.structure Definition ArchiNumField :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.NumField R }.
Module ArchiNumFieldExports.
Bind Scope ring_scope with ArchiNumField.sort.
End ArchiNumFieldExports.
HB.export ArchiNumFieldExports.
#[short(type="archiClosedFieldType")]
HB.structure Definition ArchiClosedField :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.ClosedField R }.
Module ArchiClosedFieldExports.
Bind Scope ring_scope with ArchiClosedField.sort.
End ArchiClosedFieldExports.
HB.export ArchiClosedFieldExports.
#[short(type="archiRealDomainType")]
HB.structure Definition ArchiRealDomain :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.RealDomain R }.
Module ArchiRealDomainExports.
Bind Scope ring_scope with ArchiRealDomain.sort.
End ArchiRealDomainExports.
HB.export ArchiRealDomainExports.
#[short(type="archiRealFieldType")]
HB.structure Definition ArchiRealField :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.RealField R }.
Module ArchiRealFieldExports.
Bind Scope ring_scope with ArchiRealField.sort.
End ArchiRealFieldExports.
HB.export ArchiRealFieldExports.
#[short(type="archiRcfType")]
HB.structure Definition ArchiRealClosedField :=
{ R of NumDomain_hasFloorCeilTruncn R & Num.RealClosedField R }.
Module ArchiRealClosedFieldExports.
Bind Scope ring_scope with ArchiRealClosedField.sort.
End ArchiRealClosedFieldExports.
HB.export ArchiRealClosedFieldExports.
Section Def.
Context {R : archiNumDomainType}.
Definition nat_num : qualifier 1 R := [qualify a x : R | nat_num_subdef x].
Definition int_num : qualifier 1 R := [qualify a x : R | int_num_subdef x].
Definition bound (x : R) := (truncn `|x|).+1.
End Def.
Arguments floor {R} : rename, simpl never.
Arguments ceil {R} : rename, simpl never.
Arguments truncn {R} : rename, simpl never.
Arguments nat_num {R} : simpl never.
Arguments int_num {R} : simpl never.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")]
Notation trunc := truncn.
Module Def.
Export ssrnum.Num.Def.
Notation truncn := truncn.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn.")]
Notation trunc := truncn.
Notation floor := floor.
Notation ceil := ceil.
Notation nat_num := nat_num.
Notation int_num := int_num.
Notation archi_bound := bound.
End Def.
Module intArchimedean.
Section intArchimedean.
Implicit Types n : int.
Lemma floorP n : if n \is Rreal then n%:~R <= n < (n + 1)%:~R else n == 0.
Proof. by rewrite num_real !intz ltzD1 lexx. Qed.
Lemma intrP n : reflect (exists m, n = m%:~R) true.
Proof. by apply: ReflectT; exists n; rewrite intz. Qed.
Lemma natrP n : reflect (exists m, n = m%:R) (0 <= n).
Proof.
apply: (iffP idP); last by case=> m ->; rewrite ler0n.
by case: n => // n _; exists n; rewrite natz.
Qed.
End intArchimedean.
End intArchimedean.
#[export]
HB.instance Definition _ :=
@NumDomain_hasFloorCeilTruncn.Build int id id _ xpredT Rnneg_pred
intArchimedean.floorP (fun=> esym (opprK _)) (fun=> erefl)
intArchimedean.intrP intArchimedean.natrP.
Module Import Theory.
Export ssrnum.Num.Theory.
Section ArchiNumDomainTheory.
Variable R : archiNumDomainType.
Implicit Types x y z : R.
Local Notation truncn := (@truncn R).
Local Notation floor := (@floor R).
Local Notation ceil := (@ceil R).
Local Notation nat_num := (@Def.nat_num R).
Local Notation int_num := (@Def.int_num R).
Local Lemma floorP x :
if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0.
Proof. exact: floor_subproof. Qed.
Lemma floorNceil x : floor x = - ceil (- x).
Proof. by rewrite ceil_subproof !opprK. Qed.
Lemma ceilNfloor x : ceil x = - floor (- x).
Proof. exact: ceil_subproof. Qed.
Lemma truncEfloor x : truncn x = if floor x is Posz n then n else 0.
Proof. exact: truncn_subproof. Qed.
Lemma natrP x : reflect (exists n, x = n%:R) (x \is a nat_num).
Proof. exact: nat_num_subproof. Qed.
Lemma intrP x : reflect (exists m, x = m%:~R) (x \is a int_num).
Proof. exact: int_num_subproof. Qed.
(* int_num and nat_num *)
Lemma intr_int m : m%:~R \is a int_num. Proof. by apply/intrP; exists m. Qed.
Lemma natr_nat n : n%:R \is a nat_num. Proof. by apply/natrP; exists n. Qed.
#[local] Hint Resolve intr_int natr_nat : core.
Lemma rpred_int_num (S : subringClosed R) x : x \is a int_num -> x \in S.
Proof. by move=> /intrP[n ->]; rewrite rpred_int. Qed.
Lemma rpred_nat_num (S : semiringClosed R) x : x \is a nat_num -> x \in S.
Proof. by move=> /natrP[n ->]; apply: rpred_nat. Qed.
Lemma int_num0 : 0 \is a int_num. Proof. exact: (intr_int 0). Qed.
Lemma int_num1 : 1 \is a int_num. Proof. exact: (intr_int 1). Qed.
Lemma nat_num0 : 0 \is a nat_num. Proof. exact: (natr_nat 0). Qed.
Lemma nat_num1 : 1 \is a nat_num. Proof. exact: (natr_nat 1). Qed.
#[local] Hint Resolve int_num0 int_num1 nat_num0 nat_num1 : core.
Fact int_num_subring : subring_closed int_num.
Proof.
by split=> // _ _ /intrP[n ->] /intrP[m ->]; rewrite -(intrB, intrM).
Qed.
#[export]
HB.instance Definition _ := GRing.isSubringClosed.Build R int_num_subdef
int_num_subring.
Fact nat_num_semiring : semiring_closed nat_num.
Proof.
by do 2![split] => //= _ _ /natrP[n ->] /natrP[m ->]; rewrite -(natrD, natrM).
Qed.
#[export]
HB.instance Definition _ := GRing.isSemiringClosed.Build R nat_num_subdef
nat_num_semiring.
Lemma Rreal_nat : {subset nat_num <= Rreal}. Proof. exact: rpred_nat_num. Qed.
Lemma intr_nat : {subset nat_num <= int_num}.
Proof. by move=> _ /natrP[n ->]; rewrite pmulrn intr_int. Qed.
Lemma Rreal_int : {subset int_num <= Rreal}. Proof. exact: rpred_int_num. Qed.
Lemma intrE x : (x \is a int_num) = (x \is a nat_num) || (- x \is a nat_num).
Proof.
apply/idP/orP => [/intrP[[n|n] ->]|[]/intr_nat]; rewrite ?rpredN //.
by left; apply/natrP; exists n.
by rewrite NegzE intrN opprK; right; apply/natrP; exists n.+1.
Qed.
Lemma intr_normK x : x \is a int_num -> `|x| ^+ 2 = x ^+ 2.
Proof. by move/Rreal_int/real_normK. Qed.
Lemma natr_normK x : x \is a nat_num -> `|x| ^+ 2 = x ^+ 2.
Proof. by move/Rreal_nat/real_normK. Qed.
Lemma natr_norm_int x : x \is a int_num -> `|x| \is a nat_num.
Proof. by move=> /intrP[m ->]; rewrite -intr_norm rpred_nat_num ?natr_nat. Qed.
Lemma natr_ge0 x : x \is a nat_num -> 0 <= x.
Proof. by move=> /natrP[n ->]; apply: ler0n. Qed.
Lemma natr_gt0 x : x \is a nat_num -> (0 < x) = (x != 0).
Proof. by move/natr_ge0; case: comparableP. Qed.
Lemma natrEint x : (x \is a nat_num) = (x \is a int_num) && (0 <= x).
Proof.
apply/idP/andP=> [Nx | [Zx x_ge0]]; first by rewrite intr_nat ?natr_ge0.
by rewrite -(ger0_norm x_ge0) natr_norm_int.
Qed.
Lemma intrEge0 x : 0 <= x -> (x \is a int_num) = (x \is a nat_num).
Proof. by rewrite natrEint andbC => ->. Qed.
Lemma intrEsign x : x \is a int_num -> x = (-1) ^+ (x < 0)%R * `|x|.
Proof. by move/Rreal_int/realEsign. Qed.
Lemma norm_natr x : x \is a nat_num -> `|x| = x.
Proof. by move/natr_ge0/ger0_norm. Qed.
Lemma natr_exp_even x n : ~~ odd n -> x \is a int_num -> x ^+ n \is a nat_num.
Proof.
move=> n_oddF x_intr.
by rewrite natrEint rpredX //= real_exprn_even_ge0 // Rreal_int.
Qed.
Lemma norm_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= `|x|.
Proof.
rewrite -normr_eq0 => /natr_norm_int/natrP[n ->].
by rewrite pnatr_eq0 ler1n lt0n.
Qed.
Lemma sqr_intr_ge1 x : x \is a int_num -> x != 0 -> 1 <= x ^+ 2.
Proof.
by move=> Zx nz_x; rewrite -intr_normK // expr_ge1 ?normr_ge0 ?norm_intr_ge1.
Qed.
Lemma intr_ler_sqr x : x \is a int_num -> x <= x ^+ 2.
Proof.
move=> Zx; have [-> | nz_x] := eqVneq x 0; first by rewrite expr0n.
apply: le_trans (_ : `|x| <= _); first by rewrite real_ler_norm ?Rreal_int.
by rewrite -intr_normK // ler_eXnr // norm_intr_ge1.
Qed.
(* floor and int_num *)
Lemma real_floor_itv x : x \is Rreal -> (floor x)%:~R <= x < (floor x + 1)%:~R.
Proof. by case: ifP (floorP x). Qed.
Lemma real_floor_le x : x \is Rreal -> (floor x)%:~R <= x.
Proof. by case/real_floor_itv/andP. Qed.
Lemma real_floorD1_gt x : x \is Rreal -> x < (floor x + 1)%:~R.
Proof. by case/real_floor_itv/andP. Qed.
Lemma floor_def x m : m%:~R <= x < (m + 1)%:~R -> floor x = m.
Proof.
case/andP=> lemx ltxm1; apply/eqP; rewrite eq_le -!ltzD1.
move: (ger_real lemx); rewrite realz => /real_floor_itv/andP[lefx ltxf1].
by rewrite -!(ltr_int R) 2?(@le_lt_trans _ _ x).
Qed.
(* TODO: rename to real_floor_ge_int,
once the currently deprecated one has been removed *)
Lemma real_floor_ge_int_tmp x n : x \is Rreal -> (n <= floor x) = (n%:~R <= x).
Proof.
move=> /real_floor_itv /andP[lefx ltxf1]; apply/idP/idP => lenx.
by apply: le_trans lefx; rewrite ler_int.
by rewrite -ltzD1 -(ltr_int R); apply: le_lt_trans ltxf1.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use real_floor_ge_int_tmp instead.")]
Lemma real_floor_ge_int x n : x \is Rreal -> (n%:~R <= x) = (n <= floor x).
Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed.
Lemma real_floor_lt_int x n : x \is Rreal -> (floor x < n) = (x < n%:~R).
Proof.
by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_floor_ge_int_tmp -?ltNge.
Qed.
Lemma real_floor_eq x n : x \is Rreal ->
(floor x == n) = (n%:~R <= x < (n + 1)%:~R).
Proof.
by move=> xr; apply/eqP/idP => [<-|]; [exact: real_floor_itv|exact: floor_def].
Qed.
Lemma le_floor : {homo floor : x y / x <= y}.
Proof.
move=> x y lexy; move: (floorP x) (floorP y); rewrite (ger_real lexy).
case: ifP => [_ /andP[lefx _] /andP[_] | _ /eqP-> /eqP-> //].
by move=> /(le_lt_trans lexy) /(le_lt_trans lefx); rewrite ltr_int ltzD1.
Qed.
Lemma intrKfloor : cancel intr floor.
Proof. by move=> m; apply: floor_def; rewrite lexx rmorphD ltrDl ltr01. Qed.
Lemma natr_int n : n%:R \is a int_num.
Proof. by rewrite intrE natr_nat. Qed.
#[local] Hint Resolve natr_int : core.
Lemma intrEfloor x : x \is a int_num = ((floor x)%:~R == x).
Proof.
by apply/intrP/eqP => [[n ->] | <-]; [rewrite intrKfloor | exists (floor x)].
Qed.
Lemma floorK : {in int_num, cancel floor intr}.
Proof. by move=> z; rewrite intrEfloor => /eqP. Qed.
Lemma floor0 : floor 0 = 0. Proof. exact: intrKfloor 0. Qed.
Lemma floor1 : floor 1 = 1. Proof. exact: intrKfloor 1. Qed.
#[local] Hint Resolve floor0 floor1 : core.
Lemma real_floorDzr : {in int_num & Rreal, {morph floor : x y / x + y}}.
Proof.
move=> _ y /intrP[m ->] Ry; apply: floor_def.
by rewrite -addrA 2!rmorphD /= intrKfloor lerD2l ltrD2l real_floor_itv.
Qed.
Lemma real_floorDrz : {in Rreal & int_num, {morph floor : x y / x + y}}.
Proof. by move=> x y xr yz; rewrite addrC real_floorDzr // addrC. Qed.
Lemma floorN : {in int_num, {morph floor : x / - x}}.
Proof. by move=> _ /intrP[m ->]; rewrite -rmorphN !intrKfloor. Qed.
Lemma floorM : {in int_num &, {morph floor : x y / x * y}}.
Proof.
by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKfloor.
Qed.
Lemma floorX n : {in int_num, {morph floor : x / x ^+ n}}.
Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKfloor. Qed.
Lemma real_floor_ge0 x : x \is Rreal -> (0 <= floor x) = (0 <= x).
Proof. by move=> ?; rewrite real_floor_ge_int_tmp. Qed.
Lemma floor_lt0 x : (floor x < 0) = (x < 0).
Proof.
case: ifP (floorP x) => [xr _ | xr /eqP <-]; first by rewrite real_floor_lt_int.
by rewrite ltxx; apply/esym/(contraFF _ xr)/ltr0_real.
Qed.
Lemma real_floor_le0 x : x \is Rreal -> (floor x <= 0) = (x < 1).
Proof. by move=> ?; rewrite -ltzD1 add0r real_floor_lt_int. Qed.
Lemma floor_gt0 x : (floor x > 0) = (x >= 1).
Proof.
case: ifP (floorP x) => [xr _ | xr /eqP->].
by rewrite gtz0_ge1 real_floor_ge_int_tmp.
by rewrite ltxx; apply/esym/(contraFF _ xr)/ger1_real.
Qed.
Lemma floor_neq0 x : (floor x != 0) = (x < 0) || (x >= 1).
Proof.
case: ifP (floorP x) => [xr _ | xr /eqP->]; rewrite ?eqxx/=.
by rewrite neq_lt floor_lt0 floor_gt0.
by apply/esym/(contraFF _ xr) => /orP[/ltr0_real|/ger1_real].
Qed.
Lemma floorpK : {in polyOver int_num, cancel (map_poly floor) (map_poly intr)}.
Proof.
move=> p /(all_nthP 0) Zp; apply/polyP=> i.
rewrite coef_map coef_map_id0 //= -[p]coefK coef_poly.
by case: ifP => [/Zp/floorK // | _]; rewrite floor0.
Qed.
Lemma floorpP (p : {poly R}) :
p \is a polyOver int_num -> {q | p = map_poly intr q}.
Proof. by exists (map_poly floor p); rewrite floorpK. Qed.
(* ceil and int_num *)
Lemma real_ceil_itv x : x \is Rreal -> (ceil x - 1)%:~R < x <= (ceil x)%:~R.
Proof.
rewrite ceilNfloor -opprD !intrN ltrNl lerNr andbC -realN.
exact: real_floor_itv.
Qed.
Lemma real_ceilB1_lt x : x \is Rreal -> (ceil x - 1)%:~R < x.
Proof. by case/real_ceil_itv/andP. Qed.
Lemma real_ceil_ge x : x \is Rreal -> x <= (ceil x)%:~R.
Proof. by case/real_ceil_itv/andP. Qed.
Lemma ceil_def x m : (m - 1)%:~R < x <= m%:~R -> ceil x = m.
Proof.
rewrite -ltrN2 -lerN2 andbC -!intrN opprD opprK ceilNfloor.
by move=> /floor_def ->; rewrite opprK.
Qed.
(* TODO: rename to real_ceil_le_int,
once the currently deprecated one has been removed *)
Lemma real_ceil_le_int_tmp x n : x \is Rreal -> (ceil x <= n) = (x <= n%:~R).
Proof.
rewrite ceilNfloor lerNl -realN => /real_floor_ge_int_tmp ->.
by rewrite intrN lerN2.
Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use real_ceil_le_int_tmp instead.")]
Lemma real_ceil_le_int x n : x \is Rreal -> x <= n%:~R = (ceil x <= n).
Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed.
Lemma real_ceil_gt_int x n : x \is Rreal -> (n < ceil x) = (n%:~R < x).
Proof.
by move=> ?; rewrite [RHS]real_ltNge ?realz -?real_ceil_le_int_tmp ?ltNge.
Qed.
Lemma real_ceil_eq x n : x \is Rreal ->
(ceil x == n) = ((n - 1)%:~R < x <= n%:~R).
Proof.
by move=> xr; apply/eqP/idP => [<-|]; [exact: real_ceil_itv|exact: ceil_def].
Qed.
(* TODO: rename to le_ceil,
once the currently deprecated one has been removed *)
Lemma le_ceil_tmp : {homo ceil : x y / x <= y}.
Proof. by move=> x y lexy; rewrite !ceilNfloor lerN2 le_floor ?lerN2. Qed.
Lemma intrKceil : cancel intr ceil.
Proof. by move=> m; rewrite ceilNfloor -intrN intrKfloor opprK. Qed.
Lemma intrEceil x : x \is a int_num = ((ceil x)%:~R == x).
Proof. by rewrite -rpredN intrEfloor -eqr_oppLR -intrN -ceilNfloor. Qed.
Lemma ceilK : {in int_num, cancel ceil intr}.
Proof. by move=> z; rewrite intrEceil => /eqP. Qed.
Lemma ceil0 : ceil 0 = 0. Proof. exact: intrKceil 0. Qed.
Lemma ceil1 : ceil 1 = 1. Proof. exact: intrKceil 1. Qed.
#[local] Hint Resolve ceil0 ceil1 : core.
Lemma real_ceilDzr : {in int_num & Rreal, {morph ceil : x y / x + y}}.
Proof.
move=> x y x_int y_real.
by rewrite ceilNfloor opprD real_floorDzr ?rpredN // opprD -!ceilNfloor.
Qed.
Lemma real_ceilDrz : {in Rreal & int_num, {morph ceil : x y / x + y}}.
Proof. by move=> x y xr yz; rewrite addrC real_ceilDzr // addrC. Qed.
Lemma ceilN : {in int_num, {morph ceil : x / - x}}.
Proof. by move=> ? ?; rewrite !ceilNfloor !opprK floorN. Qed.
Lemma ceilM : {in int_num &, {morph ceil : x y / x * y}}.
Proof.
by move=> _ _ /intrP[m1 ->] /intrP[m2 ->]; rewrite -rmorphM !intrKceil.
Qed.
Lemma ceilX n : {in int_num, {morph ceil : x / x ^+ n}}.
Proof. by move=> _ /intrP[m ->]; rewrite -rmorphXn !intrKceil. Qed.
Lemma real_ceil_ge0 x : x \is Rreal -> (0 <= ceil x) = (-1 < x).
Proof.
by move=> ?; rewrite ceilNfloor oppr_ge0 real_floor_le0 ?realN 1?ltrNl.
Qed.
Lemma ceil_lt0 x : (ceil x < 0) = (x <= -1).
Proof. by rewrite ceilNfloor oppr_lt0 floor_gt0 lerNr. Qed.
Lemma real_ceil_le0 x : x \is Rreal -> (ceil x <= 0) = (x <= 0).
Proof. by move=> ?; rewrite real_ceil_le_int_tmp. Qed.
Lemma ceil_gt0 x : (ceil x > 0) = (x > 0).
Proof. by rewrite ceilNfloor oppr_gt0 floor_lt0 oppr_lt0. Qed.
Lemma ceil_neq0 x : (ceil x != 0) = (x <= -1) || (x > 0).
Proof. by rewrite ceilNfloor oppr_eq0 floor_neq0 oppr_lt0 lerNr orbC. Qed.
Lemma real_ceil_floor x : x \is Rreal ->
ceil x = floor x + (x \isn't a int_num).
Proof.
case Ix: (x \is a int_num) => Rx /=.
by apply/eqP; rewrite addr0 ceilNfloor eqr_oppLR floorN.
apply/ceil_def; rewrite addrK; move: (real_floor_itv Rx).
by rewrite le_eqVlt -intrEfloor Ix /= => /andP[-> /ltW].
Qed.
(* Relating Cnat and oldCnat. *)
Lemma truncn_floor x : truncn x = if 0 <= x then `|floor x|%N else 0%N.
Proof.
move: (floorP x); rewrite truncEfloor realE.
have [/le_floor|_]/= := boolP (0 <= x); first by rewrite floor0; case: floor.
by case: ifP => [/le_floor|_ /eqP->//]; rewrite floor0; case: floor => [[]|].
Qed.
(* trunc and nat_num *)
Local Lemma truncnP x :
if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N.
Proof.
rewrite truncn_floor.
case: (boolP (0 <= x)) => //= /[dup] /le_floor + /ger0_real/real_floor_itv.
by rewrite floor0; case: (floor x) => // n _; rewrite absz_nat addrC -intS.
Qed.
Lemma truncn_itv x : 0 <= x -> (truncn x)%:R <= x < (truncn x).+1%:R.
Proof. by move=> x_ge0; move: (truncnP x); rewrite x_ge0. Qed.
Lemma truncn_le x : (truncn x)%:R <= x = (0 <= x).
Proof. by case: ifP (truncnP x) => [+ /andP[] | + /eqP->//]. Qed.
Lemma real_truncnS_gt x : x \is Rreal -> x < (truncn x).+1%:R.
Proof. by move/real_ge0P => [/truncn_itv/andP[]|/lt_le_trans->]. Qed.
Lemma truncn_def x n : n%:R <= x < n.+1%:R -> truncn x = n.
Proof.
case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS.
have/truncn_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n.
by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x).
Qed.
Lemma truncn_ge_nat x n : 0 <= x -> (n <= truncn x)%N = (n%:R <= x).
Proof.
move=> /truncn_itv /andP[letx ltxt1]; apply/idP/idP => lenx.
by apply: le_trans letx; rewrite ler_nat.
by rewrite -ltnS -(ltr_nat R); apply: le_lt_trans ltxt1.
Qed.
Lemma truncn_gt_nat x n : (n < truncn x)%N = (n.+1%:R <= x).
Proof.
case: ifP (truncnP x) => [x0 _ | x0 /eqP->]; first by rewrite truncn_ge_nat.
by rewrite ltn0; apply/esym/(contraFF _ x0)/le_trans.
Qed.
Lemma truncn_lt_nat x n : 0 <= x -> (truncn x < n)%N = (x < n%:R).
Proof. by move=> ?; rewrite real_ltNge ?ger0_real// ltnNge truncn_ge_nat. Qed.
Lemma real_truncn_le_nat x n : x \is Rreal -> (truncn x <= n)%N = (x < n.+1%:R).
Proof. by move=> ?; rewrite real_ltNge// leqNgt truncn_gt_nat. Qed.
Lemma truncn_eq x n : 0 <= x -> (truncn x == n) = (n%:R <= x < n.+1%:R).
Proof.
by move=> xr; apply/eqP/idP => [<-|]; [exact: truncn_itv|exact: truncn_def].
Qed.
Lemma le_truncn : {homo truncn : x y / x <= y >-> (x <= y)%N}.
Proof.
move=> x y lexy; move: (truncnP x) (truncnP y).
case: ifP => [x0 /andP[letx _] | x0 /eqP->//].
case: ifP => [y0 /andP[_] | y0 /eqP->]; [|by rewrite (le_trans x0 lexy) in y0].
by move=> /(le_lt_trans lexy) /(le_lt_trans letx); rewrite ltr_nat ltnS.
Qed.
Lemma natrK : cancel (GRing.natmul 1) truncn.
Proof. by move=> m; apply: truncn_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed.
Lemma natrEtruncn x : (x \is a nat_num) = ((truncn x)%:R == x).
Proof.
by apply/natrP/eqP => [[n ->]|<-]; [rewrite natrK | exists (truncn x)].
Qed.
Lemma archi_boundP x : 0 <= x -> x < (bound x)%:R.
Proof.
move=> x_ge0; case/truncn_itv/andP: (normr_ge0 x) => _.
exact/le_lt_trans/real_ler_norm/ger0_real.
Qed.
Lemma truncnK : {in nat_num, cancel truncn (GRing.natmul 1)}.
Proof. by move=> x; rewrite natrEtruncn => /eqP. Qed.
Lemma truncn0 : truncn 0 = 0%N. Proof. exact: natrK 0%N. Qed.
Lemma truncn1 : truncn 1 = 1%N. Proof. exact: natrK 1%N. Qed.
#[local] Hint Resolve truncn0 truncn1 : core.
Lemma truncnD :
{in nat_num & Rnneg, {morph truncn : x y / x + y >-> (x + y)%N}}.
Proof.
move=> _ y /natrP[n ->] y_ge0; apply: truncn_def.
by rewrite -addnS !natrD !natrK lerD2l ltrD2l truncn_itv.
Qed.
Lemma truncnM : {in nat_num &, {morph truncn : x y / x * y >-> (x * y)%N}}.
Proof. by move=> _ _ /natrP[n1 ->] /natrP[n2 ->]; rewrite -natrM !natrK. Qed.
Lemma truncnX n : {in nat_num, {morph truncn : x / x ^+ n >-> (x ^ n)%N}}.
Proof. by move=> _ /natrP[n1 ->]; rewrite -natrX !natrK. Qed.
Lemma truncn_gt0 x : (0 < truncn x)%N = (1 <= x).
Proof.
case: ifP (truncnP x) => [x0 | x0 /eqP<-]; first by rewrite truncn_ge_nat.
by rewrite ltnn; apply/esym/(contraFF _ x0)/le_trans.
Qed.
Lemma truncn0Pn x : reflect (truncn x = 0%N) (~~ (1 <= x)).
Proof. by rewrite -truncn_gt0 -eqn0Ngt; apply: eqP. Qed.
Lemma sum_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) ->
(\sum_(i <- r | P i) truncn (F i))%:R = \sum_(i <- r | P i) F i.
Proof. by rewrite natr_sum => natr; apply: eq_bigr => i /natr /truncnK. Qed.
Lemma prod_truncnK I r (P : pred I) F : (forall i, P i -> F i \is a nat_num) ->
(\prod_(i <- r | P i) truncn (F i))%:R = \prod_(i <- r | P i) F i.
Proof. by rewrite natr_prod => natr; apply: eq_bigr => i /natr /truncnK. Qed.
Lemma natr_sum_eq1 (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> F i \is a nat_num) -> \sum_(i | P i) F i = 1 ->
{i : I | [/\ P i, F i = 1 & forall j, j != i -> P j -> F j = 0]}.
Proof.
move=> natF /eqP; rewrite -sum_truncnK// -[1]/1%:R eqr_nat => /sum_nat_eq1 exi.
have [i /and3P[Pi /eqP f1 /forallP a]] : {i : I | [&& P i, truncn (F i) == 1
& [forall j : I, ((j != i) ==> P j ==> (truncn (F j) == 0))]]}.
apply/sigW; have [i [Pi /eqP f1 a]] := exi; exists i; apply/and3P; split=> //.
by apply/forallP => j; apply/implyP => ji; apply/implyP => Pj; apply/eqP/a.
exists i; split=> [//||j ji Pj]; rewrite -[LHS]truncnK ?natF ?f1//; apply/eqP.
by rewrite -[0]/0%:R eqr_nat; apply: implyP Pj; apply: implyP ji; apply: a.
Qed.
Lemma natr_mul_eq1 x y :
x \is a nat_num -> y \is a nat_num -> (x * y == 1) = (x == 1) && (y == 1).
Proof. by do 2!move/truncnK <-; rewrite -natrM !pnatr_eq1 muln_eq1. Qed.
Lemma natr_prod_eq1 (I : finType) (P : pred I) (F : I -> R) :
(forall i, P i -> F i \is a nat_num) -> \prod_(i | P i) F i = 1 ->
forall i, P i -> F i = 1.
Proof.
move=> natF /eqP; rewrite -prod_truncnK// -[1]/1%:R eqr_nat prod_nat_seq_eq1.
move/allP => a i Pi; apply/eqP; rewrite -[F i]truncnK ?natF// eqr_nat.
by apply: implyP Pi; apply: a; apply: mem_index_enum.
Qed.
(* predCmod *)
Variables (U V : lmodType R) (f : {additive U -> V}).
Lemma raddfZ_nat a u : a \is a nat_num -> f (a *: u) = a *: f u.
Proof. by move=> /natrP[n ->]; apply: raddfZnat. Qed.
Lemma rpredZ_nat (S : addrClosed V) :
{in nat_num & S, forall z u, z *: u \in S}.
Proof. by move=> _ u /natrP[n ->]; apply: rpredZnat. Qed.
Lemma raddfZ_int a u : a \is a int_num -> f (a *: u) = a *: f u.
Proof. by move=> /intrP[m ->]; rewrite !scaler_int raddfMz. Qed.
Lemma rpredZ_int (S : zmodClosed V) :
{in int_num & S, forall z u, z *: u \in S}.
Proof. by move=> _ u /intrP[m ->] ?; rewrite scaler_int rpredMz. Qed.
(* autC *)
Implicit Type nu : {rmorphism R -> R}.
Lemma aut_natr nu : {in nat_num, nu =1 id}.
Proof. by move=> _ /natrP[n ->]; apply: rmorph_nat. Qed.
Lemma aut_intr nu : {in int_num, nu =1 id}.
Proof. by move=> _ /intrP[m ->]; apply: rmorph_int. Qed.
End ArchiNumDomainTheory.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_itv.")]
Notation trunc_itv := truncn_itv.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_def.")]
Notation trunc_def := truncn_def.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnK.")]
Notation truncK := truncnK.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0.")]
Notation trunc0 := truncn0.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn1.")]
Notation trunc1 := truncn1.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnD.")]
Notation truncD := truncnD.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnM.")]
Notation truncM := truncnM.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncnX.")]
Notation truncX := truncnX.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_gt0.")]
Notation trunc_gt0 := truncn_gt0.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn0Pn.")]
Notation trunc0Pn := truncn0Pn.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to sum_truncnK.")]
Notation sum_truncK := sum_truncnK.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to prod_truncnK.")]
Notation prod_truncK := prod_truncnK.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to truncn_floor.")]
Notation trunc_floor := truncn_floor.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floor_le.")]
Notation real_ge_floor := real_floor_le.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to real_floorD1_gt.")]
Notation real_lt_succ_floor := real_floorD1_gt.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceilB1_lt.")]
Notation real_gt_pred_ceil := real_floorD1_gt.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to real_ceil_ge.")]
Notation real_le_ceil := real_ceil_ge.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to le_floor.")]
Notation floor_le := le_floor.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to le_ceil.")]
Notation ceil_le := le_ceil_tmp.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to natrEtruncn.")]
Notation natrE := natrEtruncn.
Arguments natrK {R} _%_N.
Arguments intrKfloor {R}.
Arguments intrKceil {R}.
Arguments natrP {R x}.
Arguments intrP {R x}.
#[global] Hint Resolve truncn0 truncn1 : core.
#[global] Hint Resolve floor0 floor1 : core.
#[global] Hint Resolve ceil0 ceil1 : core.
#[global] Hint Extern 0 (is_true (_%:R \is a nat_num)) => apply: natr_nat : core.
#[global] Hint Extern 0 (is_true (_%:R \in nat_num_subdef)) => apply: natr_nat : core.
#[global] Hint Extern 0 (is_true (_%:~R \is a int_num)) => apply: intr_int : core.
#[global] Hint Extern 0 (is_true (_%:~R \in int_num_subdef)) => apply: intr_int : core.
#[global] Hint Extern 0 (is_true (_%:R \is a int_num)) => apply: natr_int : core.
#[global] Hint Extern 0 (is_true (_%:R \in int_num_subdef)) => apply: natr_int : core.
#[global] Hint Extern 0 (is_true (0 \is a nat_num)) => apply: nat_num0 : core.
#[global] Hint Extern 0 (is_true (0 \in nat_num_subdef)) => apply: nat_num0 : core.
#[global] Hint Extern 0 (is_true (1 \is a nat_num)) => apply: nat_num1 : core.
#[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: nat_num1 : core.
#[global] Hint Extern 0 (is_true (0 \is a int_num)) => apply: int_num0 : core.
#[global] Hint Extern 0 (is_true (0 \in int_num_subdef)) => apply: int_num0 : core.
#[global] Hint Extern 0 (is_true (1 \is a int_num)) => apply: int_num1 : core.
#[global] Hint Extern 0 (is_true (1 \in int_num_subdef)) => apply: int_num1 : core.
Section ArchiRealDomainTheory.
Variables (R : archiRealDomainType).
Implicit Type x : R.
Lemma upper_nthrootP x i : (bound x <= i)%N -> x < 2%:R ^+ i.
Proof.
case/truncn_itv/andP: (normr_ge0 x) => _ /ltr_normlW xlt le_b_i.
by rewrite (lt_le_trans xlt) // -natrX ler_nat (ltn_trans le_b_i) // ltn_expl.
Qed.
Lemma truncnS_gt x : x < (truncn x).+1%:R.
Proof. exact: real_truncnS_gt. Qed.
Lemma truncn_le_nat x n : (truncn x <= n)%N = (x < n.+1%:R).
Proof. exact: real_truncn_le_nat. Qed.
Lemma floor_itv x : (floor x)%:~R <= x < (floor x + 1)%:~R.
Proof. exact: real_floor_itv. Qed.
(* TODO: rename to floor_le, once the deprecated one has been removed *)
Lemma floor_le_tmp x : (floor x)%:~R <= x. Proof. exact: real_floor_le. Qed.
Lemma floorD1_gt x : x < (floor x + 1)%:~R.
Proof. exact: real_floorD1_gt. Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use floor_ge_int_tmp instead.")]
Lemma floor_ge_int x n : n%:~R <= x = (n <= floor x).
Proof. by rewrite real_floor_ge_int_tmp. Qed.
(* TODO: rename to floor_ge_int,
once the currently deprecated one has been removed *)
Lemma floor_ge_int_tmp x n : (n <= floor x) = (n%:~R <= x).
Proof. exact: real_floor_ge_int_tmp. Qed.
Lemma floor_lt_int x n : (floor x < n) = (x < n%:~R).
Proof. exact: real_floor_lt_int. Qed.
Lemma floor_eq x n : (floor x == n) = (n%:~R <= x < (n + 1)%:~R).
Proof. exact: real_floor_eq. Qed.
Lemma floorDzr : {in @int_num R, {morph floor : x y / x + y}}.
Proof. by move=> x xz y; apply/real_floorDzr/num_real. Qed.
Lemma floorDrz x y : y \is a int_num -> floor (x + y) = floor x + floor y.
Proof. by move=> yz; apply/real_floorDrz/yz/num_real. Qed.
Lemma floor_ge0 x : (0 <= floor x) = (0 <= x).
Proof. exact: real_floor_ge0. Qed.
Lemma floor_le0 x : (floor x <= 0) = (x < 1).
Proof. exact: real_floor_le0. Qed.
Lemma ceil_itv x : (ceil x - 1)%:~R < x <= (ceil x)%:~R.
Proof. exact: real_ceil_itv. Qed.
Lemma ceilB1_lt x : (ceil x - 1)%:~R < x.
Proof. exact: real_ceilB1_lt. Qed.
Lemma ceil_ge x : x <= (ceil x)%:~R. Proof. exact: real_ceil_ge. Qed.
#[deprecated(since="mathcomp 2.4.0", note="Use ceil_le_int_tmp instead.")]
Lemma ceil_le_int x n : x <= n%:~R = (ceil x <= n).
Proof. by rewrite real_ceil_le_int_tmp. Qed.
(* TODO: rename to ceil_le_int,
once the currently deprecated one has been removed *)
Lemma ceil_le_int_tmp x n : (ceil x <= n) = (x <= n%:~R).
Proof. exact: real_ceil_le_int_tmp. Qed.
Lemma ceil_gt_int x n : (n < ceil x) = (n%:~R < x).
Proof. exact: real_ceil_gt_int. Qed.
Lemma ceil_eq x n : (ceil x == n) = ((n - 1)%:~R < x <= n%:~R).
Proof. exact: real_ceil_eq. Qed.
Lemma ceilDzr : {in @int_num R, {morph ceil : x y / x + y}}.
Proof. by move=> x xz y; apply/real_ceilDzr/num_real. Qed.
Lemma ceilDrz x y : y \is a int_num -> ceil (x + y) = ceil x + ceil y.
Proof. by move=> yz; apply/real_ceilDrz/yz/num_real. Qed.
Lemma ceil_ge0 x : (0 <= ceil x) = (-1 < x).
Proof. exact: real_ceil_ge0. Qed.
Lemma ceil_le0 x : (ceil x <= 0) = (x <= 0).
Proof. exact: real_ceil_le0. Qed.
Lemma ceil_floor x : ceil x = floor x + (x \isn't a int_num).
Proof. exact: real_ceil_floor. Qed.
End ArchiRealDomainTheory.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to floor_le_tmp.")]
Notation ge_floor := floor_le_tmp.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to floorD1_gt.")]
Notation lt_succ_floor := floorD1_gt.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to ceilB1_lt.")]
Notation gt_pred_ceil := ceilB1_lt.
#[deprecated(since="mathcomp 2.4.0", note="Renamed to ceil_ge.")]
Notation le_ceil := ceil_ge.
Section ArchiNumFieldTheory.
(* autLmodC *)
Variables (R : archiNumFieldType) (nu : {rmorphism R -> R}).
Lemma natr_aut x : (nu x \is a nat_num) = (x \is a nat_num).
Proof. by apply/idP/idP=> /[dup] ? /(aut_natr nu) => [/fmorph_inj <-| ->]. Qed.
Lemma intr_aut x : (nu x \is a int_num) = (x \is a int_num).
Proof. by rewrite !intrE -rmorphN !natr_aut. Qed.
End ArchiNumFieldTheory.
Section ArchiClosedFieldTheory.
Variable R : archiClosedFieldType.
Implicit Type x : R.
Lemma conj_natr x : x \is a nat_num -> x^* = x.
Proof. by move/Rreal_nat/CrealP. Qed.
Lemma conj_intr x : x \is a int_num -> x^* = x.
Proof. by move/Rreal_int/CrealP. Qed.
End ArchiClosedFieldTheory.
Section ZnatPred.
Lemma Znat_def (n : int) : (n \is a nat_num) = (0 <= n).
Proof. by []. Qed.
Lemma ZnatP (m : int) : reflect (exists n : nat, m = n) (m \is a nat_num).
Proof. by case: m => m; constructor; [exists m | case]. Qed.
End ZnatPred.
End Theory.
(* Factories *)
HB.factory Record NumDomain_hasTruncn R of Num.NumDomain R := {
trunc : R -> nat;
nat_num : pred R;
int_num : pred R;
truncP : forall x,
if 0 <= x then (trunc x)%:R <= x < (trunc x).+1%:R else trunc x == 0;
natrE : forall x, nat_num x = ((trunc x)%:R == x);
intrE : forall x, int_num x = nat_num x || nat_num (- x);
}.
#[deprecated(since="mathcomp 2.4.0",
note="Use NumDomain_hasTruncn instead.")]
Notation NumDomain_isArchimedean R := (NumDomain_hasTruncn R) (only parsing).
Module NumDomain_isArchimedean.
#[deprecated(since="mathcomp 2.4.0",
note="Use NumDomain_hasTruncn.Build instead.")]
Notation Build T U := (NumDomain_hasTruncn.Build T U) (only parsing).
End NumDomain_isArchimedean.
HB.builders Context R of NumDomain_hasTruncn R.
Fact trunc_itv x : 0 <= x -> (trunc x)%:R <= x < (trunc x).+1%:R.
Proof. by move=> x_ge0; move: (truncP x); rewrite x_ge0. Qed.
Definition floor (x : R) : int :=
if 0 <= x then Posz (trunc x)
else if x < 0 then - Posz (trunc (- x) + ~~ int_num x) else 0.
Fact floorP x :
if x \is Rreal then (floor x)%:~R <= x < (floor x + 1)%:~R else floor x == 0.
Proof.
rewrite /floor intrE !natrE negb_or realE.
case: (comparableP x 0) (@trunc_itv x) => //=;
try by rewrite -PoszD addn1 -pmulrn => _ ->.
move=> x_lt0 _; move: (truncP x); rewrite lt_geF // => /eqP ->.
rewrite gt_eqF //=; move: x_lt0.
rewrite [_ + 1]addrC -opprB !intrN lerNl ltrNr andbC -oppr_gt0.
move: {x}(- x) => x x_gt0; rewrite PoszD -addrA -PoszD.
have ->: Posz ((trunc x)%:R != x) - 1 = - Posz ((trunc x)%:R == x) by case: eqP.
have := trunc_itv (ltW x_gt0); rewrite le_eqVlt.
case: eqVneq => /=; last first.
by rewrite subr0 addn1 -!pmulrn => _ /andP[-> /ltW ->].
by rewrite intrB mulr1z addn0 -!pmulrn => -> _; rewrite gtrBl lexx andbT.
Qed.
Fact truncE x : trunc x = if floor x is Posz n then n else 0.
Proof.
rewrite /floor.
case: (comparableP x 0) (truncP x) => [+ /eqP ->| |_ /eqP ->|] //=.
by case: (_ + _)%N.
Qed.
Fact trunc_def x n : n%:R <= x < n.+1%:R -> trunc x = n.
Proof.
case/andP=> lemx ltxm1; apply/eqP; rewrite eqn_leq -ltnS -[(n <= _)%N]ltnS.
have/trunc_itv/andP[lefx ltxf1]: 0 <= x by apply: le_trans lemx; apply: ler0n.
by rewrite -!(ltr_nat R) 2?(@le_lt_trans _ _ x).
Qed.
Fact natrK : cancel (GRing.natmul 1) trunc.
Proof. by move=> m; apply: trunc_def; rewrite ler_nat ltr_nat ltnS leqnn. Qed.
Fact intrP x : reflect (exists n, x = n%:~R) (int_num x).
Proof.
rewrite intrE !natrE; apply: (iffP idP) => [|[n ->]]; last first.
by case: n => n; rewrite ?NegzE ?opprK natrK eqxx // orbT.
rewrite -eqr_oppLR !pmulrn -intrN.
by move=> /orP[] /eqP<-; [exists (trunc x) | exists (- Posz (trunc (- x)))].
Qed.
Fact natrP x : reflect (exists n, x = n%:R) (nat_num x).
Proof.
rewrite natrE.
by apply: (iffP eqP) => [<-|[n ->]]; [exists (trunc x) | rewrite natrK].
Qed.
HB.instance Definition _ :=
@NumDomain_hasFloorCeilTruncn.Build R floor _ trunc int_num nat_num
floorP (fun=> erefl) truncE intrP natrP.
HB.end.
HB.factory Record NumDomain_bounded_isArchimedean R of Num.NumDomain R := {
archi_bound_subproof : Num.archimedean_axiom R
}.
HB.builders Context R of NumDomain_bounded_isArchimedean R.
Implicit Type x : R.
Definition bound x := sval (sigW (archi_bound_subproof x)).
Lemma boundP x : 0 <= x -> x < (bound x)%:R.
Proof. by move/ger0_norm=> {1}<-; rewrite /bound; case: (sigW _). Qed.
Fact truncn_subproof x : {m | 0 <= x -> m%:R <= x < m.+1%:R }.
Proof.
have [Rx | _] := boolP (0 <= x); last by exists 0%N.
have/ex_minnP[n lt_x_n1 min_n]: exists n, x < n.+1%:R.
by exists (bound x); rewrite (lt_trans (boundP Rx)) ?ltr_nat.
exists n => _; rewrite {}lt_x_n1 andbT; case: n min_n => //= n min_n.
rewrite real_leNgt ?rpred_nat ?ger0_real //; apply/negP => /min_n.
by rewrite ltnn.
Qed.
Definition truncn x := if 0 <= x then sval (truncn_subproof x) else 0%N.
Lemma truncnP x :
if 0 <= x then (truncn x)%:R <= x < (truncn x).+1%:R else truncn x == 0%N.
Proof.
rewrite /truncn; case: truncn_subproof => // n hn.
by case: ifP => x_ge0; rewrite ?(ifT _ _ x_ge0) ?(ifF _ _ x_ge0) // hn.
Qed.
HB.instance Definition _ := NumDomain_hasTruncn.Build R
truncnP (fun => erefl) (fun => erefl).
HB.end.
Module Exports. HB.reexport. End Exports.
(* Not to pollute the local namespace, we define Num.nat and Num.int here. *)
Notation nat := nat_num.
Notation int := int_num.
#[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealDomain instead.")]
Notation ArchiDomain T := (ArchiRealDomain T).
Module ArchiDomain.
#[deprecated(since="mathcomp 2.3.0",
note="Use Num.ArchiRealDomain.type instead.")]
Notation type := ArchiRealDomain.type.
#[deprecated(since="mathcomp 2.3.0",
note="Use Num.ArchiRealDomain.copy instead.")]
Notation copy T C := (ArchiRealDomain.copy T C).
#[deprecated(since="mathcomp 2.3.0",
note="Use Num.ArchiRealDomain.on instead.")]
Notation on T := (ArchiRealDomain.on T).
End ArchiDomain.
#[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField instead.")]
Notation ArchiField T := (ArchiRealField T).
Module ArchiField.
#[deprecated(since="mathcomp 2.3.0",
note="Use Num.ArchiRealField.type instead.")]
Notation type := ArchiRealField.type.
#[deprecated(since="mathcomp 2.3.0",
note="Use Num.ArchiRealField.copy instead.")]
Notation copy T C := (ArchiRealField.copy T C).
#[deprecated(since="mathcomp 2.3.0", note="Use Num.ArchiRealField.on instead.")]
Notation on T := (ArchiRealField.on T).
End ArchiField.
#[deprecated(since="mathcomp 2.3.0", note="Use real_floorDzr instead.")]
Notation floorD := real_floorDzr.
#[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")]
Notation ceilD := real_ceilDzr.
#[deprecated(since="mathcomp 2.3.0", note="Use real_ceilDzr instead.")]
Notation real_ceilD := real_ceilDzr.
End Num.
Export Num.Exports.
#[deprecated(since="mathcomp 2.3.0", note="Use archiRealDomainType instead.")]
Notation archiDomainType := archiRealDomainType (only parsing).
#[deprecated(since="mathcomp 2.3.0", note="Use archiRealFieldType instead.")]
Notation archiFieldType := archiRealFieldType (only parsing).
|
poly.v
|
(* (c) Copyright 2006-2016 Microsoft Corporation and Inria. *)
(* Distributed under the terms of CeCILL-B. *)
From HB Require Import structures.
From mathcomp Require Import ssreflect ssrbool ssrfun eqtype ssrnat seq choice.
From mathcomp Require Import fintype bigop finset tuple div ssralg.
From mathcomp Require Import countalg binomial.
(******************************************************************************)
(* This file provides a library for univariate polynomials over ring *)
(* structures; it also provides an extended theory for polynomials whose *)
(* coefficients range over commutative rings and integral domains. *)
(* *)
(* {poly R} == the type of polynomials with coefficients of type R, *)
(* represented as lists with a non zero last element *)
(* (big endian representation); the coefficient type R *)
(* must have a canonical nzRingType structure cR. In *)
(* fact {poly R} denotes the concrete type polynomial *)
(* cR; R is just a phantom argument that lets type *)
(* inferencereconstruct the (hidden) nzRingType *)
(* structure cR. *)
(* p : seq R == the big-endian sequence of coefficients of p, via *)
(* the coercion polyseq : polynomial >-> seq. *)
(* Poly s == the polynomial with coefficient sequence s (ignoring *)
(* trailing zeroes). *)
(* \poly_(i < n) E(i) == the polynomial of degree at most n - 1 whose *)
(* coefficients are given by the general term E(i) *)
(* 0, 1, - p, p + q, == the usual ring operations: {poly R} has a canonical *)
(* p * q, p ^+ n, ... nzRingType structure, which is commutative / integral*)
(* when R is commutative / integral, respectively. *)
(* polyC c, c%:P == the constant polynomial c *)
(* 'X == the (unique) variable *)
(* 'X^n == a power of 'X; 'X^0 is 1, 'X^1 is convertible to 'X *)
(* p`_i == the coefficient of 'X^i in p; this is in fact just *)
(* the ring_scope notation generic seq-indexing using *)
(* nth 0%R, combined with the polyseq coercion. *)
(* *** The multi-rule coefE simplifies p`_i *)
(* coefp i == the linear function p |-> p`_i (self-exapanding). *)
(* size p == 1 + the degree of p, or 0 if p = 0 (this is the *)
(* generic seq function combined with polyseq). *)
(* lead_coef p == the coefficient of the highest monomial in p, or 0 *)
(* if p = 0 (hence lead_coef p = 0 iff p = 0) *)
(* p \is monic <=> lead_coef p == 1 (0 is not monic). *)
(* p \is a polyOver S <=> the coefficients of p satisfy S; S should have a *)
(* key that should be (at least) an addrPred. *)
(* p.[x] == the evaluation of a polynomial p at a point x using *)
(* the Horner scheme *)
(* *** The multi-rule hornerE (resp., hornerE_comm) unwinds *)
(* horner evaluation of a polynomial expression (resp., *)
(* in a non commutative ring, with side conditions). *)
(* p^`() == formal derivative of p *)
(* p^`(n) == formal n-derivative of p *)
(* p^`N(n) == formal n-derivative of p divided by n! *)
(* p \Po q == polynomial composition; because this is naturally a *)
(* a linear morphism in the first argument, this *)
(* notation is transposed (q comes before p for redex *)
(* selection, etc). *)
(* := \sum(i < size p) p`_i *: q ^+ i *)
(* odd_poly p == monomials of odd degree of p *)
(* even_poly p == monomials of even degree of p *)
(* take_poly n p == polynomial p without its monomials of degree >= n *)
(* drop_poly n p == polynomial p divided by X^n *)
(* comm_poly p x == x and p.[x] commute; this is a sufficient condition *)
(* for evaluating (q * p).[x] as q.[x] * p.[x] when R *)
(* is not commutative. *)
(* comm_coef p x == x commutes with all the coefficients of p (clearly, *)
(* this implies comm_poly p x). *)
(* root p x == x is a root of p, i.e., p.[x] = 0 *)
(* n.-unity_root x == x is an nth root of unity, i.e., a root of 'X^n - 1 *)
(* n.-primitive_root x == x is a primitive nth root of unity, i.e., n is the *)
(* least positive integer m > 0 such that x ^+ m = 1. *)
(* *** The submodule poly.UnityRootTheory can be used to *)
(* import selectively the part of the theory of roots *)
(* of unity that doesn't mention polynomials explicitly *)
(* map_poly f p == the image of the polynomial by the function f (which *)
(* (locally, p^f) is usually a ring morphism). *)
(* p^:P == p lifted to {poly {poly R}} (:= map_poly polyC p). *)
(* commr_rmorph f u == u commutes with the image of f (i.e., with all f x). *)
(* horner_morph cfu == given cfu : commr_rmorph f u, the function mapping p *)
(* to the value of map_poly f p at u; this is a ring *)
(* morphism from {poly R} to the codomain of f when f *)
(* is a ring morphism. *)
(* horner_eval u == the function mapping p to p.[u]; this function can *)
(* only be used for u in a commutative ring, so it is *)
(* always a linear ring morphism from {poly R} to R. *)
(* horner_alg a == given a in some R-algebra A, the function evaluating *)
(* a polynomial p at a; it is always a linear ring *)
(* morphism from {poly R} to A. *)
(* diff_roots x y == x and y are distinct roots; if R is a field, this *)
(* just means x != y, but this concept is generalized *)
(* to the case where R is only a ring with units (i.e., *)
(* a unitRingType); in which case it means that x and y *)
(* commute, and that the difference x - y is a unit *)
(* (i.e., has a multiplicative inverse) in R. *)
(* to just x != y). *)
(* uniq_roots s == s is a sequence or pairwise distinct roots, in the *)
(* sense of diff_roots p above. *)
(* *** We only show that these operations and properties are transferred by *)
(* morphisms whose domain is a field (thus ensuring injectivity). *)
(* We prove the factor_theorem, and the max_poly_roots inequality relating *)
(* the number of distinct roots of a polynomial and its size. *)
(* The some polynomial lemmas use following suffix interpretation : *)
(* C - constant polynomial (as in polyseqC : a%:P = nseq (a != 0) a). *)
(* X - the polynomial variable 'X (as in coefX : 'X`_i = (i == 1%N)). *)
(* Xn - power of 'X (as in monicXn : monic 'X^n). *)
(* *)
(* Pdeg2.Field (exported by the present library) : theory of the degree 2 *)
(* polynomials. *)
(* Pdeg2.FieldMonic : theory of Pdeg2.Field specialized to monic polynomials. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope unity_root_scope.
Import GRing.Theory.
Local Open Scope ring_scope.
Reserved Notation "{ 'poly' T }" (format "{ 'poly' T }").
Reserved Notation "c %:P" (format "c %:P").
Reserved Notation "p ^:P" (format "p ^:P").
Reserved Notation "'X".
Reserved Notation "''X^' n" (at level 1, format "''X^' n").
Reserved Notation "\poly_ ( i < n ) E"
(at level 34, E at level 36, i, n at level 50,
format "\poly_ ( i < n ) E").
Reserved Notation "p \Po q" (at level 50).
Reserved Notation "p ^`N ( n )" (format "p ^`N ( n )").
Reserved Notation "n .-unity_root" (format "n .-unity_root").
Reserved Notation "n .-primitive_root" (format "n .-primitive_root").
Local Notation simp := Monoid.simpm.
Section Polynomial.
Variable R : nzSemiRingType.
(* Defines a polynomial as a sequence with <> 0 last element *)
Record polynomial := Polynomial {polyseq :> seq R; _ : last 1 polyseq != 0}.
HB.instance Definition _ := [isSub for polyseq].
HB.instance Definition _ := [Choice of polynomial by <:].
Lemma poly_inj : injective polyseq. Proof. exact: val_inj. Qed.
Definition coefp i (p : polynomial) := p`_i.
End Polynomial.
(* We need to break off the section here to let the Bind Scope directives *)
(* take effect. *)
Bind Scope ring_scope with polynomial.
Arguments polynomial R%_type.
Arguments polyseq {R} p%_R.
Arguments poly_inj {R} [p1%_R p2%_R] : rename.
Arguments coefp {R} i%_N / p%_R.
Notation "{ 'poly' T }" := (polynomial T) : type_scope.
Section SemiPolynomialTheory.
Variable R : nzSemiRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Definition lead_coef p := p`_(size p).-1.
Lemma lead_coefE p : lead_coef p = p`_(size p).-1. Proof. by []. Qed.
Definition poly_nil := @Polynomial R [::] (oner_neq0 R).
Definition polyC c : {poly R} := insubd poly_nil [:: c].
Local Notation "c %:P" := (polyC c).
(* Remember the boolean (c != 0) is coerced to 1 if true and 0 if false *)
Lemma polyseqC c : c%:P = nseq (c != 0) c :> seq R.
Proof. by rewrite val_insubd /=; case: (c == 0). Qed.
Lemma size_polyC c : size c%:P = (c != 0).
Proof. by rewrite polyseqC size_nseq. Qed.
Lemma coefC c i : c%:P`_i = if i == 0 then c else 0.
Proof. by rewrite polyseqC; case: i => [|[]]; case: eqP. Qed.
Lemma polyCK : cancel polyC (coefp 0).
Proof. by move=> c; rewrite [coefp 0 _]coefC. Qed.
Lemma polyC_inj : injective polyC.
Proof. by move=> c1 c2 eqc12; have:= coefC c2 0; rewrite -eqc12 coefC. Qed.
Lemma lead_coefC c : lead_coef c%:P = c.
Proof. by rewrite /lead_coef polyseqC; case: eqP. Qed.
(* Extensional interpretation (poly <=> nat -> R) *)
Lemma polyP p q : nth 0 p =1 nth 0 q <-> p = q.
Proof.
split=> [eq_pq | -> //]; apply: poly_inj.
without loss lt_pq: p q eq_pq / size p < size q.
move=> IH; case: (ltngtP (size p) (size q)); try by move/IH->.
by move/(@eq_from_nth _ 0); apply.
case: q => q nz_q /= in lt_pq eq_pq *; case/eqP: nz_q.
by rewrite (last_nth 0) -(subnKC lt_pq) /= -eq_pq nth_default ?leq_addr.
Qed.
Lemma size1_polyC p : size p <= 1 -> p = (p`_0)%:P.
Proof.
move=> le_p_1; apply/polyP=> i; rewrite coefC.
by case: i => // i; rewrite nth_default // (leq_trans le_p_1).
Qed.
(* Builds a polynomial by extension. *)
Definition cons_poly c p : {poly R} :=
if p is Polynomial ((_ :: _) as s) ns then
@Polynomial R (c :: s) ns
else c%:P.
Lemma polyseq_cons c p :
cons_poly c p = (if ~~ nilp p then c :: p else c%:P) :> seq R.
Proof. by case: p => [[]]. Qed.
Lemma size_cons_poly c p :
size (cons_poly c p) = (if nilp p && (c == 0) then 0 else (size p).+1).
Proof. by case: p => [[|c' s] _] //=; rewrite size_polyC; case: eqP. Qed.
Lemma coef_cons c p i : (cons_poly c p)`_i = if i == 0 then c else p`_i.-1.
Proof.
by case: p i => [[|c' s] _] [] //=; rewrite polyseqC; case: eqP => //= _ [].
Qed.
(* Build a polynomial directly from a list of coefficients. *)
Definition Poly := foldr cons_poly 0%:P.
Lemma PolyK c s : last c s != 0 -> Poly s = s :> seq R.
Proof.
case: s => {c}/= [_ |c s]; first by rewrite polyseqC eqxx.
elim: s c => /= [|a s IHs] c nz_c; rewrite polyseq_cons ?{}IHs //.
by rewrite !polyseqC !eqxx nz_c.
Qed.
Lemma polyseqK p : Poly p = p.
Proof. by apply: poly_inj; apply: PolyK (valP p). Qed.
Lemma size_Poly s : size (Poly s) <= size s.
Proof.
elim: s => [|c s IHs] /=; first by rewrite polyseqC eqxx.
by rewrite polyseq_cons; case: ifP => // _; rewrite size_polyC; case: (~~ _).
Qed.
Lemma coef_Poly s i : (Poly s)`_i = s`_i.
Proof.
by elim: s i => [|c s IHs] /= [|i]; rewrite !(coefC, eqxx, coef_cons) /=.
Qed.
(* Build a polynomial from an infinite sequence of coefficients and a bound. *)
Definition poly_expanded_def n E := Poly (mkseq E n).
Fact poly_key : unit. Proof. by []. Qed.
Definition poly := locked_with poly_key poly_expanded_def.
Canonical poly_unlockable := [unlockable fun poly].
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
Lemma polyseq_poly n E :
E n.-1 != 0 -> \poly_(i < n) E i = mkseq [eta E] n :> seq R.
Proof.
rewrite unlock; case: n => [|n] nzEn; first by rewrite polyseqC eqxx.
by rewrite (@PolyK 0) // -nth_last nth_mkseq size_mkseq.
Qed.
Lemma size_poly n E : size (\poly_(i < n) E i) <= n.
Proof. by rewrite unlock (leq_trans (size_Poly _)) ?size_mkseq. Qed.
Lemma size_poly_eq n E : E n.-1 != 0 -> size (\poly_(i < n) E i) = n.
Proof. by move/polyseq_poly->; apply: size_mkseq. Qed.
Lemma coef_poly n E k : (\poly_(i < n) E i)`_k = (if k < n then E k else 0).
Proof.
rewrite unlock coef_Poly.
have [lt_kn | le_nk] := ltnP k n; first by rewrite nth_mkseq.
by rewrite nth_default // size_mkseq.
Qed.
Lemma lead_coef_poly n E :
n > 0 -> E n.-1 != 0 -> lead_coef (\poly_(i < n) E i) = E n.-1.
Proof.
by case: n => // n _ nzE; rewrite /lead_coef size_poly_eq // coef_poly leqnn.
Qed.
Lemma coefK p : \poly_(i < size p) p`_i = p.
Proof.
by apply/polyP=> i; rewrite coef_poly; case: ltnP => // /(nth_default 0)->.
Qed.
(* Nmodule structure for polynomial *)
Definition add_poly_def p q := \poly_(i < maxn (size p) (size q)) (p`_i + q`_i).
Fact add_poly_key : unit. Proof. by []. Qed.
Definition add_poly := locked_with add_poly_key add_poly_def.
Canonical add_poly_unlockable := [unlockable fun add_poly].
Fact coef_add_poly p q i : (add_poly p q)`_i = p`_i + q`_i.
Proof.
rewrite unlock coef_poly; case: leqP => //.
by rewrite geq_max => /andP[le_p_i le_q_i]; rewrite !nth_default ?add0r.
Qed.
Fact add_polyA : associative add_poly.
Proof. by move=> p q r; apply/polyP=> i; rewrite !coef_add_poly addrA. Qed.
Fact add_polyC : commutative add_poly.
Proof. by move=> p q; apply/polyP=> i; rewrite !coef_add_poly addrC. Qed.
Fact add_poly0 : left_id 0%:P add_poly.
Proof.
by move=> p; apply/polyP=> i; rewrite coef_add_poly coefC if_same add0r.
Qed.
HB.instance Definition _ := GRing.isNmodule.Build (polynomial R)
add_polyA add_polyC add_poly0.
(* Properties of the zero polynomial *)
Lemma polyC0 : 0%:P = 0 :> {poly R}. Proof. by []. Qed.
Lemma polyseq0 : (0 : {poly R}) = [::] :> seq R.
Proof. by rewrite polyseqC eqxx. Qed.
Lemma size_poly0 : size (0 : {poly R}) = 0%N.
Proof. by rewrite polyseq0. Qed.
Lemma coef0 i : (0 : {poly R})`_i = 0.
Proof. by rewrite coefC if_same. Qed.
Lemma lead_coef0 : lead_coef 0 = 0 :> R. Proof. exact: lead_coefC. Qed.
Lemma size_poly_eq0 p : (size p == 0) = (p == 0).
Proof. by rewrite size_eq0 -polyseq0. Qed.
Lemma size_poly_leq0 p : (size p <= 0) = (p == 0).
Proof. by rewrite leqn0 size_poly_eq0. Qed.
Lemma size_poly_leq0P p : reflect (p = 0) (size p <= 0).
Proof. by apply: (iffP idP); rewrite size_poly_leq0; move/eqP. Qed.
Lemma size_poly_gt0 p : (0 < size p) = (p != 0).
Proof. by rewrite lt0n size_poly_eq0. Qed.
Lemma gt_size_poly_neq0 p n : (size p > n)%N -> p != 0.
Proof. by move=> /(leq_ltn_trans _) h; rewrite -size_poly_eq0 lt0n_neq0 ?h. Qed.
Lemma nil_poly p : nilp p = (p == 0).
Proof. exact: size_poly_eq0. Qed.
Lemma poly0Vpos p : {p = 0} + {size p > 0}.
Proof. by rewrite lt0n size_poly_eq0; case: eqVneq; [left | right]. Qed.
Lemma polySpred p : p != 0 -> size p = (size p).-1.+1.
Proof. by rewrite -size_poly_eq0 -lt0n => /prednK. Qed.
Lemma lead_coef_eq0 p : (lead_coef p == 0) = (p == 0).
Proof.
rewrite -nil_poly /lead_coef nth_last.
by case: p => [[|x s] /= /negbTE // _]; rewrite eqxx.
Qed.
Lemma polyC_eq0 (c : R) : (c%:P == 0) = (c == 0).
Proof. by rewrite -nil_poly polyseqC; case: (c == 0). Qed.
Lemma size_poly1P p : reflect (exists2 c, c != 0 & p = c%:P) (size p == 1).
Proof.
apply: (iffP eqP) => [pC | [c nz_c ->]]; last by rewrite size_polyC nz_c.
have def_p: p = (p`_0)%:P by rewrite -size1_polyC ?pC.
by exists p`_0; rewrite // -polyC_eq0 -def_p -size_poly_eq0 pC.
Qed.
Lemma size_polyC_leq1 (c : R) : (size c%:P <= 1)%N.
Proof. by rewrite size_polyC; case: (c == 0). Qed.
Lemma leq_sizeP p i : reflect (forall j, i <= j -> p`_j = 0) (size p <= i).
Proof.
apply: (iffP idP) => [hp j hij| hp].
by apply: nth_default; apply: leq_trans hij.
case: (eqVneq p) (lead_coef_eq0 p) => [->|p0]; first by rewrite size_poly0.
rewrite leqNgt; apply/contraFN => hs.
by apply/eqP/hp; rewrite -ltnS (ltn_predK hs).
Qed.
(* Size, leading coef, morphism properties of coef *)
Lemma coefD p q i : (p + q)`_i = p`_i + q`_i.
Proof. exact: coef_add_poly. Qed.
Lemma polyCD : {morph polyC : a b / a + b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefD !coefC ?addr0. Qed.
Lemma size_polyD p q : size (p + q) <= maxn (size p) (size q).
Proof. by rewrite -[+%R]/add_poly unlock; exact: size_poly. Qed.
Lemma size_polyDl p q : size p > size q -> size (p + q) = size p.
Proof.
move=> ltqp; rewrite -[+%R]/add_poly unlock size_poly_eq (maxn_idPl (ltnW _))//.
by rewrite addrC nth_default ?simp ?nth_last //; case: p ltqp => [[]].
Qed.
Lemma size_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) :
size (\sum_(i <- r | P i) F i) <= \max_(i <- r | P i) size (F i).
Proof.
elim/big_rec2: _ => [|i p q _ IHp]; first by rewrite size_poly0.
by rewrite -(maxn_idPr IHp) maxnA leq_max size_polyD.
Qed.
Lemma lead_coefDl p q : size p > size q -> lead_coef (p + q) = lead_coef p.
Proof.
move=> ltqp; rewrite /lead_coef coefD size_polyDl //.
by rewrite addrC nth_default ?simp // -ltnS (ltn_predK ltqp).
Qed.
Lemma lead_coefDr p q : size q > size p -> lead_coef (p + q) = lead_coef q.
Proof. by move/lead_coefDl<-; rewrite addrC. Qed.
(* Polynomial semiring structure. *)
Definition mul_poly_def p q :=
\poly_(i < (size p + size q).-1) (\sum_(j < i.+1) p`_j * q`_(i - j)).
Fact mul_poly_key : unit. Proof. by []. Qed.
Definition mul_poly := locked_with mul_poly_key mul_poly_def.
Canonical mul_poly_unlockable := [unlockable fun mul_poly].
Fact coef_mul_poly p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof.
rewrite unlock coef_poly -subn1 ltn_subRL add1n; case: leqP => // le_pq_i1.
rewrite big1 // => j _; have [lq_q_ij | gt_q_ij] := leqP (size q) (i - j).
by rewrite [q`__]nth_default ?mulr0.
rewrite nth_default ?mul0r // -(leq_add2r (size q)) (leq_trans le_pq_i1) //.
by rewrite -leq_subLR -subnSK.
Qed.
Fact coef_mul_poly_rev p q i :
(mul_poly p q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof.
rewrite coef_mul_poly (reindex_inj rev_ord_inj) /=.
by apply: eq_bigr => j _; rewrite (sub_ordK j).
Qed.
Fact mul_polyA : associative mul_poly.
Proof.
move=> p q r; apply/polyP=> i; rewrite coef_mul_poly coef_mul_poly_rev.
pose coef3 j k := p`_j * (q`_(i - j - k)%N * r`_k).
transitivity (\sum_(j < i.+1) \sum_(k < i.+1 | k <= i - j) coef3 j k).
apply: eq_bigr => /= j _; rewrite coef_mul_poly_rev big_distrr /=.
by rewrite (big_ord_narrow_leq (leq_subr _ _)).
rewrite (exchange_big_dep predT) //=; apply: eq_bigr => k _.
transitivity (\sum_(j < i.+1 | j <= i - k) coef3 j k).
apply: eq_bigl => j; rewrite -ltnS -(ltnS j) -!subSn ?leq_ord //.
by rewrite -subn_gt0 -(subn_gt0 j) -!subnDA addnC.
rewrite (big_ord_narrow_leq (leq_subr _ _)) coef_mul_poly big_distrl /=.
by apply: eq_bigr => j _; rewrite /coef3 -!subnDA addnC mulrA.
Qed.
Fact mul_1poly : left_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_poly1 : right_id 1%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Fact mul_polyDl : left_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDl.
Qed.
Fact mul_polyDr : right_distributive mul_poly +%R.
Proof.
move=> p q r; apply/polyP=> i; rewrite coefD !coef_mul_poly -big_split.
by apply: eq_bigr => j _; rewrite coefD mulrDr.
Qed.
Fact mul_0poly : left_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact mul_poly0 : right_zero 0%:P mul_poly.
Proof.
move=> p; apply/polyP => i; rewrite coef_mul_poly_rev big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp // coefC; case: ifP.
Qed.
Fact poly1_neq0 : 1%:P != 0 :> {poly R}.
Proof. by rewrite polyC_eq0 oner_neq0. Qed.
HB.instance Definition _ := GRing.Nmodule_isNzSemiRing.Build (polynomial R)
mul_polyA mul_1poly mul_poly1 mul_polyDl mul_polyDr mul_0poly mul_poly0
poly1_neq0.
Lemma polyC1 : 1%:P = 1 :> {poly R}. Proof. by []. Qed.
Lemma polyseq1 : (1 : {poly R}) = [:: 1] :> seq R.
Proof. by rewrite polyseqC oner_neq0. Qed.
Lemma size_poly1 : size (1 : {poly R}) = 1.
Proof. by rewrite polyseq1. Qed.
Lemma coef1 i : (1 : {poly R})`_i = (i == 0)%:R.
Proof. by case: i => [|i]; rewrite polyseq1 /= ?nth_nil. Qed.
Lemma lead_coef1 : lead_coef 1 = 1 :> R. Proof. exact: lead_coefC. Qed.
Lemma coefM p q i : (p * q)`_i = \sum_(j < i.+1) p`_j * q`_(i - j)%N.
Proof. exact: coef_mul_poly. Qed.
Lemma coefMr p q i : (p * q)`_i = \sum_(j < i.+1) p`_(i - j)%N * q`_j.
Proof. exact: coef_mul_poly_rev. Qed.
Lemma coef0M p q : (p * q)`_0 = p`_0 * q`_0.
Proof. by rewrite coefM big_ord1. Qed.
Lemma coef0_prod I rI (F : I -> {poly R}) P :
(\prod_(i <- rI| P i) F i)`_0 = \prod_(i <- rI | P i) (F i)`_0.
Proof. by apply: (big_morph _ coef0M); rewrite coef1 eqxx. Qed.
Lemma size_polyMleq p q : size (p * q) <= (size p + size q).-1.
Proof. by rewrite -[*%R]/mul_poly unlock size_poly. Qed.
Lemma mul_lead_coef p q :
lead_coef p * lead_coef q = (p * q)`_(size p + size q).-2.
Proof.
pose dp := (size p).-1; pose dq := (size q).-1.
have [-> | nz_p] := eqVneq p 0; first by rewrite lead_coef0 !mul0r coef0.
have [-> | nz_q] := eqVneq q 0; first by rewrite lead_coef0 !mulr0 coef0.
have ->: (size p + size q).-2 = (dp + dq)%N.
by do 2!rewrite polySpred // addSn addnC.
have lt_p_pq: dp < (dp + dq).+1 by rewrite ltnS leq_addr.
rewrite coefM (bigD1 (Ordinal lt_p_pq)) ?big1 ?simp ?addKn //= => i.
rewrite -val_eqE neq_ltn /= => /orP[lt_i_p | gt_i_p]; last first.
by rewrite nth_default ?mul0r //; rewrite -polySpred in gt_i_p.
rewrite [q`__]nth_default ?mulr0 //= -subSS -{1}addnS -polySpred //.
by rewrite addnC -addnBA ?leq_addr.
Qed.
Lemma size_proper_mul p q :
lead_coef p * lead_coef q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
apply: contraNeq; rewrite mul_lead_coef eqn_leq size_polyMleq -ltnNge => lt_pq.
by rewrite nth_default // -subn1 -(leq_add2l 1) -leq_subLR leq_sub2r.
Qed.
Lemma lead_coef_proper_mul p q :
let c := lead_coef p * lead_coef q in c != 0 -> lead_coef (p * q) = c.
Proof. by move=> /= nz_c; rewrite mul_lead_coef -size_proper_mul. Qed.
Lemma size_poly_prod_leq (I : finType) (P : pred I) (F : I -> {poly R}) :
size (\prod_(i | P i) F i) <= (\sum_(i | P i) size (F i)).+1 - #|P|.
Proof.
rewrite -sum1_card.
elim/big_rec3: _ => [|i n m p _ IHp]; first by rewrite size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
rewrite (leq_trans (size_polyMleq _ _)) // subnS -!subn1 leq_sub2r //.
rewrite -addnS -addnBA ?leq_add2l // ltnW // -subn_gt0 (leq_trans _ IHp) //.
by rewrite polySpred.
Qed.
Lemma coefCM c p i : (c%:P * p)`_i = c * p`_i.
Proof.
rewrite coefM big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma coefMC c p i : (p * c%:P)`_i = p`_i * c.
Proof.
rewrite coefMr big_ord_recl subn0.
by rewrite big1 => [|j _]; rewrite coefC !simp.
Qed.
Lemma polyCM : {morph polyC : a b / a * b}.
Proof. by move=> a b; apply/polyP=> [[|i]]; rewrite coefCM !coefC ?simp. Qed.
Lemma size_poly_exp_leq p n : size (p ^+ n) <= ((size p).-1 * n).+1.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1.
have [-> | nzp] := poly0Vpos p; first by rewrite exprS mul0r size_poly0.
rewrite exprS (leq_trans (size_polyMleq _ _)) //.
by rewrite -{1}(prednK nzp) mulnS -addnS leq_add2l.
Qed.
End SemiPolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyD`")]
Notation size_add := size_polyD (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyDl`")]
Notation size_addl := size_polyDl (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyMleq`")]
Notation size_mul_leq := size_polyMleq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_prod_leq`")]
Notation size_prod_leq := size_poly_prod_leq (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_poly_exp_leq`")]
Notation size_exp_leq := size_poly_exp_leq (only parsing).
Section PolynomialTheory.
Variable R : nzRingType.
Implicit Types (a b c x y z : R) (p q r d : {poly R}).
Local Notation "c %:P" := (polyC c).
Local Notation "\poly_ ( i < n ) E" := (poly n (fun i : nat => E)).
(* Zmodule structure for polynomial *)
Definition opp_poly_def p := \poly_(i < size p) - p`_i.
Fact opp_poly_key : unit. Proof. by []. Qed.
Definition opp_poly := locked_with opp_poly_key opp_poly_def.
Canonical opp_poly_unlockable := [unlockable fun opp_poly].
Fact coef_opp_poly p i : (opp_poly p)`_i = - p`_i.
Proof.
rewrite unlock coef_poly /=.
by case: leqP => // le_p_i; rewrite nth_default ?oppr0.
Qed.
Fact add_polyN : left_inverse 0%:P opp_poly (@add_poly _).
Proof.
move=> p; apply/polyP=> i.
by rewrite coef_add_poly coef_opp_poly coefC if_same addNr.
Qed.
HB.instance Definition _ := GRing.Nmodule_isZmodule.Build (polynomial R)
add_polyN.
(* Size, leading coef, morphism properties of coef *)
Lemma coefN p i : (- p)`_i = - p`_i.
Proof. exact: coef_opp_poly. Qed.
Lemma coefB p q i : (p - q)`_i = p`_i - q`_i.
Proof. by rewrite coefD coefN. Qed.
HB.instance Definition _ i := GRing.isZmodMorphism.Build {poly R} R (coefp i)
(fun p => (coefB p)^~ i).
Lemma coefMn p n i : (p *+ n)`_i = p`_i *+ n.
Proof. exact: (raddfMn (coefp i)). Qed.
Lemma coefMNn p n i : (p *- n)`_i = p`_i *- n.
Proof. by rewrite coefN coefMn. Qed.
Lemma coef_sum I (r : seq I) (P : pred I) (F : I -> {poly R}) k :
(\sum_(i <- r | P i) F i)`_k = \sum_(i <- r | P i) (F i)`_k.
Proof. exact: (raddf_sum (coefp k)). Qed.
Lemma polyCN : {morph (@polyC R) : c / - c}.
Proof. by move=> c; apply/polyP=> [[|i]]; rewrite coefN !coefC ?oppr0. Qed.
Lemma polyCB : {morph (@polyC R) : a b / a - b}.
Proof. by move=> a b; rewrite polyCD polyCN. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build R {poly R} (@polyC _) polyCB.
Lemma polyCMn n : {morph (@polyC R) : c / c *+ n}. Proof. exact: raddfMn. Qed.
Lemma size_polyN p : size (- p) = size p.
Proof.
by apply/eqP; rewrite eqn_leq -{3}(opprK p) -[-%R]/opp_poly unlock !size_poly.
Qed.
Lemma lead_coefN p : lead_coef (- p) = - lead_coef p.
Proof. by rewrite /lead_coef size_polyN coefN. Qed.
(* Polynomial ring structure. *)
Fact polyC_is_monoid_morphism : monoid_morphism (@polyC R).
Proof. by split; last apply: polyCM. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `polyC_is_monoid_morphism` instead")]
Definition polyC_multiplicative :=
(fun g => (g.2, g.1)) polyC_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build R {poly R} (@polyC R)
polyC_is_monoid_morphism.
Lemma polyC_exp n : {morph (@polyC R) : c / c ^+ n}. Proof. exact: rmorphXn. Qed.
Lemma polyC_natr n : n%:R%:P = n%:R :> {poly R}.
Proof. by rewrite rmorph_nat. Qed.
Lemma pchar_poly : [pchar {poly R}] =i [pchar R].
Proof.
move=> p; rewrite !inE; congr (_ && _).
apply/eqP/eqP=> [/(congr1 val) /=|]; last by rewrite -polyC_natr => ->.
by rewrite polyseq0 -polyC_natr polyseqC; case: eqP.
Qed.
Lemma size_Msign p n : size ((-1) ^+ n * p) = size p.
Proof.
by rewrite -signr_odd; case: (odd n); rewrite ?mul1r// mulN1r size_polyN.
Qed.
Fact coefp0_is_monoid_morphism : monoid_morphism (coefp 0 : {poly R} -> R).
Proof.
split=> [|p q]; first by rewrite polyCK.
by rewrite [coefp 0 _]coefM big_ord_recl big_ord0 addr0.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `coefp0_is_monoid_morphism` instead")]
Definition coefp0_multiplicative :=
(fun g => (g.2, g.1)) coefp0_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build {poly R} R (coefp 0)
coefp0_is_monoid_morphism.
(* Algebra structure of polynomials. *)
Definition scale_poly_def a (p : {poly R}) := \poly_(i < size p) (a * p`_i).
Fact scale_poly_key : unit. Proof. by []. Qed.
Definition scale_poly := locked_with scale_poly_key scale_poly_def.
Canonical scale_poly_unlockable := [unlockable fun scale_poly].
Fact scale_polyE a p : scale_poly a p = a%:P * p.
Proof.
apply/polyP=> n; rewrite unlock coef_poly coefCM.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Fact scale_polyA a b p : scale_poly a (scale_poly b p) = scale_poly (a * b) p.
Proof. by rewrite !scale_polyE mulrA polyCM. Qed.
Fact scale_1poly : left_id 1 scale_poly.
Proof. by move=> p; rewrite scale_polyE mul1r. Qed.
Fact scale_polyDr a : {morph scale_poly a : p q / p + q}.
Proof. by move=> p q; rewrite !scale_polyE mulrDr. Qed.
Fact scale_polyDl p : {morph scale_poly^~ p : a b / a + b}.
Proof. by move=> a b /=; rewrite !scale_polyE raddfD mulrDl. Qed.
Fact scale_polyAl a p q : scale_poly a (p * q) = scale_poly a p * q.
Proof. by rewrite !scale_polyE mulrA. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build R (polynomial R)
scale_polyA scale_1poly scale_polyDr scale_polyDl.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build R (polynomial R)
scale_polyAl.
Lemma mul_polyC a p : a%:P * p = a *: p.
Proof. by rewrite -scale_polyE. Qed.
Lemma scale_polyC a b : a *: b%:P = (a * b)%:P.
Proof. by rewrite -mul_polyC polyCM. Qed.
Lemma alg_polyC a : a%:A = a%:P :> {poly R}.
Proof. by rewrite -mul_polyC mulr1. Qed.
Lemma coefZ a p i : (a *: p)`_i = a * p`_i.
Proof.
rewrite -[*:%R]/scale_poly unlock coef_poly.
by case: leqP => // le_p_n; rewrite nth_default ?mulr0.
Qed.
Lemma size_scale_leq a p : size (a *: p) <= size p.
Proof. by rewrite -[*:%R]/scale_poly unlock size_poly. Qed.
HB.instance Definition _ i := GRing.isScalable.Build R {poly R} R *%R (coefp i)
(fun a => (coefZ a) ^~ i).
HB.instance Definition _ := GRing.Linear.on (coefp 0).
(* The indeterminate, at last! *)
Definition polyX_def := @Poly R [:: 0; 1].
Fact polyX_key : unit. Proof. by []. Qed.
Definition polyX : {poly R} := locked_with polyX_key polyX_def.
Canonical polyX_unlockable := [unlockable of polyX].
Local Notation "'X" := polyX.
Lemma polyseqX : 'X = [:: 0; 1] :> seq R.
Proof. by rewrite unlock !polyseq_cons nil_poly eqxx /= polyseq1. Qed.
Lemma size_polyX : size 'X = 2. Proof. by rewrite polyseqX. Qed.
Lemma polyX_eq0 : ('X == 0) = false.
Proof. by rewrite -size_poly_eq0 size_polyX. Qed.
Lemma coefX i : 'X`_i = (i == 1)%:R.
Proof. by case: i => [|[|i]]; rewrite polyseqX //= nth_nil. Qed.
Lemma lead_coefX : lead_coef 'X = 1.
Proof. by rewrite /lead_coef polyseqX. Qed.
Lemma commr_polyX p : GRing.comm p 'X.
Proof.
apply/polyP=> i; rewrite coefMr coefM.
by apply: eq_bigr => j _; rewrite coefX commr_nat.
Qed.
Lemma coefMX p i : (p * 'X)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof.
rewrite coefMr big_ord_recl coefX ?simp.
case: i => [|i]; rewrite ?big_ord0 //= big_ord_recl polyseqX subn1 /=.
by rewrite big1 ?simp // => j _; rewrite nth_nil !simp.
Qed.
Lemma coefXM p i : ('X * p)`_i = (if (i == 0)%N then 0 else p`_i.-1).
Proof. by rewrite -commr_polyX coefMX. Qed.
Lemma cons_poly_def p a : cons_poly a p = p * 'X + a%:P.
Proof.
apply/polyP=> i; rewrite coef_cons coefD coefMX coefC.
by case: ifP; rewrite !simp.
Qed.
Lemma poly_ind (K : {poly R} -> Type) :
K 0 -> (forall p c, K p -> K (p * 'X + c%:P)) -> (forall p, K p).
Proof.
move=> K0 Kcons p; rewrite -[p]polyseqK.
by elim: {p}(p : seq R) => //= p c IHp; rewrite cons_poly_def; apply: Kcons.
Qed.
Lemma polyseqXaddC a : 'X + a%:P = [:: a; 1] :> seq R.
Proof. by rewrite -['X]mul1r -cons_poly_def polyseq_cons polyseq1. Qed.
Lemma polyseqXsubC a : 'X - a%:P = [:: - a; 1] :> seq R.
Proof. by rewrite -polyCN polyseqXaddC. Qed.
Lemma size_XsubC a : size ('X - a%:P) = 2.
Proof. by rewrite polyseqXsubC. Qed.
Lemma size_XaddC b : size ('X + b%:P) = 2.
Proof. by rewrite -[b]opprK rmorphN size_XsubC. Qed.
Lemma lead_coefXaddC a : lead_coef ('X + a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXaddC. Qed.
Lemma lead_coefXsubC a : lead_coef ('X - a%:P) = 1.
Proof. by rewrite lead_coefE polyseqXsubC. Qed.
Lemma polyXsubC_eq0 a : ('X - a%:P == 0) = false.
Proof. by rewrite -nil_poly polyseqXsubC. Qed.
Lemma size_MXaddC p c :
size (p * 'X + c%:P) = (if (p == 0) && (c == 0) then 0 else (size p).+1).
Proof. by rewrite -cons_poly_def size_cons_poly nil_poly. Qed.
Lemma polyseqMX p : p != 0 -> p * 'X = 0 :: p :> seq R.
Proof.
by move=> nz_p; rewrite -[p * _]addr0 -cons_poly_def polyseq_cons nil_poly nz_p.
Qed.
Lemma size_mulX p : p != 0 -> size (p * 'X) = (size p).+1.
Proof. by move/polyseqMX->. Qed.
Lemma lead_coefMX p : lead_coef (p * 'X) = lead_coef p.
Proof.
have [-> | nzp] := eqVneq p 0; first by rewrite mul0r.
by rewrite /lead_coef !nth_last polyseqMX.
Qed.
Lemma size_XmulC a : a != 0 -> size ('X * a%:P) = 2.
Proof.
by move=> nz_a; rewrite -commr_polyX size_mulX ?polyC_eq0 ?size_polyC nz_a.
Qed.
Local Notation "''X^' n" := ('X ^+ n).
Lemma coefXn n i : 'X^n`_i = (i == n)%:R.
Proof.
by elim: n i => [|n IHn] [|i]; rewrite ?coef1 // exprS coefXM ?IHn.
Qed.
Lemma polyseqXn n : 'X^n = rcons (nseq n 0) 1 :> seq R.
Proof.
elim: n => [|n IHn]; rewrite ?polyseq1 // exprSr.
by rewrite polyseqMX -?size_poly_eq0 IHn ?size_rcons.
Qed.
Lemma size_polyXn n : size 'X^n = n.+1.
Proof. by rewrite polyseqXn size_rcons size_nseq. Qed.
Lemma commr_polyXn p n : GRing.comm p 'X^n.
Proof. exact/commrX/commr_polyX. Qed.
Lemma lead_coefXn n : lead_coef 'X^n = 1.
Proof. by rewrite /lead_coef nth_last polyseqXn last_rcons. Qed.
Lemma lead_coefXnaddC n c : 0 < n -> lead_coef ('X^n + c%:P) = 1.
Proof.
move=> n_gt0; rewrite lead_coefDl ?lead_coefXn//.
by rewrite size_polyC size_polyXn ltnS (leq_trans (leq_b1 _)).
Qed.
Lemma lead_coefXnsubC n c : 0 < n -> lead_coef ('X^n - c%:P) = 1.
Proof. by move=> n_gt0; rewrite -polyCN lead_coefXnaddC. Qed.
Lemma size_XnaddC n c : 0 < n -> size ('X^n + c%:P) = n.+1.
Proof.
by move=> *; rewrite size_polyDl ?size_polyXn// size_polyC; case: eqP.
Qed.
Lemma size_XnsubC n c : 0 < n -> size ('X^n - c%:P) = n.+1.
Proof. by move=> *; rewrite -polyCN size_XnaddC. Qed.
Lemma polyseqMXn n p : p != 0 -> p * 'X^n = ncons n 0 p :> seq R.
Proof.
case: n => [|n] nz_p; first by rewrite mulr1.
elim: n => [|n IHn]; first exact: polyseqMX.
by rewrite exprSr mulrA polyseqMX -?nil_poly IHn.
Qed.
Lemma coefMXn n p i : (p * 'X^n)`_i = if i < n then 0 else p`_(i - n).
Proof.
have [-> | /polyseqMXn->] := eqVneq p 0; last exact: nth_ncons.
by rewrite mul0r !coef0 if_same.
Qed.
Lemma size_mulXn n p : p != 0 -> size (p * 'X^n) = (n + size p)%N.
Proof.
elim: n p => [p p_neq0| n IH p p_neq0]; first by rewrite mulr1.
by rewrite exprS mulrA IH -?size_poly_eq0 size_mulX // addnS.
Qed.
Lemma coefXnM n p i : ('X^n * p)`_i = if i < n then 0 else p`_(i - n).
Proof. by rewrite -commr_polyXn coefMXn. Qed.
Lemma coef_sumMXn I (r : seq I) (P : pred I) (p : I -> R) (n : I -> nat) k :
(\sum_(i <- r | P i) p i *: 'X^(n i))`_k =
\sum_(i <- r | P i && (n i == k)) p i.
Proof.
rewrite coef_sum big_mkcondr; apply: eq_bigr => i Pi.
by rewrite coefZ coefXn mulr_natr mulrb eq_sym.
Qed.
(* Expansion of a polynomial as an indexed sum *)
Lemma poly_def n E : \poly_(i < n) E i = \sum_(i < n) E i *: 'X^i.
Proof. by apply/polyP => i; rewrite coef_sumMXn coef_poly big_ord1_eq. Qed.
(* Monic predicate *)
Definition monic_pred := fun p => lead_coef p == 1.
Arguments monic_pred _ /.
Definition monic := [qualify p | monic_pred p].
Lemma monicE p : (p \is monic) = (lead_coef p == 1). Proof. by []. Qed.
Lemma monicP p : reflect (lead_coef p = 1) (p \is monic).
Proof. exact: eqP. Qed.
Lemma monic1 : 1 \is monic. Proof. exact/eqP/lead_coef1. Qed.
Lemma monicX : 'X \is monic. Proof. exact/eqP/lead_coefX. Qed.
Lemma monicXn n : 'X^n \is monic. Proof. exact/eqP/lead_coefXn. Qed.
Lemma monic_neq0 p : p \is monic -> p != 0.
Proof. by rewrite -lead_coef_eq0 => /eqP->; apply: oner_neq0. Qed.
Lemma lead_coef_monicM p q : p \is monic -> lead_coef (p * q) = lead_coef q.
Proof.
have [-> | nz_q] := eqVneq q 0; first by rewrite mulr0.
by move/monicP=> mon_p; rewrite lead_coef_proper_mul mon_p mul1r ?lead_coef_eq0.
Qed.
Lemma lead_coef_Mmonic p q : q \is monic -> lead_coef (p * q) = lead_coef p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
by move/monicP=> mon_q; rewrite lead_coef_proper_mul mon_q mulr1 ?lead_coef_eq0.
Qed.
Lemma size_monicM p q :
p \is monic -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
move/monicP=> mon_p nz_q.
by rewrite size_proper_mul // mon_p mul1r lead_coef_eq0.
Qed.
Lemma size_Mmonic p q :
p != 0 -> q \is monic -> size (p * q) = (size p + size q).-1.
Proof.
move=> nz_p /monicP mon_q.
by rewrite size_proper_mul // mon_q mulr1 lead_coef_eq0.
Qed.
Lemma monicMl p q : p \is monic -> (p * q \is monic) = (q \is monic).
Proof. by move=> mon_p; rewrite !monicE lead_coef_monicM. Qed.
Lemma monicMr p q : q \is monic -> (p * q \is monic) = (p \is monic).
Proof. by move=> mon_q; rewrite !monicE lead_coef_Mmonic. Qed.
Fact monic_mulr_closed : mulr_closed monic.
Proof. by split=> [|p q mon_p]; rewrite (monic1, monicMl). Qed.
HB.instance Definition _ := GRing.isMulClosed.Build {poly R} monic_pred
monic_mulr_closed.
Lemma monic_exp p n : p \is monic -> p ^+ n \is monic.
Proof. exact: rpredX. Qed.
Lemma monic_prod I rI (P : pred I) (F : I -> {poly R}):
(forall i, P i -> F i \is monic) -> \prod_(i <- rI | P i) F i \is monic.
Proof. exact: rpred_prod. Qed.
Lemma monicXaddC c : 'X + c%:P \is monic.
Proof. exact/eqP/lead_coefXaddC. Qed.
Lemma monicXsubC c : 'X - c%:P \is monic.
Proof. exact/eqP/lead_coefXsubC. Qed.
Lemma monic_prod_XsubC I rI (P : pred I) (F : I -> R) :
\prod_(i <- rI | P i) ('X - (F i)%:P) \is monic.
Proof. by apply: monic_prod => i _; apply: monicXsubC. Qed.
Lemma lead_coef_prod_XsubC I rI (P : pred I) (F : I -> R) :
lead_coef (\prod_(i <- rI | P i) ('X - (F i)%:P)) = 1.
Proof. exact/eqP/monic_prod_XsubC. Qed.
Lemma size_prod_XsubC I rI (F : I -> R) :
size (\prod_(i <- rI) ('X - (F i)%:P)) = (size rI).+1.
Proof.
elim: rI => [|i r /= <-]; rewrite ?big_nil ?size_poly1 // big_cons.
rewrite size_monicM ?monicXsubC ?monic_neq0 ?monic_prod_XsubC //.
by rewrite size_XsubC.
Qed.
Lemma size_exp_XsubC n a : size (('X - a%:P) ^+ n) = n.+1.
Proof.
rewrite -[n]card_ord -prodr_const -big_filter size_prod_XsubC.
by have [e _ _ [_ ->]] := big_enumP.
Qed.
Lemma monicXnaddC n c : 0 < n -> 'X^n + c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnaddC. Qed.
Lemma monicXnsubC n c : 0 < n -> 'X^n - c%:P \is monic.
Proof. by move=> n_gt0; rewrite monicE lead_coefXnsubC. Qed.
(* Some facts about regular elements. *)
Lemma lreg_lead p : GRing.lreg (lead_coef p) -> GRing.lreg p.
Proof.
move/mulrI_eq0=> reg_p; apply: mulrI0_lreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma rreg_lead p : GRing.rreg (lead_coef p) -> GRing.rreg p.
Proof.
move/mulIr_eq0=> reg_p; apply: mulIr0_rreg => q /eqP; apply: contraTeq => nz_q.
by rewrite -lead_coef_eq0 lead_coef_proper_mul reg_p lead_coef_eq0.
Qed.
Lemma lreg_lead0 p : GRing.lreg (lead_coef p) -> p != 0.
Proof. by move/lreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma rreg_lead0 p : GRing.rreg (lead_coef p) -> p != 0.
Proof. by move/rreg_neq0; rewrite lead_coef_eq0. Qed.
Lemma lreg_size c p : GRing.lreg c -> size (c *: p) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite scaler0.
rewrite -mul_polyC size_proper_mul; first by rewrite size_polyC lreg_neq0.
by rewrite lead_coefC mulrI_eq0 ?lead_coef_eq0.
Qed.
Lemma lreg_polyZ_eq0 c p : GRing.lreg c -> (c *: p == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /lreg_size->. Qed.
Lemma lead_coef_lreg c p :
GRing.lreg c -> lead_coef (c *: p) = c * lead_coef p.
Proof. by move=> reg_c; rewrite !lead_coefE coefZ lreg_size. Qed.
Lemma rreg_size c p : GRing.rreg c -> size (p * c%:P) = size p.
Proof.
move=> reg_c; have [-> | nz_p] := eqVneq p 0; first by rewrite mul0r.
rewrite size_proper_mul; first by rewrite size_polyC rreg_neq0 ?addn1.
by rewrite lead_coefC mulIr_eq0 ?lead_coef_eq0.
Qed.
Lemma rreg_polyMC_eq0 c p : GRing.rreg c -> (p * c%:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /rreg_size->. Qed.
Lemma rreg_div0 q r d :
GRing.rreg (lead_coef d) -> size r < size d ->
(q * d + r == 0) = (q == 0) && (r == 0).
Proof.
move=> reg_d lt_r_d; rewrite addrC addr_eq0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r oppr0.
apply: contraTF lt_r_d => /eqP->; rewrite -leqNgt size_polyN.
rewrite size_proper_mul ?mulIr_eq0 ?lead_coef_eq0 //.
by rewrite (polySpred nz_q) leq_addl.
Qed.
Lemma monic_comreg p :
p \is monic -> GRing.comm p (lead_coef p)%:P /\ GRing.rreg (lead_coef p).
Proof. by move/monicP->; split; [apply: commr1 | apply: rreg1]. Qed.
Lemma monic_lreg p : p \is monic -> GRing.lreg p.
Proof. by move=> /eqP lp1; apply/lreg_lead; rewrite lp1; apply/lreg1. Qed.
Lemma monic_rreg p : p \is monic -> GRing.rreg p.
Proof. by move=> /eqP lp1; apply/rreg_lead; rewrite lp1; apply/rreg1. Qed.
(* Horner evaluation of polynomials *)
Implicit Types s rs : seq R.
Fixpoint horner_rec s x := if s is a :: s' then horner_rec s' x * x + a else 0.
Definition horner p := horner_rec p.
Local Notation "p .[ x ]" := (horner p x) : ring_scope.
Lemma horner0 x : (0 : {poly R}).[x] = 0.
Proof. by rewrite /horner polyseq0. Qed.
Lemma hornerC c x : (c%:P).[x] = c.
Proof. by rewrite /horner polyseqC; case: eqP; rewrite /= ?simp. Qed.
Lemma hornerX x : 'X.[x] = x.
Proof. by rewrite /horner polyseqX /= !simp. Qed.
Lemma horner_cons p c x : (cons_poly c p).[x] = p.[x] * x + c.
Proof.
rewrite /horner polyseq_cons; case: nilP => //= ->.
by rewrite !simp -/(_.[x]) hornerC.
Qed.
Lemma horner_coef0 p : p.[0] = p`_0.
Proof. by rewrite /horner; case: (p : seq R) => //= c p'; rewrite !simp. Qed.
Lemma hornerMXaddC p c x : (p * 'X + c%:P).[x] = p.[x] * x + c.
Proof. by rewrite -cons_poly_def horner_cons. Qed.
Lemma hornerMX p x : (p * 'X).[x] = p.[x] * x.
Proof. by rewrite -[p * 'X]addr0 hornerMXaddC addr0. Qed.
Lemma horner_Poly s x : (Poly s).[x] = horner_rec s x.
Proof. by elim: s => [|a s /= <-]; rewrite (horner0, horner_cons). Qed.
Lemma horner_coef p x : p.[x] = \sum_(i < size p) p`_i * x ^+ i.
Proof.
rewrite /horner.
elim: {p}(p : seq R) => /= [|a s ->]; first by rewrite big_ord0.
rewrite big_ord_recl simp addrC big_distrl /=.
by congr (_ + _); apply: eq_bigr => i _; rewrite -mulrA exprSr.
Qed.
Lemma horner_coef_wide n p x :
size p <= n -> p.[x] = \sum_(i < n) p`_i * x ^+ i.
Proof.
move=> le_p_n.
rewrite horner_coef (big_ord_widen n (fun i => p`_i * x ^+ i)) // big_mkcond.
by apply: eq_bigr => i _; case: ltnP => // le_p_i; rewrite nth_default ?simp.
Qed.
Lemma horner_poly n E x : (\poly_(i < n) E i).[x] = \sum_(i < n) E i * x ^+ i.
Proof.
rewrite (@horner_coef_wide n) ?size_poly //.
by apply: eq_bigr => i _; rewrite coef_poly ltn_ord.
Qed.
Lemma hornerN p x : (- p).[x] = - p.[x].
Proof.
rewrite -[-%R]/opp_poly unlock horner_poly horner_coef -sumrN /=.
by apply: eq_bigr => i _; rewrite mulNr.
Qed.
Lemma hornerD p q x : (p + q).[x] = p.[x] + q.[x].
Proof.
rewrite -[+%R]/(@add_poly R) unlock horner_poly; set m := maxn _ _.
rewrite !(@horner_coef_wide m) ?leq_max ?leqnn ?orbT // -big_split /=.
by apply: eq_bigr => i _; rewrite -mulrDl.
Qed.
Lemma hornerXsubC a x : ('X - a%:P).[x] = x - a.
Proof. by rewrite hornerD hornerN hornerC hornerX. Qed.
Lemma horner_sum I (r : seq I) (P : pred I) F x :
(\sum_(i <- r | P i) F i).[x] = \sum_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (horner0, hornerD). Qed.
Lemma hornerCM a p x : (a%:P * p).[x] = a * p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(mulr0, horner0).
by rewrite mulrDr mulrA -polyCM !hornerMXaddC IHp mulrDr mulrA.
Qed.
Lemma hornerZ c p x : (c *: p).[x] = c * p.[x].
Proof. by rewrite -mul_polyC hornerCM. Qed.
Lemma hornerMn n p x : (p *+ n).[x] = p.[x] *+ n.
Proof. by elim: n => [| n IHn]; rewrite ?horner0 // !mulrS hornerD IHn. Qed.
Definition comm_coef p x := forall i, p`_i * x = x * p`_i.
Definition comm_poly p x := x * p.[x] = p.[x] * x.
Lemma comm_coef_poly p x : comm_coef p x -> comm_poly p x.
Proof.
move=> cpx; rewrite /comm_poly !horner_coef big_distrl big_distrr /=.
by apply: eq_bigr => i _; rewrite /= mulrA -cpx -!mulrA commrX.
Qed.
Lemma comm_poly0 x : comm_poly 0 x.
Proof. by rewrite /comm_poly !horner0 !simp. Qed.
Lemma comm_poly1 x : comm_poly 1 x.
Proof. by rewrite /comm_poly !hornerC !simp. Qed.
Lemma comm_polyX x : comm_poly 'X x.
Proof. by rewrite /comm_poly !hornerX. Qed.
Lemma comm_polyD p q x: comm_poly p x -> comm_poly q x -> comm_poly (p + q) x.
Proof. by rewrite /comm_poly hornerD mulrDr mulrDl => -> ->. Qed.
Lemma commr_horner a b p : GRing.comm a b -> comm_coef p a -> GRing.comm a p.[b].
Proof.
move=> cab cpa; rewrite horner_coef; apply: commr_sum => i _.
by apply: commrM => //; apply: commrX.
Qed.
Lemma hornerM_comm p q x : comm_poly q x -> (p * q).[x] = p.[x] * q.[x].
Proof.
move=> comm_qx.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(simp, horner0).
rewrite mulrDl hornerD hornerCM -mulrA -commr_polyX mulrA hornerMX.
by rewrite {}IHp -mulrA -comm_qx mulrA -mulrDl hornerMXaddC.
Qed.
Lemma comm_polyM p q x: comm_poly p x -> comm_poly q x -> comm_poly (p * q) x.
Proof.
by move=> px qx; rewrite /comm_poly hornerM_comm// mulrA px -mulrA qx mulrA.
Qed.
Lemma horner_exp_comm p x n : comm_poly p x -> (p ^+ n).[x] = p.[x] ^+ n.
Proof.
move=> comm_px; elim: n => [|n IHn]; first by rewrite hornerC.
by rewrite !exprSr -IHn hornerM_comm.
Qed.
Lemma comm_poly_exp p n x: comm_poly p x -> comm_poly (p ^+ n) x.
Proof. by move=> px; rewrite /comm_poly !horner_exp_comm// commrX. Qed.
Lemma hornerXn x n : ('X^n).[x] = x ^+ n.
Proof. by rewrite horner_exp_comm /comm_poly hornerX. Qed.
Definition hornerE_comm :=
(hornerD, hornerN, hornerX, hornerC, horner_cons,
simp, hornerCM, hornerZ,
(fun p x => hornerM_comm p (comm_polyX x))).
Definition root p : pred R := fun x => p.[x] == 0.
Lemma mem_root p x : x \in root p = (p.[x] == 0).
Proof. by []. Qed.
Lemma rootE p x : (root p x = (p.[x] == 0)) * ((x \in root p) = (p.[x] == 0)).
Proof. by []. Qed.
Lemma rootP p x : reflect (p.[x] = 0) (root p x).
Proof. exact: eqP. Qed.
Lemma rootPt p x : reflect (p.[x] == 0) (root p x).
Proof. exact: idP. Qed.
Lemma rootPf p x : reflect ((p.[x] == 0) = false) (~~ root p x).
Proof. exact: negPf. Qed.
Lemma rootC a x : root a%:P x = (a == 0).
Proof. by rewrite rootE hornerC. Qed.
Lemma root0 x : root 0 x.
Proof. by rewrite rootC. Qed.
Lemma root1 x : ~~ root 1 x.
Proof. by rewrite rootC oner_eq0. Qed.
Lemma rootX x : root 'X x = (x == 0).
Proof. by rewrite rootE hornerX. Qed.
Lemma rootN p x : root (- p) x = root p x.
Proof. by rewrite rootE hornerN oppr_eq0. Qed.
Lemma root_size_gt1 a p : p != 0 -> root p a -> 1 < size p.
Proof.
rewrite ltnNge => nz_p; apply: contraL => /size1_polyC Dp.
by rewrite Dp rootC -polyC_eq0 -Dp.
Qed.
Lemma root_XsubC a x : root ('X - a%:P) x = (x == a).
Proof. by rewrite rootE hornerXsubC subr_eq0. Qed.
Lemma root_XaddC a x : root ('X + a%:P) x = (x == - a).
Proof. by rewrite -root_XsubC rmorphN opprK. Qed.
Theorem factor_theorem p a : reflect (exists q, p = q * ('X - a%:P)) (root p a).
Proof.
apply: (iffP eqP) => [pa0 | [q ->]]; last first.
by rewrite hornerM_comm /comm_poly hornerXsubC subrr ?simp.
exists (\poly_(i < size p) horner_rec (drop i.+1 p) a).
apply/polyP=> i; rewrite mulrBr coefB coefMX coefMC !coef_poly.
apply: canRL (addrK _) _; rewrite addrC; have [le_p_i | lt_i_p] := leqP.
rewrite nth_default // !simp drop_oversize ?if_same //.
exact: leq_trans (leqSpred _).
case: i => [|i] in lt_i_p *; last by rewrite ltnW // (drop_nth 0 lt_i_p).
by rewrite drop1 /= -{}pa0 /horner; case: (p : seq R) lt_i_p.
Qed.
Lemma multiplicity_XsubC p a :
{m | exists2 q, (p != 0) ==> ~~ root q a & p = q * ('X - a%:P) ^+ m}.
Proof.
have [n le_p_n] := ubnP (size p); elim: n => // n IHn in p le_p_n *.
have [-> | nz_p /=] := eqVneq p 0; first by exists 0, 0; rewrite ?mul0r.
have [/sig_eqW[p1 Dp] | nz_pa] := altP (factor_theorem p a); last first.
by exists 0%N, p; rewrite ?mulr1.
have nz_p1: p1 != 0 by apply: contraNneq nz_p => p1_0; rewrite Dp p1_0 mul0r.
have /IHn[m /sig2_eqW[q nz_qa Dp1]]: size p1 < n.
by rewrite Dp size_Mmonic ?monicXsubC // size_XsubC addn2 in le_p_n.
by exists m.+1, q; [rewrite nz_p1 in nz_qa | rewrite exprSr mulrA -Dp1].
Qed.
(* Roots of unity. *)
#[deprecated(since="mathcomp 2.3.0",note="Use size_XnsubC instead.")]
Lemma size_Xn_sub_1 n : n > 0 -> size ('X^n - 1 : {poly R}) = n.+1.
Proof. exact/size_XnsubC. Qed.
#[deprecated(since="mathcomp 2.3.0'",note="Use monicXnsubC instead.")]
Lemma monic_Xn_sub_1 n : n > 0 -> 'X^n - 1 \is monic.
Proof. exact/monicXnsubC. Qed.
Definition root_of_unity n : pred R := root ('X^n - 1).
Local Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Lemma unity_rootE n z : n.-unity_root z = (z ^+ n == 1).
Proof.
by rewrite /root_of_unity rootE hornerD hornerN hornerXn hornerC subr_eq0.
Qed.
Lemma unity_rootP n z : reflect (z ^+ n = 1) (n.-unity_root z).
Proof. by rewrite unity_rootE; apply: eqP. Qed.
Definition primitive_root_of_unity n z :=
(n > 0) && [forall i : 'I_n, i.+1.-unity_root z == (i.+1 == n)].
Local Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Lemma prim_order_exists n z :
n > 0 -> z ^+ n = 1 -> {m | m.-primitive_root z & (m %| n)}.
Proof.
move=> n_gt0 zn1.
have: exists m, (m > 0) && (z ^+ m == 1) by exists n; rewrite n_gt0 /= zn1.
case/ex_minnP=> m /andP[m_gt0 /eqP zm1] m_min.
exists m.
apply/andP; split=> //; apply/eqfunP=> [[i]] /=.
rewrite leq_eqVlt unity_rootE.
case: eqP => [-> _ | _]; first by rewrite zm1 eqxx.
by apply: contraTF => zi1; rewrite -leqNgt m_min.
have: n %% m < m by rewrite ltn_mod.
apply: contraLR; rewrite -lt0n -leqNgt => nm_gt0; apply: m_min.
by rewrite nm_gt0 /= expr_mod ?zn1.
Qed.
Section OnePrimitive.
Variables (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Lemma prim_order_gt0 : n > 0. Proof. by case/andP: prim_z. Qed.
Let n_gt0 := prim_order_gt0.
Lemma prim_expr_order : z ^+ n = 1.
Proof.
case/andP: prim_z => _; rewrite -(prednK n_gt0) => /forallP/(_ ord_max).
by rewrite unity_rootE eqxx eqb_id => /eqP.
Qed.
Lemma prim_expr_mod i : z ^+ (i %% n) = z ^+ i.
Proof. exact: expr_mod prim_expr_order. Qed.
Lemma prim_order_dvd i : (n %| i) = (z ^+ i == 1).
Proof.
move: n_gt0; rewrite -prim_expr_mod /dvdn -(ltn_mod i).
case: {i}(i %% n)%N => [|i] lt_i; first by rewrite !eqxx.
case/andP: prim_z => _ /forallP/(_ (Ordinal (ltnW lt_i)))/eqP.
by rewrite unity_rootE eqn_leq andbC leqNgt lt_i.
Qed.
Lemma eq_prim_root_expr i j : (z ^+ i == z ^+ j) = (i == j %[mod n]).
Proof.
wlog le_ji: i j / j <= i.
move=> IH; case: (leqP j i) => [|/ltnW] /IH //.
by rewrite eq_sym (eq_sym (j %% n)%N).
rewrite -{1}(subnKC le_ji) exprD -prim_expr_mod eqn_mod_dvd //.
rewrite prim_order_dvd; apply/eqP/eqP=> [|->]; last by rewrite mulr1.
move/(congr1 ( *%R (z ^+ (n - j %% n)))); rewrite mulrA -exprD.
by rewrite subnK ?prim_expr_order ?mul1r // ltnW ?ltn_mod.
Qed.
Lemma exp_prim_root k : (n %/ gcdn k n).-primitive_root (z ^+ k).
Proof.
set d := gcdn k n; have d_gt0: (0 < d)%N by rewrite gcdn_gt0 orbC n_gt0.
have [d_dv_k d_dv_n]: (d %| k /\ d %| n)%N by rewrite dvdn_gcdl dvdn_gcdr.
set q := (n %/ d)%N; rewrite /q.-primitive_root ltn_divRL // n_gt0.
apply/forallP=> i; rewrite unity_rootE -exprM -prim_order_dvd.
rewrite -(divnK d_dv_n) -/q -(divnK d_dv_k) mulnAC dvdn_pmul2r //.
apply/eqP; apply/idP/idP=> [|/eqP->]; last by rewrite dvdn_mull.
rewrite Gauss_dvdr; first by rewrite eqn_leq ltn_ord; apply: dvdn_leq.
by rewrite /coprime gcdnC -(eqn_pmul2r d_gt0) mul1n muln_gcdl !divnK.
Qed.
Lemma dvdn_prim_root m : (m %| n)%N -> m.-primitive_root (z ^+ (n %/ m)).
Proof.
set k := (n %/ m)%N => m_dv_n; rewrite -{1}(mulKn m n_gt0) -divnA // -/k.
by rewrite -{1}(@gcdn_idPl k n _) ?exp_prim_root // -(divnK m_dv_n) dvdn_mulr.
Qed.
Lemma prim_root_eq0 : (z == 0) = (n == 0%N).
Proof.
rewrite gtn_eqF//; apply/eqP => z0; have /esym/eqP := prim_expr_order.
by rewrite z0 expr0n gtn_eqF//= oner_eq0.
Qed.
End OnePrimitive.
Lemma prim_root_exp_coprime n z k :
n.-primitive_root z -> n.-primitive_root (z ^+ k) = coprime k n.
Proof.
move=> prim_z; have n_gt0 := prim_order_gt0 prim_z.
apply/idP/idP=> [prim_zk | co_k_n].
set d := gcdn k n; have dv_d_n: (d %| n)%N := dvdn_gcdr _ _.
rewrite /coprime -/d -(eqn_pmul2r n_gt0) mul1n -{2}(gcdnMl n d).
rewrite -{2}(divnK dv_d_n) (mulnC _ d) -muln_gcdr (gcdn_idPr _) //.
rewrite (prim_order_dvd prim_zk) -exprM -(prim_order_dvd prim_z).
by rewrite muln_divCA_gcd dvdn_mulr.
have zkn_1: z ^+ k ^+ n = 1 by rewrite exprAC (prim_expr_order prim_z) expr1n.
have{zkn_1} [m prim_zk dv_m_n]:= prim_order_exists n_gt0 zkn_1.
suffices /eqP <-: m == n by [].
rewrite eqn_dvd dv_m_n -(@Gauss_dvdr n k m) 1?coprime_sym //=.
by rewrite (prim_order_dvd prim_z) exprM (prim_expr_order prim_zk).
Qed.
(* Lifting a ring predicate to polynomials. *)
Implicit Type S : {pred R}.
Definition polyOver_pred S := fun p : {poly R} => all (mem S) p.
Arguments polyOver_pred _ _ /.
Definition polyOver S := [qualify a p | polyOver_pred S p].
Lemma polyOverS (S1 S2 : {pred R}) :
{subset S1 <= S2} -> {subset polyOver S1 <= polyOver S2}.
Proof.
by move=> sS12 p /(all_nthP 0)S1p; apply/(all_nthP 0)=> i /S1p; apply: sS12.
Qed.
Lemma polyOver0 S : 0 \is a polyOver S.
Proof. by rewrite qualifE /= polyseq0. Qed.
Lemma polyOver_poly S n E :
(forall i, i < n -> E i \in S) -> \poly_(i < n) E i \is a polyOver S.
Proof.
move=> S_E; apply/(all_nthP 0)=> i lt_i_p /=; rewrite coef_poly.
by case: ifP => [/S_E// | /idP[]]; apply: leq_trans lt_i_p (size_poly n E).
Qed.
Section PolyOverAdd.
Variable S : addrClosed R.
Lemma polyOverP {p} : reflect (forall i, p`_i \in S) (p \in polyOver S).
Proof.
apply: (iffP (all_nthP 0)) => [Sp i | Sp i _]; last exact: Sp.
by have [/Sp // | /(nth_default 0)->] := ltnP i (size p); apply: rpred0.
Qed.
Lemma polyOverC c : (c%:P \in polyOver S) = (c \in S).
Proof.
by rewrite [LHS]qualifE /= polyseqC; case: eqP => [->|] /=; rewrite ?andbT ?rpred0.
Qed.
Fact polyOver_addr_closed : addr_closed (polyOver S).
Proof.
split=> [|p q Sp Sq]; first exact: polyOver0.
by apply/polyOverP=> i; rewrite coefD rpredD ?(polyOverP _).
Qed.
HB.instance Definition _ := GRing.isAddClosed.Build {poly R} (polyOver_pred S)
polyOver_addr_closed.
End PolyOverAdd.
Section PolyOverSemiRing2.
Variable S : semiring2Closed R.
Lemma polyOver_mulr_2closed : GRing.mulr_2closed (polyOver S).
Proof.
move=> p q /polyOverP Sp /polyOverP Sq; apply/polyOverP=> i.
by rewrite coefM rpred_sum // => j _; rewrite rpredM.
Qed.
HB.instance Definition _ := GRing.isMul2Closed.Build {poly R} (polyOver_pred S)
polyOver_mulr_2closed.
End PolyOverSemiRing2.
Fact polyOverNr (zmodS : zmodClosed R) : oppr_closed (polyOver zmodS).
Proof.
by move=> p /polyOverP Sp; apply/polyOverP=> i; rewrite coefN rpredN.
Qed.
HB.instance Definition _ (zmodS : zmodClosed R) :=
GRing.isOppClosed.Build {poly R} (polyOver_pred zmodS) (@polyOverNr _).
Section PolyOverSemiring.
Variable S : semiringClosed R.
Fact polyOver_mul1_closed : 1 \in (polyOver S).
Proof. by rewrite polyOverC rpred1. Qed.
HB.instance Definition _ := GRing.isMul1Closed.Build {poly R} (polyOver_pred S)
polyOver_mul1_closed.
Lemma polyOverZ : {in S & polyOver S, forall c p, c *: p \is a polyOver S}.
Proof.
by move=> c p Sc /polyOverP Sp; apply/polyOverP=> i; rewrite coefZ rpredM ?Sp.
Qed.
Lemma polyOverX : 'X \in polyOver S.
Proof. by rewrite qualifE /= polyseqX /= rpred0 rpred1. Qed.
Lemma polyOverXn n : 'X^n \in polyOver S.
Proof. by rewrite rpredX// polyOverX. Qed.
Lemma rpred_horner : {in polyOver S & S, forall p x, p.[x] \in S}.
Proof.
move=> p x /polyOverP Sp Sx; rewrite horner_coef rpred_sum // => i _.
by rewrite rpredM ?rpredX.
Qed.
End PolyOverSemiring.
Section PolyOverRing.
Variable S : subringClosed R.
HB.instance Definition _ := GRing.MulClosed.on (polyOver_pred S).
Lemma polyOverXaddC c : ('X + c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnaddC n c : ('X^n + c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredDl ?polyOverXn// ?polyOverC. Qed.
Lemma polyOverXsubC c : ('X - c%:P \in polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverX ?polyOverC. Qed.
Lemma polyOverXnsubC n c : ('X^n - c%:P \is a polyOver S) = (c \in S).
Proof. by rewrite rpredBl ?polyOverXn// ?polyOverC. Qed.
End PolyOverRing.
(* Single derivative. *)
Definition deriv p := \poly_(i < (size p).-1) (p`_i.+1 *+ i.+1).
Local Notation "a ^` ()" := (deriv a).
Lemma coef_deriv p i : p^`()`_i = p`_i.+1 *+ i.+1.
Proof.
rewrite coef_poly -subn1 ltn_subRL.
by case: leqP => // /(nth_default 0) ->; rewrite mul0rn.
Qed.
Lemma polyOver_deriv (ringS : semiringClosed R) :
{in polyOver ringS, forall p, p^`() \is a polyOver ringS}.
Proof.
by move=> p /polyOverP Kp; apply/polyOverP=> i; rewrite coef_deriv rpredMn ?Kp.
Qed.
Lemma derivC c : c%:P^`() = 0.
Proof. by apply/polyP=> i; rewrite coef_deriv coef0 coefC mul0rn. Qed.
Lemma derivX : ('X)^`() = 1.
Proof. by apply/polyP=> [[|i]]; rewrite coef_deriv coef1 coefX ?mul0rn. Qed.
Lemma derivXn n : ('X^n)^`() = 'X^(n.-1) *+ n.
Proof.
case: n => [|n]; first exact: derivC.
apply/polyP=> i; rewrite coef_deriv coefMn !coefXn eqSS.
by case: eqP => [-> // | _]; rewrite !mul0rn.
Qed.
Fact deriv_is_linear : linear deriv.
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_deriv, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build R {poly R} {poly R} _ deriv
(GRing.semilinear_linear deriv_is_linear).
Lemma deriv0 : 0^`() = 0.
Proof. exact: linear0. Qed.
Lemma derivD : {morph deriv : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivN : {morph deriv : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivB : {morph deriv : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivXsubC (a : R) : ('X - a%:P)^`() = 1.
Proof. by rewrite derivB derivX derivC subr0. Qed.
Lemma derivMn n p : (p *+ n)^`() = p^`() *+ n.
Proof. exact: linearMn. Qed.
Lemma derivMNn n p : (p *- n)^`() = p^`() *- n.
Proof. exact: linearMNn. Qed.
Lemma derivZ c p : (c *: p)^`() = c *: p^`().
Proof. exact: linearZ. Qed.
Lemma deriv_mulC c p : (c%:P * p)^`() = c%:P * p^`().
Proof. by rewrite !mul_polyC derivZ. Qed.
Lemma derivMXaddC p c : (p * 'X + c%:P)^`() = p + p^`() * 'X.
Proof.
apply/polyP=> i; rewrite raddfD /= derivC addr0 coefD !(coefMX, coef_deriv).
by case: i; rewrite ?addr0.
Qed.
Lemma derivM p q : (p * q)^`() = p^`() * q + p * q^`().
Proof.
elim/poly_ind: p => [|p b IHp]; first by rewrite !(mul0r, add0r, derivC).
rewrite mulrDl -mulrA -commr_polyX mulrA -[_ * 'X]addr0 raddfD /= !derivMXaddC.
by rewrite deriv_mulC IHp !mulrDl -!mulrA !commr_polyX !addrA.
Qed.
Definition derivE := Eval lazy beta delta [morphism_2 morphism_1] in
(derivZ, deriv_mulC, derivC, derivX, derivMXaddC, derivXsubC, derivM, derivB,
derivD, derivN, derivXn, derivM, derivMn).
(* Iterated derivative. *)
Definition derivn n p := iter n deriv p.
Local Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Lemma derivn0 p : p^`(0) = p.
Proof. by []. Qed.
Lemma derivn1 p : p^`(1) = p^`().
Proof. by []. Qed.
Lemma derivnS p n : p^`(n.+1) = p^`(n)^`().
Proof. by []. Qed.
Lemma derivSn p n : p^`(n.+1) = p^`()^`(n).
Proof. exact: iterSr. Qed.
Lemma coef_derivn n p i : p^`(n)`_i = p`_(n + i) *+ (n + i) ^_ n.
Proof.
elim: n i => [|n IHn] i; first by rewrite ffactn0 mulr1n.
by rewrite derivnS coef_deriv IHn -mulrnA ffactnSr addSnnS addKn.
Qed.
Lemma polyOver_derivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`(n) \is a polyOver ringS}.
Proof.
move=> p /polyOverP Kp /= n; apply/polyOverP=> i.
by rewrite coef_derivn rpredMn.
Qed.
Fact derivn_is_linear n : linear (derivn n).
Proof. by elim: n => // n IHn a p q; rewrite derivnS IHn linearP. Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (derivn n)
(GRing.semilinear_linear (derivn_is_linear n)).
Lemma derivnC c n : c%:P^`(n) = if n == 0 then c%:P else 0.
Proof. by case: n => // n; rewrite derivSn derivC linear0. Qed.
Lemma derivnD n : {morph derivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma derivnB n : {morph derivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma derivnMn n m p : (p *+ m)^`(n) = p^`(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma derivnMNn n m p : (p *- m)^`(n) = p^`(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma derivnN n : {morph derivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma derivnZ n : scalable (derivn n).
Proof. exact: linearZZ. Qed.
Lemma derivnXn m n : ('X^m)^`(n) = 'X^(m - n) *+ m ^_ n.
Proof.
apply/polyP=>i; rewrite coef_derivn coefMn !coefXn.
case: (ltnP m n) => [lt_m_n | le_m_n].
by rewrite eqn_leq leqNgt ltn_addr // mul0rn ffact_small.
by rewrite -{1 3}(subnKC le_m_n) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Lemma derivnMXaddC n p c :
(p * 'X + c%:P)^`(n.+1) = p^`(n) *+ n.+1 + p^`(n.+1) * 'X.
Proof.
elim: n => [|n IHn]; first by rewrite derivn1 derivMXaddC.
rewrite derivnS IHn derivD derivM derivX mulr1 derivMn -!derivnS.
by rewrite addrA addrAC -mulrSr.
Qed.
Lemma derivn_poly0 p n : size p <= n -> p^`(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_derivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma lt_size_deriv (p : {poly R}) : p != 0 -> size p^`() < size p.
Proof. by move=> /polySpred->; apply: size_poly. Qed.
(* A normalising version of derivation to get the division by n! in Taylor *)
Definition nderivn n p := \poly_(i < size p - n) (p`_(n + i) *+ 'C(n + i, n)).
Local Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Lemma coef_nderivn n p i : p^`N(n)`_i = p`_(n + i) *+ 'C(n + i, n).
Proof.
rewrite coef_poly ltn_subRL; case: leqP => // le_p_ni.
by rewrite nth_default ?mul0rn.
Qed.
(* Here is the division by n! *)
Lemma nderivn_def n p : p^`(n) = p^`N(n) *+ n`!.
Proof.
by apply/polyP=> i; rewrite coefMn coef_nderivn coef_derivn -mulrnA bin_ffact.
Qed.
Lemma polyOver_nderivn (ringS : semiringClosed R) :
{in polyOver ringS, forall p n, p^`N(n) \in polyOver ringS}.
Proof.
move=> p /polyOverP Sp /= n; apply/polyOverP=> i.
by rewrite coef_nderivn rpredMn.
Qed.
Lemma nderivn0 p : p^`N(0) = p.
Proof. by rewrite -[p^`N(0)](nderivn_def 0). Qed.
Lemma nderivn1 p : p^`N(1) = p^`().
Proof. by rewrite -[p^`N(1)](nderivn_def 1). Qed.
Lemma nderivnC c n : (c%:P)^`N(n) = if n == 0 then c%:P else 0.
Proof.
apply/polyP=> i; rewrite coef_nderivn.
by case: n => [|n]; rewrite ?bin0 // coef0 coefC mul0rn.
Qed.
Lemma nderivnXn m n : ('X^m)^`N(n) = 'X^(m - n) *+ 'C(m, n).
Proof.
apply/polyP=> i; rewrite coef_nderivn coefMn !coefXn.
have [lt_m_n | le_n_m] := ltnP m n.
by rewrite eqn_leq leqNgt ltn_addr // mul0rn bin_small.
by rewrite -{1 3}(subnKC le_n_m) eqn_add2l; case: eqP => [->|]; rewrite ?mul0rn.
Qed.
Fact nderivn_is_linear n : linear (nderivn n).
Proof.
move=> k p q; apply/polyP=> i.
by rewrite !(coef_nderivn, coefD, coefZ) mulrnDl mulrnAr.
Qed.
HB.instance Definition _ n :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (nderivn n)
(GRing.semilinear_linear (nderivn_is_linear n)).
Lemma nderivnD n : {morph nderivn n : p q / p + q}.
Proof. exact: linearD. Qed.
Lemma nderivnB n : {morph nderivn n : p q / p - q}.
Proof. exact: linearB. Qed.
Lemma nderivnMn n m p : (p *+ m)^`N(n) = p^`N(n) *+ m.
Proof. exact: linearMn. Qed.
Lemma nderivnMNn n m p : (p *- m)^`N(n) = p^`N(n) *- m.
Proof. exact: linearMNn. Qed.
Lemma nderivnN n : {morph nderivn n : p / - p}.
Proof. exact: linearN. Qed.
Lemma nderivnZ n : scalable (nderivn n).
Proof. exact: linearZZ. Qed.
Lemma nderivnMXaddC n p c :
(p * 'X + c%:P)^`N(n.+1) = p^`N(n) + p^`N(n.+1) * 'X.
Proof.
apply/polyP=> i; rewrite coef_nderivn !coefD !coefMX coefC.
rewrite !addSn /= !coef_nderivn addr0 binS mulrnDr addrC; congr (_ + _).
by rewrite addSnnS; case: i; rewrite // addn0 bin_small.
Qed.
Lemma nderivn_poly0 p n : size p <= n -> p^`N(n) = 0.
Proof.
move=> le_p_n; apply/polyP=> i; rewrite coef_nderivn.
rewrite nth_default; first by rewrite mul0rn coef0.
exact/(leq_trans le_p_n)/leq_addr.
Qed.
Lemma nderiv_taylor p x h :
GRing.comm x h -> p.[x + h] = \sum_(i < size p) p^`N(i).[x] * h ^+ i.
Proof.
move/commrX=> cxh; elim/poly_ind: p => [|p c IHp].
by rewrite size_poly0 big_ord0 horner0.
rewrite hornerMXaddC size_MXaddC.
have [-> | nz_p] := eqVneq p 0.
rewrite horner0 !simp; have [-> | _] := c =P 0; first by rewrite big_ord0.
by rewrite size_poly0 big_ord_recl big_ord0 nderivn0 hornerC !simp.
rewrite big_ord_recl nderivn0 !simp hornerMXaddC addrAC; congr (_ + _).
rewrite mulrDr {}IHp !big_distrl polySpred //= big_ord_recl /= mulr1 -addrA.
rewrite nderivn0 /bump /(addn 1) /=; congr (_ + _).
rewrite !big_ord_recr /= nderivnMXaddC -mulrA -exprSr -polySpred // !addrA.
congr (_ + _); last by rewrite (nderivn_poly0 (leqnn _)) !simp.
rewrite addrC -big_split /=; apply: eq_bigr => i _.
by rewrite nderivnMXaddC !hornerE_comm /= mulrDl -!mulrA -exprSr cxh.
Qed.
Lemma nderiv_taylor_wide n p x h :
GRing.comm x h -> size p <= n ->
p.[x + h] = \sum_(i < n) p^`N(i).[x] * h ^+ i.
Proof.
move/nderiv_taylor=> -> le_p_n.
rewrite (big_ord_widen n (fun i => p^`N(i).[x] * h ^+ i)) // big_mkcond.
apply: eq_bigr => i _; case: leqP => // /nderivn_poly0->.
by rewrite horner0 simp.
Qed.
Lemma eq_poly n E1 E2 : (forall i, i < n -> E1 i = E2 i) ->
poly n E1 = poly n E2 :> {poly R}.
Proof. by move=> E; rewrite !poly_def; apply: eq_bigr => i _; rewrite E. Qed.
End PolynomialTheory.
#[deprecated(since="mathcomp 2.4.0", note="renamed to `size_polyN`")]
Notation size_opp := size_polyN (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_poly instead.")]
Notation char_poly := pchar_poly (only parsing).
Prenex Implicits polyC polyCK Poly polyseqK lead_coef root horner polyOver.
Arguments monic {R}.
Notation "\poly_ ( i < n ) E" := (poly n (fun i => E)) : ring_scope.
Notation "c %:P" := (polyC c) : ring_scope.
Notation "'X" := (polyX _) : ring_scope.
Notation "''X^' n" := ('X ^+ n) : ring_scope.
Notation "p .[ x ]" := (horner p x) : ring_scope.
Notation "n .-unity_root" := (root_of_unity n) : ring_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : ring_scope.
Notation "a ^` ()" := (deriv a) : ring_scope.
Notation "a ^` ( n )" := (derivn n a) : ring_scope.
Notation "a ^`N ( n )" := (nderivn n a) : ring_scope.
Arguments monic_pred _ _ /.
Arguments monicP {R p}.
Arguments rootP {R p x}.
Arguments rootPf {R p x}.
Arguments rootPt {R p x}.
Arguments unity_rootP {R n z}.
Arguments polyOver_pred _ _ _ /.
Arguments polyOverP {R S p}.
Arguments polyC_inj {R} [x1 x2] eq_x12P.
Arguments eq_poly {R n} [E1] E2 eq_E12.
Section IdomainPrimRoot.
Variables (R : idomainType) (n : nat) (z : R).
Hypothesis prim_z : n.-primitive_root z.
Import prime.
Let n_gt0 := prim_order_gt0 prim_z.
Lemma prim_root_pcharF p : (p %| n)%N -> p \in [pchar R] = false.
Proof.
move=> pn; apply: contraTF isT => pchar_p; have p_prime := pcharf_prime pchar_p.
have /dvdnP[[|k] n_eq_kp] := pn; first by rewrite n_eq_kp in (n_gt0).
have /eqP := prim_expr_order prim_z; rewrite n_eq_kp exprM.
rewrite -pFrobenius_autE -(pFrobenius_aut1 pchar_p) -subr_eq0 -rmorphB/=.
rewrite pFrobenius_autE expf_eq0// prime_gt0//= subr_eq0 => /eqP.
move=> /eqP; rewrite -(prim_order_dvd prim_z) n_eq_kp.
rewrite -[X in _ %| X]muln1 dvdn_pmul2l ?dvdn1// => /eqP peq1.
by rewrite peq1 in p_prime.
Qed.
Lemma pchar_prim_root : [pchar R]^'.-nat n.
Proof. by apply/pnatP=> // p pp pn; rewrite inE/= prim_root_pcharF. Qed.
Lemma prim_root_pi_eq0 m : \pi(n).-nat m -> m%:R != 0 :> R.
Proof.
by rewrite natf_neq0_pchar; apply: sub_in_pnat => p _; apply: pnatPpi pchar_prim_root.
Qed.
Lemma prim_root_dvd_eq0 m : (m %| n)%N -> m%:R != 0 :> R.
Proof.
case: m => [|m mn]; first by rewrite dvd0n gtn_eqF.
by rewrite prim_root_pi_eq0 ?(sub_in_pnat (in1W (pi_of_dvd mn _))) ?pnat_pi.
Qed.
Lemma prim_root_natf_neq0 : n%:R != 0 :> R.
Proof. by rewrite prim_root_dvd_eq0. Qed.
End IdomainPrimRoot.
#[deprecated(since="mathcomp 2.4.0", note="Use prim_root_pcharF instead.")]
Notation prim_root_charF := prim_root_pcharF (only parsing).
#[deprecated(since="mathcomp 2.4.0", note="Use pchar_prim_root instead.")]
Notation char_prim_root := pchar_prim_root (only parsing).
(* Container morphism. *)
Section MapPoly.
Section Definitions.
Variables (aR rR : nzRingType) (f : aR -> rR).
Definition map_poly (p : {poly aR}) := \poly_(i < size p) f p`_i.
(* Alternative definition; the one above is more convenient because it lets *)
(* us use the lemmas on \poly, e.g., size (map_poly p) <= size p is an *)
(* instance of size_poly. *)
Lemma map_polyE p : map_poly p = Poly (map f p).
Proof.
rewrite /map_poly unlock; congr Poly.
apply: (@eq_from_nth _ 0); rewrite size_mkseq ?size_map // => i lt_i_p.
by rewrite [RHS](nth_map 0) ?nth_mkseq.
Qed.
Definition commr_rmorph u := forall x, GRing.comm u (f x).
Definition horner_morph u of commr_rmorph u := fun p => (map_poly p).[u].
End Definitions.
Variables aR rR : nzRingType.
Section Combinatorial.
Variables (iR : nzRingType) (f : aR -> rR).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma map_poly0 : 0^f = 0.
Proof. by rewrite map_polyE polyseq0. Qed.
Lemma eq_map_poly (g : aR -> rR) : f =1 g -> map_poly f =1 map_poly g.
Proof. by move=> eq_fg p; rewrite !map_polyE (eq_map eq_fg). Qed.
Lemma map_poly_id g (p : {poly iR}) :
{in (p : seq iR), g =1 id} -> map_poly g p = p.
Proof. by move=> g_id; rewrite map_polyE map_id_in ?polyseqK. Qed.
Lemma coef_map_id0 p i : f 0 = 0 -> (p^f)`_i = f p`_i.
Proof.
by move=> f0; rewrite coef_poly; case: ltnP => // le_p_i; rewrite nth_default.
Qed.
Lemma map_Poly_id0 s : f 0 = 0 -> (Poly s)^f = Poly (map f s).
Proof.
move=> f0; apply/polyP=> j; rewrite coef_map_id0 ?coef_Poly //.
have [/(nth_map 0 0)->// | le_s_j] := ltnP j (size s).
by rewrite !nth_default ?size_map.
Qed.
Lemma map_poly_comp_id0 (g : iR -> aR) p :
f 0 = 0 -> map_poly (f \o g) p = (map_poly g p)^f.
Proof. by move=> f0; rewrite map_polyE map_comp -map_Poly_id0 -?map_polyE. Qed.
Lemma size_map_poly_id0 p : f (lead_coef p) != 0 -> size p^f = size p.
Proof. by move=> nz_fp; apply: size_poly_eq. Qed.
Lemma map_poly_eq0_id0 p : f (lead_coef p) != 0 -> (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_map_poly_id0->. Qed.
Lemma lead_coef_map_id0 p :
f 0 = 0 -> f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof.
by move=> f0 nz_fp; rewrite lead_coefE coef_map_id0 ?size_map_poly_id0.
Qed.
Hypotheses (inj_f : injective f) (f_0 : f 0 = 0).
Lemma size_map_inj_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite map_poly0 !size_poly0.
by rewrite size_map_poly_id0 // -f_0 (inj_eq inj_f) lead_coef_eq0.
Qed.
Lemma map_inj_poly : injective (map_poly f).
Proof.
move=> p q /polyP eq_pq; apply/polyP=> i; apply: inj_f.
by rewrite -!coef_map_id0 ?eq_pq.
Qed.
Lemma lead_coef_map_inj p : lead_coef p^f = f (lead_coef p).
Proof. by rewrite !lead_coefE size_map_inj_poly coef_map_id0. Qed.
End Combinatorial.
Lemma map_polyK (f : aR -> rR) g :
cancel g f -> f 0 = 0 -> cancel (map_poly g) (map_poly f).
Proof.
by move=> gK f_0 p; rewrite /= -map_poly_comp_id0 ?map_poly_id // => x _ //=.
Qed.
Lemma eq_in_map_poly_id0 (f g : aR -> rR) (S : addrClosed aR) :
f 0 = 0 -> g 0 = 0 -> {in S, f =1 g} ->
{in polyOver S, map_poly f =1 map_poly g}.
Proof.
move=> f0 g0 eq_fg p pP; apply/polyP => i.
by rewrite !coef_map_id0// eq_fg// (polyOverP _).
Qed.
Lemma eq_in_map_poly (f g : {additive aR -> rR}) (S : addrClosed aR) :
{in S, f =1 g} -> {in polyOver S, map_poly f =1 map_poly g}.
Proof. by move=> /eq_in_map_poly_id0; apply; rewrite //?raddf0. Qed.
Section Additive.
Variables (iR : nzRingType) (f : {additive aR -> rR}).
Local Notation "p ^f" := (map_poly (GRing.Additive.sort f) p) : ring_scope.
Lemma coef_map p i : p^f`_i = f p`_i.
Proof. exact: coef_map_id0 (raddf0 f). Qed.
Lemma map_Poly s : (Poly s)^f = Poly (map f s).
Proof. exact: map_Poly_id0 (raddf0 f). Qed.
Lemma map_poly_comp (g : iR -> aR) p :
map_poly (f \o g) p = map_poly f (map_poly g p).
Proof. exact: map_poly_comp_id0 (raddf0 f). Qed.
Fact map_poly_is_zmod_morphism : zmod_morphism (map_poly f).
Proof. by move=> p q; apply/polyP=> i; rewrite !(coef_map, coefB) raddfB. Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_zmod_morphism` instead")]
Definition map_poly_is_additive := map_poly_is_zmod_morphism.
HB.instance Definition _ :=
GRing.isZmodMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_zmod_morphism.
Lemma map_polyC a : (a%:P)^f = (f a)%:P.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefC) -!mulrb raddfMn. Qed.
Lemma lead_coef_map_eq p :
f (lead_coef p) != 0 -> lead_coef p^f = f (lead_coef p).
Proof. exact: lead_coef_map_id0 (raddf0 f). Qed.
End Additive.
Variable f : {rmorphism aR -> rR}.
Implicit Types p : {poly aR}.
Local Notation "p ^f" := (map_poly (GRing.RMorphism.sort f) p) : ring_scope.
Fact map_poly_is_monoid_morphism : monoid_morphism (map_poly f).
Proof.
split=> [|p q]; apply/polyP=> i.
by rewrite !(coef_map, coef1) /= rmorph_nat.
rewrite coef_map /= !coefM /= !rmorph_sum; apply: eq_bigr => j _.
by rewrite !coef_map rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `map_poly_is_monoid_morphism` instead")]
Definition map_poly_is_multiplicative :=
(fun g => (g.2, g.1)) map_poly_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} {poly rR} (map_poly f)
map_poly_is_monoid_morphism.
Lemma map_polyZ c p : (c *: p)^f = f c *: p^f.
Proof. by apply/polyP=> i; rewrite !(coef_map, coefZ) /= rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build aR {poly aR} {poly rR} (f \; *:%R) (map_poly f)
map_polyZ.
Lemma map_polyX : ('X)^f = 'X.
Proof. by apply/polyP=> i; rewrite coef_map !coefX /= rmorph_nat. Qed.
Lemma map_polyXn n : ('X^n)^f = 'X^n.
Proof. by rewrite rmorphXn /= map_polyX. Qed.
Lemma map_polyXaddC x : ('X + x%:P)^f = 'X + (f x)%:P.
Proof. by rewrite raddfD/= map_polyX map_polyC. Qed.
Lemma map_polyXsubC x : ('X - x%:P)^f = 'X - (f x)%:P.
Proof. by rewrite raddfB/= map_polyX map_polyC. Qed.
Lemma map_prod_XsubC I (rI : seq I) P F :
(\prod_(i <- rI | P i) ('X - (F i)%:P))^f =
\prod_(i <- rI | P i) ('X - (f (F i))%:P).
Proof.
by rewrite rmorph_prod//; apply/eq_bigr => x /=; rewrite map_polyXsubC.
Qed.
Lemma prod_map_poly (ar : seq aR) P :
\prod_(x <- map f ar | P x) ('X - x%:P) =
(\prod_(x <- ar | P (f x)) ('X - x%:P))^f.
Proof. by rewrite big_map map_prod_XsubC. Qed.
Lemma monic_map p : p \is monic -> p^f \is monic.
Proof.
move/monicP=> mon_p; rewrite monicE.
by rewrite lead_coef_map_eq mon_p /= rmorph1 ?oner_neq0.
Qed.
Lemma horner_map p x : p^f.[f x] = f p.[x].
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(rmorph0, horner0).
rewrite hornerMXaddC !rmorphD !rmorphM /=.
by rewrite map_polyX map_polyC hornerMXaddC IHp.
Qed.
Lemma map_comm_poly p x : comm_poly p x -> comm_poly p^f (f x).
Proof. by rewrite /comm_poly horner_map -!rmorphM // => ->. Qed.
Lemma map_comm_coef p x : comm_coef p x -> comm_coef p^f (f x).
Proof. by move=> cpx i; rewrite coef_map -!rmorphM ?cpx. Qed.
Lemma rmorph_root p x : root p x -> root p^f (f x).
Proof. by move/eqP=> px0; rewrite rootE horner_map px0 rmorph0. Qed.
Lemma rmorph_unity_root n z : n.-unity_root z -> n.-unity_root (f z).
Proof.
move/rmorph_root; rewrite rootE rmorphB hornerD hornerN.
by rewrite /= map_polyXn rmorph1 hornerC hornerXn subr_eq0 unity_rootE.
Qed.
Section HornerMorph.
Variable u : rR.
Hypothesis cfu : commr_rmorph f u.
Lemma horner_morphC a : horner_morph cfu a%:P = f a.
Proof. by rewrite /horner_morph map_polyC hornerC. Qed.
Lemma horner_morphX : horner_morph cfu 'X = u.
Proof. by rewrite /horner_morph map_polyX hornerX. Qed.
Fact horner_is_linear : linear_for (f \; *%R) (horner_morph cfu).
Proof. by move=> c p q; rewrite /horner_morph linearP /= hornerD hornerZ. Qed.
Fact horner_is_monoid_morphism : monoid_morphism (horner_morph cfu).
Proof.
split=> [|p q]; first by rewrite /horner_morph rmorph1 hornerC.
rewrite /horner_morph rmorphM /= hornerM_comm //.
by apply: comm_coef_poly => i; rewrite coef_map cfu.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_is_monoid_morphism` instead")]
Definition horner_is_multiplicative :=
(fun g => (g.2, g.1)) horner_is_monoid_morphism.
HB.instance Definition _ :=
GRing.isSemilinear.Build aR {poly aR} rR _ (horner_morph cfu)
(GRing.semilinear_linear horner_is_linear).
HB.instance Definition _ :=
GRing.isMonoidMorphism.Build {poly aR} rR (horner_morph cfu)
horner_is_monoid_morphism.
End HornerMorph.
Lemma deriv_map p : p^f^`() = (p^`())^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_deriv) //= rmorphMn. Qed.
Lemma derivn_map p n : p^f^`(n) = (p^`(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_derivn) //= rmorphMn. Qed.
Lemma nderivn_map p n : p^f^`N(n) = (p^`N(n))^f.
Proof. by apply/polyP => i; rewrite !(coef_map, coef_nderivn) //= rmorphMn. Qed.
End MapPoly.
Lemma mapf_root (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R})
(p : {poly F}) (x : F) : root (map_poly f p) (f x) = root p x.
Proof. by rewrite !rootE horner_map fmorph_eq0. Qed.
(* Morphisms from the polynomial ring, and the initiality of polynomials *)
(* with respect to these. *)
Section MorphPoly.
Variable (aR rR : nzRingType) (pf : {rmorphism {poly aR} -> rR}).
Lemma poly_morphX_comm : commr_rmorph (pf \o polyC) (pf 'X).
Proof. by move=> a; rewrite /GRing.comm /= -!rmorphM // commr_polyX. Qed.
Lemma poly_initial : pf =1 horner_morph poly_morphX_comm.
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
by rewrite !rmorphD !rmorphM /= -{}IHp horner_morphC ?horner_morphX.
Qed.
End MorphPoly.
Notation "p ^:P" := (map_poly polyC p) : ring_scope.
Section PolyCompose.
Variable R : nzRingType.
Implicit Types p q : {poly R}.
Definition comp_poly q p := p^:P.[q].
Local Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma size_map_polyC p : size p^:P = size p.
Proof. exact/(size_map_inj_poly polyC_inj). Qed.
Lemma map_polyC_eq0 p : (p^:P == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_polyC. Qed.
Lemma root_polyC p x : root p^:P x%:P = root p x.
Proof. by rewrite rootE horner_map polyC_eq0. Qed.
Lemma comp_polyE p q : p \Po q = \sum_(i < size p) p`_i *: q^+i.
Proof.
by rewrite [p \Po q]horner_poly; apply: eq_bigr => i _; rewrite mul_polyC.
Qed.
Lemma coef_comp_poly p q n :
(p \Po q)`_n = \sum_(i < size p) p`_i * (q ^+ i)`_n.
Proof. by rewrite comp_polyE coef_sum; apply: eq_bigr => i; rewrite coefZ. Qed.
Lemma polyOver_comp (ringS : semiringClosed R) :
{in polyOver ringS &, forall p q, p \Po q \in polyOver ringS}.
Proof.
move=> p q /polyOverP Sp Sq; rewrite comp_polyE rpred_sum // => i _.
by rewrite polyOverZ ?rpredX.
Qed.
Lemma comp_polyCr p c : p \Po c%:P = p.[c]%:P.
Proof. exact: horner_map. Qed.
Lemma comp_poly0r p : p \Po 0 = (p`_0)%:P.
Proof. by rewrite comp_polyCr horner_coef0. Qed.
Lemma comp_polyC c p : c%:P \Po p = c%:P.
Proof. by rewrite /(_ \Po p) map_polyC hornerC. Qed.
Fact comp_poly_is_linear p : linear (comp_poly p).
Proof.
move=> a q r.
by rewrite /comp_poly rmorphD /= map_polyZ !hornerE_comm mul_polyC.
Qed.
HB.instance Definition _ p :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (comp_poly p)
(GRing.semilinear_linear (comp_poly_is_linear p)).
Lemma comp_poly0 p : 0 \Po p = 0.
Proof. exact: raddf0. Qed.
Lemma comp_polyD p q r : (p + q) \Po r = (p \Po r) + (q \Po r).
Proof. exact: raddfD. Qed.
Lemma comp_polyB p q r : (p - q) \Po r = (p \Po r) - (q \Po r).
Proof. exact: raddfB. Qed.
Lemma comp_polyZ c p q : (c *: p) \Po q = c *: (p \Po q).
Proof. exact: linearZZ. Qed.
Lemma comp_polyXr p : p \Po 'X = p.
Proof. by rewrite -{2}/(idfun p) poly_initial. Qed.
Lemma comp_polyX p : 'X \Po p = p.
Proof. by rewrite /(_ \Po p) map_polyX hornerX. Qed.
Lemma comp_poly_MXaddC c p q : (p * 'X + c%:P) \Po q = (p \Po q) * q + c%:P.
Proof.
by rewrite /(_ \Po q) rmorphD rmorphM /= map_polyX map_polyC hornerMXaddC.
Qed.
Lemma comp_polyXaddC_K p z : (p \Po ('X + z%:P)) \Po ('X - z%:P) = p.
Proof.
have addzK: ('X + z%:P) \Po ('X - z%:P) = 'X.
by rewrite raddfD /= comp_polyC comp_polyX subrK.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_poly0.
rewrite comp_poly_MXaddC linearD /= comp_polyC {1}/comp_poly rmorphM /=.
by rewrite hornerM_comm /comm_poly -!/(_ \Po _) ?IHp ?addzK ?commr_polyX.
Qed.
Lemma size_comp_poly_leq p q :
size (p \Po q) <= ((size p).-1 * (size q).-1).+1.
Proof.
rewrite comp_polyE (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _))//.
rewrite (leq_trans (size_poly_exp_leq _ _))//.
by rewrite ltnS mulnC leq_mul // -{2}(subnKC (valP i)) leq_addr.
Qed.
Lemma comp_Xn_poly p n : 'X^n \Po p = p ^+ n.
Proof. by rewrite /(_ \Po p) map_polyXn hornerXn. Qed.
Lemma coef_comp_poly_Xn p n i : 0 < n ->
(p \Po 'X^n)`_i = if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; rewrite comp_polyE; under eq_bigr do rewrite -exprM mulnC.
rewrite coef_sumMXn/=; case: dvdnP => [[j ->]|nD]; last first.
by rewrite big1// => j /eqP ?; case: nD; exists j.
under eq_bigl do rewrite eqn_mul2r gtn_eqF//.
by rewrite big_ord1_eq if_nth ?leqVgt ?mulnK.
Qed.
Lemma comp_poly_Xn p n : 0 < n ->
p \Po 'X^n = \poly_(i < size p * n) if n %| i then p`_(i %/ n) else 0.
Proof.
move=> n_gt0; apply/polyP => i; rewrite coef_comp_poly_Xn // coef_poly.
case: dvdnP => [[k ->]|]; last by rewrite if_same.
by rewrite mulnK // ltn_mul2r n_gt0 if_nth ?leqVgt.
Qed.
End PolyCompose.
Notation "p \Po q" := (comp_poly q p) : ring_scope.
Lemma map_comp_poly (aR rR : nzRingType) (f : {rmorphism aR -> rR}) p q :
map_poly f (p \Po q) = map_poly f p \Po map_poly f q.
Proof.
elim/poly_ind: p => [|p a IHp]; first by rewrite !raddf0.
rewrite comp_poly_MXaddC !rmorphD !rmorphM /= !map_polyC map_polyX.
by rewrite comp_poly_MXaddC -IHp.
Qed.
Section Surgery.
Variable R : nzRingType.
Implicit Type p q : {poly R}.
(* Even part of a polynomial *)
Definition even_poly p : {poly R} := \poly_(i < uphalf (size p)) p`_i.*2.
Lemma size_even_poly p : size (even_poly p) <= uphalf (size p).
Proof. exact: size_poly. Qed.
Lemma coef_even_poly p i : (even_poly p)`_i = p`_i.*2.
Proof. by rewrite coef_poly gtn_uphalf_double if_nth ?leqVgt. Qed.
Lemma even_polyE s p : size p <= s.*2 -> even_poly p = \poly_(i < s) p`_i.*2.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_even_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?leq_double.
Qed.
Lemma size_even_poly_eq p : odd (size p) ->
size (even_poly p) = uphalf (size p).
Proof.
move=> p_even; rewrite size_poly_eq// double_pred odd_uphalfK//=.
by rewrite lead_coef_eq0 -size_poly_eq0; case: size p_even.
Qed.
Lemma even_polyD p q : even_poly (p + q) = even_poly p + even_poly q.
Proof. by apply/polyP => i; rewrite !(coef_even_poly, coefD). Qed.
Lemma even_polyZ k p : even_poly (k *: p) = k *: even_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_even_poly). Qed.
Fact even_poly_is_linear : linear even_poly.
Proof. by move=> k p q; rewrite even_polyD even_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ even_poly
(GRing.semilinear_linear even_poly_is_linear).
Lemma even_polyC (c : R) : even_poly c%:P = c%:P.
Proof. by apply/polyP => i; rewrite coef_even_poly !coefC; case: i. Qed.
(* Odd part of a polynomial *)
Definition odd_poly p : {poly R} := \poly_(i < (size p)./2) p`_i.*2.+1.
Lemma size_odd_poly p : size (odd_poly p) <= (size p)./2.
Proof. exact: size_poly. Qed.
Lemma coef_odd_poly p i : (odd_poly p)`_i = p`_i.*2.+1.
Proof. by rewrite coef_poly gtn_half_double if_nth ?leqVgt. Qed.
Lemma odd_polyE s p :
size p <= s.*2.+1 -> odd_poly p = \poly_(i < s) p`_i.*2.+1.
Proof.
move=> pLs2; apply/polyP => i; rewrite coef_odd_poly !coef_poly if_nth //.
by case: ltnP => //= ?; rewrite (leq_trans pLs2) ?ltnS ?leq_double.
Qed.
Lemma odd_polyC (c : R) : odd_poly c%:P = 0.
Proof. by apply/polyP => i; rewrite coef_odd_poly !coefC; case: i. Qed.
Lemma odd_polyD p q : odd_poly (p + q) = odd_poly p + odd_poly q.
Proof. by apply/polyP => i; rewrite !(coef_odd_poly, coefD). Qed.
Lemma odd_polyZ k p : odd_poly (k *: p) = k *: odd_poly p.
Proof. by apply/polyP => i; rewrite !(coefZ, coef_odd_poly). Qed.
Fact odd_poly_is_linear : linear odd_poly.
Proof. by move=> k p q; rewrite odd_polyD odd_polyZ. Qed.
HB.instance Definition _ :=
GRing.isSemilinear.Build R {poly R} {poly R} _ odd_poly
(GRing.semilinear_linear odd_poly_is_linear).
Lemma size_odd_poly_eq p : ~~ odd (size p) -> size (odd_poly p) = (size p)./2.
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite odd_polyC size_poly0.
move=> p_odd; rewrite size_poly_eq// -subn1 doubleB subn2 even_halfK//.
rewrite prednK ?lead_coef_eq0// ltn_predRL.
by move: p_neq0 p_odd; rewrite -size_poly_eq0; case: (size p) => [|[]].
Qed.
Lemma odd_polyMX p : odd_poly (p * 'X) = even_poly p.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC.
by apply/polyP => i; rewrite !coef_poly size_mulX // coefMX.
Qed.
Lemma even_polyMX p : even_poly (p * 'X) = odd_poly p * 'X.
Proof.
have [->|pN0] := eqVneq p 0; first by rewrite mul0r even_polyC odd_polyC mul0r.
by apply/polyP => -[|i]; rewrite !(coefMX, coef_poly, if_same, size_mulX).
Qed.
Lemma sum_even_poly p :
\sum_(i < size p | ~~ odd i) p`_i *: 'X^i = even_poly p \Po 'X^2.
Proof.
apply/polyP => i; rewrite coef_comp_poly_Xn// coef_sumMXn coef_even_poly.
rewrite (big_ord1_cond_eq _ _ (negb \o _))/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
Lemma sum_odd_poly p :
\sum_(i < size p | odd i) p`_i *: 'X^i = (odd_poly p \Po 'X^2) * 'X.
Proof.
apply/polyP => i; rewrite coefMX coef_comp_poly_Xn// coef_sumMXn coef_odd_poly/=.
case: i => [|i]//=; first by rewrite big_andbC big1// => -[[|j]//].
rewrite big_ord1_cond_eq/= -dvdn2 andbC -muln2.
by case: dvdnP => //= -[k ->]; rewrite mulnK// if_nth ?leqVgt.
Qed.
(* Decomposition in odd and even part *)
Lemma poly_even_odd p : even_poly p \Po 'X^2 + (odd_poly p \Po 'X^2) * 'X = p.
Proof.
rewrite -sum_even_poly -sum_odd_poly addrC -(bigID _ xpredT).
by rewrite -[RHS]coefK poly_def.
Qed.
(* take and drop for polynomials *)
Definition take_poly m p := \poly_(i < m) p`_i.
Lemma size_take_poly m p : size (take_poly m p) <= m.
Proof. exact: size_poly. Qed.
Lemma coef_take_poly m p i : (take_poly m p)`_i = if i < m then p`_i else 0.
Proof. exact: coef_poly. Qed.
Lemma take_poly_id m p : size p <= m -> take_poly m p = p.
Proof.
move=> /leq_trans gep; apply/polyP => i; rewrite coef_poly if_nth//=.
by case: ltnP => // /gep->.
Qed.
Lemma take_polyD m p q : take_poly m (p + q) = take_poly m p + take_poly m q.
Proof.
by apply/polyP => i; rewrite !(coefD, coef_poly); case: leqP; rewrite ?add0r.
Qed.
Lemma take_polyZ k m p : take_poly m (k *: p) = k *: take_poly m p.
Proof.
apply/polyP => i; rewrite !(coefZ, coef_take_poly); case: leqP => //.
by rewrite mulr0.
Qed.
Fact take_poly_is_linear m : linear (take_poly m).
Proof. by move=> k p q; rewrite take_polyD take_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (take_poly m)
(GRing.semilinear_linear (take_poly_is_linear m)).
Lemma take_poly_sum m I r P (p : I -> {poly R}) :
take_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r| P i) take_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma take_poly0l p : take_poly 0 p = 0.
Proof. exact/size_poly_leq0P/size_take_poly. Qed.
Lemma take_poly0r m : take_poly m 0 = 0.
Proof. exact: linear0. Qed.
Lemma take_polyMXn m n p :
take_poly m (p * 'X^n) = take_poly (m - n) p * 'X^n.
Proof.
have [->|/eqP p_neq0] := p =P 0; first by rewrite !(mul0r, take_poly0r).
apply/polyP => i; rewrite !(coef_take_poly, coefMXn).
by have [iLn|nLi] := leqP n i; rewrite ?if_same// ltn_sub2rE.
Qed.
Lemma take_polyMXn_0 n p : take_poly n (p * 'X^n) = 0.
Proof. by rewrite take_polyMXn subnn take_poly0l mul0r. Qed.
Lemma take_polyDMXn n p q : size p <= n -> take_poly n (p + q * 'X^n) = p.
Proof. by move=> ?; rewrite take_polyD take_poly_id// take_polyMXn_0 addr0. Qed.
Definition drop_poly m p := \poly_(i < size p - m) p`_(i + m).
Lemma coef_drop_poly m p i : (drop_poly m p)`_i = p`_(i + m).
Proof. by rewrite coef_poly ltn_subRL addnC if_nth ?leqVgt. Qed.
Lemma drop_poly_eq0 m p : size p <= m -> drop_poly m p = 0.
Proof.
move=> sLm; apply/polyP => i; rewrite coef_poly coef0 ltn_subRL addnC.
by rewrite if_nth ?leqVgt// nth_default// (leq_trans _ (leq_addl _ _)).
Qed.
Lemma size_drop_poly n p : size (drop_poly n p) = (size p - n)%N.
Proof.
have [pLn|nLp] := leqP (size p) n.
by rewrite (eqP pLn) drop_poly_eq0 ?size_poly0.
have p_neq0 : p != 0 by rewrite -size_poly_gt0 (leq_trans _ nLp).
by rewrite size_poly_eq// predn_sub subnK ?lead_coef_eq0// -ltnS -polySpred.
Qed.
Lemma sum_drop_poly n p :
\sum_(n <= i < size p) p`_i *: 'X^i = drop_poly n p * 'X^n.
Proof.
rewrite (big_addn 0) big_mkord /drop_poly poly_def mulr_suml.
by apply: eq_bigr => i _; rewrite exprD scalerAl.
Qed.
Lemma drop_polyD m p q : drop_poly m (p + q) = drop_poly m p + drop_poly m q.
Proof. by apply/polyP => i; rewrite coefD !coef_drop_poly coefD. Qed.
Lemma drop_polyZ k m p : drop_poly m (k *: p) = k *: drop_poly m p.
Proof. by apply/polyP => i; rewrite coefZ !coef_drop_poly coefZ. Qed.
Fact drop_poly_is_linear m : linear (drop_poly m).
Proof. by move=> k p q; rewrite drop_polyD drop_polyZ. Qed.
HB.instance Definition _ m :=
GRing.isSemilinear.Build R {poly R} {poly R} _ (drop_poly m)
(GRing.semilinear_linear (drop_poly_is_linear m)).
Lemma drop_poly_sum m I r P (p : I -> {poly R}) :
drop_poly m (\sum_(i <- r | P i) p i) = \sum_(i <- r | P i) drop_poly m (p i).
Proof. exact: linear_sum. Qed.
Lemma drop_poly0l p : drop_poly 0 p = p.
Proof. by apply/polyP => i; rewrite coef_poly subn0 addn0 if_nth ?leqVgt. Qed.
Lemma drop_poly0r m : drop_poly m 0 = 0. Proof. exact: linear0. Qed.
Lemma drop_polyMXn m n p :
drop_poly m (p * 'X^n) = drop_poly (m - n) p * 'X^(n - m).
Proof.
have [->|p_neq0] := eqVneq p 0; first by rewrite mul0r !drop_poly0r mul0r.
apply/polyP => i; rewrite !(coefMXn, coef_drop_poly) ltn_subRL [(m + i)%N]addnC.
have [i_small|i_big]// := ltnP; congr nth.
by have [mn|/ltnW mn] := leqP m n;
rewrite (eqP mn) (addn0, subn0) (subnBA, addnBA).
Qed.
Lemma drop_polyMXn_id n p : drop_poly n (p * 'X^ n) = p.
Proof. by rewrite drop_polyMXn subnn drop_poly0l expr0 mulr1. Qed.
Lemma drop_polyDMXn n p q : size p <= n -> drop_poly n (p + q * 'X^n) = q.
Proof. by move=> ?; rewrite drop_polyD drop_poly_eq0// drop_polyMXn_id add0r. Qed.
Lemma poly_take_drop n p : take_poly n p + drop_poly n p * 'X^n = p.
Proof.
apply/polyP => i; rewrite coefD coefMXn coef_take_poly coef_drop_poly.
by case: ltnP => ni; rewrite ?addr0 ?add0r//= subnK.
Qed.
Lemma eqp_take_drop n p q :
take_poly n p = take_poly n q -> drop_poly n p = drop_poly n q -> p = q.
Proof.
by move=> tpq dpq; rewrite -[p](poly_take_drop n) -[q](poly_take_drop n) tpq dpq.
Qed.
End Surgery.
Definition coefE :=
(coef0, coef1, coefC, coefX, coefXn, coef_sumMXn,
coefZ, coefMC, coefCM, coefXnM, coefMXn, coefXM, coefMX, coefMNn, coefMn,
coefN, coefB, coefD, coef_even_poly, coef_odd_poly,
coef_take_poly, coef_drop_poly, coef_cons, coef_Poly, coef_poly,
coef_deriv, coef_nderivn, coef_derivn, coef_map, coef_sum,
coef_comp_poly_Xn, coef_comp_poly).
Section PolynomialComNzRing.
Variable R : comNzRingType.
Implicit Types p q : {poly R}.
Fact poly_mul_comm p q : p * q = q * p.
Proof.
apply/polyP=> i; rewrite coefM coefMr.
by apply: eq_bigr => j _; rewrite mulrC.
Qed.
HB.instance Definition _ := GRing.PzRing_hasCommutativeMul.Build (polynomial R)
poly_mul_comm.
HB.instance Definition _ := GRing.Lalgebra_isComAlgebra.Build R (polynomial R).
Lemma coef_prod_XsubC (ps : seq R) (n : nat) :
(n <= size ps)%N ->
(\prod_(p <- ps) ('X - p%:P))`_n =
(-1) ^+ (size ps - n)%N *
\sum_(I in {set 'I_(size ps)} | #|I| == (size ps - n)%N)
\prod_(i in I) ps`_i.
Proof.
move=> nle.
under eq_bigr => i _ do rewrite addrC -raddfN/=.
rewrite -{1}(in_tupleE ps) -(map_tnth_enum (_ ps)) big_map.
rewrite enumT bigA_distr /= coef_sum.
transitivity (\sum_(I in {set 'I_(size ps)}) if #|I| == (size ps - n)%N then
\prod_(i < size ps | i \in I) - ps`_i else 0).
apply eq_bigr => I _.
rewrite big_if/= big_const iter_mulr_1 -rmorph_prod/= coefCM coefXn.
under eq_bigr => i _ do rewrite (tnth_nth 0)/=.
rewrite -[#|I| == _](eqn_add2r n) subnK//.
rewrite -[X in (_ + _)%N == X]card_ord -(cardC I) eqn_add2l.
by case: ifP; rewrite ?mulr1 ?mulr0.
by rewrite -big_mkcond mulr_sumr/=; apply: eq_bigr => I /eqP <-; rewrite prodrN.
Qed.
Lemma coefPn_prod_XsubC (ps : seq R) : size ps != 0 ->
(\prod_(p <- ps) ('X - p%:P))`_(size ps).-1 =
- \sum_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC ?leq_pred// => ps0.
have -> : (size ps - (size ps).-1 = 1)%N.
by move: ps0; case: (size ps) => // n _; exact: subSnn.
rewrite expr1 mulN1r; congr GRing.opp.
set f : 'I_(size ps) -> {set 'I_(size ps)} := fun a => [set a].
transitivity (\sum_(I in imset f (mem setT)) \prod_(i in I) ps`_i).
apply: congr_big => // I /=.
by apply/cards1P/imsetP => [[a ->] | [a _ ->]]; exists a.
rewrite big_imset/=; last first.
by move=> i j _ _ ij; apply/set1P; rewrite -/(f j) -ij set11.
rewrite -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite big_set1 (tnth_nth 0).
Qed.
Lemma coef0_prod_XsubC (ps : seq R) :
(\prod_(p <- ps) ('X - p%:P))`_0 =
(-1) ^+ (size ps) * \prod_(p <- ps) p.
Proof.
rewrite coef_prod_XsubC// subn0; congr GRing.mul.
transitivity (\sum_(I in [set setT : {set 'I_(size ps)}]) \prod_(i in I) ps`_i).
apply: congr_big =>// i/=.
apply/idP/set1P => [/eqP cardE | ->]; last by rewrite cardsT card_ord.
by apply/eqP; rewrite eqEcard subsetT cardsT card_ord cardE leqnn.
rewrite big_set1 -[in RHS](in_tupleE ps) -(map_tnth_enum (_ ps)) big_map enumT.
apply: congr_big => // i; first exact: in_setT.
by rewrite (tnth_nth 0).
Qed.
Lemma hornerM p q x : (p * q).[x] = p.[x] * q.[x].
Proof. by rewrite hornerM_comm //; apply: mulrC. Qed.
Lemma horner_exp p x n : (p ^+ n).[x] = p.[x] ^+ n.
Proof. by rewrite horner_exp_comm //; apply: mulrC. Qed.
Lemma horner_prod I r (P : pred I) (F : I -> {poly R}) x :
(\prod_(i <- r | P i) F i).[x] = \prod_(i <- r | P i) (F i).[x].
Proof. by elim/big_rec2: _ => [|i _ p _ <-]; rewrite (hornerM, hornerC). Qed.
Definition hornerE :=
(hornerD, hornerN, hornerX, hornerC, horner_exp,
simp, hornerCM, hornerZ, hornerM, horner_cons).
Definition horner_eval (x : R) := horner^~ x.
Lemma horner_evalE x p : horner_eval x p = p.[x]. Proof. by []. Qed.
Fact horner_eval_is_linear x : linear_for *%R (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by move=> c p q; rewrite !evalE linearP.
Qed.
Fact horner_eval_is_monoid_morphism x : monoid_morphism (horner_eval x).
Proof.
have cxid: commr_rmorph idfun x by apply: mulrC.
have evalE : horner_eval x =1 horner_morph cxid.
by move=> p; congr _.[x]; rewrite map_poly_id.
by split=> [|p q]; rewrite !evalE ?rmorph1// rmorphM.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `horner_eval_is_monoid_morphism` instead")]
Definition horner_eval_is_multiplicative x :=
(fun g => (g.2, g.1)) (horner_eval_is_monoid_morphism x).
HB.instance Definition _ x :=
GRing.isSemilinear.Build R {poly R} R _ (horner_eval x)
(GRing.semilinear_linear (horner_eval_is_linear x)).
HB.instance Definition _ x :=
GRing.isMonoidMorphism.Build {poly R} R (horner_eval x)
(horner_eval_is_monoid_morphism x).
Section HornerAlg.
Variable A : algType R. (* For univariate polys, commutativity is not needed *)
Section Defs.
Variable a : A.
Lemma in_alg_comm : commr_rmorph (in_alg A) a.
Proof. move=> r /=; by rewrite /GRing.comm comm_alg. Qed.
Definition horner_alg := horner_morph in_alg_comm.
Lemma horner_algC c : horner_alg c%:P = c%:A.
Proof. exact: horner_morphC. Qed.
Lemma horner_algX : horner_alg 'X = a.
Proof. exact: horner_morphX. Qed.
HB.instance Definition _ := GRing.LRMorphism.on horner_alg.
End Defs.
Variable (pf : {lrmorphism {poly R} -> A}).
Lemma poly_alg_initial : pf =1 horner_alg (pf 'X).
Proof.
apply: poly_ind => [|p a IHp]; first by rewrite !rmorph0.
rewrite !rmorphD !rmorphM /= -{}IHp horner_algC ?horner_algX.
by rewrite -alg_polyC rmorph_alg.
Qed.
End HornerAlg.
Fact comp_poly_is_monoid_morphism q : monoid_morphism (comp_poly q).
Proof.
split=> [|p1 p2]; first by rewrite comp_polyC.
by rewrite /comp_poly rmorphM hornerM_comm //; apply: mulrC.
Qed.
#[deprecated(since="mathcomp 2.5.0",
note="use `comp_poly_is_monoid_morphism` instead")]
Definition comp_poly_multiplicative q :=
(fun g => (g.2, g.1)) (comp_poly_is_monoid_morphism q).
HB.instance Definition _ q := GRing.isMonoidMorphism.Build _ _ (comp_poly q)
(comp_poly_is_monoid_morphism q).
Lemma comp_polyM p q r : (p * q) \Po r = (p \Po r) * (q \Po r).
Proof. exact: rmorphM. Qed.
Lemma comp_polyA p q r : p \Po (q \Po r) = (p \Po q) \Po r.
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !comp_polyC.
by rewrite !comp_polyD !comp_polyM !comp_polyX IHp !comp_polyC.
Qed.
Lemma horner_comp p q x : (p \Po q).[x] = p.[q.[x]].
Proof. by apply: polyC_inj; rewrite -!comp_polyCr comp_polyA. Qed.
Lemma root_comp p q x : root (p \Po q) x = root p (q.[x]).
Proof. by rewrite !rootE horner_comp. Qed.
Lemma deriv_comp p q : (p \Po q) ^`() = (p ^`() \Po q) * q^`().
Proof.
elim/poly_ind: p => [|p c IHp]; first by rewrite !(deriv0, comp_poly0) mul0r.
rewrite comp_poly_MXaddC derivD derivC derivM IHp derivMXaddC comp_polyD.
by rewrite comp_polyM comp_polyX addr0 addrC mulrAC -mulrDl.
Qed.
Lemma deriv_exp p n : (p ^+ n)^`() = p^`() * p ^+ n.-1 *+ n.
Proof.
elim: n => [|n IHn]; first by rewrite expr0 mulr0n derivC.
by rewrite exprS derivM {}IHn (mulrC p) mulrnAl -mulrA -exprSr mulrS; case n.
Qed.
Definition derivCE := (derivE, deriv_exp).
End PolynomialComNzRing.
Section PolynomialIdomain.
(* Integral domain structure on poly *)
Variable R : idomainType.
Implicit Types (a b x y : R) (p q r m : {poly R}).
Lemma size_mul p q : p != 0 -> q != 0 -> size (p * q) = (size p + size q).-1.
Proof.
by move=> nz_p nz_q; rewrite -size_proper_mul ?mulf_neq0 ?lead_coef_eq0.
Qed.
Fact poly_idomainAxiom p q : p * q = 0 -> (p == 0) || (q == 0).
Proof.
move=> pq0; apply/norP=> [[p_nz q_nz]]; move/eqP: (size_mul p_nz q_nz).
by rewrite eq_sym pq0 size_poly0 (polySpred p_nz) (polySpred q_nz) addnS.
Qed.
Definition poly_unit : pred {poly R} :=
fun p => (size p == 1) && (p`_0 \in GRing.unit).
Definition poly_inv p := if p \in poly_unit then (p`_0)^-1%:P else p.
Fact poly_mulVp : {in poly_unit, left_inverse 1 poly_inv *%R}.
Proof.
move=> p Up; rewrite /poly_inv Up.
by case/andP: Up => /size_poly1P[c _ ->]; rewrite coefC -polyCM => /mulVr->.
Qed.
Fact poly_intro_unit p q : q * p = 1 -> p \in poly_unit.
Proof.
move=> pq1; apply/andP; split; last first.
apply/unitrP; exists q`_0.
by rewrite 2!mulrC -!/(coefp 0 _) -rmorphM pq1 rmorph1.
have: size (q * p) == 1 by rewrite pq1 size_poly1.
have [-> | nz_p] := eqVneq p 0; first by rewrite mulr0 size_poly0.
have [-> | nz_q] := eqVneq q 0; first by rewrite mul0r size_poly0.
rewrite size_mul // (polySpred nz_p) (polySpred nz_q) addnS addSn !eqSS.
by rewrite addn_eq0 => /andP[].
Qed.
Fact poly_inv_out : {in [predC poly_unit], poly_inv =1 id}.
Proof. by rewrite /poly_inv => p /negbTE/= ->. Qed.
HB.instance Definition _ := GRing.ComNzRing_hasMulInverse.Build (polynomial R)
poly_mulVp poly_intro_unit poly_inv_out.
HB.instance Definition _ := GRing.ComUnitRing_isIntegral.Build (polynomial R)
poly_idomainAxiom.
Lemma poly_unitE p :
(p \in GRing.unit) = (size p == 1) && (p`_0 \in GRing.unit).
Proof. by []. Qed.
Lemma poly_invE p : p ^-1 = if p \in GRing.unit then (p`_0)^-1%:P else p.
Proof. by []. Qed.
Lemma polyCV c : c%:P^-1 = (c^-1)%:P.
Proof.
have [/rmorphV-> // | nUc] := boolP (c \in GRing.unit).
by rewrite !invr_out // poly_unitE coefC (negbTE nUc) andbF.
Qed.
Lemma rootM p q x : root (p * q) x = root p x || root q x.
Proof. by rewrite !rootE hornerM mulf_eq0. Qed.
Lemma rootZ x a p : a != 0 -> root (a *: p) x = root p x.
Proof. by move=> nz_a; rewrite -mul_polyC rootM rootC (negPf nz_a). Qed.
Lemma root_exp p n a: comm_poly p a -> (0 < n)%N -> root (p ^+ n) a = root p a.
Proof. by move=> ? n0; rewrite !rootE horner_exp_comm// expf_eq0 n0. Qed.
Lemma size_scale a p : a != 0 -> size (a *: p) = size p.
Proof. by move/lregP/lreg_size->. Qed.
Lemma size_Cmul a p : a != 0 -> size (a%:P * p) = size p.
Proof. by rewrite mul_polyC => /size_scale->. Qed.
Lemma lead_coefM p q : lead_coef (p * q) = lead_coef p * lead_coef q.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(mul0r, lead_coef0).
have [-> | nz_q] := eqVneq q 0; first by rewrite !(mulr0, lead_coef0).
by rewrite lead_coef_proper_mul // mulf_neq0 ?lead_coef_eq0.
Qed.
Lemma lead_coef_prod I rI (P : {pred I}) (p : I -> {poly R}) :
lead_coef (\prod_(i <- rI | P i) p i) = \prod_(i <- rI | P i) lead_coef (p i).
Proof. by apply/big_morph/lead_coef1; apply: lead_coefM. Qed.
Lemma lead_coefZ a p : lead_coef (a *: p) = a * lead_coef p.
Proof. by rewrite -mul_polyC lead_coefM lead_coefC. Qed.
Lemma scale_poly_eq0 a p : (a *: p == 0) = (a == 0) || (p == 0).
Proof. by rewrite -mul_polyC mulf_eq0 polyC_eq0. Qed.
Lemma size_prod (I : finType) (P : pred I) (F : I -> {poly R}) :
(forall i, P i -> F i != 0) ->
size (\prod_(i | P i) F i) = ((\sum_(i | P i) size (F i)).+1 - #|P|)%N.
Proof.
move=> nzF; transitivity (\sum_(i | P i) (size (F i)).-1).+1; last first.
apply: canRL (addKn _) _; rewrite addnS -sum1_card -big_split /=.
by congr _.+1; apply: eq_bigr => i /nzF/polySpred.
elim/big_rec2: _ => [|i d p /nzF nzFi IHp]; first by rewrite size_poly1.
by rewrite size_mul // -?size_poly_eq0 IHp // addnS polySpred.
Qed.
Lemma size_prod_seq (I : eqType) (s : seq I) (F : I -> {poly R}) :
(forall i, i \in s -> F i != 0) ->
size (\prod_(i <- s) F i) = ((\sum_(i <- s) size (F i)).+1 - size s)%N.
Proof.
move=> nzF; rewrite big_tnth size_prod; last by move=> i; rewrite nzF ?mem_tnth.
by rewrite cardT /= size_enum_ord [in RHS]big_tnth.
Qed.
Lemma size_mul_eq1 p q : (size (p * q) == 1) = ((size p == 1) && (size q == 1)).
Proof.
have [->|pNZ] := eqVneq p 0; first by rewrite mul0r size_poly0.
have [->|qNZ] := eqVneq q 0; first by rewrite mulr0 size_poly0 andbF.
rewrite size_mul //.
by move: pNZ qNZ; rewrite -!size_poly_gt0; (do 2 case: size) => //= n [|[|]].
Qed.
Lemma size_prod_seq_eq1 (I : eqType) (s : seq I) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i && (i \in s) -> size (F i) = 1)
(size (\prod_(i <- s | P i) F i) == 1%N).
Proof.
rewrite (big_morph _ (id1:=true) size_mul_eq1) ?size_polyC ?oner_neq0//.
rewrite big_all_cond; apply/(iffP allP).
by move=> h i /andP[Pi ins]; apply/eqP/(implyP (h i ins) Pi).
by move=> h i ins; apply/implyP => Pi; rewrite h ?Pi.
Qed.
Lemma size_prod_eq1 (I : finType) (P : pred I) (F : I -> {poly R}) :
reflect (forall i, P i -> size (F i) = 1)
(size (\prod_(i | P i) F i) == 1).
Proof.
apply: (iffP (size_prod_seq_eq1 _ _ _)) => Hi i.
by move=> Pi; apply: Hi; rewrite Pi /= mem_index_enum.
by rewrite mem_index_enum andbT; apply: Hi.
Qed.
Lemma size_exp p n : (size (p ^+ n)).-1 = ((size p).-1 * n)%N.
Proof.
elim: n => [|n IHn]; first by rewrite size_poly1 muln0.
have [-> | nz_p] := eqVneq p 0; first by rewrite exprS mul0r size_poly0.
rewrite exprS size_mul ?expf_neq0 // mulnS -{}IHn.
by rewrite polySpred // [size (p ^+ n)]polySpred ?expf_neq0 ?addnS.
Qed.
Lemma lead_coef_exp p n : lead_coef (p ^+ n) = lead_coef p ^+ n.
Proof.
elim: n => [|n IHn]; first by rewrite !expr0 lead_coef1.
by rewrite !exprS lead_coefM IHn.
Qed.
Lemma root_prod_XsubC rs x :
root (\prod_(a <- rs) ('X - a%:P)) x = (x \in rs).
Proof.
elim: rs => [|a rs IHrs]; first by rewrite rootE big_nil hornerC oner_eq0.
by rewrite big_cons rootM IHrs root_XsubC.
Qed.
Lemma root_exp_XsubC n a x : root (('X - a%:P) ^+ n.+1) x = (x == a).
Proof. by rewrite rootE horner_exp expf_eq0 [_ == 0]root_XsubC. Qed.
Lemma size_comp_poly p q :
(size (p \Po q)).-1 = ((size p).-1 * (size q).-1)%N.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite comp_poly0 size_poly0.
have [/size1_polyC-> | nc_q] := leqP (size q) 1.
by rewrite comp_polyCr !size_polyC -!sub1b -!subnS muln0.
have nz_q: q != 0 by rewrite -size_poly_eq0 -(subnKC nc_q).
rewrite mulnC comp_polyE (polySpred nz_p) /= big_ord_recr /= addrC.
rewrite size_polyDl size_scale ?lead_coef_eq0 ?size_exp //=.
rewrite [ltnRHS]polySpred ?expf_neq0 // ltnS size_exp.
rewrite (leq_trans (size_sum _ _ _)) //; apply/bigmax_leqP => i _.
rewrite (leq_trans (size_scale_leq _ _)) // polySpred ?expf_neq0 //.
by rewrite size_exp -(subnKC nc_q) ltn_pmul2l.
Qed.
Lemma lead_coef_comp p q : size q > 1 ->
lead_coef (p \Po q) = (lead_coef p) * lead_coef q ^+ (size p).-1.
Proof.
move=> q_gt1; rewrite !lead_coefE coef_comp_poly size_comp_poly.
have [->|nz_p] := eqVneq p 0; first by rewrite size_poly0 big_ord0 coef0 mul0r.
rewrite polySpred //= big_ord_recr /= big1 ?add0r => [|i _].
by rewrite -!lead_coefE -lead_coef_exp !lead_coefE size_exp mulnC.
rewrite [X in _ * X]nth_default ?mulr0 ?(leq_trans (size_poly_exp_leq _ _)) //.
by rewrite mulnC ltn_mul2r -subn1 subn_gt0 q_gt1 /=.
Qed.
Lemma comp_poly_eq0 p q : size q > 1 -> (p \Po q == 0) = (p == 0).
Proof.
move=> sq_gt1; rewrite -!lead_coef_eq0 lead_coef_comp //.
rewrite mulf_eq0 expf_eq0 !lead_coef_eq0 -[q == 0]size_poly_leq0.
by rewrite [_ <= 0]leqNgt (leq_ltn_trans _ sq_gt1) ?andbF ?orbF.
Qed.
Lemma size_comp_poly2 p q : size q = 2 -> size (p \Po q) = size p.
Proof.
move=> sq2; have [->|pN0] := eqVneq p 0; first by rewrite comp_polyC.
by rewrite polySpred ?size_comp_poly ?comp_poly_eq0 ?sq2 // muln1 polySpred.
Qed.
Lemma comp_poly2_eq0 p q : size q = 2 -> (p \Po q == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 => /size_comp_poly2->. Qed.
Theorem max_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq rs -> size rs < size p.
Proof.
elim: rs p => [p pn0 _ _ | r rs ihrs p pn0] /=; first by rewrite size_poly_gt0.
case/andP => rpr arrs /andP [rnrs urs]; case/factor_theorem: rpr => q epq.
have [q0 | ?] := eqVneq q 0; first by move: pn0; rewrite epq q0 mul0r eqxx.
have -> : size p = (size q).+1.
by rewrite epq size_Mmonic ?monicXsubC // size_XsubC addnC.
suff /eq_in_all h : {in rs, root q =1 root p} by apply: ihrs => //; rewrite h.
move=> x xrs; rewrite epq rootM root_XsubC orbC; case: (eqVneq x r) => // exr.
by move: rnrs; rewrite -exr xrs.
Qed.
Lemma roots_geq_poly_eq0 p (rs : seq R) : all (root p) rs -> uniq rs ->
(size rs >= size p)%N -> p = 0.
Proof. by move=> ??; apply: contraTeq => ?; rewrite leqNgt max_poly_roots. Qed.
End PolynomialIdomain.
(* FIXME: these are seamingly artificial ways to close the inheritance graph *)
(* We make parameters more and more precise to trigger completion by HB *)
HB.instance Definition _ (R : countNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countComNzRingType) :=
[Countable of polynomial R by <:].
HB.instance Definition _ (R : countIdomainType) :=
[Countable of polynomial R by <:].
Section MapFieldPoly.
Variables (F : fieldType) (R : nzRingType) (f : {rmorphism F -> R}).
Local Notation "p ^f" := (map_poly f p) : ring_scope.
Lemma size_map_poly p : size p^f = size p.
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite rmorph0 !size_poly0.
by rewrite size_poly_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma lead_coef_map p : lead_coef p^f = f (lead_coef p).
Proof.
have [-> | nz_p] := eqVneq p 0; first by rewrite !(rmorph0, lead_coef0).
by rewrite lead_coef_map_eq // fmorph_eq0 // lead_coef_eq0.
Qed.
Lemma map_poly_eq0 p : (p^f == 0) = (p == 0).
Proof. by rewrite -!size_poly_eq0 size_map_poly. Qed.
Lemma map_poly_inj : injective (map_poly f).
Proof.
move=> p q eqfpq; apply/eqP; rewrite -subr_eq0 -map_poly_eq0.
by rewrite rmorphB /= eqfpq subrr.
Qed.
Lemma map_monic p : (p^f \is monic) = (p \is monic).
Proof. by rewrite [in LHS]monicE lead_coef_map fmorph_eq1. Qed.
Lemma map_poly_com p x : comm_poly p^f (f x).
Proof. exact: map_comm_poly (mulrC x _). Qed.
Lemma fmorph_root p x : root p^f (f x) = root p x.
Proof. by rewrite rootE horner_map // fmorph_eq0. Qed.
Lemma fmorph_unity_root n z : n.-unity_root (f z) = n.-unity_root z.
Proof. by rewrite !unity_rootE -(inj_eq (fmorph_inj f)) rmorphXn ?rmorph1. Qed.
Lemma fmorph_primitive_root n z :
n.-primitive_root (f z) = n.-primitive_root z.
Proof.
by congr (_ && _); apply: eq_forallb => i; rewrite fmorph_unity_root.
Qed.
End MapFieldPoly.
Arguments map_poly_inj {F R} f [p1 p2] : rename.
Section MaxRoots.
Variable R : unitRingType.
Implicit Types (x y : R) (rs : seq R) (p : {poly R}).
Definition diff_roots (x y : R) := (x * y == y * x) && (y - x \in GRing.unit).
Fixpoint uniq_roots rs :=
if rs is x :: rs' then all (diff_roots x) rs' && uniq_roots rs' else true.
Lemma uniq_roots_prod_XsubC p rs :
all (root p) rs -> uniq_roots rs ->
exists q, p = q * \prod_(z <- rs) ('X - z%:P).
Proof.
elim: rs => [|z rs IHrs] /=; first by rewrite big_nil; exists p; rewrite mulr1.
case/andP=> rpz rprs /andP[drs urs]; case: IHrs => {urs rprs}// q def_p.
have [|q' def_q] := factor_theorem q z _; last first.
by exists q'; rewrite big_cons mulrA -def_q.
rewrite {p}def_p in rpz.
elim/last_ind: rs drs rpz => [|rs t IHrs] /=; first by rewrite big_nil mulr1.
rewrite all_rcons => /andP[/andP[/eqP czt Uzt] /IHrs{}IHrs].
rewrite -cats1 big_cat big_seq1 /= mulrA rootE hornerM_comm; last first.
by rewrite /comm_poly hornerXsubC mulrBl mulrBr czt.
rewrite hornerXsubC -opprB mulrN oppr_eq0 -(mul0r (t - z)).
by rewrite (inj_eq (mulIr Uzt)) => /IHrs.
Qed.
Theorem max_ring_poly_roots p rs :
p != 0 -> all (root p) rs -> uniq_roots rs -> size rs < size p.
Proof.
move=> nz_p _ /(@uniq_roots_prod_XsubC p)[// | q def_p]; rewrite def_p in nz_p *.
have nz_q: q != 0 by apply: contraNneq nz_p => ->; rewrite mul0r.
rewrite size_Mmonic ?monic_prod_XsubC // (polySpred nz_q) addSn /=.
by rewrite size_prod_XsubC leq_addl.
Qed.
Lemma all_roots_prod_XsubC p rs :
size p = (size rs).+1 -> all (root p) rs -> uniq_roots rs ->
p = lead_coef p *: \prod_(z <- rs) ('X - z%:P).
Proof.
move=> size_p /uniq_roots_prod_XsubC def_p Urs.
case/def_p: Urs => q -> {p def_p} in size_p *.
have [q0 | nz_q] := eqVneq q 0; first by rewrite q0 mul0r size_poly0 in size_p.
have{q nz_q size_p} /size_poly1P[c _ ->]: size q == 1.
rewrite -(eqn_add2r (size rs)) add1n -size_p.
by rewrite size_Mmonic ?monic_prod_XsubC // size_prod_XsubC addnS.
by rewrite lead_coef_Mmonic ?monic_prod_XsubC // lead_coefC mul_polyC.
Qed.
End MaxRoots.
Section FieldRoots.
Variable F : fieldType.
Implicit Types (p : {poly F}) (rs : seq F).
Lemma poly2_root p : size p = 2 -> {r | root p r}.
Proof.
case: p => [[|p0 [|p1 []]] //= nz_p1]; exists (- p0 / p1).
by rewrite /root addr_eq0 /= mul0r add0r mulrC divfK ?opprK.
Qed.
Lemma uniq_rootsE rs : uniq_roots rs = uniq rs.
Proof.
elim: rs => //= r rs ->; congr (_ && _); rewrite -has_pred1 -all_predC.
by apply: eq_all => t; rewrite /diff_roots mulrC eqxx unitfE subr_eq0.
Qed.
Lemma root_ZXsubC (a b r : F) : a != 0 ->
root (a *: 'X - b%:P) r = (r == b / a).
Proof.
move=> a0; rewrite rootE !hornerE.
by rewrite -[r in RHS]divr1 eqr_div ?oner_neq0// mulr1 mulrC subr_eq0.
Qed.
Section UnityRoots.
Variable n : nat.
Lemma max_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs <= n.
Proof.
move=> n_gt0 rs_n_1 Urs; have szPn := size_XnsubC (1 : F) n_gt0.
by rewrite -ltnS -szPn max_poly_roots -?size_poly_eq0 ?szPn.
Qed.
Lemma mem_unity_roots rs :
n > 0 -> all n.-unity_root rs -> uniq rs -> size rs = n ->
n.-unity_root =i rs.
Proof.
move=> n_gt0 rs_n_1 Urs sz_rs_n x; rewrite -topredE /=.
apply/idP/idP=> xn1; last exact: (allP rs_n_1).
apply: contraFT (ltnn n) => not_rs_x.
by rewrite -{1}sz_rs_n (@max_unity_roots (x :: rs)) //= ?xn1 ?not_rs_x.
Qed.
(* Showing the existence of a primitive root requires the theory in cyclic. *)
Variable z : F.
Hypothesis prim_z : n.-primitive_root z.
Let zn := [seq z ^+ i | i <- index_iota 0 n].
Lemma factor_Xn_sub_1 : \prod_(0 <= i < n) ('X - (z ^+ i)%:P) = 'X^n - 1.
Proof.
transitivity (\prod_(w <- zn) ('X - w%:P)); first by rewrite big_map.
have n_gt0: n > 0 := prim_order_gt0 prim_z.
rewrite (@all_roots_prod_XsubC _ ('X^n - 1) zn); first 1 last.
- by rewrite size_XnsubC // size_map size_iota subn0.
- apply/allP=> _ /mapP[i _ ->] /=; rewrite rootE !hornerE.
by rewrite exprAC (prim_expr_order prim_z) expr1n subrr.
- rewrite uniq_rootsE map_inj_in_uniq ?iota_uniq // => i j.
rewrite !mem_index_iota => ltin ltjn /eqP.
by rewrite (eq_prim_root_expr prim_z) !modn_small // => /eqP.
by rewrite (monicP (monicXnsubC 1 n_gt0)) scale1r.
Qed.
Lemma prim_rootP x : x ^+ n = 1 -> {i : 'I_n | x = z ^+ i}.
Proof.
move=> xn1; pose logx := [pred i : 'I_n | x == z ^+ i].
case: (pickP logx) => [i /eqP-> | no_i]; first by exists i.
case: notF; suffices{no_i}: x \in zn.
case/mapP=> i; rewrite mem_index_iota => lt_i_n def_x.
by rewrite -(no_i (Ordinal lt_i_n)) /= -def_x.
rewrite -root_prod_XsubC big_map factor_Xn_sub_1.
by rewrite [root _ x]unity_rootE xn1.
Qed.
End UnityRoots.
End FieldRoots.
Section MapPolyRoots.
Variables (F : fieldType) (R : unitRingType) (f : {rmorphism F -> R}).
Lemma map_diff_roots x y : diff_roots (f x) (f y) = (x != y).
Proof.
rewrite /diff_roots -rmorphB // fmorph_unit // subr_eq0 //.
by rewrite rmorph_comm // eqxx eq_sym.
Qed.
Lemma map_uniq_roots s : uniq_roots (map f s) = uniq s.
Proof.
elim: s => //= x s ->; congr (_ && _); elim: s => //= y s ->.
by rewrite map_diff_roots -negb_or.
Qed.
End MapPolyRoots.
Section AutPolyRoot.
(* The action of automorphisms on roots of unity. *)
Variable F : fieldType.
Implicit Types u v : {rmorphism F -> F}.
Lemma aut_prim_rootP u z n :
n.-primitive_root z -> {k | coprime k n & u z = z ^+ k}.
Proof.
move=> prim_z; have:= prim_z; rewrite -(fmorph_primitive_root u) => prim_uz.
have [[k _] /= def_uz] := prim_rootP prim_z (prim_expr_order prim_uz).
by exists k; rewrite // -(prim_root_exp_coprime _ prim_z) -def_uz.
Qed.
Lemma aut_unity_rootP u z n : n > 0 -> z ^+ n = 1 -> {k | u z = z ^+ k}.
Proof.
by move=> _ /prim_order_exists[// | m /(aut_prim_rootP u)[k]]; exists k.
Qed.
Lemma aut_unity_rootC u v z n : n > 0 -> z ^+ n = 1 -> u (v z) = v (u z).
Proof.
move=> n_gt0 /(aut_unity_rootP _ n_gt0) def_z.
have [[i def_uz] [j def_vz]] := (def_z u, def_z v).
by rewrite def_vz def_uz !rmorphXn /= def_vz def_uz exprAC.
Qed.
End AutPolyRoot.
Module UnityRootTheory.
Notation "n .-unity_root" := (root_of_unity n) : unity_root_scope.
Notation "n .-primitive_root" := (primitive_root_of_unity n) : unity_root_scope.
Open Scope unity_root_scope.
Definition unity_rootE := unity_rootE.
Definition unity_rootP := @unity_rootP.
Arguments unity_rootP {R n z}.
Definition prim_order_exists := prim_order_exists.
Notation prim_order_gt0 := prim_order_gt0.
Notation prim_expr_order := prim_expr_order.
Definition prim_expr_mod := prim_expr_mod.
Definition prim_order_dvd := prim_order_dvd.
Definition eq_prim_root_expr := eq_prim_root_expr.
Definition rmorph_unity_root := rmorph_unity_root.
Definition fmorph_unity_root := fmorph_unity_root.
Definition fmorph_primitive_root := fmorph_primitive_root.
Definition max_unity_roots := max_unity_roots.
Definition mem_unity_roots := mem_unity_roots.
Definition prim_rootP := prim_rootP.
End UnityRootTheory.
Module Export Pdeg2.
Module Export Field.
Section Pdeg2Field.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
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 a2neq0 : 2 * a != 0. Proof. by rewrite mulf_neq0. Qed.
Let sqa2neq0 : (2 * a) ^+ 2 != 0. Proof. exact: expf_neq0. Qed.
Let aa4 : 4 * a * a = (2 * a)^+2.
Proof. by rewrite expr2 mulrACA mulrA -natrM. Qed.
Let splitr (x : F) : x = x / 2 + x / 2.
Proof.
by apply: (mulIf nz2); rewrite -mulrDl mulfVK// mulr_natr mulr2n.
Qed.
Let pE : p = a *: 'X^2 + b *: 'X + c%:P.
Proof.
apply/polyP => + /[!coefE] => -[|[|[|i]]] /=; rewrite !Monoid.simpm//.
by rewrite nth_default// degp.
Qed.
Let delta := b ^+ 2 - 4 * a * c.
Lemma deg2_poly_canonical :
p = a *: (('X + (b / (2 * a))%:P)^+2 - (delta / (4 * a ^+ 2))%:P).
Proof.
rewrite pE sqrrD -!addrA scalerDr; congr +%R; rewrite addrA scalerDr; congr +%R.
- rewrite -mulrDr -polyCD -!mul_polyC mulrA mulrAC -polyCM.
by rewrite [a * _]mulrC mulrDl invfM -!mulrA mulVf// mulr1 -splitr.
- rewrite [a ^+ 2]expr2 mulrA aa4 -polyC_exp -polyCB expr_div_n -mulrBl subKr.
by rewrite scale_polyC mulrCA mulrACA aa4 mulrCA mulfV// mulr1.
Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / (2 * a).
Let r2 := (- b + r) / (2 * a).
Lemma deg2_poly_factor : p = a *: ('X - r1%:P) * ('X - r2%:P).
Proof.
rewrite [p]deg2_poly_canonical//= -/a -/b -/c -/delta /r1 /r2.
rewrite ![(- b + _) * _]mulrDl 2!polyCD 2!opprD 2!addrA !mulNr !polyCN !opprK.
rewrite -scalerAl [in RHS]mulrC -subr_sqr -polyC_exp -[4]/(2 * 2)%:R natrM.
by rewrite -expr2 -exprMn [in RHS]exprMn exprVn r_sqrt_delta.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r2%:P)); rewrite deg2_poly_factor -!scalerAl mulrC.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
apply/factor_theorem.
by exists (a *: ('X - r1%:P)); rewrite deg2_poly_factor -!scalerAl.
Qed.
End Pdeg2Field.
End Field.
Module FieldMonic.
Section Pdeg2FieldMonic.
Variable F : fieldType.
Hypothesis nz2 : 2 != 0 :> F.
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 a1 : a = 1. Proof. by move: (monicP monicp); rewrite lead_coefE degp. Qed.
Let delta := b ^+ 2 - 4 * c.
Lemma deg2_poly_canonical : p = (('X + (b / 2)%:P)^+2 - (delta / 4)%:P).
Proof. by rewrite [p]deg2_poly_canonical// -/a a1 scale1r expr1n !mulr1. Qed.
Variable r : F.
Hypothesis r_sqrt_delta : r ^+ 2 = delta.
Let r1 := (- b - r) / 2.
Let r2 := (- b + r) / 2.
Lemma deg2_poly_factor : p = ('X - r1%:P) * ('X - r2%:P).
Proof.
by rewrite [p](@deg2_poly_factor _ _ _ _ r)// -/a a1 !mulr1 ?scale1r.
Qed.
Lemma deg2_poly_root1 : root p r1.
Proof.
rewrite /r1 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root1; rewrite // -/a a1 mulr1.
Qed.
Lemma deg2_poly_root2 : root p r2.
Proof.
rewrite /r2 -[2]mulr1 -[X in 2 * X]a1.
by apply: deg2_poly_root2; rewrite // -/a a1 mulr1.
Qed.
End Pdeg2FieldMonic.
End FieldMonic.
End Pdeg2.
Section DecField.
Variable F : decFieldType.
Lemma dec_factor_theorem (p : {poly F}) :
{s : seq F & {q : {poly F} | p = q * \prod_(x <- s) ('X - x%:P)
/\ (q != 0 -> forall x, ~~ root q x)}}.
Proof.
pose polyT (p : seq F) := (foldr (fun c f => f * 'X_0 + c%:T) (0%R)%:T p)%T.
have eval_polyT (q : {poly F}) x : GRing.eval [:: x] (polyT q) = q.[x].
by rewrite /horner; elim: (val q) => //= ? ? ->.
have [n] := ubnP (size p); elim: n => // n IHn in p *.
have /decPcases /= := @satP F [::] ('exists 'X_0, polyT p == 0%T).
case: ifP => [_ /sig_eqW[x]|_ noroot]; last first.
exists [::], p; rewrite big_nil mulr1; split => // p_neq0 x.
by apply/negP=> /rootP rpx; apply: noroot; exists x; rewrite eval_polyT.
rewrite eval_polyT => /rootP/factor_theorem/sig_eqW[p1 ->].
have [->|nz_p1] := eqVneq p1 0; first by exists [::], 0; rewrite !mul0r eqxx.
rewrite size_Mmonic ?monicXsubC // size_XsubC addn2 => /IHn[s [q [-> irr_q]]].
by exists (rcons s x), q; rewrite -cats1 big_cat big_seq1 mulrA.
Qed.
End DecField.
Module PreClosedField.
Section UseAxiom.
Variable F : fieldType.
Hypothesis closedF : GRing.closed_field_axiom F.
Implicit Type p : {poly F}.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof.
have [-> | nz_p] := eqVneq p 0.
by rewrite size_poly0; left; exists 0; rewrite root0.
rewrite neq_ltn [in _ < 1]polySpred //=.
apply: (iffP idP) => [p_gt1 | [a]]; last exact: root_size_gt1.
pose n := (size p).-1; have n_gt0: n > 0 by rewrite -ltnS -polySpred.
have [a Dan] := closedF (fun i => - p`_i / lead_coef p) n_gt0.
exists a; apply/rootP; rewrite horner_coef polySpred // big_ord_recr /= -/n.
rewrite {}Dan mulr_sumr -big_split big1 //= => i _.
by rewrite -!mulrA mulrCA mulNr mulVKf ?subrr ?lead_coef_eq0.
Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof.
apply: (iffP idP) => [nz_p | [x]]; last first.
by apply: contraNneq => ->; apply: root0.
have [[x /rootP p1x0]|] := altP (closed_rootP (p - 1)).
by exists x; rewrite -[p](subrK 1) /root hornerD p1x0 add0r hornerC oner_eq0.
rewrite negbK => /size_poly1P[c _ /(canRL (subrK 1)) Dp].
by exists 0; rewrite Dp -raddfD polyC_eq0 rootC in nz_p *.
Qed.
End UseAxiom.
End PreClosedField.
Section ClosedField.
Variable F : closedFieldType.
Implicit Type p : {poly F}.
Let closedF := @solve_monicpoly F.
Lemma closed_rootP p : reflect (exists x, root p x) (size p != 1).
Proof. exact: PreClosedField.closed_rootP. Qed.
Lemma closed_nonrootP p : reflect (exists x, ~~ root p x) (p != 0).
Proof. exact: PreClosedField.closed_nonrootP. Qed.
Lemma closed_field_poly_normal p :
{r : seq F | p = lead_coef p *: \prod_(z <- r) ('X - z%:P)}.
Proof.
apply: sig_eqW; have [r [q [->]]] /= := dec_factor_theorem p.
have [->|] := eqVneq; first by exists [::]; rewrite mul0r lead_coef0 scale0r.
have [[x rqx ? /(_ isT x) /negP /(_ rqx)] //|] := altP (closed_rootP q).
rewrite negbK => /size_poly1P [c c_neq0-> _ _]; exists r.
rewrite mul_polyC lead_coefZ (monicP _) ?mulr1 //.
by rewrite monic_prod => // i; rewrite monicXsubC.
Qed.
End ClosedField.
|
Dist.lean
|
/-
Copyright (c) 2014 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn, Jeremy Avigad
-/
import Mathlib.Algebra.Order.Group.Nat
import Mathlib.Algebra.Order.Ring.Canonical
/-!
# Distance function on β
This file defines a simple distance function on naturals from truncated subtraction.
-/
namespace Nat
/-- Distance (absolute value of difference) between natural numbers. -/
def dist (n m : β) :=
n - m + (m - n)
theorem dist_comm (n m : β) : dist n m = dist m n := by simp [dist, add_comm]
@[simp]
theorem dist_self (n : β) : dist n n = 0 := by simp [dist, tsub_self]
theorem eq_of_dist_eq_zero {n m : β} (h : dist n m = 0) : n = m :=
have : n - m = 0 := Nat.eq_zero_of_add_eq_zero_right h
have : n β€ m := tsub_eq_zero_iff_le.mp this
have : m - n = 0 := Nat.eq_zero_of_add_eq_zero_left h
have : m β€ n := tsub_eq_zero_iff_le.mp this
le_antisymm βΉn β€ mβΊ βΉm β€ nβΊ
theorem dist_eq_zero {n m : β} (h : n = m) : dist n m = 0 := by rw [h, dist_self]
theorem dist_eq_sub_of_le {n m : β} (h : n β€ m) : dist n m = m - n := by
rw [dist, tsub_eq_zero_iff_le.mpr h, zero_add]
theorem dist_eq_sub_of_le_right {n m : β} (h : m β€ n) : dist n m = n - m := by
rw [dist_comm]; apply dist_eq_sub_of_le h
theorem dist_tri_left (n m : β) : m β€ dist n m + n :=
le_trans le_tsub_add (add_le_add_right (Nat.le_add_left _ _) _)
theorem dist_tri_right (n m : β) : m β€ n + dist n m := by rw [add_comm]; apply dist_tri_left
theorem dist_tri_left' (n m : β) : n β€ dist n m + m := by rw [dist_comm]; apply dist_tri_left
theorem dist_tri_right' (n m : β) : n β€ m + dist n m := by rw [dist_comm]; apply dist_tri_right
theorem dist_zero_right (n : β) : dist n 0 = n :=
Eq.trans (dist_eq_sub_of_le_right (zero_le n)) (tsub_zero n)
theorem dist_zero_left (n : β) : dist 0 n = n :=
Eq.trans (dist_eq_sub_of_le (zero_le n)) (tsub_zero n)
theorem dist_add_add_right (n k m : β) : dist (n + k) (m + k) = dist n m :=
calc
dist (n + k) (m + k) = n + k - (m + k) + (m + k - (n + k)) := rfl
_ = n - m + (m + k - (n + k)) := by rw [@add_tsub_add_eq_tsub_right]
_ = n - m + (m - n) := by rw [@add_tsub_add_eq_tsub_right]
theorem dist_add_add_left (k n m : β) : dist (k + n) (k + m) = dist n m := by
rw [add_comm k n, add_comm k m]; apply dist_add_add_right
theorem dist_eq_intro {n m k l : β} (h : n + m = k + l) : dist n k = dist l m :=
calc
dist n k = dist (n + m) (k + m) := by rw [dist_add_add_right]
_ = dist (k + l) (k + m) := by rw [h]
_ = dist l m := by rw [dist_add_add_left]
theorem dist.triangle_inequality (n m k : β) : dist n k β€ dist n m + dist m k := by
have : dist n m + dist m k = n - m + (m - k) + (k - m + (m - n)) := by
simp [dist, add_comm, add_left_comm, add_assoc]
rw [this, dist]
exact add_le_add tsub_le_tsub_add_tsub tsub_le_tsub_add_tsub
theorem dist_mul_right (n k m : β) : dist (n * k) (m * k) = dist n m * k := by
rw [dist, dist, right_distrib, tsub_mul n, tsub_mul m]
theorem dist_mul_left (k n m : β) : dist (k * n) (k * m) = k * dist n m := by
rw [mul_comm k n, mul_comm k m, dist_mul_right, mul_comm]
theorem dist_eq_max_sub_min {i j : β} : dist i j = (max i j) - min i j :=
Or.elim (lt_or_ge i j)
(by intro h; rw [max_eq_right_of_lt h, min_eq_left_of_lt h, dist_eq_sub_of_le (Nat.le_of_lt h)])
(by intro h; rw [max_eq_left h, min_eq_right h, dist_eq_sub_of_le_right h])
theorem dist_succ_succ {i j : Nat} : dist (succ i) (succ j) = dist i j := by
simp [dist, succ_sub_succ]
theorem dist_pos_of_ne {i j : Nat} (h : i β j) : 0 < dist i j := by
cases h.lt_or_gt with
| inl h => rw [dist_eq_sub_of_le h.le]; apply tsub_pos_of_lt h
| inr h => rw [dist_eq_sub_of_le_right h.le]; apply tsub_pos_of_lt h
end Nat
|
ExistsOfLE.lean
|
/-
Copyright (c) 2021 Peter Nelson. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Peter Nelson, YaΓ«l Dillies
-/
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
import Mathlib.Order.MinMax
/-!
# Unbundled and weaker forms of canonically ordered monoids
This file provides a Prop-valued mixin for monoids satisfying a one-sided cancellativity property,
namely that there is some `c` such that `b = a + c` if `a β€ b`. This is particularly useful for
generalising statements from groups/rings/fields that don't mention negation or subtraction to
monoids/semirings/semifields.
-/
universe u
variable {Ξ± : Type u}
/-- An `OrderedAddCommMonoid` with one-sided 'subtraction' in the sense that
if `a β€ b`, then there is some `c` for which `a + c = b`. This is a weaker version
of the condition on canonical orderings defined by `CanonicallyOrderedAddCommMonoid`. -/
class ExistsAddOfLE (Ξ± : Type u) [Add Ξ±] [LE Ξ±] : Prop where
/-- For `a β€ b`, there is a `c` so `b = a + c`. -/
exists_add_of_le : β {a b : Ξ±}, a β€ b β β c : Ξ±, b = a + c
/-- An `OrderedCommMonoid` with one-sided 'division' in the sense that
if `a β€ b`, there is some `c` for which `a * c = b`. This is a weaker version
of the condition on canonical orderings defined by `CanonicallyOrderedCommMonoid`. -/
@[to_additive]
class ExistsMulOfLE (Ξ± : Type u) [Mul Ξ±] [LE Ξ±] : Prop where
/-- For `a β€ b`, `a` left divides `b` -/
exists_mul_of_le : β {a b : Ξ±}, a β€ b β β c : Ξ±, b = a * c
export ExistsMulOfLE (exists_mul_of_le)
export ExistsAddOfLE (exists_add_of_le)
-- See note [lower instance priority]
@[to_additive]
instance (priority := 100) Group.existsMulOfLE (Ξ± : Type u) [Group Ξ±] [LE Ξ±] : ExistsMulOfLE Ξ± :=
β¨fun {a b} _ => β¨aβ»ΒΉ * b, (mul_inv_cancel_left _ _).symmβ©β©
section MulOneClass
variable [MulOneClass Ξ±] [Preorder Ξ±] [ExistsMulOfLE Ξ±] {a b : Ξ±}
@[to_additive] lemma exists_one_le_mul_of_le [MulLeftReflectLE Ξ±] (h : a β€ b) :
β c, 1 β€ c β§ a * c = b := by
obtain β¨c, rflβ© := exists_mul_of_le h; exact β¨c, one_le_of_le_mul_right h, rflβ©
@[to_additive] lemma exists_one_lt_mul_of_lt' [MulLeftReflectLT Ξ±] (h : a < b) :
β c, 1 < c β§ a * c = b := by
obtain β¨c, rflβ© := exists_mul_of_le h.le; exact β¨c, one_lt_of_lt_mul_right h, rflβ©
@[to_additive] lemma le_iff_exists_one_le_mul [MulLeftMono Ξ±]
[MulLeftReflectLE Ξ±] : a β€ b β β c, 1 β€ c β§ a * c = b :=
β¨exists_one_le_mul_of_le, by rintro β¨c, hc, rflβ©; exact le_mul_of_one_le_right' hcβ©
@[to_additive] lemma lt_iff_exists_one_lt_mul [MulLeftStrictMono Ξ±]
[MulLeftReflectLT Ξ±] : a < b β β c, 1 < c β§ a * c = b :=
β¨exists_one_lt_mul_of_lt', by rintro β¨c, hc, rflβ©; exact lt_mul_of_one_lt_right' _ hcβ©
end MulOneClass
section ExistsMulOfLE
variable [LinearOrder Ξ±] [DenselyOrdered Ξ±] [Monoid Ξ±] [ExistsMulOfLE Ξ±]
[MulLeftReflectLT Ξ±] {a b : Ξ±}
@[to_additive]
theorem le_of_forall_one_lt_le_mul (h : β Ξ΅ : Ξ±, 1 < Ξ΅ β a β€ b * Ξ΅) : a β€ b :=
le_of_forall_gt_imp_ge_of_dense fun x hxb => by
obtain β¨Ξ΅, rflβ© := exists_mul_of_le hxb.le
exact h _ (one_lt_of_lt_mul_right hxb)
@[to_additive]
theorem le_of_forall_one_lt_lt_mul' (h : β Ξ΅ : Ξ±, 1 < Ξ΅ β a < b * Ξ΅) : a β€ b :=
le_of_forall_one_lt_le_mul fun Ξ΅ hΞ΅ => (h Ξ΅ hΞ΅).le
@[to_additive]
theorem le_iff_forall_one_lt_lt_mul' [MulLeftStrictMono Ξ±] :
a β€ b β β Ξ΅, 1 < Ξ΅ β a < b * Ξ΅ :=
β¨fun h _ => lt_mul_of_le_of_one_lt h, le_of_forall_one_lt_lt_mul'β©
@[to_additive]
theorem le_iff_forall_one_lt_le_mul [MulLeftStrictMono Ξ±] :
a β€ b β β Ξ΅, 1 < Ξ΅ β a β€ b * Ξ΅ :=
β¨fun h _ hΞ΅ β¦ lt_mul_of_le_of_one_lt h hΞ΅ |>.le, le_of_forall_one_lt_le_mulβ©
end ExistsMulOfLE
|
Basis.lean
|
/-
Copyright (c) 2024 Jz Pan. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jz Pan
-/
import Mathlib.Algebra.Polynomial.Basic
import Mathlib.LinearAlgebra.Basis.Defs
/-!
# Basis of a polynomial ring
-/
open Module
universe u
variable (R : Type u) [Semiring R]
namespace Polynomial
/-- The monomials form a basis on `R[X]`. To get the rank of a polynomial ring,
use this and `Basis.mk_eq_rank`. -/
def basisMonomials : Basis β R R[X] :=
Basis.ofRepr (toFinsuppIsoLinear R)
@[simp]
theorem coe_basisMonomials : (basisMonomials R : β β R[X]) = fun s => monomial s 1 :=
funext fun _ => ofFinsupp_single _ _
end Polynomial
|
ZMod.lean
|
/-
Copyright (c) 2023 Lawrence Wu. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Lawrence Wu
-/
import Mathlib.Algebra.Module.LinearMap.Defs
import Mathlib.Algebra.Module.Submodule.Defs
import Mathlib.GroupTheory.Sylow
/-!
# The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`
-/
assert_not_exists TwoSidedIdeal
variable {n : β} {M Mβ : Type*}
/-- The `ZMod n`-module structure on commutative monoids whose elements have order dividing `n β 0`.
Also implies a group structure via `Module.addCommMonoidToAddCommGroup`.
See note [reducible non-instances]. -/
abbrev AddCommMonoid.zmodModule [NeZero n] [AddCommMonoid M] (h : β (x : M), n β’ x = 0) :
Module (ZMod n) M := by
have h_mod (c : β) (x : M) : (c % n) β’ x = c β’ x := by
suffices (c % n + c / n * n) β’ x = c β’ x by rwa [add_nsmul, mul_nsmul, h, add_zero] at this
rw [Nat.mod_add_div']
have := NeZero.ne n
match n with
| n + 1 => exact {
smul := fun (c : Fin _) x β¦ c.val β’ x
smul_zero := fun _ β¦ nsmul_zero _
zero_smul := fun _ β¦ zero_nsmul _
smul_add := fun _ _ _ β¦ nsmul_add _ _ _
one_smul := fun _ β¦ (h_mod _ _).trans <| one_nsmul _
add_smul := fun _ _ _ β¦ (h_mod _ _).trans <| add_nsmul _ _ _
mul_smul := fun _ _ _ β¦ (h_mod _ _).trans <| mul_nsmul' _ _ _
}
/-- The `ZMod n`-module structure on Abelian groups whose elements have order dividing `n`.
See note [reducible non-instances]. -/
abbrev AddCommGroup.zmodModule {G : Type*} [AddCommGroup G] (h : β (x : G), n β’ x = 0) :
Module (ZMod n) G :=
match n with
| 0 => AddCommGroup.toIntModule G
| _ + 1 => AddCommMonoid.zmodModule h
/-- The quotient of an abelian group by a subgroup containing all multiples of `n` is a
`n`-torsion group. -/
-- See note [reducible non-instances]
abbrev QuotientAddGroup.zmodModule {G : Type*} [AddCommGroup G] {H : AddSubgroup G}
(hH : β x, n β’ x β H) : Module (ZMod n) (G β§Έ H) :=
AddCommGroup.zmodModule <| by simpa [QuotientAddGroup.forall_mk, β QuotientAddGroup.mk_nsmul]
variable {F S : Type*} [AddCommGroup M] [AddCommGroup Mβ] [FunLike F M Mβ]
[AddMonoidHomClass F M Mβ] [Module (ZMod n) M] [Module (ZMod n) Mβ] [SetLike S M]
[AddSubgroupClass S M] {x : M} {K : S}
namespace ZMod
theorem map_smul (f : F) (c : ZMod n) (x : M) : f (c β’ x) = c β’ f x := by
rw [β ZMod.intCast_zmod_cast c]
exact map_intCast_smul f _ _ (cast c) x
theorem smul_mem (hx : x β K) (c : ZMod n) : c β’ x β K := by
rw [β ZMod.intCast_zmod_cast c, Int.cast_smul_eq_zsmul]
exact zsmul_mem hx (cast c)
end ZMod
variable (n)
namespace AddMonoidHom
/-- Reinterpret an additive homomorphism as a `β€/nβ€`-linear map.
See also:
`AddMonoidHom.toIntLinearMap`, `AddMonoidHom.toNatLinearMap`, `AddMonoidHom.toRatLinearMap` -/
def toZModLinearMap (f : M β+ Mβ) : M ββ[ZMod n] Mβ := { f with map_smul' := ZMod.map_smul f }
theorem toZModLinearMap_injective : Function.Injective <| toZModLinearMap n (M := M) (Mβ := Mβ) :=
fun _ _ h β¦ ext fun x β¦ congr($h x)
@[simp]
theorem coe_toZModLinearMap (f : M β+ Mβ) : β(f.toZModLinearMap n) = f := rfl
/-- `AddMonoidHom.toZModLinearMap` as an equivalence. -/
def toZModLinearMapEquiv : (M β+ Mβ) β+ (M ββ[ZMod n] Mβ) where
toFun f := f.toZModLinearMap n
invFun g := g
map_add' fβ fβ := by ext; simp
end AddMonoidHom
namespace AddSubgroup
/-- Reinterpret an additive subgroup of a `β€/nβ€`-module as a `β€/nβ€`-submodule.
See also: `AddSubgroup.toIntSubmodule`, `AddSubmonoid.toNatSubmodule`. -/
def toZModSubmodule : AddSubgroup M βo Submodule (ZMod n) M where
toFun S := { S with smul_mem' := fun c _ h β¦ ZMod.smul_mem (K := S) h c }
invFun := Submodule.toAddSubgroup
map_rel_iff' := Iff.rfl
@[simp]
theorem toZModSubmodule_symm :
β((toZModSubmodule n).symm : _ βo AddSubgroup M) = Submodule.toAddSubgroup :=
rfl
@[simp] lemma coe_toZModSubmodule (S : AddSubgroup M) : (toZModSubmodule n S : Set M) = S := rfl
@[simp] lemma mem_toZModSubmodule {S : AddSubgroup M} : x β toZModSubmodule n S β x β S := .rfl
@[simp]
theorem toZModSubmodule_toAddSubgroup (S : AddSubgroup M) :
(toZModSubmodule n S).toAddSubgroup = S :=
rfl
@[simp]
theorem _root_.Submodule.toAddSubgroup_toZModSubmodule (S : Submodule (ZMod n) M) :
toZModSubmodule n S.toAddSubgroup = S :=
rfl
end AddSubgroup
namespace ZModModule
variable {p : β} {G : Type*} [AddCommGroup G]
/-- In an elementary abelian `p`-group, every finite subgroup `H` contains a further subgroup of
cardinality between `k` and `p * k`, if `k β€ |H|`. -/
lemma exists_submodule_subset_card_le (hp : p.Prime) [Module (ZMod p) G]
(H : Submodule (ZMod p) G) {k : β} (hk : k β€ Nat.card H) (h'k : k β 0) :
β H' : Submodule (ZMod p) G, Nat.card H' β€ k β§ k < p * Nat.card H' β§ H' β€ H := by
obtain β¨H'm, H'mHm, H'mk, kH'mβ© := Sylow.exists_subgroup_le_card_le
(H := AddSubgroup.toSubgroup ((AddSubgroup.toZModSubmodule _).symm H)) hp
isPGroup_multiplicative hk h'k
exact β¨AddSubgroup.toZModSubmodule _ (AddSubgroup.toSubgroup.symm H'm), H'mk, kH'm, H'mHmβ©
end ZModModule
|
HasCardinalLT.lean
|
/-
Copyright (c) 2024 JoΓ«l Riou. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: JoΓ«l Riou
-/
import Mathlib.SetTheory.Cardinal.Regular
/-!
# The property of being of cardinality less than a cardinal
Given `X : Type u` and `ΞΊ : Cardinal.{v}`, we introduce a predicate
`HasCardinalLT X ΞΊ` expressing that
`Cardinal.lift.{v} (Cardinal.mk X) < Cardinal.lift ΞΊ`.
-/
universe w v u u'
/-- The property that the cardinal of a type `X : Type u` is less than `ΞΊ : Cardinal.{v}`. -/
def HasCardinalLT (X : Type u) (ΞΊ : Cardinal.{v}) : Prop :=
Cardinal.lift.{v} (Cardinal.mk X) < Cardinal.lift ΞΊ
lemma hasCardinalLT_iff_cardinal_mk_lt (X : Type u) (ΞΊ : Cardinal.{u}) :
HasCardinalLT X ΞΊ β Cardinal.mk X < ΞΊ := by
simp [HasCardinalLT]
namespace HasCardinalLT
section
variable {X : Type u} {ΞΊ : Cardinal.{v}} (h : HasCardinalLT X ΞΊ)
include h
lemma small : Small.{v} X := by
dsimp [HasCardinalLT] at h
rw [β Cardinal.lift_lt.{_, v + 1}, Cardinal.lift_lift, Cardinal.lift_lift] at h
simpa only [Cardinal.small_iff_lift_mk_lt_univ] using h.trans (Cardinal.lift_lt_univ' ΞΊ)
lemma of_le {ΞΊ' : Cardinal.{v}} (hΞΊ' : ΞΊ β€ ΞΊ') :
HasCardinalLT X ΞΊ' :=
lt_of_lt_of_le h (by simpa only [Cardinal.lift_le] using hΞΊ')
variable {Y : Type u'}
lemma of_injective (f : Y β X) (hf : Function.Injective f) :
HasCardinalLT Y ΞΊ := by
dsimp [HasCardinalLT] at h β’
rw [β Cardinal.lift_lt.{_, u}, Cardinal.lift_lift, Cardinal.lift_lift]
rw [β Cardinal.lift_lt.{_, u'}, Cardinal.lift_lift, Cardinal.lift_lift] at h
exact lt_of_le_of_lt (Cardinal.mk_le_of_injective
(Function.Injective.comp ULift.up_injective
(Function.Injective.comp hf ULift.down_injective))) h
lemma of_surjective (f : X β Y) (hf : Function.Surjective f) :
HasCardinalLT Y ΞΊ := by
dsimp [HasCardinalLT] at h β’
rw [β Cardinal.lift_lt.{_, u}, Cardinal.lift_lift, Cardinal.lift_lift]
rw [β Cardinal.lift_lt.{_, u'}, Cardinal.lift_lift, Cardinal.lift_lift] at h
exact lt_of_le_of_lt (Cardinal.mk_le_of_surjective
(Function.Surjective.comp ULift.up_surjective (Function.Surjective.comp hf
ULift.down_surjective))) h
end
end HasCardinalLT
lemma hasCardinalLT_iff_of_equiv {X : Type u} {Y : Type u'} (e : X β Y) (ΞΊ : Cardinal.{v}) :
HasCardinalLT X ΞΊ β HasCardinalLT Y ΞΊ :=
β¨fun h β¦ h.of_injective _ e.symm.injective,
fun h β¦ h.of_injective _ e.injectiveβ©
@[simp]
lemma hasCardinalLT_aleph0_iff (X : Type u) :
HasCardinalLT X Cardinal.aleph0.{v} β Finite X := by
simpa [HasCardinalLT] using Cardinal.mk_lt_aleph0_iff
lemma hasCardinalLT_sum_iff (X : Type u) (Y : Type u') (ΞΊ : Cardinal.{w})
(hΞΊ : Cardinal.aleph0 β€ ΞΊ) :
HasCardinalLT (X β Y) ΞΊ β HasCardinalLT X ΞΊ β§ HasCardinalLT Y ΞΊ := by
constructor
Β· intro h
exact β¨h.of_injective _ Sum.inl_injective,
h.of_injective _ Sum.inr_injectiveβ©
Β· rintro β¨hX, hYβ©
dsimp [HasCardinalLT] at hX hY β’
rw [β Cardinal.lift_lt.{_, u'}, Cardinal.lift_lift, Cardinal.lift_lift] at hX
rw [β Cardinal.lift_lt.{_, u}, Cardinal.lift_lift, Cardinal.lift_lift] at hY
simp only [Cardinal.mk_sum, Cardinal.lift_add, Cardinal.lift_lift]
exact Cardinal.add_lt_of_lt (by simpa using hΞΊ) hX hY
lemma hasCardinalLT_option_iff (X : Type u) (ΞΊ : Cardinal.{w})
(hΞΊ : Cardinal.aleph0 β€ ΞΊ) :
HasCardinalLT (Option X) ΞΊ β HasCardinalLT X ΞΊ := by
rw [hasCardinalLT_iff_of_equiv (Equiv.optionEquivSumPUnit.{0} X),
hasCardinalLT_sum_iff _ _ _ hΞΊ, and_iff_left_iff_imp]
refine fun _ β¦ HasCardinalLT.of_le ?_ hΞΊ
rw [hasCardinalLT_aleph0_iff]
infer_instance
namespace HasCardinalLT
/-- For any `w`-small type `X`, there exists a regular cardinal `ΞΊ : Cardinal.{w}`
such that `HasCardinalLT X ΞΊ`. -/
lemma exists_regular_cardinal (X : Type u) [Small.{w} X] :
β (ΞΊ : Cardinal.{w}), ΞΊ.IsRegular β§ HasCardinalLT X ΞΊ :=
β¨Order.succ (max (Cardinal.mk (Shrink.{w} X)) .aleph0),
Cardinal.isRegular_succ (le_max_right _ _), by
simp [hasCardinalLT_iff_of_equiv (equivShrink.{w} X),
hasCardinalLT_iff_cardinal_mk_lt]β©
/-- For any `w`-small family `X : ΞΉ β Type u` of `w`-small types, there exists
a regular cardinal `ΞΊ : Cardinal.{w}` such that `HasCardinalLT (X i) ΞΊ` for all `i : ΞΉ`. -/
lemma exists_regular_cardinal_forall {ΞΉ : Type v} {X : ΞΉ β Type u} [Small.{w} ΞΉ]
[β i, Small.{w} (X i)] :
β (ΞΊ : Cardinal.{w}), ΞΊ.IsRegular β§ β (i : ΞΉ), HasCardinalLT (X i) ΞΊ := by
obtain β¨ΞΊ, hΞΊ, hβ© := exists_regular_cardinal.{w} (Sigma X)
exact β¨ΞΊ, hΞΊ, fun i β¦ h.of_injective _ sigma_mk_injectiveβ©
end HasCardinalLT
|
Pi.lean
|
/-
Copyright (c) 2025 Eric Wieser. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Eric Wieser
-/
import Mathlib.Algebra.Regular.SMul
/-!
# Results about `IsRegular` and pi types
-/
variable {ΞΉ Ξ± : Type*} {R : ΞΉ β Type*}
namespace Pi
section
variable [β i, Mul (R i)]
@[to_additive (attr := simp)]
theorem isLeftRegular_iff {a : β i, R i} : IsLeftRegular a β β i, IsLeftRegular (a i) :=
have (i : _) : Nonempty (R i) := β¨a iβ©; Pi.map_injective
@[to_additive (attr := simp)]
theorem isRightRegular_iff {a : β i, R i} : IsRightRegular a β β i, IsRightRegular (a i) :=
have (i : _) : Nonempty (R i) := β¨a iβ©; .symm <| Pi.map_injective.symm
@[to_additive (attr := simp)]
theorem isRegular_iff {a : β i, R i} : IsRegular a β β i, IsRegular (a i) := by
simp [_root_.isRegular_iff, forall_and]
end
@[simp]
theorem isSMulRegular_iff [β i, SMul Ξ± (R i)] {r : Ξ±} [β i, Nonempty (R i)] :
IsSMulRegular (β i, R i) r β β i, IsSMulRegular (R i) r :=
Pi.map_injective
end Pi
|
classfun.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 tuple finfun bigop prime order.
From mathcomp Require Import ssralg poly finset fingroup morphism perm.
From mathcomp Require Import automorphism quotient finalg action gproduct zmodp.
From mathcomp Require Import commutator cyclic center pgroup sylow matrix.
From mathcomp Require Import vector falgebra ssrnum algC algnum archimedean.
(******************************************************************************)
(* This file contains the basic theory of class functions: *)
(* 'CF(G) == the type of class functions on G : {group gT}, i.e., *)
(* which map gT to the type algC of complex algebraics, *)
(* have support in G, and are constant on each conjugacy *)
(* class of G. 'CF(G) implements the falgType interface of *)
(* finite-dimensional F-algebras. *)
(* The identity 1 : 'CF(G) is the indicator function of G, *)
(* and (later) the principal character. *)
(* --> The %CF scope (cfun_scope) is bound to the 'CF(_) types. *)
(* 'CF(G)%VS == the (total) vector space of 'CF(G). *)
(* 'CF(G, A) == the subspace of functions in 'CF(G) with support in A. *)
(* phi x == the image of x : gT under phi : 'CF(G). *)
(* #[phi]%CF == the multiplicative order of phi : 'CF(G). *)
(* cfker phi == the kernel of phi : 'CF(G); note that cfker phi <| G. *)
(* cfaithful phi <=> phi : 'CF(G) is faithful (has a trivial kernel). *)
(* '1_A == the indicator function of A as a function of 'CF(G). *)
(* (Provided A <| G; G is determined by the context.) *)
(* phi^*%CF == the function conjugate to phi : 'CF(G). *)
(* cfAut u phi == the function conjugate to phi by an algC-automorphism u *)
(* phi^u The notation "_ ^u" is only reserved; it is up to *)
(* clients to set Notation "phi ^u" := (cfAut u phi). *)
(* '[phi, psi] == the convolution of phi, psi : 'CF(G) over G, normalised *)
(* '[phi, psi]_G by #|G| so that '[1, 1]_G = 1 (G is usually inferred). *)
(* cfdotr psi phi == '[phi, psi] (self-expanding). *)
(* '[phi], '[phi]_G == the squared norm '[phi, phi] of phi : 'CF(G). *)
(* orthogonal R S <=> each phi in R : seq 'CF(G) is orthogonal to each psi in *)
(* S, i.e., '[phi, psi] = 0. As 'CF(G) coerces to seq, one *)
(* can write orthogonal phi S and orthogonal phi psi. *)
(* pairwise_orthogonal S <=> the class functions in S are pairwise orthogonal *)
(* AND non-zero. *)
(* orthonormal S <=> S is pairwise orthogonal and all class functions in S *)
(* have norm 1. *)
(* isometry tau <-> tau : 'CF(D) -> 'CF(R) is an isometry, mapping *)
(* '[_, _]_D to '[_, _]_R. *)
(* {in CD, isometry tau, to CR} <-> in the domain CD, tau is an isometry *)
(* whose range is contained in CR. *)
(* cfReal phi <=> phi is real, i.e., phi^* == phi. *)
(* cfAut_closed u S <-> S : seq 'CF(G) is closed under conjugation by u. *)
(* cfConjC_closed S <-> S : seq 'CF(G) is closed under complex conjugation. *)
(* conjC_subset S1 S2 <-> S1 : seq 'CF(G) represents a subset of S2 closed *)
(* under complex conjugation. *)
(* := [/\ uniq S1, {subset S1 <= S2} & cfConjC_closed S1]. *)
(* 'Res[H] phi == the restriction of phi : 'CF(G) to a function of 'CF(H) *)
(* 'Res[H, G] phi 'Res[H] phi x = phi x if x \in H (when H \subset G), *)
(* 'Res phi 'Res[H] phi x = 0 if x \notin H. The syntax variants *)
(* allow H and G to be inferred; the default is to specify *)
(* H explicitly, and infer G from the type of phi. *)
(* 'Ind[G] phi == the class function of 'CF(G) induced by phi : 'CF(H), *)
(* 'Ind[G, H] phi when H \subset G. As with 'Res phi, both G and H can *)
(* 'Ind phi be inferred, though usually G isn't. *)
(* cfMorph phi == the class function in 'CF(G) that maps x to phi (f x), *)
(* where phi : 'CF(f @* G), provided G \subset 'dom f. *)
(* cfIsom isoGR phi == the class function in 'CF(R) that maps f x to phi x, *)
(* given isoGR : isom G R f, f : {morphism G >-> rT} and *)
(* phi : 'CF(G). *)
(* (phi %% H)%CF == special case of cfMorph phi, when phi : 'CF(G / H). *)
(* (phi / H)%CF == the class function in 'CF(G / H) that coincides with *)
(* phi : 'CF(G) on cosets of H \subset cfker phi. *)
(* For a group G that is a semidirect product (defG : K ><| H = G), we have *)
(* cfSdprod KxH phi == for phi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* For a group G that is a direct product (with KxH : K \x H = G), we have *)
(* cfDprodl KxH phi == for phi : 'CF(K), the class function of 'CF(G) that *)
(* maps k * h to phi k when k \in K and h \in H. *)
(* cfDprodr KxH psi == for psi : 'CF(H), the class function of 'CF(G) that *)
(* maps k * h to psi h when k \in K and h \in H. *)
(* cfDprod KxH phi psi == for phi : 'CF(K), psi : 'CF(H), the class function *)
(* of 'CF(G) that maps k * h to phi k * psi h (this is *)
(* the product of the two functions above). *)
(* Finally, given defG : \big[dprod/1]_(i | P i) A i = G, with G and A i *)
(* groups and i ranges over a finType, we have *)
(* cfBigdprodi defG phi == for phi : 'CF(A i) s.t. P i, the class function *)
(* of 'CF(G) that maps x to phi x_i, where x_i is the *)
(* (A i)-component of x : G. *)
(* cfBigdprod defG phi == for phi : forall i, 'CF(A i), the class function *)
(* of 'CF(G) that maps x to \prod_(i | P i) phi i x_i, *)
(* where x_i is the (A i)-component of x : G. *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope cfun_scope.
Import Order.TTheory GroupScope GRing.Theory Num.Theory.
Local Open Scope ring_scope.
Delimit Scope cfun_scope with CF.
Reserved Notation "''CF' ( G , A )" (format "''CF' ( G , A )").
Reserved Notation "''CF' ( G )" (format "''CF' ( G )").
Reserved Notation "''1_' G" (at level 8, G at level 2, format "''1_' G").
Reserved Notation "''Res[' H , G ]". (* only parsing *)
Reserved Notation "''Res[' H ]" (format "''Res[' H ]").
Reserved Notation "''Res'". (* only parsing *)
Reserved Notation "''Ind[' G , H ]". (* only parsing *)
Reserved Notation "''Ind[' G ]". (* only "''Ind[' G ]" *)
Reserved Notation "''Ind'". (* only parsing *)
Reserved Notation "'[ phi , psi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "'[ phi ]_ G"
(at level 0, G at level 2). (* only parsing *)
Reserved Notation "phi ^u" (format "phi ^u").
Section AlgC.
(* Arithmetic properties of group orders in the characteristic 0 field algC. *)
Variable (gT : finGroupType).
Implicit Types (G : {group gT}) (B : {set gT}).
Lemma neq0CG G : (#|G|)%:R != 0 :> algC. Proof. exact: natrG_neq0. Qed.
Lemma neq0CiG G B : (#|G : B|)%:R != 0 :> algC.
Proof. exact: natr_indexg_neq0. Qed.
Lemma gt0CG G : 0 < #|G|%:R :> algC. Proof. exact: natrG_gt0. Qed.
Lemma gt0CiG G B : 0 < #|G : B|%:R :> algC. Proof. exact: natr_indexg_gt0. Qed.
Lemma algC'G_pchar G : [pchar algC]^'.-group G.
Proof. by apply/pgroupP=> p _; rewrite inE /= pchar_num. Qed.
End AlgC.
#[deprecated(since="mathcomp 2.4.0", note="Use algC'G_pchar instead.")]
Notation algC'G := (algC'G_pchar) (only parsing).
Section Defs.
Variable gT : finGroupType.
Definition is_class_fun (B : {set gT}) (f : {ffun gT -> algC}) :=
[forall x, forall y in B, f (x ^ y) == f x] && (support f \subset B).
Lemma intro_class_fun (G : {group gT}) f :
{in G &, forall x y, f (x ^ y) = f x} ->
(forall x, x \notin G -> f x = 0) ->
is_class_fun G (finfun f).
Proof.
move=> fJ Gf; apply/andP; split; last first.
by apply/supportP=> x notAf; rewrite ffunE Gf.
apply/'forall_eqfun_inP=> x y Gy; rewrite !ffunE.
by have [/fJ-> // | notGx] := boolP (x \in G); rewrite !Gf ?groupJr.
Qed.
Variable B : {set gT}.
Local Notation G := <<B>>.
Record classfun : predArgType :=
Classfun {cfun_val; _ : is_class_fun G cfun_val}.
Implicit Types phi psi xi : classfun.
(* The default expansion lemma cfunE requires key = 0. *)
Fact classfun_key : unit. Proof. by []. Qed.
Definition Cfun := locked_with classfun_key (fun flag : nat => Classfun).
HB.instance Definition _ := [isSub for cfun_val].
HB.instance Definition _ := [Choice of classfun by <:].
Definition cfun_eqType : eqType := classfun.
Definition fun_of_cfun phi := cfun_val phi : gT -> algC.
Coercion fun_of_cfun : classfun >-> Funclass.
Lemma cfunElock k f fP : @Cfun k (finfun f) fP =1 f.
Proof. by rewrite locked_withE; apply: ffunE. Qed.
Lemma cfunE f fP : @Cfun 0 (finfun f) fP =1 f.
Proof. exact: cfunElock. Qed.
Lemma cfunP phi psi : phi =1 psi <-> phi = psi.
Proof. by split=> [/ffunP/val_inj | ->]. Qed.
Lemma cfun0gen phi x : x \notin G -> phi x = 0.
Proof. by case: phi => f fP; case: (andP fP) => _ /supportP; apply. Qed.
Lemma cfun_in_genP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof.
move=> eq_phi; apply/cfunP=> x.
by have [/eq_phi-> // | notAx] := boolP (x \in G); rewrite !cfun0gen.
Qed.
Lemma cfunJgen phi x y : y \in G -> phi (x ^ y) = phi x.
Proof.
case: phi => f fP Gy; apply/eqP.
by case: (andP fP) => /'forall_forall_inP->.
Qed.
Fact cfun_zero_subproof : is_class_fun G (0 : {ffun _}).
Proof. exact: intro_class_fun. Qed.
Definition cfun_zero := Cfun 0 cfun_zero_subproof.
Fact cfun_comp_subproof f phi :
f 0 = 0 -> is_class_fun G [ffun x => f (phi x)].
Proof.
by move=> f0; apply: intro_class_fun => [x y _ /cfunJgen | x /cfun0gen] ->.
Qed.
Definition cfun_comp f f0 phi := Cfun 0 (@cfun_comp_subproof f phi f0).
Definition cfun_opp := cfun_comp (oppr0 _).
Fact cfun_add_subproof phi psi : is_class_fun G [ffun x => phi x + psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite !cfun0gen ?add0r.
Qed.
Definition cfun_add phi psi := Cfun 0 (cfun_add_subproof phi psi).
Fact cfun_indicator_subproof (A : {set gT}) :
is_class_fun G [ffun x => ((x \in G) && (x ^: G \subset A))%:R].
Proof.
apply: intro_class_fun => [x y Gx Gy | x /negbTE/= -> //].
by rewrite groupJr ?classGidl.
Qed.
Definition cfun_indicator A := Cfun 1 (cfun_indicator_subproof A).
Local Notation "''1_' A" := (cfun_indicator A) : ring_scope.
Lemma cfun1Egen x : '1_G x = (x \in G)%:R.
Proof. by rewrite cfunElock andb_idr // => /class_subG->. Qed.
Fact cfun_mul_subproof phi psi : is_class_fun G [ffun x => phi x * psi x].
Proof.
apply: intro_class_fun => [x y Gx Gy | x notGx]; rewrite ?cfunJgen //.
by rewrite cfun0gen ?mul0r.
Qed.
Definition cfun_mul phi psi := Cfun 0 (cfun_mul_subproof phi psi).
Definition cfun_unit := [pred phi : classfun | [forall x in G, phi x != 0]].
Definition cfun_inv phi :=
if phi \in cfun_unit then cfun_comp (invr0 _) phi else phi.
Definition cfun_scale a := cfun_comp (mulr0 a).
Fact cfun_addA : associative cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE addrA. Qed.
Fact cfun_addC : commutative cfun_add.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE addrC. Qed.
Fact cfun_add0 : left_id cfun_zero cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE add0r. Qed.
Fact cfun_addN : left_inverse cfun_zero cfun_opp cfun_add.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE addNr. Qed.
HB.instance Definition _ := GRing.isZmodule.Build classfun
cfun_addA cfun_addC cfun_add0 cfun_addN.
Lemma muln_cfunE phi n x : (phi *+ n) x = phi x *+ n.
Proof. by elim: n => [|n IHn]; rewrite ?mulrS !cfunE ?IHn. Qed.
Lemma sum_cfunE I r (P : pred I) (phi : I -> classfun) x :
(\sum_(i <- r | P i) phi i) x = \sum_(i <- r | P i) (phi i) x.
Proof. by elim/big_rec2: _ => [|i _ psi _ <-]; rewrite cfunE. Qed.
Fact cfun_mulA : associative cfun_mul.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_mulC : commutative cfun_mul.
Proof. by move=> phi psi; apply/cfunP=> x; rewrite !cfunE mulrC. Qed.
Fact cfun_mul1 : left_id '1_G cfun_mul.
Proof.
by move=> phi; apply: cfun_in_genP => x Gx; rewrite !cfunE cfun1Egen Gx mul1r.
Qed.
Fact cfun_mulD : left_distributive cfun_mul cfun_add.
Proof. by move=> phi psi xi; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
Fact cfun_nz1 : '1_G != 0.
Proof.
by apply/eqP=> /cfunP/(_ 1%g)/eqP; rewrite cfun1Egen cfunE group1 oner_eq0.
Qed.
HB.instance Definition _ := GRing.Zmodule_isComNzRing.Build classfun
cfun_mulA cfun_mulC cfun_mul1 cfun_mulD cfun_nz1.
Definition cfun_nzRingType : nzRingType := classfun.
#[deprecated(since="mathcomp 2.4.0",
note="Use cfun_nzRingType instead.")]
Notation cfun_ringType := (cfun_nzRingType) (only parsing).
Lemma expS_cfunE phi n x : (phi ^+ n.+1) x = phi x ^+ n.+1.
Proof. by elim: n => //= n IHn; rewrite !cfunE IHn. Qed.
Fact cfun_mulV : {in cfun_unit, left_inverse 1 cfun_inv *%R}.
Proof.
move=> phi Uphi; rewrite /cfun_inv Uphi; apply/cfun_in_genP=> x Gx.
by rewrite !cfunE cfun1Egen Gx mulVf ?(forall_inP Uphi).
Qed.
Fact cfun_unitP phi psi : psi * phi = 1 -> phi \in cfun_unit.
Proof.
move/cfunP=> phiK; apply/forall_inP=> x Gx; rewrite -unitfE; apply/unitrP.
by exists (psi x); have:= phiK x; rewrite !cfunE cfun1Egen Gx mulrC.
Qed.
Fact cfun_inv0id : {in [predC cfun_unit], cfun_inv =1 id}.
Proof. by rewrite /cfun_inv => phi /negbTE/= ->. Qed.
HB.instance Definition _ :=
GRing.ComNzRing_hasMulInverse.Build classfun cfun_mulV cfun_unitP cfun_inv0id.
Fact cfun_scaleA a b phi :
cfun_scale a (cfun_scale b phi) = cfun_scale (a * b) phi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scale1 : left_id 1 cfun_scale.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE mul1r. Qed.
Fact cfun_scaleDr : right_distributive cfun_scale +%R.
Proof. by move=> a phi psi; apply/cfunP=> x; rewrite !cfunE mulrDr. Qed.
Fact cfun_scaleDl phi : {morph cfun_scale^~ phi : a b / a + b}.
Proof. by move=> a b; apply/cfunP=> x; rewrite !cfunE mulrDl. Qed.
HB.instance Definition _ := GRing.Zmodule_isLmodule.Build algC classfun
cfun_scaleA cfun_scale1 cfun_scaleDr cfun_scaleDl.
Fact cfun_scaleAl a phi psi : a *: (phi * psi) = (a *: phi) * psi.
Proof. by apply/cfunP=> x; rewrite !cfunE mulrA. Qed.
Fact cfun_scaleAr a phi psi : a *: (phi * psi) = phi * (a *: psi).
Proof. by rewrite !(mulrC phi) cfun_scaleAl. Qed.
HB.instance Definition _ := GRing.Lmodule_isLalgebra.Build algC classfun
cfun_scaleAl.
HB.instance Definition _ := GRing.Lalgebra_isAlgebra.Build algC classfun
cfun_scaleAr.
Section Automorphism.
Variable u : {rmorphism algC -> algC}.
Definition cfAut := cfun_comp (rmorph0 u).
Lemma cfAut_cfun1i A : cfAut '1_A = '1_A.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cfAutZ a phi : cfAut (a *: phi) = u a *: cfAut phi.
Proof. by apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
Lemma cfAut_is_zmod_morphism : zmod_morphism cfAut.
Proof.
by move=> phi psi; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE /= rmorphB.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_zmod_morphism` instead")]
Definition cfAut_is_additive := cfAut_is_zmod_morphism.
Lemma cfAut_is_monoid_morphism : monoid_morphism cfAut.
Proof.
by split=> [|phi psi]; apply/cfunP=> x; rewrite ?cfAut_cfun1i // !cfunE rmorphM.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfAut_is_monoid_morphism` instead")]
Definition cfAut_is_multiplicative :=
(fun g => (g.2,g.1)) cfAut_is_monoid_morphism.
HB.instance Definition _ := GRing.isZmodMorphism.Build classfun classfun cfAut
cfAut_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build classfun classfun cfAut
cfAut_is_monoid_morphism.
Lemma cfAut_cfun1 : cfAut 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfAut_scalable : scalable_for (u \; *:%R) cfAut.
Proof. by move=> a phi; apply/cfunP=> x; rewrite !cfunE rmorphM. Qed.
HB.instance Definition _ :=
GRing.isScalable.Build algC classfun classfun (u \; *:%R) cfAut
cfAut_scalable.
Definition cfAut_closed (S : seq classfun) :=
{in S, forall phi, cfAut phi \in S}.
End Automorphism.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Definition cfReal phi := cfAut conjC phi == phi.
Definition cfConjC_subset (S1 S2 : seq classfun) :=
[/\ uniq S1, {subset S1 <= S2} & cfAut_closed conjC S1].
Fact cfun_vect_iso : Vector.axiom #|classes G| classfun.
Proof.
exists (fun phi => \row_i phi (repr (enum_val i))) => [a phi psi|].
by apply/rowP=> i; rewrite !(mxE, cfunE).
set n := #|_|; pose eK x : 'I_n := enum_rank_in (classes1 _) (x ^: G).
have rV2vP v : is_class_fun G [ffun x => v (eK x) *+ (x \in G)].
apply: intro_class_fun => [x y Gx Gy | x /negbTE/=-> //].
by rewrite groupJr // /eK classGidl.
exists (fun v : 'rV_n => Cfun 0 (rV2vP (v 0))) => [phi | v].
apply/cfun_in_genP=> x Gx; rewrite cfunE Gx mxE enum_rankK_in ?mem_classes //.
by have [y Gy ->] := repr_class <<B>> x; rewrite cfunJgen.
apply/rowP=> i; rewrite mxE cfunE; have /imsetP[x Gx def_i] := enum_valP i.
rewrite def_i; have [y Gy ->] := repr_class <<B>> x.
by rewrite groupJ // /eK classGidl // -def_i enum_valK_in.
Qed.
HB.instance Definition _ := Lmodule_hasFinDim.Build algC classfun cfun_vect_iso.
Definition cfun_vectType : vectType _ := classfun.
Definition cfun_base A : #|classes B ::&: A|.-tuple classfun :=
[tuple of [seq '1_xB | xB in classes B ::&: A]].
Definition classfun_on A := <<cfun_base A>>%VS.
Definition cfdot phi psi := #|B|%:R^-1 * \sum_(x in B) phi x * (psi x)^*.
Definition cfdotr psi phi := cfdot phi psi.
Definition cfnorm phi := cfdot phi phi.
Coercion seq_of_cfun phi := [:: phi].
Definition cforder phi := \big[lcmn/1]_(x in <<B>>) #[phi x]%C.
End Defs.
Bind Scope cfun_scope with classfun.
Arguments classfun {gT} B%_g.
Arguments classfun_on {gT} B%_g A%_g.
Arguments cfun_indicator {gT} B%_g.
Arguments cfAut {gT B%_g} u phi%_CF.
Arguments cfReal {gT B%_g} phi%_CF.
Arguments cfdot {gT B%_g} phi%_CF psi%_CF.
Arguments cfdotr {gT B%_g} psi%_CF phi%_CF /.
Arguments cfnorm {gT B%_g} phi%_CF /.
Notation "''CF' ( G )" := (classfun G) : type_scope.
Notation "''CF' ( G )" := (@fullv _ (cfun_vectType G)) : vspace_scope.
Notation "''1_' A" := (cfun_indicator _ A) : ring_scope.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Notation "1" := (@GRing.one (cfun_nzRingType _)) (only parsing) : cfun_scope.
(* FIX ME this has changed *)
Notation conjC := Num.conj_op.
Notation "phi ^*" := (cfAut conjC phi) : cfun_scope.
Notation cfConjC_closed := (cfAut_closed conjC).
Prenex Implicits cfReal.
(* Workaround for overeager projection reduction. *)
Notation eqcfP := (@eqP (cfun_eqType _) _ _) (only parsing).
Notation "#[ phi ]" := (cforder phi) : cfun_scope.
Notation "''[' u , v ]_ G":= (@cfdot _ G u v) (only parsing) : ring_scope.
Notation "''[' u , v ]" := (cfdot u v) : ring_scope.
Notation "''[' u ]_ G" := '[u, u]_G (only parsing) : ring_scope.
Notation "''[' u ]" := '[u, u] : ring_scope.
Section Predicates.
Variables (gT rT : finGroupType) (D : {set gT}) (R : {set rT}).
Implicit Types (phi psi : 'CF(D)) (S : seq 'CF(D)) (tau : 'CF(D) -> 'CF(R)).
Definition cfker phi := [set x in D | [forall y, phi (x * y)%g == phi y]].
Definition cfaithful phi := cfker phi \subset [1].
Definition ortho_rec S1 S2 :=
all [pred phi | all [pred psi | '[phi, psi] == 0] S2] S1.
Definition orthogonal := ortho_rec.
Arguments orthogonal : simpl never.
Fixpoint pair_ortho_rec S :=
if S is psi :: S' then ortho_rec psi 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 orthonormal S := all [pred psi | '[psi] == 1] S && pair_ortho_rec S.
Definition isometry tau := forall phi psi, '[tau phi, tau psi] = '[phi, psi].
Definition isometry_from_to mCFD tau mCFR :=
prop_in2 mCFD (inPhantom (isometry tau))
/\ prop_in1 mCFD (inPhantom (forall phi, in_mem (tau phi) mCFR)).
End Predicates.
Arguments orthogonal : simpl never.
Arguments cfker {gT D%_g} phi%_CF.
Arguments cfaithful {gT D%_g} phi%_CF.
Arguments orthogonal {gT D%_g} S1%_CF S2%_CF.
Arguments pairwise_orthogonal {gT D%_g} S%_CF.
Arguments orthonormal {gT D%_g} S%_CF.
Arguments isometry {gT rT D%_g R%_g} tau%_CF.
Notation "{ 'in' CFD , 'isometry' tau , 'to' CFR }" :=
(isometry_from_to (mem CFD) tau (mem CFR))
(format "{ 'in' CFD , 'isometry' tau , 'to' CFR }")
: type_scope.
Section ClassFun.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (A B : {set gT}) (H K : {group gT}) (phi psi xi : 'CF(G)).
Local Notation "''1_' A" := (cfun_indicator G A).
Lemma cfun0 phi x : x \notin G -> phi x = 0.
Proof. by rewrite -{1}(genGid G) => /(cfun0gen phi). Qed.
Lemma support_cfun phi : support phi \subset G.
Proof. by apply/subsetP=> g; apply: contraR => /cfun0->. Qed.
Lemma cfunJ phi x y : y \in G -> phi (x ^ y) = phi x.
Proof. by rewrite -{1}(genGid G) => /(cfunJgen phi)->. Qed.
Lemma cfun_repr phi x : phi (repr (x ^: G)) = phi x.
Proof. by have [y Gy ->] := repr_class G x; apply: cfunJ. Qed.
Lemma cfun_inP phi psi : {in G, phi =1 psi} -> phi = psi.
Proof. by rewrite -{1}genGid => /cfun_in_genP. Qed.
Lemma cfuniE A x : A <| G -> '1_A x = (x \in A)%:R.
Proof.
case/andP=> sAG nAG; rewrite cfunElock genGid.
by rewrite class_sub_norm // andb_idl // => /(subsetP sAG).
Qed.
Lemma support_cfuni A : A <| G -> support '1_A =i A.
Proof. by move=> nsAG x; rewrite !inE cfuniE // pnatr_eq0 -lt0n lt0b. Qed.
Lemma eq_mul_cfuni A phi : A <| G -> {in A, phi * '1_A =1 phi}.
Proof. by move=> nsAG x Ax; rewrite cfunE cfuniE // Ax mulr1. Qed.
Lemma eq_cfuni A : A <| G -> {in A, '1_A =1 (1 : 'CF(G))}.
Proof. by rewrite -['1_A]mul1r; apply: eq_mul_cfuni. Qed.
Lemma cfuniG : '1_G = 1.
Proof. by rewrite -[G in '1_G]genGid. Qed.
Lemma cfun1E g : (1 : 'CF(G)) g = (g \in G)%:R.
Proof. by rewrite -cfuniG cfuniE. Qed.
Lemma cfun11 : (1 : 'CF(G)) 1%g = 1.
Proof. by rewrite cfun1E group1. Qed.
Lemma prod_cfunE I r (P : pred I) (phi : I -> 'CF(G)) x :
x \in G -> (\prod_(i <- r | P i) phi i) x = \prod_(i <- r | P i) (phi i) x.
Proof.
by move=> Gx; elim/big_rec2: _ => [|i _ psi _ <-]; rewrite ?cfunE ?cfun1E ?Gx.
Qed.
Lemma exp_cfunE phi n x : x \in G -> (phi ^+ n) x = phi x ^+ n.
Proof. by rewrite -[n]card_ord -!prodr_const; apply: prod_cfunE. Qed.
Lemma mul_cfuni A B : '1_A * '1_B = '1_(A :&: B) :> 'CF(G).
Proof.
apply/cfunP=> g; rewrite !cfunElock -natrM mulnb subsetI.
by rewrite andbCA !andbA andbb.
Qed.
Lemma cfun_classE x y : '1_(x ^: G) y = ((x \in G) && (y \in x ^: G))%:R.
Proof.
rewrite cfunElock genGid class_sub_norm ?class_norm //; congr (_ : bool)%:R.
by apply: andb_id2r => /imsetP[z Gz ->]; rewrite groupJr.
Qed.
Lemma cfun_on_sum A :
'CF(G, A) = (\sum_(xG in classes G | xG \subset A) <['1_xG]>)%VS.
Proof.
by rewrite ['CF(G, A)]span_def big_image; apply: eq_bigl => xG; rewrite !inE.
Qed.
Lemma cfun_onP A phi :
reflect (forall x, x \notin A -> phi x = 0) (phi \in 'CF(G, A)).
Proof.
apply: (iffP idP) => [/coord_span-> x notAx | Aphi].
set b := cfun_base G A; rewrite sum_cfunE big1 // => i _; rewrite cfunE.
have /mapP[xG]: b`_i \in b by rewrite -tnth_nth mem_tnth.
rewrite mem_enum => /setIdP[/imsetP[y Gy ->] Ay] ->.
by rewrite cfun_classE Gy (contraNF (subsetP Ay x)) ?mulr0.
suffices <-: \sum_(xG in classes G) phi (repr xG) *: '1_xG = phi.
apply: memv_suml => _ /imsetP[x Gx ->]; rewrite rpredZeq cfun_repr.
have [s_xG_A | /subsetPn[_ /imsetP[y Gy ->]]] := boolP (x ^: G \subset A).
by rewrite cfun_on_sum [_ \in _](sumv_sup (x ^: G)) ?mem_classes ?orbT.
by move/Aphi; rewrite cfunJ // => ->; rewrite eqxx.
apply/cfun_inP=> x Gx; rewrite sum_cfunE (bigD1 (x ^: G)) ?mem_classes //=.
rewrite cfunE cfun_repr cfun_classE Gx class_refl mulr1.
rewrite big1 ?addr0 // => _ /andP[/imsetP[y Gy ->]]; apply: contraNeq.
rewrite cfunE cfun_repr cfun_classE Gy mulf_eq0 => /norP[_].
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Arguments cfun_onP {A phi}.
Lemma cfun_on0 A phi x : phi \in 'CF(G, A) -> x \notin A -> phi x = 0.
Proof. by move/cfun_onP; apply. Qed.
Lemma sum_by_classes (R : nzRingType) (F : gT -> R) :
{in G &, forall g h, F (g ^ h) = F g} ->
\sum_(g in G) F g = \sum_(xG in classes G) #|xG|%:R * F (repr xG).
Proof.
move=> FJ; rewrite {1}(partition_big _ _ ((@mem_classes gT)^~ G)) /=.
apply: eq_bigr => _ /imsetP[x Gx ->]; have [y Gy ->] := repr_class G x.
rewrite mulr_natl -sumr_const FJ {y Gy}//; apply/esym/eq_big=> y /=.
apply/idP/andP=> [xGy | [Gy /eqP<-]]; last exact: class_refl.
by rewrite (class_eqP xGy) (subsetP (class_subG Gx (subxx _))).
by case/imsetP=> z Gz ->; rewrite FJ.
Qed.
Lemma cfun_base_free A : free (cfun_base G A).
Proof.
have b_i (i : 'I_#|classes G ::&: A|) : (cfun_base G A)`_i = '1_(enum_val i).
by rewrite /enum_val -!tnth_nth tnth_map.
apply/freeP => s S0 i; move/cfunP/(_ (repr (enum_val i))): S0.
rewrite sum_cfunE (bigD1 i) //= big1 ?addr0 => [|j].
rewrite b_i !cfunE; have /setIdP[/imsetP[x Gx ->] _] := enum_valP i.
by rewrite cfun_repr cfun_classE Gx class_refl mulr1.
apply: contraNeq; rewrite b_i !cfunE mulf_eq0 => /norP[_].
rewrite -(inj_eq enum_val_inj).
have /setIdP[/imsetP[x _ ->] _] := enum_valP i; rewrite cfun_repr.
have /setIdP[/imsetP[y Gy ->] _] := enum_valP j; rewrite cfun_classE Gy.
by rewrite pnatr_eq0 -lt0n lt0b => /class_eqP->.
Qed.
Lemma dim_cfun : \dim 'CF(G) = #|classes G|.
Proof. by rewrite dimvf /dim /= genGid. Qed.
Lemma dim_cfun_on A : \dim 'CF(G, A) = #|classes G ::&: A|.
Proof. by rewrite (eqnP (cfun_base_free A)) size_tuple. Qed.
Lemma dim_cfun_on_abelian A : abelian G -> A \subset G -> \dim 'CF(G, A) = #|A|.
Proof.
move/abelian_classP=> cGG sAG; rewrite -(card_imset _ set1_inj) dim_cfun_on.
apply/eq_card=> xG; rewrite !inE.
apply/andP/imsetP=> [[/imsetP[x Gx ->] Ax] | [x Ax ->]] {xG}.
by rewrite cGG ?sub1set // in Ax *; exists x.
by rewrite -{1}(cGG x) ?mem_classes ?(subsetP sAG) ?sub1set.
Qed.
Lemma cfuni_on A : '1_A \in 'CF(G, A).
Proof.
apply/cfun_onP=> x notAx; rewrite cfunElock genGid.
by case: andP => // [[_ s_xG_A]]; rewrite (subsetP s_xG_A) ?class_refl in notAx.
Qed.
Lemma mul_cfuni_on A phi : phi * '1_A \in 'CF(G, A).
Proof.
by apply/cfun_onP=> x /(cfun_onP (cfuni_on A)) Ax0; rewrite cfunE Ax0 mulr0.
Qed.
Lemma cfun_onE phi A : (phi \in 'CF(G, A)) = (support phi \subset A).
Proof. exact: (sameP cfun_onP supportP). Qed.
Lemma cfun_onT phi : phi \in 'CF(G, [set: gT]).
Proof. by rewrite cfun_onE. Qed.
Lemma cfun_onD1 phi A :
(phi \in 'CF(G, A^#)) = (phi \in 'CF(G, A)) && (phi 1%g == 0).
Proof.
by rewrite !cfun_onE -!(eq_subset (in_set (support _))) subsetD1 !inE negbK.
Qed.
Lemma cfun_onG phi : phi \in 'CF(G, G).
Proof. by rewrite cfun_onE support_cfun. Qed.
Lemma cfunD1E phi : (phi \in 'CF(G, G^#)) = (phi 1%g == 0).
Proof. by rewrite cfun_onD1 cfun_onG. Qed.
Lemma cfunGid : 'CF(G, G) = 'CF(G)%VS.
Proof. by apply/vspaceP=> phi; rewrite cfun_onG memvf. Qed.
Lemma cfun_onS A B phi : B \subset A -> phi \in 'CF(G, B) -> phi \in 'CF(G, A).
Proof. by rewrite !cfun_onE => sBA /subset_trans->. Qed.
Lemma cfun_complement A :
A <| G -> ('CF(G, A) + 'CF(G, G :\: A)%SET = 'CF(G))%VS.
Proof.
case/andP=> sAG nAG; rewrite -cfunGid [rhs in _ = rhs]cfun_on_sum.
rewrite (bigID (fun B => B \subset A)) /=.
congr (_ + _)%VS; rewrite cfun_on_sum; apply: eq_bigl => /= xG.
rewrite andbAC; apply/esym/andb_idr=> /andP[/imsetP[x Gx ->] _].
by rewrite class_subG.
rewrite -andbA; apply: andb_id2l => /imsetP[x Gx ->].
by rewrite !class_sub_norm ?normsD ?normG // inE andbC.
Qed.
Lemma cfConjCE phi x : ( phi^* )%CF x = (phi x)^*.
Proof. by rewrite cfunE. Qed.
Lemma cfConjCK : involutive (fun phi => phi^* )%CF.
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= conjCK. Qed.
Lemma cfConjC_cfun1 : ( 1^* )%CF = 1 :> 'CF(G).
Proof. exact: rmorph1. Qed.
(* Class function kernel and faithful class functions *)
Fact cfker_is_group phi : group_set (cfker phi).
Proof.
apply/group_setP; split=> [|x y]; rewrite !inE ?group1.
by apply/forallP=> y; rewrite mul1g.
case/andP=> Gx /forallP-Kx /andP[Gy /forallP-Ky]; rewrite groupM //.
by apply/forallP=> z; rewrite -mulgA (eqP (Kx _)) Ky.
Qed.
Canonical cfker_group phi := Group (cfker_is_group phi).
Lemma cfker_sub phi : cfker phi \subset G.
Proof. by rewrite /cfker setIdE subsetIl. Qed.
Lemma cfker_norm phi : G \subset 'N(cfker phi).
Proof.
apply/subsetP=> z Gz; have phiJz := cfunJ phi _ (groupVr Gz).
rewrite inE; apply/subsetP=> _ /imsetP[x /setIdP[Gx /forallP-Kx] ->].
rewrite inE groupJ //; apply/forallP=> y.
by rewrite -(phiJz y) -phiJz conjMg conjgK Kx.
Qed.
Lemma cfker_normal phi : cfker phi <| G.
Proof. by rewrite /normal cfker_sub cfker_norm. Qed.
Lemma cfkerMl phi x y : x \in cfker phi -> phi (x * y)%g = phi y.
Proof. by case/setIdP=> _ /eqfunP->. Qed.
Lemma cfkerMr phi x y : x \in cfker phi -> phi (y * x)%g = phi y.
Proof.
by move=> Kx; rewrite conjgC cfkerMl ?cfunJ ?(subsetP (cfker_sub phi)).
Qed.
Lemma cfker1 phi x : x \in cfker phi -> phi x = phi 1%g.
Proof. by move=> Kx; rewrite -[x]mulg1 cfkerMl. Qed.
Lemma cfker_cfun0 : @cfker _ G 0 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfunE.
Qed.
Lemma cfker_add phi psi : cfker phi :&: cfker psi \subset cfker (phi + psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_sum I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\sum_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun0.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_add _ _).
Qed.
Lemma cfker_scale a phi : cfker phi \subset cfker (a *: phi).
Proof.
apply/subsetP=> x Kphi_x; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE cfkerMl.
Qed.
Lemma cfker_scale_nz a phi : a != 0 -> cfker (a *: phi) = cfker phi.
Proof.
move=> nz_a; apply/eqP.
by rewrite eqEsubset -{2}(scalerK nz_a phi) !cfker_scale.
Qed.
Lemma cfker_opp phi : cfker (- phi) = cfker phi.
Proof. by rewrite -scaleN1r cfker_scale_nz // oppr_eq0 oner_eq0. Qed.
Lemma cfker_cfun1 : @cfker _ G 1 = G.
Proof.
apply/setP=> x; rewrite !inE andb_idr // => Gx; apply/forallP=> y.
by rewrite !cfun1E groupMl.
Qed.
Lemma cfker_mul phi psi : cfker phi :&: cfker psi \subset cfker (phi * psi).
Proof.
apply/subsetP=> x /setIP[Kphi_x Kpsi_x]; have [Gx _] := setIdP Kphi_x.
by rewrite inE Gx; apply/forallP=> y; rewrite !cfunE !cfkerMl.
Qed.
Lemma cfker_prod I r (P : pred I) (Phi : I -> 'CF(G)) :
G :&: \bigcap_(i <- r | P i) cfker (Phi i)
\subset cfker (\prod_(i <- r | P i) Phi i).
Proof.
elim/big_rec2: _ => [|i K psi Pi sK_psi]; first by rewrite setIT cfker_cfun1.
by rewrite setICA; apply: subset_trans (setIS _ sK_psi) (cfker_mul _ _).
Qed.
Lemma cfaithfulE phi : cfaithful phi = (cfker phi \subset [1]).
Proof. by []. Qed.
End ClassFun.
Arguments classfun_on {gT} B%_g A%_g.
Notation "''CF' ( G , A )" := (classfun_on G A) : ring_scope.
Arguments cfun_onP {gT G A phi}.
Arguments cfConjCK {gT G} phi : rename.
#[global] Hint Resolve cfun_onT : core.
Section DotProduct.
Variable (gT : finGroupType) (G : {group gT}).
Implicit Types (M : {group gT}) (phi psi xi : 'CF(G)) (R S : seq 'CF(G)).
Lemma cfdotE phi psi :
'[phi, psi] = #|G|%:R^-1 * \sum_(x in G) phi x * (psi x)^*.
Proof. by []. Qed.
Lemma cfdotElr A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A :&: B) phi x * (psi x)^*.
Proof.
move=> Aphi Bpsi; rewrite (big_setID G)/= cfdotE (big_setID (A :&: B))/= setIC.
congr (_ * (_ + _)); rewrite !big1 // => x /setDP[_].
by move/cfun0->; rewrite mul0r.
rewrite inE; case/nandP=> notABx; first by rewrite (cfun_on0 Aphi) ?mul0r.
by rewrite (cfun_on0 Bpsi) // rmorph0 mulr0.
Qed.
Lemma cfdotEl A phi psi :
phi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Aphi; rewrite (cfdotElr Aphi (cfun_onT psi)) setIT. Qed.
Lemma cfdotEr A phi psi :
psi \in 'CF(G, A) ->
'[phi, psi] = #|G|%:R^-1 * \sum_(x in A) phi x * (psi x)^*.
Proof. by move=> Apsi; rewrite (cfdotElr (cfun_onT phi) Apsi) setTI. Qed.
Lemma cfdot_complement A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, G :\: A) -> '[phi, psi] = 0.
Proof.
move=> Aphi A'psi; rewrite (cfdotElr Aphi A'psi).
by rewrite setDE setICA setICr setI0 big_set0 mulr0.
Qed.
Lemma cfnormE A phi :
phi \in 'CF(G, A) -> '[phi] = #|G|%:R^-1 * (\sum_(x in A) `|phi x| ^+ 2).
Proof. by move/cfdotEl->; rewrite (eq_bigr _ (fun _ _ => normCK _)). Qed.
Lemma eq_cfdotl A phi1 phi2 psi :
psi \in 'CF(G, A) -> {in A, phi1 =1 phi2} -> '[phi1, psi] = '[phi2, psi].
Proof.
move/cfdotEr=> eq_dot eq_phi; rewrite !eq_dot; congr (_ * _).
by apply: eq_bigr => x Ax; rewrite eq_phi.
Qed.
Lemma cfdot_cfuni A B :
A <| G -> B <| G -> '['1_A, '1_B]_G = #|A :&: B|%:R / #|G|%:R.
Proof.
move=> nsAG nsBG; rewrite (cfdotElr (cfuni_on G A) (cfuni_on G B)) mulrC.
congr (_ / _); rewrite -sumr_const; apply: eq_bigr => x /setIP[Ax Bx].
by rewrite !cfuniE // Ax Bx mul1r rmorph1.
Qed.
Lemma cfnorm1 : '[1]_G = 1.
Proof. by rewrite cfdot_cfuni ?genGid // setIid divff ?neq0CG. Qed.
Lemma cfdotrE psi phi : cfdotr psi phi = '[phi, psi]. Proof. by []. Qed.
Lemma cfdotr_is_linear xi : linear (cfdotr xi : 'CF(G) -> algC^o).
Proof.
move=> a phi psi; rewrite scalerAr -mulrDr; congr (_ * _).
rewrite linear_sum -big_split; apply: eq_bigr => x _ /=.
by rewrite !cfunE mulrDl -mulrA.
Qed.
HB.instance Definition _ xi := GRing.isSemilinear.Build algC _ _ _ (cfdotr xi)
(GRing.semilinear_linear (cfdotr_is_linear xi)).
Lemma cfdot0l xi : '[0, xi] = 0.
Proof. by rewrite -cfdotrE linear0. Qed.
Lemma cfdotNl xi phi : '[- phi, xi] = - '[phi, xi].
Proof. by rewrite -!cfdotrE linearN. Qed.
Lemma cfdotDl xi phi psi : '[phi + psi, xi] = '[phi, xi] + '[psi, xi].
Proof. by rewrite -!cfdotrE linearD. Qed.
Lemma cfdotBl xi phi psi : '[phi - psi, xi] = '[phi, xi] - '[psi, xi].
Proof. by rewrite -!cfdotrE linearB. Qed.
Lemma cfdotMnl xi phi n : '[phi *+ n, xi] = '[phi, xi] *+ n.
Proof. by rewrite -!cfdotrE linearMn. Qed.
Lemma cfdot_suml xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[\sum_(i <- r | P i) phi i, xi] = \sum_(i <- r | P i) '[phi i, xi].
Proof. by rewrite -!cfdotrE linear_sum. Qed.
Lemma cfdotZl xi a phi : '[a *: phi, xi] = a * '[phi, xi].
Proof. by rewrite -!cfdotrE linearZ. Qed.
Lemma cfdotC phi psi : '[phi, psi] = ('[psi, phi])^*.
Proof.
rewrite /cfdot rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr=> x _; rewrite rmorphM /= conjCK mulrC.
Qed.
Lemma eq_cfdotr A phi psi1 psi2 :
phi \in 'CF(G, A) -> {in A, psi1 =1 psi2} -> '[phi, psi1] = '[phi, psi2].
Proof. by move=> Aphi /eq_cfdotl eq_dot; rewrite cfdotC eq_dot // -cfdotC. Qed.
Lemma cfdotBr xi phi psi : '[xi, phi - psi] = '[xi, phi] - '[xi, psi].
Proof. by rewrite !(cfdotC xi) -rmorphB cfdotBl. Qed.
HB.instance Definition _ xi :=
GRing.isZmodMorphism.Build _ _ (cfdot xi) (cfdotBr xi).
Lemma cfdot0r xi : '[xi, 0] = 0. Proof. exact: raddf0. Qed.
Lemma cfdotNr xi phi : '[xi, - phi] = - '[xi, phi].
Proof. exact: raddfN. Qed.
Lemma cfdotDr xi phi psi : '[xi, phi + psi] = '[xi, phi] + '[xi, psi].
Proof. exact: raddfD. Qed.
Lemma cfdotMnr xi phi n : '[xi, phi *+ n] = '[xi, phi] *+ n.
Proof. exact: raddfMn. Qed.
Lemma cfdot_sumr xi I r (P : pred I) (phi : I -> 'CF(G)) :
'[xi, \sum_(i <- r | P i) phi i] = \sum_(i <- r | P i) '[xi, phi i].
Proof. exact: raddf_sum. Qed.
Lemma cfdotZr a xi phi : '[xi, a *: phi] = a^* * '[xi, phi].
Proof. by rewrite !(cfdotC xi) cfdotZl rmorphM. Qed.
Lemma cfdot_cfAut (u : {rmorphism algC -> algC}) phi psi :
{in image psi G, {morph u : x / x^*}} ->
'[cfAut u phi, cfAut u psi] = u '[phi, psi].
Proof.
move=> uC; rewrite rmorphM /= fmorphV rmorph_nat rmorph_sum; congr (_ * _).
by apply: eq_bigr => x Gx; rewrite !cfunE rmorphM /= uC ?map_f ?mem_enum.
Qed.
Lemma cfdot_conjC phi psi : '[phi^*, psi^*] = '[phi, psi]^*.
Proof. by rewrite cfdot_cfAut. Qed.
Lemma cfdot_conjCl phi psi : '[phi^*, psi] = '[phi, psi^*]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfdot_conjCr phi psi : '[phi, psi^*] = '[phi^*, psi]^*.
Proof. by rewrite -cfdot_conjC cfConjCK. Qed.
Lemma cfnorm_ge0 phi : 0 <= '[phi].
Proof.
by rewrite mulr_ge0 ?invr_ge0 ?ler0n ?sumr_ge0 // => x _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_eq0 phi : ('[phi] == 0) = (phi == 0).
Proof.
apply/idP/eqP=> [|->]; last by rewrite cfdot0r.
rewrite mulf_eq0 invr_eq0 (negbTE (neq0CG G)) /= => /eqP/psumr_eq0P phi0.
apply/cfun_inP=> x Gx; apply/eqP; rewrite cfunE -mul_conjC_eq0.
by rewrite phi0 // => y _; apply: mul_conjC_ge0.
Qed.
Lemma cfnorm_gt0 phi : ('[phi] > 0) = (phi != 0).
Proof. by rewrite lt_def cfnorm_ge0 cfnorm_eq0 andbT. Qed.
Lemma sqrt_cfnorm_ge0 phi : 0 <= sqrtC '[phi].
Proof. by rewrite sqrtC_ge0 cfnorm_ge0. Qed.
Lemma sqrt_cfnorm_eq0 phi : (sqrtC '[phi] == 0) = (phi == 0).
Proof. by rewrite sqrtC_eq0 cfnorm_eq0. Qed.
Lemma sqrt_cfnorm_gt0 phi : (sqrtC '[phi] > 0) = (phi != 0).
Proof. by rewrite sqrtC_gt0 cfnorm_gt0. Qed.
Lemma cfnormZ a phi : '[a *: phi]= `|a| ^+ 2 * '[phi]_G.
Proof. by rewrite cfdotZl cfdotZr mulrA normCK. Qed.
Lemma cfnormN phi : '[- phi] = '[phi].
Proof. by rewrite cfdotNl raddfN opprK. Qed.
Lemma cfnorm_sign n phi : '[(-1) ^+ n *: phi] = '[phi].
Proof. by rewrite -signr_odd scaler_sign; case: (odd n); rewrite ?cfnormN. Qed.
Lemma cfnormD phi psi :
let d := '[phi, psi] in '[phi + psi] = '[phi] + '[psi] + ( d + d^* ).
Proof. by rewrite /= addrAC -cfdotC cfdotDl !cfdotDr !addrA. Qed.
Lemma cfnormB phi psi :
let d := '[phi, psi] in '[phi - psi] = '[phi] + '[psi] - ( d + d^* ).
Proof. by rewrite /= cfnormD cfnormN cfdotNr rmorphN -opprD. Qed.
Lemma cfnormDd phi psi : '[phi, psi] = 0 -> '[phi + psi] = '[phi] + '[psi].
Proof. by move=> ophipsi; rewrite cfnormD ophipsi rmorph0 !addr0. Qed.
Lemma cfnormBd phi psi : '[phi, psi] = 0 -> '[phi - psi] = '[phi] + '[psi].
Proof.
by move=> ophipsi; rewrite cfnormDd ?cfnormN // cfdotNr ophipsi oppr0.
Qed.
Lemma cfnorm_conjC phi : '[phi^*] = '[phi].
Proof. by rewrite cfdot_conjC geC0_conj // cfnorm_ge0. Qed.
Lemma cfCauchySchwarz phi psi :
`|'[phi, psi]| ^+ 2 <= '[phi] * '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC.
have [-> | nz_psi] /= := eqVneq psi 0.
by apply/leifP; rewrite !cfdot0r normCK mul0r mulr0.
without loss ophi: phi / '[phi, psi] = 0.
move=> IHo; pose a := '[phi, psi] / '[psi]; pose phi1 := phi - a *: psi.
have ophi: '[phi1, psi] = 0.
by rewrite cfdotBl cfdotZl divfK ?cfnorm_eq0 ?subrr.
rewrite (canRL (subrK _) (erefl phi1)) rpredDr ?rpredZ ?memv_line //.
rewrite cfdotDl ophi add0r cfdotZl normrM (ger0_norm (cfnorm_ge0 _)).
rewrite exprMn mulrA -cfnormZ cfnormDd; last by rewrite cfdotZr ophi mulr0.
by have:= IHo _ ophi; rewrite mulrDl -leifBLR subrr ophi normCK mul0r.
rewrite ophi normCK mul0r; split; first by rewrite mulr_ge0 ?cfnorm_ge0.
rewrite eq_sym mulf_eq0 orbC cfnorm_eq0 (negPf nz_psi) /=.
apply/idP/idP=> [|/vlineP[a {2}->]]; last by rewrite cfdotZr ophi mulr0.
by rewrite cfnorm_eq0 => /eqP->; apply: rpred0.
Qed.
Lemma cfCauchySchwarz_sqrt phi psi :
`|'[phi, psi]| <= sqrtC '[phi] * sqrtC '[psi] ?= iff ~~ free (phi :: psi).
Proof.
rewrite -(sqrCK (normr_ge0 _)) -sqrtCM ?qualifE/= ?cfnorm_ge0 //.
rewrite (mono_in_leif (@ler_sqrtC _)) 1?rpredM ?qualifE/= ?cfnorm_ge0 //;
[ exact: cfCauchySchwarz | exact: O.. ].
Qed.
Lemma cf_triangle_leif phi psi :
sqrtC '[phi + psi] <= sqrtC '[phi] + sqrtC '[psi]
?= iff ~~ free (phi :: psi) && (0 <= coord [tuple psi] 0 phi).
Proof.
rewrite -(mono_in_leif ler_sqr) ?rpredD ?qualifE/= ?sqrtC_ge0 ?cfnorm_ge0 //;
[| exact: O.. ].
rewrite andbC sqrrD !sqrtCK addrAC cfnormD (mono_leif (lerD2l _)).
rewrite -mulr_natr -[_ + _](divfK (negbT (eqC_nat 2 0))) -/('Re _).
rewrite (mono_leif (ler_pM2r _)) ?ltr0n //.
have:= leif_trans (leif_Re_Creal '[phi, psi]) (cfCauchySchwarz_sqrt phi psi).
congr (_ <= _ ?= iff _); first by rewrite ReE.
apply: andb_id2r; rewrite free_cons span_seq1 seq1_free -negb_or negbK orbC /=.
have [-> | nz_psi] := eqVneq psi 0; first by rewrite cfdot0r coord0.
case/vlineP=> [x ->]; rewrite cfdotZl linearZ pmulr_lge0 ?cfnorm_gt0 //=.
by rewrite (coord_free 0) ?seq1_free // eqxx mulr1.
Qed.
Lemma orthogonal_cons phi R S :
orthogonal (phi :: R) S = orthogonal phi S && orthogonal R S.
Proof. by rewrite /orthogonal /= andbT. Qed.
Lemma orthoP phi psi : reflect ('[phi, psi] = 0) (orthogonal phi psi).
Proof. by rewrite /orthogonal /= !andbT; apply: eqP. Qed.
Lemma orthogonalP S R :
reflect {in S & R, forall phi psi, '[phi, psi] = 0} (orthogonal S R).
Proof.
apply: (iffP allP) => oSR phi => [psi /oSR/allP opS /opS/eqP // | /oSR opS].
by apply/allP=> psi /= /opS->.
Qed.
Lemma orthoPl phi S :
reflect {in S, forall psi, '[phi, psi] = 0} (orthogonal phi S).
Proof.
by rewrite [orthogonal _ S]andbT /=; apply: (iffP allP) => ophiS ? /ophiS/eqP.
Qed.
Arguments orthoPl {phi S}.
Lemma orthogonal_sym : symmetric (@orthogonal _ G).
Proof.
apply: symmetric_from_pre => R S /orthogonalP oRS.
by apply/orthogonalP=> phi psi Rpsi Sphi; rewrite cfdotC oRS ?rmorph0.
Qed.
Lemma orthoPr S psi :
reflect {in S, forall phi, '[phi, psi] = 0} (orthogonal S psi).
Proof.
rewrite orthogonal_sym.
by apply: (iffP orthoPl) => oSpsi phi Sphi; rewrite cfdotC oSpsi ?conjC0.
Qed.
Lemma eq_orthogonal R1 R2 S1 S2 :
R1 =i R2 -> S1 =i S2 -> orthogonal R1 S1 = orthogonal R2 S2.
Proof.
move=> eqR eqS; rewrite [orthogonal _ _](eq_all_r eqR).
by apply: eq_all => psi /=; apply: eq_all_r.
Qed.
Lemma orthogonal_catl R1 R2 S :
orthogonal (R1 ++ R2) S = orthogonal R1 S && orthogonal R2 S.
Proof. exact: all_cat. Qed.
Lemma orthogonal_catr R S1 S2 :
orthogonal R (S1 ++ S2) = orthogonal R S1 && orthogonal R S2.
Proof. by rewrite !(orthogonal_sym R) orthogonal_catl. Qed.
Lemma span_orthogonal S1 S2 phi1 phi2 :
orthogonal 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 cfdot_suml big1 // => i _; rewrite cfdot_sumr big1 // => j _.
by rewrite cfdotZl cfdotZr oS12 ?mem_nth ?mulr0.
Qed.
Lemma orthogonal_split S beta :
{X : 'CF(G) & X \in <<S>>%VS &
{Y | [/\ beta = X + Y, '[X, Y] = 0 & orthogonal Y S]}}.
Proof.
suffices [X S_X [Y -> oYS]]:
{X : _ & X \in <<S>>%VS & {Y | beta = X + Y & orthogonal Y S}}.
- exists X => //; exists Y.
by rewrite cfdotC (span_orthogonal oYS) ?memv_span1 ?conjC0.
elim: S beta => [|phi S IHS] beta.
by exists 0; last exists beta; rewrite ?mem0v ?add0r.
have [[U 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 U 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 /[!inE] /predU1P[-> | Spsi]; last first.
by rewrite cfdotBl cfdotZl (orthoPl oVS _ Spsi) mulr0 subr0 (orthoPl oYS).
rewrite cfdotBl !cfdotDr (span_orthogonal oYS) // ?memv_span ?mem_head //.
rewrite !cfdotZl (span_orthogonal oVS _ S_U) ?mulr0 ?memv_span ?mem_head //.
have [-> | nzV] := eqVneq V 0; first by rewrite cfdot0r !mul0r subrr.
by rewrite divfK ?cfnorm_eq0 ?subrr.
Qed.
Lemma map_orthogonal M (nu : 'CF(G) -> 'CF(M)) S R (A : {pred 'CF(G)}) :
{in A &, isometry nu} -> {subset S <= A} -> {subset R <= A} ->
orthogonal (map nu S) (map nu R) = orthogonal S R.
Proof.
move=> Inu sSA sRA; rewrite [orthogonal _ _]all_map.
apply: eq_in_all => phi Sphi; rewrite /= all_map.
by apply: eq_in_all => psi Rpsi; rewrite /= Inu ?(sSA phi) ?(sRA psi).
Qed.
Lemma orthogonal_oppr S R : orthogonal S (map -%R R) = orthogonal S R.
Proof.
wlog suffices IH: S R / orthogonal S R -> orthogonal 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 cfdotNr oSR ?oppr0.
Qed.
Lemma orthogonal_oppl S R : orthogonal (map -%R S) R = orthogonal S R.
Proof. by rewrite -!(orthogonal_sym R) orthogonal_oppr. Qed.
Lemma pairwise_orthogonalP S :
reflect (uniq (0 :: S)
/\ {in S &, forall phi psi, phi != psi -> '[phi, psi] = 0})
(pairwise_orthogonal 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 _)) /= ?cfnorm_eq0 //.
apply: (iffP IH) => [] [uniqS oSS]; last first.
by split=> //; apply: sub_in2 oSS => psi Spsi; apply: mem_behead.
split=> // psi xi /[!inE] /predU1P[-> // | Spsi].
by case/predU1P=> [-> | /opS] /eqP.
case/predU1P=> [-> _ | Sxi /oSS-> //].
by apply/eqP; rewrite cfdotC conjC_eq0 [_ == 0]opS.
Qed.
Lemma pairwise_orthogonal_cat R S :
pairwise_orthogonal (R ++ S) =
[&& pairwise_orthogonal R, pairwise_orthogonal S & orthogonal R S].
Proof.
rewrite /pairwise_orthogonal mem_cat negb_or -!andbA; do !bool_congr.
elim: R => [|phi R /= ->]; rewrite ?andbT // orthogonal_cons all_cat -!andbA /=.
by do !bool_congr.
Qed.
Lemma eq_pairwise_orthogonal R S :
perm_eq R S -> pairwise_orthogonal R = pairwise_orthogonal 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 sub_pairwise_orthogonal S1 S2 :
{subset S1 <= S2} -> uniq S1 ->
pairwise_orthogonal S2 -> pairwise_orthogonal 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 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]_G = 0 := cfdot0r _.
rewrite -{2}aS0 raddf_sum /= (bigD1 i) //= big1 => [|j neq_ji]; last 1 first.
by rewrite cfdotZr oSS ?mulr0 ?mem_nth // eq_sym nth_uniq.
rewrite addr0 cfdotZr mulf_eq0 conjC_eq0 cfnorm_eq0.
by case/pred2P=> // Si0; rewrite -Si0 S_i in notS0.
Qed.
Lemma filter_pairwise_orthogonal S p :
pairwise_orthogonal S -> pairwise_orthogonal (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_not0 S : orthonormal S -> 0 \notin S.
Proof.
by case/andP=> /allP S1 _; rewrite (contra (S1 _)) //= cfdot0r 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.
Lemma orthonormal_cat R S :
orthonormal (R ++ S) = [&& orthonormal R, orthonormal S & orthogonal R S].
Proof.
rewrite !orthonormalE pairwise_orthogonal_cat all_cat -!andbA.
by do !bool_congr.
Qed.
Lemma eq_orthonormal R S : perm_eq R S -> orthonormal R = orthonormal S.
Proof.
move=> eqRS; rewrite !orthonormalE (eq_all_r (perm_mem eqRS)).
by rewrite (eq_pairwise_orthogonal eqRS).
Qed.
Lemma orthonormal_free S : orthonormal S -> free S.
Proof. by move/orthonormal_orthogonal/orthogonal_free. Qed.
Lemma orthonormalP S :
reflect (uniq S /\ {in S &, forall phi psi, '[phi, psi]_G = (phi == psi)%:R})
(orthonormal 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] := eqVneq.
split=> // [|phi psi Sphi Spsi /negbTE]; last by rewrite oSS // => ->.
by rewrite /= (contra (normS _)) // cfdot0r eq_sym oner_eq0.
Qed.
Lemma sub_orthonormal S1 S2 :
{subset S1 <= S2} -> uniq S1 -> orthonormal S2 -> orthonormal 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 [:: phi; psi]).
Proof.
rewrite /orthonormal /= !andbT andbC.
by apply: (iffP and3P) => [] []; do 3!move/eqP->.
Qed.
Lemma conjC_pair_orthogonal S chi :
cfConjC_closed S -> ~~ has cfReal S -> pairwise_orthogonal S -> chi \in S ->
pairwise_orthogonal (chi :: chi^*%CF).
Proof.
move=> ccS /hasPn nrS oSS Schi; apply: sub_pairwise_orthogonal oSS.
by apply/allP; rewrite /= Schi ccS.
by rewrite /= inE eq_sym nrS.
Qed.
Lemma cfdot_real_conjC phi psi : cfReal phi -> '[phi, psi^*]_G = '[phi, psi]^*.
Proof. by rewrite -cfdot_conjC => /eqcfP->. Qed.
Lemma extend_cfConjC_subset S X phi :
cfConjC_closed S -> ~~ has cfReal S -> phi \in S -> phi \notin X ->
cfConjC_subset X S -> cfConjC_subset [:: phi, phi^* & X]%CF S.
Proof.
move=> ccS nrS Sphi X'phi [uniqX /allP-sXS ccX].
split; last 1 [by apply/allP; rewrite /= Sphi ccS | apply/allP]; rewrite /= inE.
by rewrite negb_or X'phi eq_sym (hasPn nrS) // (contra (ccX _)) ?cfConjCK.
by rewrite cfConjCK !mem_head orbT; apply/allP=> xi Xxi; rewrite !inE ccX ?orbT.
Qed.
(* Note: other isometry lemmas, and the dot product lemmas for orthogonal *)
(* and orthonormal sequences are in vcharacter, because we need the 'Z[S] *)
(* notation for the isometry domains. Alternatively, this could be moved to *)
(* cfun. *)
End DotProduct.
Arguments orthoP {gT G phi psi}.
Arguments orthoPl {gT G phi S}.
Arguments orthoPr {gT G S psi}.
Arguments orthogonalP {gT G S R}.
Arguments pairwise_orthogonalP {gT G S}.
Arguments orthonormalP {gT G S}.
Section CfunOrder.
Variables (gT : finGroupType) (G : {group gT}) (phi : 'CF(G)).
Lemma dvdn_cforderP n :
reflect {in G, forall x, phi x ^+ n = 1} (#[phi]%CF %| n)%N.
Proof.
apply: (iffP (dvdn_biglcmP _ _ _)); rewrite genGid => phiG1 x Gx.
by apply/eqP; rewrite -dvdn_orderC phiG1.
by rewrite dvdn_orderC phiG1.
Qed.
Lemma dvdn_cforder n : (#[phi]%CF %| n) = (phi ^+ n == 1).
Proof.
apply/dvdn_cforderP/eqP=> phi_n_1 => [|x Gx].
by apply/cfun_inP=> x Gx; rewrite exp_cfunE // cfun1E Gx phi_n_1.
by rewrite -exp_cfunE // phi_n_1 // cfun1E Gx.
Qed.
Lemma exp_cforder : phi ^+ #[phi]%CF = 1.
Proof. by apply/eqP; rewrite -dvdn_cforder. Qed.
End CfunOrder.
Arguments dvdn_cforderP {gT G phi n}.
Section MorphOrder.
Variables (aT rT : finGroupType) (G : {group aT}) (R : {group rT}).
Variable f : {rmorphism 'CF(G) -> 'CF(R)}.
Lemma cforder_rmorph phi : #[f phi]%CF %| #[phi]%CF.
Proof. by rewrite dvdn_cforder -rmorphXn exp_cforder rmorph1. Qed.
Lemma cforder_inj_rmorph phi : injective f -> #[f phi]%CF = #[phi]%CF.
Proof.
move=> inj_f; apply/eqP; rewrite eqn_dvd cforder_rmorph dvdn_cforder /=.
by rewrite -(rmorph_eq1 _ inj_f) rmorphXn exp_cforder.
Qed.
End MorphOrder.
Section BuildIsometries.
Variable (gT : finGroupType) (L G : {group gT}).
Implicit Types (phi psi xi : 'CF(L)) (R S : seq 'CF(L)).
Implicit Types (U : {pred 'CF(L)}) (W : {pred 'CF(G)}).
Lemma sub_iso_to U1 U2 W1 W2 tau :
{subset U2 <= U1} -> {subset W1 <= W2} ->
{in U1, isometry tau, to W1} -> {in U2, isometry tau, to W2}.
Proof.
by move=> sU sW [Itau Wtau]; split=> [|u /sU/Wtau/sW //]; apply: sub_in2 Itau.
Qed.
Lemma isometry_of_free S f :
free S -> {in S &, isometry f} ->
{tau : {linear 'CF(L) -> 'CF(G)} |
{in S, tau =1 f} & {in <<S>>%VS &, isometry 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 !{1}linear_sum !{1}cfdot_suml; apply/eq_big_seq=> xi1 Sxi1.
rewrite !{1}cfdot_sumr; apply/eq_big_seq=> xi2 Sxi2.
by rewrite !linearZ /= !Dtau // !cfdotZl !cfdotZr If.
Qed.
Lemma isometry_of_cfnorm S tauS :
pairwise_orthogonal S -> pairwise_orthogonal tauS ->
map cfnorm tauS = map cfnorm S ->
{tau : {linear 'CF(L) -> 'CF(G)} | map tau S = tauS
& {in <<S>>%VS &, isometry 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 !cfdotZr !cfdot_suml; congr (_ * _).
apply: eq_bigr => j _ /=; rewrite linearZ !cfdotZl; congr (_ * _).
rewrite -!(nth_map 0 0 tau) ?{}defT //; have [-> | neq_ji] := eqVneq j i.
by rewrite -!['[_]](nth_map 0 0 cfnorm) ?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_raddf_inj U (tau : {additive 'CF(L) -> 'CF(G)}) :
{in U &, isometry tau} -> {in U &, forall u v, u - v \in U} ->
{in U &, injective tau}.
Proof.
move=> Itau linU phi psi Uphi Upsi /eqP; rewrite -subr_eq0 -raddfB.
by rewrite -cfnorm_eq0 Itau ?linU // cfnorm_eq0 subr_eq0 => /eqP.
Qed.
Lemma opp_isometry : @isometry _ _ G G -%R.
Proof. by move=> x y; rewrite cfdotNl cfdotNr opprK. Qed.
End BuildIsometries.
Section Restrict.
Variables (gT : finGroupType) (A B : {set gT}).
Local Notation H := <<A>>.
Local Notation G := <<B>>.
Fact cfRes_subproof (phi : 'CF(B)) :
is_class_fun H [ffun x => phi (if H \subset G then x else 1%g) *+ (x \in H)].
Proof.
apply: intro_class_fun => /= [x y Hx Hy | x /negbTE/=-> //].
by rewrite Hx (groupJ Hx) //; case: subsetP => // sHG; rewrite cfunJgen ?sHG.
Qed.
Definition cfRes phi := Cfun 1 (cfRes_subproof phi).
Lemma cfResE phi : A \subset B -> {in A, cfRes phi =1 phi}.
Proof. by move=> sAB x Ax; rewrite cfunElock mem_gen ?genS. Qed.
Lemma cfRes1 phi : cfRes phi 1%g = phi 1%g.
Proof. by rewrite cfunElock if_same group1. Qed.
Lemma cfRes_is_linear : linear cfRes.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfRes
(GRing.semilinear_linear cfRes_is_linear).
Lemma cfRes_cfun1 : cfRes 1 = 1.
Proof.
apply: cfun_in_genP => x Hx; rewrite cfunElock Hx !cfun1Egen Hx.
by case: subsetP => [-> // | _]; rewrite group1.
Qed.
Lemma cfRes_is_monoid_morphism : monoid_morphism cfRes.
Proof.
split=> [|phi psi]; [exact: cfRes_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfRes_is_monoid_morphism` instead")]
Definition cfRes_is_multiplicative :=
(fun g => (g.2,g.1)) cfRes_is_monoid_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfRes
cfRes_is_monoid_morphism.
End Restrict.
Arguments cfRes {gT} A%_g {B%_g} phi%_CF.
Notation "''Res[' H , G ]" := (@cfRes _ H G) (only parsing) : ring_scope.
Notation "''Res[' H ]" := 'Res[H, _] : ring_scope.
Notation "''Res'" := 'Res[_] (only parsing) : ring_scope.
Section MoreRestrict.
Variables (gT : finGroupType) (G H : {group gT}).
Implicit Types (A : {set gT}) (phi : 'CF(G)).
Lemma cfResEout phi : ~~ (H \subset G) -> 'Res[H] phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x.
by rewrite cfunE cfun1E mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfResRes A phi :
A \subset H -> H \subset G -> 'Res[A] ('Res[H] phi) = 'Res[A] phi.
Proof.
move=> sAH sHG; apply/cfunP=> x; rewrite !cfunElock !genGid !gen_subG sAH sHG.
by rewrite (subset_trans sAH) // -mulrnA mulnb -in_setI (setIidPr _) ?gen_subG.
Qed.
Lemma cfRes_id A psi : 'Res[A] psi = psi.
Proof. by apply/cfun_in_genP=> x Ax; rewrite cfunElock Ax subxx. Qed.
Lemma sub_cfker_Res A phi :
A \subset H -> A \subset cfker phi -> A \subset cfker ('Res[H, G] phi).
Proof.
move=> sAH kerA; apply/subsetP=> x Ax; have Hx := subsetP sAH x Ax.
rewrite inE Hx; apply/forallP=> y; rewrite !cfunElock !genGid groupMl //.
by rewrite !(fun_if phi) cfkerMl // (subsetP kerA).
Qed.
Lemma eq_cfker_Res phi : H \subset cfker phi -> cfker ('Res[H, G] phi) = H.
Proof. by move=> kH; apply/eqP; rewrite eqEsubset cfker_sub sub_cfker_Res. Qed.
Lemma cfRes_sub_ker phi : H \subset cfker phi -> 'Res[H, G] phi = (phi 1%g)%:A.
Proof.
move=> kerHphi; have sHG := subset_trans kerHphi (cfker_sub phi).
apply/cfun_inP=> x Hx; have ker_x := subsetP kerHphi x Hx.
by rewrite cfResE // cfunE cfun1E Hx mulr1 cfker1.
Qed.
Lemma cforder_Res phi : #['Res[H] phi]%CF %| #[phi]%CF.
Proof. exact: cforder_rmorph. Qed.
End MoreRestrict.
Section Morphim.
Variables (aT rT : finGroupType) (D : {group aT}) (f : {morphism D >-> rT}).
Section Main.
Variable G : {group aT}.
Implicit Type phi : 'CF(f @* G).
Fact cfMorph_subproof phi :
is_class_fun <<G>>
[ffun x => phi (if G \subset D then f x else 1%g) *+ (x \in G)].
Proof.
rewrite genGid; apply: intro_class_fun => [x y Gx Gy | x /negPf-> //].
rewrite Gx groupJ //; case subsetP => // sGD.
by rewrite morphJ ?cfunJ ?mem_morphim ?sGD.
Qed.
Definition cfMorph phi := Cfun 1 (cfMorph_subproof phi).
Lemma cfMorphE phi x : G \subset D -> x \in G -> cfMorph phi x = phi (f x).
Proof. by rewrite cfunElock => -> ->. Qed.
Lemma cfMorph1 phi : cfMorph phi 1%g = phi 1%g.
Proof. by rewrite cfunElock morph1 if_same group1. Qed.
Lemma cfMorphEout phi : ~~ (G \subset D) -> cfMorph phi = (phi 1%g)%:A.
Proof.
move/negPf=> not_sGD; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_sGD.
Qed.
Lemma cfMorph_cfun1 : cfMorph 1 = 1.
Proof.
apply/cfun_inP=> x Gx; rewrite cfunElock !cfun1E Gx.
by case: subsetP => [sGD | _]; rewrite ?group1 // mem_morphim ?sGD.
Qed.
Fact cfMorph_is_linear : linear cfMorph.
Proof.
by move=> a phi psi; apply/cfunP=> x; rewrite !cfunElock mulrnAr -mulrnDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfMorph
(GRing.semilinear_linear cfMorph_is_linear).
Fact cfMorph_is_monoid_morphism : monoid_morphism cfMorph.
Proof.
split=> [|phi psi]; [exact: cfMorph_cfun1 | apply/cfunP=> x].
by rewrite !cfunElock mulrnAr mulrnAl -mulrnA mulnb andbb.
Qed.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfMorph
cfMorph_is_monoid_morphism.
Hypothesis sGD : G \subset D.
Lemma cfMorph_inj : injective cfMorph.
Proof.
move=> phi1 phi2 eq_phi; apply/cfun_inP=> _ /morphimP[x Dx Gx ->].
by rewrite -!cfMorphE // eq_phi.
Qed.
Lemma cfMorph_eq1 phi : (cfMorph phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfMorph_inj. Qed.
Lemma cfker_morph phi : cfker (cfMorph phi) = G :&: f @*^-1 (cfker phi).
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
have Dx := subsetP sGD x Gx; rewrite Dx mem_morphim //=.
apply/forallP/forallP=> Kx y.
have [{y} /morphimP[y Dy Gy ->] | fG'y] := boolP (y \in f @* G).
by rewrite -morphM // -!(cfMorphE phi) ?groupM.
by rewrite !cfun0 ?groupMl // mem_morphim.
have [Gy | G'y] := boolP (y \in G); last by rewrite !cfun0 ?groupMl.
by rewrite !cfMorphE ?groupM ?morphM // (subsetP sGD).
Qed.
Lemma cfker_morph_im phi : f @* cfker (cfMorph phi) = cfker phi.
Proof. by rewrite cfker_morph // morphim_setIpre (setIidPr (cfker_sub _)). Qed.
Lemma sub_cfker_morph phi (A : {set aT}) :
(A \subset cfker (cfMorph phi)) = (A \subset G) && (f @* A \subset cfker phi).
Proof.
rewrite cfker_morph // subsetI; apply: andb_id2l => sAG.
by rewrite sub_morphim_pre // (subset_trans sAG).
Qed.
Lemma sub_morphim_cfker phi (A : {set aT}) :
A \subset G -> (f @* A \subset cfker phi) = (A \subset cfker (cfMorph phi)).
Proof. by move=> sAG; rewrite sub_cfker_morph ?sAG. Qed.
Lemma cforder_morph phi : #[cfMorph phi]%CF = #[phi]%CF.
Proof. exact/cforder_inj_rmorph/cfMorph_inj. Qed.
End Main.
Lemma cfResMorph (G H : {group aT}) (phi : 'CF(f @* G)) :
H \subset G -> G \subset D -> 'Res (cfMorph phi) = cfMorph ('Res[f @* H] phi).
Proof.
move=> sHG sGD; have sHD := subset_trans sHG sGD.
apply/cfun_inP=> x Hx; have [Gx Dx] := (subsetP sHG x Hx, subsetP sHD x Hx).
by rewrite !(cfMorphE, cfResE) ?morphimS ?mem_morphim //.
Qed.
End Morphim.
Prenex Implicits cfMorph.
Section Isomorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Let defR := isom_im isoGR.
Local Notation G1 := (isom_inv isoGR @* R).
Let defG : G1 = G := isom_im (isom_sym isoGR).
Fact cfIsom_key : unit. Proof. by []. Qed.
Definition cfIsom :=
locked_with cfIsom_key (cfMorph \o 'Res[G1] : 'CF(G) -> 'CF(R)).
Canonical cfIsom_unlockable := [unlockable of cfIsom].
Lemma cfIsomE phi (x : aT : finType) : x \in G -> cfIsom phi (f x) = phi x.
Proof.
move=> Gx; rewrite unlock cfMorphE //= /restrm ?defG ?cfRes_id ?invmE //.
by rewrite -defR mem_morphim.
Qed.
Lemma cfIsom1 phi : cfIsom phi 1%g = phi 1%g.
Proof. by rewrite -(morph1 f) cfIsomE. Qed.
Lemma cfIsom_is_zmod_morphism : zmod_morphism cfIsom.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_zmod_morphism` instead")]
Definition cfIsom_is_additive := cfIsom_is_zmod_morphism.
Lemma cfIsom_is_monoid_morphism : monoid_morphism cfIsom.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfIsom_is_monoid_morphism` instead")]
Definition cfIsom_is_multiplicative :=
(fun g => (g.2,g.1)) cfIsom_is_monoid_morphism.
Lemma cfIsom_is_scalable : scalable cfIsom.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfIsom cfIsom_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfIsom
cfIsom_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfIsom
cfIsom_is_scalable.
Lemma cfIsom_cfun1 : cfIsom 1 = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_isom phi : cfker (cfIsom phi) = f @* cfker phi.
Proof.
rewrite unlock cfker_morph // defG cfRes_id morphpre_restrm morphpre_invm.
by rewrite -defR !morphimIim.
Qed.
End Isomorphism.
Prenex Implicits cfIsom.
Section InvMorphism.
Variables (aT rT : finGroupType) (G : {group aT}) (f : {morphism G >-> rT}).
Variable R : {group rT}.
Hypothesis isoGR : isom G R f.
Lemma cfIsomK : cancel (cfIsom isoGR) (cfIsom (isom_sym isoGR)).
Proof.
move=> phi; apply/cfun_inP=> x Gx; rewrite -{1}(invmE (isom_inj isoGR) Gx).
by rewrite !cfIsomE // -(isom_im isoGR) mem_morphim.
Qed.
Lemma cfIsomKV : cancel (cfIsom (isom_sym isoGR)) (cfIsom isoGR).
Proof.
move=> phi; apply/cfun_inP=> y Ry; pose injGR := isom_inj isoGR.
rewrite -{1}[y](invmK injGR) ?(isom_im isoGR) //.
suffices /morphpreP[fGy Gf'y]: y \in invm injGR @*^-1 G by rewrite !cfIsomE.
by rewrite morphpre_invm (isom_im isoGR).
Qed.
Lemma cfIsom_inj : injective (cfIsom isoGR). Proof. exact: can_inj cfIsomK. Qed.
Lemma cfIsom_eq1 phi : (cfIsom isoGR phi == 1) = (phi == 1).
Proof. exact/rmorph_eq1/cfIsom_inj. Qed.
Lemma cforder_isom phi : #[cfIsom isoGR phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfIsom_inj. Qed.
End InvMorphism.
Arguments cfIsom_inj {aT rT G f R} isoGR [phi1 phi2] : rename.
Section Coset.
Variables (gT : finGroupType) (G : {group gT}) (B : {set gT}).
Implicit Type rT : finGroupType.
Local Notation H := <<B>>%g.
Definition cfMod : 'CF(G / B) -> 'CF(G) := cfMorph.
Definition ffun_Quo (phi : 'CF(G)) :=
[ffun Hx : coset_of B =>
phi (if B \subset cfker phi then repr Hx else 1%g) *+ (Hx \in G / B)%g].
Fact cfQuo_subproof phi : is_class_fun <<G / B>> (ffun_Quo phi).
Proof.
rewrite genGid; apply: intro_class_fun => [|Hx /negPf-> //].
move=> _ _ /morphimP[x Nx Gx ->] /morphimP[z Nz Gz ->].
rewrite -morphJ ?mem_morphim ?val_coset_prim ?groupJ //= -gen_subG.
case: subsetP => // KphiH; do 2!case: repr_rcosetP => _ /KphiH/cfkerMl->.
by rewrite cfunJ.
Qed.
Definition cfQuo phi := Cfun 1 (cfQuo_subproof phi).
Local Notation "phi / 'B'" := (cfQuo phi)
(at level 40, left associativity) : cfun_scope.
Local Notation "phi %% 'B'" := (cfMod phi) (at level 40) : cfun_scope.
(* We specialize the cfMorph lemmas to cfMod by strengthening the domain *)
(* condition G \subset 'N(H) to H <| G; the cfMorph lemmas can be used if the *)
(* stronger results are needed. *)
Lemma cfModE phi x : B <| G -> x \in G -> (phi %% B)%CF x = phi (coset B x).
Proof. by move/normal_norm=> nBG; apply: cfMorphE. Qed.
Lemma cfMod1 phi : (phi %% B)%CF 1%g = phi 1%g. Proof. exact: cfMorph1. Qed.
HB.instance Definition _ := GRing.LRMorphism.on cfMod.
Lemma cfMod_cfun1 : (1 %% B)%CF = 1. Proof. exact: rmorph1. Qed.
Lemma cfker_mod phi : B <| G -> B \subset cfker (phi %% B).
Proof.
case/andP=> sBG nBG; rewrite cfker_morph // subsetI sBG.
apply: subset_trans _ (ker_sub_pre _ _); rewrite ker_coset_prim subsetI.
by rewrite (subset_trans sBG nBG) sub_gen.
Qed.
(* Note that cfQuo is nondegenerate even when G does not normalize B. *)
Lemma cfQuoEnorm (phi : 'CF(G)) x :
B \subset cfker phi -> x \in 'N_G(B) -> (phi / B)%CF (coset B x) = phi x.
Proof.
rewrite cfunElock -gen_subG => sHK /setIP[Gx nHx]; rewrite sHK /=.
rewrite mem_morphim // val_coset_prim //.
by case: repr_rcosetP => _ /(subsetP sHK)/cfkerMl->.
Qed.
Lemma cfQuoE (phi : 'CF(G)) x :
B <| G -> B \subset cfker phi -> x \in G -> (phi / B)%CF (coset B x) = phi x.
Proof. by case/andP=> _ nBG sBK Gx; rewrite cfQuoEnorm // (setIidPl _). Qed.
Lemma cfQuo1 (phi : 'CF(G)) : (phi / B)%CF 1%g = phi 1%g.
Proof. by rewrite cfunElock repr_coset1 group1 if_same. Qed.
Lemma cfQuoEout (phi : 'CF(G)) :
~~ (B \subset cfker phi) -> (phi / B)%CF = (phi 1%g)%:A.
Proof.
move/negPf=> not_kerB; apply/cfunP=> x; rewrite cfunE cfun1E mulr_natr.
by rewrite cfunElock not_kerB.
Qed.
(* cfQuo is only linear on the class functions that have H in their kernel. *)
Lemma cfQuo_cfun1 : (1 / B)%CF = 1.
Proof.
apply/cfun_inP=> Hx G_Hx; rewrite cfunElock !cfun1E G_Hx cfker_cfun1 -gen_subG.
have [x nHx Gx ->] := morphimP G_Hx.
case: subsetP=> [sHG | _]; last by rewrite group1.
by rewrite val_coset_prim //; case: repr_rcosetP => y /sHG/groupM->.
Qed.
(* Cancellation properties *)
Lemma cfModK : B <| G -> cancel cfMod cfQuo.
Proof.
move=> nsBG phi; apply/cfun_inP=> _ /morphimP[x Nx Gx ->] //.
by rewrite cfQuoE ?cfker_mod ?cfModE.
Qed.
Lemma cfQuoK :
B <| G -> forall phi, B \subset cfker phi -> (phi / B %% B)%CF = phi.
Proof.
by move=> nsHG phi sHK; apply/cfun_inP=> x Gx; rewrite cfModE ?cfQuoE.
Qed.
Lemma cfMod_eq1 psi : B <| G -> (psi %% B == 1)%CF = (psi == 1).
Proof. by move/cfModK/can_eq <-; rewrite rmorph1. Qed.
Lemma cfQuo_eq1 phi :
B <| G -> B \subset cfker phi -> (phi / B == 1)%CF = (phi == 1).
Proof. by move=> nsBG kerH; rewrite -cfMod_eq1 // cfQuoK. Qed.
End Coset.
Arguments cfQuo {gT G%_G} B%_g phi%_CF.
Arguments cfMod {gT G%_G B%_g} phi%_CF.
Notation "phi / H" := (cfQuo H phi) : cfun_scope.
Notation "phi %% H" := (@cfMod _ _ H phi) : cfun_scope.
Section MoreCoset.
Variables (gT : finGroupType) (G : {group gT}).
Implicit Types (H K : {group gT}) (phi : 'CF(G)).
Lemma cfResMod H K (psi : 'CF(G / K)) :
H \subset G -> K <| G -> ('Res (psi %% K) = 'Res[H / K] psi %% K)%CF.
Proof. by move=> sHG /andP[_]; apply: cfResMorph. Qed.
Lemma quotient_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> (cfker (psi %% K) / K)%g = cfker psi.
Proof. by case/andP=> _ /cfker_morph_im <-. Qed.
Lemma sub_cfker_mod (A : {set gT}) K (psi : 'CF(G / K)) :
K <| G -> A \subset 'N(K) ->
(A \subset cfker (psi %% K)) = (A / K \subset cfker psi)%g.
Proof.
by move=> nsKG nKA; rewrite -(quotientSGK nKA) ?quotient_cfker_mod// cfker_mod.
Qed.
Lemma cfker_quo H phi :
H <| G -> H \subset cfker (phi) -> cfker (phi / H) = (cfker phi / H)%g.
Proof.
move=> nsHG /cfQuoK {2}<- //; have [sHG nHG] := andP nsHG.
by rewrite cfker_morph 1?quotientGI // cosetpreK (setIidPr _) ?cfker_sub.
Qed.
Lemma cfQuoEker phi x :
x \in G -> (phi / cfker phi)%CF (coset (cfker phi) x) = phi x.
Proof. by move/cfQuoE->; rewrite ?cfker_normal. Qed.
Lemma cfaithful_quo phi : cfaithful (phi / cfker phi).
Proof. by rewrite cfaithfulE cfker_quo ?cfker_normal ?trivg_quotient. Qed.
(* Note that there is no requirement that K be normal in H or G. *)
Lemma cfResQuo H K phi :
K \subset cfker phi -> K \subset H -> H \subset G ->
('Res[H / K] (phi / K) = 'Res[H] phi / K)%CF.
Proof.
move=> kerK sKH sHG; apply/cfun_inP=> xb Hxb; rewrite cfResE ?quotientS //.
have{xb Hxb} [x nKx Hx ->] := morphimP Hxb.
by rewrite !cfQuoEnorm ?cfResE// 1?inE ?Hx ?(subsetP sHG)// sub_cfker_Res.
Qed.
Lemma cfQuoInorm K phi :
K \subset cfker phi -> (phi / K)%CF = 'Res ('Res['N_G(K)] phi / K)%CF.
Proof.
move=> kerK; rewrite -cfResQuo ?subsetIl ?quotientInorm ?cfRes_id //.
by rewrite subsetI normG (subset_trans kerK) ?cfker_sub.
Qed.
Lemma cforder_mod H (psi : 'CF(G / H)) : H <| G -> #[psi %% H]%CF = #[psi]%CF.
Proof. by move/cfModK/can_inj/cforder_inj_rmorph->. Qed.
Lemma cforder_quo H phi :
H <| G -> H \subset cfker phi -> #[phi / H]%CF = #[phi]%CF.
Proof. by move=> nsHG kerHphi; rewrite -cforder_mod ?cfQuoK. Qed.
End MoreCoset.
Section Product.
Variable (gT : finGroupType) (G : {group gT}).
Lemma cfunM_onI A B phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, B) -> phi * psi \in 'CF(G, A :&: B).
Proof.
rewrite !cfun_onE => Aphi Bpsi; apply/subsetP=> x; rewrite !inE cfunE mulf_eq0.
by case/norP=> /(subsetP Aphi)-> /(subsetP Bpsi).
Qed.
Lemma cfunM_on A phi psi :
phi \in 'CF(G, A) -> psi \in 'CF(G, A) -> phi * psi \in 'CF(G, A).
Proof. by move=> Aphi Bpsi; rewrite -[A]setIid cfunM_onI. Qed.
End Product.
Section SDproduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis defG : K ><| H = G.
Fact cfSdprodKey : unit. Proof. by []. Qed.
Definition cfSdprod :=
locked_with cfSdprodKey
(cfMorph \o cfIsom (tagged (sdprod_isom defG)) : 'CF(H) -> 'CF(G)).
Canonical cfSdprod_unlockable := [unlockable of cfSdprod].
Lemma cfSdprod_is_zmod_morphism : zmod_morphism cfSdprod.
Proof. rewrite unlock; exact: raddfB. Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_zmod_morphism` instead")]
Definition cfSdprod_is_additive := cfSdprod_is_zmod_morphism.
Lemma cfSdprod_is_monoid_morphism : monoid_morphism cfSdprod.
Proof. rewrite unlock; exact: (rmorph1 _, rmorphM _). Qed.
#[warning="-deprecated-since-mathcomp-2.5.0", deprecated(since="mathcomp 2.5.0",
note="use `cfSdprod_is_monoid_morphism` instead")]
Definition cfSdprod_is_multiplicative :=
(fun g => (g.2,g.1)) cfSdprod_is_monoid_morphism.
Lemma cfSdprod_is_scalable : scalable cfSdprod.
Proof. rewrite unlock; exact: linearZ_LR. Qed.
HB.instance Definition _ := GRing.isZmodMorphism.Build _ _ cfSdprod cfSdprod_is_zmod_morphism.
HB.instance Definition _ := GRing.isMonoidMorphism.Build _ _ cfSdprod
cfSdprod_is_monoid_morphism.
HB.instance Definition _ := GRing.isScalable.Build _ _ _ _ cfSdprod
cfSdprod_is_scalable.
Lemma cfSdprod1 phi : cfSdprod phi 1%g = phi 1%g.
Proof. by rewrite unlock /= cfMorph1 cfIsom1. Qed.
Let nsKG : K <| G. Proof. by have [] := sdprod_context defG. Qed.
Let sHG : H \subset G. Proof. by have [] := sdprod_context defG. Qed.
Let sKG : K \subset G. Proof. by have [] := andP nsKG. Qed.
Lemma cfker_sdprod phi : K \subset cfker (cfSdprod phi).
Proof. by rewrite unlock_with cfker_mod. Qed.
Lemma cfSdprodEr phi : {in H, cfSdprod phi =1 phi}.
Proof. by move=> y Hy; rewrite unlock cfModE ?cfIsomE ?(subsetP sHG). Qed.
Lemma cfSdprodE phi : {in K & H, forall x y, cfSdprod phi (x * y)%g = phi y}.
Proof.
by move=> x y Kx Hy; rewrite /= cfkerMl ?(subsetP (cfker_sdprod _)) ?cfSdprodEr.
Qed.
Lemma cfSdprodK : cancel cfSdprod 'Res[H].
Proof. by move=> phi; apply/cfun_inP=> x Hx; rewrite cfResE ?cfSdprodEr. Qed.
Lemma cfSdprod_inj : injective cfSdprod. Proof. exact: can_inj cfSdprodK. Qed.
Lemma cfSdprod_eq1 phi : (cfSdprod phi == 1) = (phi == 1).
Proof. exact: rmorph_eq1 cfSdprod_inj. Qed.
Lemma cfRes_sdprodK phi : K \subset cfker phi -> cfSdprod ('Res[H] phi) = phi.
Proof.
move=> kerK; apply/cfun_inP=> _ /(mem_sdprod defG)[x [y [Kx Hy -> _]]].
by rewrite cfSdprodE // cfResE // cfkerMl ?(subsetP kerK).
Qed.
Lemma sdprod_cfker phi : K ><| cfker phi = cfker (cfSdprod phi).
Proof.
have [skerH [_ _ nKH tiKH]] := (cfker_sub phi, sdprodP defG).
rewrite unlock cfker_morph ?normal_norm // cfker_isom restrmEsub //=.
rewrite -(sdprod_modl defG) ?sub_cosetpre //=; congr (_ ><| _).
by rewrite quotientK ?(subset_trans skerH) // -group_modr //= setIC tiKH mul1g.
Qed.
Lemma cforder_sdprod phi : #[cfSdprod phi]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfSdprod_inj. Qed.
End SDproduct.
Section DProduct.
Variables (gT : finGroupType) (G K H : {group gT}).
Hypothesis KxH : K \x H = G.
Lemma reindex_dprod R idx (op : Monoid.com_law idx) (F : gT -> R) :
\big[op/idx]_(g in G) F g =
\big[op/idx]_(k in K) \big[op/idx]_(h in H) F (k * h)%g.
Proof.
have /mulgmP/misomP[fM /isomP[injf im_f]] := KxH.
rewrite pair_big_dep -im_f morphimEdom big_imset; last exact/injmP.
by apply: eq_big => [][x y]; rewrite ?inE.
Qed.
Definition cfDprodr := cfSdprod (dprodWsd KxH).
Definition cfDprodl := cfSdprod (dprodWsdC KxH).
Definition cfDprod phi psi := cfDprodl phi * cfDprodr psi.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodl.
HB.instance Definition _ := GRing.LRMorphism.on cfDprodr.
Lemma cfDprodl1 phi : cfDprodl phi 1%g = phi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprodr1 psi : cfDprodr psi 1%g = psi 1%g. Proof. exact: cfSdprod1. Qed.
Lemma cfDprod1 phi psi : cfDprod phi psi 1%g = phi 1%g * psi 1%g.
Proof. by rewrite cfunE /= !cfSdprod1. Qed.
Lemma cfDprodl_eq1 phi : (cfDprodl phi == 1) = (phi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprodr_eq1 psi : (cfDprodr psi == 1) = (psi == 1).
Proof. exact: cfSdprod_eq1. Qed.
Lemma cfDprod_cfun1r phi : cfDprod phi 1 = cfDprodl phi.
Proof. by rewrite /cfDprod rmorph1 mulr1. Qed.
Lemma cfDprod_cfun1l psi : cfDprod 1 psi = cfDprodr psi.
Proof. by rewrite /cfDprod rmorph1 mul1r. Qed.
Lemma cfDprod_cfun1 : cfDprod 1 1 = 1.
Proof. by rewrite cfDprod_cfun1l rmorph1. Qed.
Lemma cfDprod_split phi psi : cfDprod phi psi = cfDprod phi 1 * cfDprod 1 psi.
Proof. by rewrite cfDprod_cfun1l cfDprod_cfun1r. Qed.
Let nsKG : K <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let nsHG : H <| G. Proof. by have [] := dprod_normal2 KxH. Qed.
Let cKH : H \subset 'C(K). Proof. by have [] := dprodP KxH. Qed.
Let sKG := normal_sub nsKG.
Let sHG := normal_sub nsHG.
Lemma cfDprodlK : cancel cfDprodl 'Res[K]. Proof. exact: cfSdprodK. Qed.
Lemma cfDprodrK : cancel cfDprodr 'Res[H]. Proof. exact: cfSdprodK. Qed.
Lemma cfker_dprodl phi : cfker phi \x H = cfker (cfDprodl phi).
Proof.
by rewrite dprodC -sdprod_cfker dprodEsd // centsC (centsS (cfker_sub _)).
Qed.
Lemma cfker_dprodr psi : K \x cfker psi = cfker (cfDprodr psi).
Proof. by rewrite -sdprod_cfker dprodEsd // (subset_trans (cfker_sub _)). Qed.
Lemma cfDprodEl phi : {in K & H, forall k h, cfDprodl phi (k * h)%g = phi k}.
Proof. by move=> k h Kk Hh /=; rewrite -(centsP cKH) // cfSdprodE. Qed.
Lemma cfDprodEr psi : {in K & H, forall k h, cfDprodr psi (k * h)%g = psi h}.
Proof. exact: cfSdprodE. Qed.
Lemma cfDprodE phi psi :
{in K & H, forall h k, cfDprod phi psi (h * k)%g = phi h * psi k}.
Proof. by move=> k h Kk Hh /=; rewrite cfunE cfDprodEl ?cfDprodEr. Qed.
Lemma cfDprod_Resl phi psi : 'Res[K] (cfDprod phi psi) = psi 1%g *: phi.
Proof.
by apply/cfun_inP=> x Kx; rewrite cfunE cfResE // -{1}[x]mulg1 mulrC cfDprodE.
Qed.
Lemma cfDprod_Resr phi psi : 'Res[H] (cfDprod phi psi) = phi 1%g *: psi.
Proof.
by apply/cfun_inP=> y Hy; rewrite cfunE cfResE // -{1}[y]mul1g cfDprodE.
Qed.
Lemma cfDprodKl (psi : 'CF(H)) : psi 1%g = 1 -> cancel (cfDprod^~ psi) 'Res.
Proof. by move=> psi1 phi; rewrite cfDprod_Resl psi1 scale1r. Qed.
Lemma cfDprodKr (phi : 'CF(K)) : phi 1%g = 1 -> cancel (cfDprod phi) 'Res.
Proof. by move=> phi1 psi; rewrite cfDprod_Resr phi1 scale1r. Qed.
(* Note that equality holds here iff either cfker phi = K and cfker psi = H, *)
(* or else phi != 0, psi != 0 and coprime #|K : cfker phi| #|H : cfker phi|. *)
Lemma cfker_dprod phi psi :
cfker phi <*> cfker psi \subset cfker (cfDprod phi psi).
Proof.
rewrite -genM_join gen_subG; apply/subsetP=> _ /mulsgP[x y kKx kHy ->] /=.
have [[Kx _] [Hy _]] := (setIdP kKx, setIdP kHy).
have Gxy: (x * y)%g \in G by rewrite -(dprodW KxH) mem_mulg.
rewrite inE Gxy; apply/forallP=> g.
have [Gg | G'g] := boolP (g \in G); last by rewrite !cfun0 1?groupMl.
have{g Gg} [k [h [Kk Hh -> _]]] := mem_dprod KxH Gg.
rewrite mulgA -(mulgA x) (centsP cKH y) // mulgA -mulgA !cfDprodE ?groupM //.
by rewrite !cfkerMl.
Qed.
Lemma cfdot_dprod phi1 phi2 psi1 psi2 :
'[cfDprod phi1 psi1, cfDprod phi2 psi2] = '[phi1, phi2] * '[psi1, psi2].
Proof.
rewrite !cfdotE mulrCA -mulrA mulrCA mulrA -invfM -natrM (dprod_card KxH).
congr (_ * _); rewrite big_distrl reindex_dprod /=; apply: eq_bigr => k Kk.
rewrite big_distrr; apply: eq_bigr => h Hh /=.
by rewrite mulrCA -mulrA -rmorphM mulrCA mulrA !cfDprodE.
Qed.
Lemma cfDprodl_iso : isometry cfDprodl.
Proof.
by move=> phi1 phi2; rewrite -!cfDprod_cfun1r cfdot_dprod cfnorm1 mulr1.
Qed.
Lemma cfDprodr_iso : isometry cfDprodr.
Proof.
by move=> psi1 psi2; rewrite -!cfDprod_cfun1l cfdot_dprod cfnorm1 mul1r.
Qed.
Lemma cforder_dprodl phi : #[cfDprodl phi]%CF = #[phi]%CF.
Proof. exact: cforder_sdprod. Qed.
Lemma cforder_dprodr psi : #[cfDprodr psi]%CF = #[psi]%CF.
Proof. exact: cforder_sdprod. Qed.
End DProduct.
Lemma cfDprodC (gT : finGroupType) (G K H : {group gT})
(KxH : K \x H = G) (HxK : H \x K = G) chi psi :
cfDprod KxH chi psi = cfDprod HxK psi chi.
Proof.
rewrite /cfDprod mulrC.
by congr (_ * _); congr (cfSdprod _ _); apply: eq_irrelevance.
Qed.
Section Bigdproduct.
Variables (gT : finGroupType) (I : finType) (P : pred I).
Variables (A : I -> {group gT}) (G : {group gT}).
Hypothesis defG : \big[dprod/1%g]_(i | P i) A i = G.
Let sAG i : P i -> A i \subset G.
Proof. by move=> Pi; rewrite -(bigdprodWY defG) (bigD1 i) ?joing_subl. Qed.
Fact cfBigdprodi_subproof i :
gval (if P i then A i else 1%G) \x <<\bigcup_(j | P j && (j != i)) A j>> = G.
Proof.
have:= defG; rewrite fun_if big_mkcond (bigD1 i) // -big_mkcondl /= => defGi.
by have [[_ Gi' _ defGi']] := dprodP defGi; rewrite (bigdprodWY defGi') -defGi'.
Qed.
Definition cfBigdprodi i := cfDprodl (cfBigdprodi_subproof i) \o 'Res[_, A i].
HB.instance Definition _ i := GRing.LRMorphism.on (@cfBigdprodi i).
Lemma cfBigdprodi1 i (phi : 'CF(A i)) : cfBigdprodi phi 1%g = phi 1%g.
Proof. by rewrite cfDprodl1 cfRes1. Qed.
Lemma cfBigdprodi_eq1 i (phi : 'CF(A i)) :
P i -> (cfBigdprodi phi == 1) = (phi == 1).
Proof. by move=> Pi; rewrite cfSdprod_eq1 Pi cfRes_id. Qed.
Lemma cfBigdprodiK i : P i -> cancel (@cfBigdprodi i) 'Res[A i].
Proof.
move=> Pi phi; have:= cfDprodlK (cfBigdprodi_subproof i) ('Res phi).
by rewrite -[cfDprodl _ _]/(cfBigdprodi phi) Pi cfRes_id.
Qed.
Lemma cfBigdprodi_inj i : P i -> injective (@cfBigdprodi i).
Proof. by move/cfBigdprodiK; apply: can_inj. Qed.
Lemma cfBigdprodEi i (phi : 'CF(A i)) x :
P i -> (forall j, P j -> x j \in A j) ->
cfBigdprodi phi (\prod_(j | P j) x j)%g = phi (x i).
Proof.
have [r big_r [Ur mem_r] _] := big_enumP P => Pi AxP.
have:= bigdprodWcp defG; rewrite -!big_r => defGr.
have{AxP} [r_i Axr]: i \in r /\ {in r, forall j, x j \in A j}.
by split=> [|j]; rewrite mem_r // => /AxP.
rewrite (perm_bigcprod defGr Axr (perm_to_rem r_i)) big_cons.
rewrite cfDprodEl ?Pi ?cfRes_id ?Axr // big_seq group_prod // => j.
rewrite mem_rem_uniq // => /andP[i'j /= r_j].
by apply/mem_gen/bigcupP; exists j; [rewrite -mem_r r_j | apply: Axr].
Qed.
Lemma cfBigdprodi_iso i : P i -> isometry (@cfBigdprodi i).
Proof. by move=> Pi phi psi; rewrite cfDprodl_iso Pi !cfRes_id. Qed.
Definition cfBigdprod (phi : forall i, 'CF(A i)) :=
\prod_(i | P i) cfBigdprodi (phi i).
Lemma cfBigdprodE phi x :
(forall i, P i -> x i \in A i) ->
cfBigdprod phi (\prod_(i | P i) x i)%g = \prod_(i | P i) phi i (x i).
Proof.
move=> Ax; rewrite prod_cfunE; last by rewrite -(bigdprodW defG) mem_prodg.
by apply: eq_bigr => i Pi; rewrite cfBigdprodEi.
Qed.
Lemma cfBigdprod1 phi : cfBigdprod phi 1%g = \prod_(i | P i) phi i 1%g.
Proof. by rewrite prod_cfunE //; apply/eq_bigr=> i _; apply: cfBigdprodi1. Qed.
Lemma cfBigdprodK phi (Phi := cfBigdprod phi) i (a := phi i 1%g / Phi 1%g) :
Phi 1%g != 0 -> P i -> a != 0 /\ a *: 'Res[A i] Phi = phi i.
Proof.
move=> nzPhi Pi; split.
rewrite mulf_neq0 ?invr_eq0 // (contraNneq _ nzPhi) // => phi_i0.
by rewrite cfBigdprod1 (bigD1 i) //= phi_i0 mul0r.
apply/cfun_inP=> x Aix; rewrite cfunE cfResE ?sAG // mulrAC.
have {1}->: x = (\prod_(j | P j) (if j == i then x else 1))%g.
rewrite -big_mkcondr (big_pred1 i) ?eqxx // => j /=.
by apply: andb_idl => /eqP->.
rewrite cfBigdprodE => [|j _]; last by case: eqP => // ->.
apply: canLR (mulfK nzPhi) _; rewrite cfBigdprod1 !(bigD1 i Pi) /= eqxx.
by rewrite mulrCA !mulrA; congr (_ * _); apply: eq_bigr => j /andP[_ /negPf->].
Qed.
Lemma cfdot_bigdprod phi psi :
'[cfBigdprod phi, cfBigdprod psi] = \prod_(i | P i) '[phi i, psi i].
Proof.
apply: canLR (mulKf (neq0CG G)) _; rewrite -(bigdprod_card defG).
rewrite (big_morph _ (@natrM _) (erefl _)) -big_split /=.
rewrite (eq_bigr _ (fun i _ => mulVKf (neq0CG _) _)) (big_distr_big_dep 1%g) /=.
set F := pfamily _ _ _; pose h (f : {ffun I -> gT}) := (\prod_(i | P i) f i)%g.
pose is_hK x f := forall f1, (f1 \in F) && (h f1 == x) = (f == f1).
have /fin_all_exists[h1 Dh1] x: exists f, x \in G -> is_hK x f.
case Gx: (x \in G); last by exists [ffun _ => x].
have [f [Af fK Uf]] := mem_bigdprod defG Gx.
exists [ffun i => if P i then f i else 1%g] => _ f1.
apply/andP/eqP=> [[/pfamilyP[Pf1 Af1] /eqP Dx] | <-].
by apply/ffunP=> i; rewrite ffunE; case: ifPn => [/Uf-> | /(supportP Pf1)].
split; last by rewrite fK; apply/eqP/eq_bigr=> i Pi; rewrite ffunE Pi.
by apply/familyP=> i; rewrite ffunE !unfold_in; case: ifP => //= /Af.
rewrite (reindex_onto h h1) /= => [|x /Dh1/(_ (h1 x))]; last first.
by rewrite eqxx => /andP[_ /eqP].
apply/eq_big => [f | f /andP[/Dh1<- /andP[/pfamilyP[_ Af] _]]]; last first.
by rewrite !cfBigdprodE // rmorph_prod -big_split /=.
apply/idP/idP=> [/andP[/Dh1<-] | Ff]; first by rewrite eqxx andbT.
have /pfamilyP[_ Af] := Ff; suffices Ghf: h f \in G by rewrite -Dh1 ?Ghf ?Ff /=.
by apply/group_prod=> i Pi; rewrite (subsetP (sAG Pi)) ?Af.
Qed.
End Bigdproduct.
Section MorphIsometry.
Variable gT : finGroupType.
Implicit Types (D G H K : {group gT}) (aT rT : finGroupType).
Lemma cfMorph_iso aT rT (G D : {group aT}) (f : {morphism D >-> rT}) :
G \subset D -> isometry (cfMorph : 'CF(f @* G) -> 'CF(G)).
Proof.
move=> sGD phi psi; rewrite !cfdotE card_morphim (setIidPr sGD).
rewrite -(LagrangeI G ('ker f)) /= mulnC natrM invfM -mulrA.
congr (_ * _); apply: (canLR (mulKf (neq0CG _))).
rewrite mulr_sumr (partition_big_imset f) /= -morphimEsub //.
apply: eq_bigr => _ /morphimP[x Dx Gx ->].
rewrite -(card_rcoset _ x) mulr_natl -sumr_const.
apply/eq_big => [y | y /andP[Gy /eqP <-]]; last by rewrite !cfMorphE.
rewrite mem_rcoset inE groupMr ?groupV // -mem_rcoset.
by apply: andb_id2l => /(subsetP sGD) Dy; apply: sameP eqP (rcoset_kerP f _ _).
Qed.
Lemma cfIsom_iso rT G (R : {group rT}) (f : {morphism G >-> rT}) :
forall isoG : isom G R f, isometry (cfIsom isoG).
Proof.
move=> isoG phi psi; rewrite unlock cfMorph_iso //; set G1 := _ @* R.
by rewrite -(isom_im (isom_sym isoG)) -/G1 in phi psi *; rewrite !cfRes_id.
Qed.
Lemma cfMod_iso H G : H <| G -> isometry (@cfMod _ G H).
Proof. by case/andP=> _; apply: cfMorph_iso. Qed.
Lemma cfQuo_iso H G :
H <| G -> {in [pred phi | H \subset cfker phi] &, isometry (@cfQuo _ G H)}.
Proof.
by move=> nsHG phi psi sHkphi sHkpsi; rewrite -(cfMod_iso nsHG) !cfQuoK.
Qed.
Lemma cfnorm_quo H G phi :
H <| G -> H \subset cfker phi -> '[phi / H] = '[phi]_G.
Proof. by move=> nsHG sHker; apply: cfQuo_iso. Qed.
Lemma cfSdprod_iso K H G (defG : K ><| H = G) : isometry (cfSdprod defG).
Proof.
move=> phi psi; have [/andP[_ nKG] _ _ _ _] := sdprod_context defG.
by rewrite [cfSdprod _]locked_withE cfMorph_iso ?cfIsom_iso.
Qed.
End MorphIsometry.
Section Induced.
Variable gT : finGroupType.
Section Def.
Variables B A : {set gT}.
Local Notation G := <<B>>.
Local Notation H := <<A>>.
(* The default value for the ~~ (H \subset G) case matches the one for cfRes *)
(* so that Frobenius reciprocity holds even in this degenerate case. *)
Definition ffun_cfInd (phi : 'CF(A)) :=
[ffun x => if H \subset G then #|A|%:R^-1 * (\sum_(y in G) phi (x ^ y))
else #|G|%:R * '[phi, 1] *+ (x == 1%g)].
Fact cfInd_subproof phi : is_class_fun G (ffun_cfInd phi).
Proof.
apply: intro_class_fun => [x y Gx Gy | x H'x]; last first.
case: subsetP => [sHG | _]; last by rewrite (negPf (group1_contra H'x)).
rewrite big1 ?mulr0 // => y Gy; rewrite cfun0gen ?(contra _ H'x) //= => /sHG.
by rewrite memJ_norm ?(subsetP (normG _)).
rewrite conjg_eq1 (reindex_inj (mulgI y^-1)%g); congr (if _ then _ * _ else _).
by apply: eq_big => [z | z Gz]; rewrite ?groupMl ?groupV // -conjgM mulKVg.
Qed.
Definition cfInd phi := Cfun 1 (cfInd_subproof phi).
Lemma cfInd_is_linear : linear cfInd.
Proof.
move=> c phi psi; apply/cfunP=> x; rewrite !cfunElock; case: ifP => _.
rewrite mulrCA -mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * _); apply: eq_bigr => y _; rewrite !cfunE.
rewrite mulrnAr -mulrnDl !(mulrCA c) -!mulrDr [c * _]mulr_sumr -big_split /=.
by congr (_ * (_ * _) *+ _); apply: eq_bigr => y; rewrite !cfunE mulrA mulrDl.
Qed.
HB.instance Definition _ := GRing.isSemilinear.Build algC _ _ _ cfInd
(GRing.semilinear_linear cfInd_is_linear).
End Def.
Local Notation "''Ind[' B , A ]" := (@cfInd B A) : ring_scope.
Local Notation "''Ind[' B ]" := 'Ind[B, _] : ring_scope.
Lemma cfIndE (G H : {group gT}) phi x :
H \subset G -> 'Ind[G, H] phi x = #|H|%:R^-1 * (\sum_(y in G) phi (x ^ y)).
Proof. by rewrite cfunElock !genGid => ->. Qed.
Variables G K H : {group gT}.
Implicit Types (phi : 'CF(H)) (psi : 'CF(G)).
Lemma cfIndEout phi :
~~ (H \subset G) -> 'Ind[G] phi = (#|G|%:R * '[phi, 1]) *: '1_1%G.
Proof.
move/negPf=> not_sHG; apply/cfunP=> x; rewrite cfunE cfuniE ?normal1 // inE.
by rewrite mulr_natr cfunElock !genGid not_sHG.
Qed.
Lemma cfIndEsdprod (phi : 'CF(K)) x :
K ><| H = G -> 'Ind[G] phi x = \sum_(w in H) phi (x ^ w)%g.
Proof.
move=> defG; have [/andP[sKG _] _ mulKH nKH _] := sdprod_context defG.
rewrite cfIndE //; apply: canLR (mulKf (neq0CG _)) _; rewrite -mulKH mulr_sumr.
rewrite (set_partition_big _ (rcosets_partition_mul H K)) ?big_imset /=.
apply: eq_bigr => y Hy; rewrite rcosetE norm_rlcoset ?(subsetP nKH) //.
rewrite -lcosetE mulr_natl big_imset /=; last exact: in2W (mulgI _).
by rewrite -sumr_const; apply: eq_bigr => z Kz; rewrite conjgM cfunJ.
have [{}nKH /isomP[injf _]] := sdprod_isom defG.
apply: can_in_inj (fun Ky => invm injf (coset K (repr Ky))) _ => y Hy.
by rewrite rcosetE -val_coset ?(subsetP nKH) // coset_reprK invmE.
Qed.
Lemma cfInd_on A phi :
H \subset G -> phi \in 'CF(H, A) -> 'Ind[G] phi \in 'CF(G, class_support A G).
Proof.
move=> sHG Af; apply/cfun_onP=> g AG'g; rewrite cfIndE ?big1 ?mulr0 // => h Gh.
apply: (cfun_on0 Af); apply: contra AG'g => Agh.
by rewrite -[g](conjgK h) memJ_class_support // groupV.
Qed.
Lemma cfInd_id phi : 'Ind[H] phi = phi.
Proof.
apply/cfun_inP=> x Hx; rewrite cfIndE // (eq_bigr _ (cfunJ phi x)) sumr_const.
by rewrite -[phi x *+ _]mulr_natl mulKf ?neq0CG.
Qed.
Lemma cfInd_normal phi : H <| G -> 'Ind[G] phi \in 'CF(G, H).
Proof.
case/andP=> sHG nHG; apply: (cfun_onS (class_support_sub_norm (subxx _) nHG)).
by rewrite cfInd_on ?cfun_onG.
Qed.
Lemma cfInd1 phi : H \subset G -> 'Ind[G] phi 1%g = #|G : H|%:R * phi 1%g.
Proof.
move=> sHG; rewrite cfIndE // natf_indexg // -mulrA mulrCA; congr (_ * _).
by rewrite mulr_natl -sumr_const; apply: eq_bigr => x; rewrite conj1g.
Qed.
Lemma cfInd_cfun1 : H <| G -> 'Ind[G, H] 1 = #|G : H|%:R *: '1_H.
Proof.
move=> nsHG; have [sHG nHG] := andP nsHG; rewrite natf_indexg // mulrC.
apply/cfunP=> x; rewrite cfIndE ?cfunE ?cfuniE // -mulrA; congr (_ * _).
rewrite mulr_natl -sumr_const; apply: eq_bigr => y Gy.
by rewrite cfun1E -{1}(normsP nHG y Gy) memJ_conjg.
Qed.
Lemma cfnorm_Ind_cfun1 : H <| G -> '['Ind[G, H] 1] = #|G : H|%:R.
Proof.
move=> nsHG; rewrite cfInd_cfun1 // cfnormZ normr_nat cfdot_cfuni // setIid.
by rewrite expr2 {2}natf_indexg ?normal_sub // !mulrA divfK ?mulfK ?neq0CG.
Qed.
Lemma cfIndInd phi :
K \subset G -> H \subset K -> 'Ind[G] ('Ind[K] phi) = 'Ind[G] phi.
Proof.
move=> sKG sHK; apply/cfun_inP=> x Gx; rewrite !cfIndE ?(subset_trans sHK) //.
apply: canLR (mulKf (neq0CG K)) _; rewrite mulr_sumr mulr_natl.
transitivity (\sum_(y in G) \sum_(z in K) #|H|%:R^-1 * phi ((x ^ y) ^ z)).
by apply: eq_bigr => y Gy; rewrite cfIndE // -mulr_sumr.
symmetry; rewrite exchange_big /= -sumr_const; apply: eq_bigr => z Kz.
rewrite (reindex_inj (mulIg z)).
by apply: eq_big => [y | y _]; rewrite ?conjgM // groupMr // (subsetP sKG).
Qed.
(* This is Isaacs, Lemma (5.2). *)
Lemma Frobenius_reciprocity phi psi : '[phi, 'Res[H] psi] = '['Ind[G] phi, psi].
Proof.
have [sHG | not_sHG] := boolP (H \subset G); last first.
rewrite cfResEout // cfIndEout // cfdotZr cfdotZl mulrAC; congr (_ * _).
rewrite (cfdotEl _ (cfuni_on _ _)) mulVKf ?neq0CG // big_set1.
by rewrite cfuniE ?normal1 ?set11 ?mul1r.
transitivity (#|H|%:R^-1 * \sum_(x in G) phi x * (psi x)^* ).
rewrite (big_setID H) /= (setIidPr sHG) addrC big1 ?add0r; last first.
by move=> x /setDP[_ /cfun0->]; rewrite mul0r.
by congr (_ * _); apply: eq_bigr => x Hx; rewrite cfResE.
set h' := _^-1; apply: canRL (mulKf (neq0CG G)) _.
transitivity (h' * \sum_(y in G) \sum_(x in G) phi (x ^ y) * (psi (x ^ y))^* ).
rewrite mulrCA mulr_natl -sumr_const; congr (_ * _); apply: eq_bigr => y Gy.
by rewrite (reindex_acts 'J _ Gy) ?astabsJ ?normG.
rewrite exchange_big mulr_sumr; apply: eq_bigr => x _; rewrite cfIndE //=.
by rewrite -mulrA mulr_suml; congr (_ * _); apply: eq_bigr => y /(cfunJ psi)->.
Qed.
Definition cfdot_Res_r := Frobenius_reciprocity.
Lemma cfdot_Res_l psi phi : '['Res[H] psi, phi] = '[psi, 'Ind[G] phi].
Proof. by rewrite cfdotC cfdot_Res_r -cfdotC. Qed.
Lemma cfIndM phi psi: H \subset G ->
'Ind[G] (phi * ('Res[H] psi)) = 'Ind[G] phi * psi.
Proof.
move=> HsG; apply/cfun_inP=> x Gx; rewrite !cfIndE // !cfunE !cfIndE // -mulrA.
congr (_ * _); rewrite mulr_suml; apply: eq_bigr=> i iG; rewrite !cfunE.
case: (boolP (x ^ i \in H)) => xJi; last by rewrite cfun0gen ?mul0r ?genGid.
by rewrite !cfResE //; congr (_ * _); rewrite cfunJgen ?genGid.
Qed.
End Induced.
Arguments cfInd {gT} B%_g {A%_g} phi%_CF.
Notation "''Ind[' G , H ]" := (@cfInd _ G H) (only parsing) : ring_scope.
Notation "''Ind[' G ]" := 'Ind[G, _] : ring_scope.
Notation "''Ind'" := 'Ind[_] (only parsing) : ring_scope.
Section MorphInduced.
Variables (aT rT : finGroupType) (D G H : {group aT}) (R S : {group rT}).
Lemma cfIndMorph (f : {morphism D >-> rT}) (phi : 'CF(f @* H)) :
'ker f \subset H -> H \subset G -> G \subset D ->
'Ind[G] (cfMorph phi) = cfMorph ('Ind[f @* G] phi).
Proof.
move=> sKH sHG sGD; have [sHD inD] := (subset_trans sHG sGD, subsetP sGD).
apply/cfun_inP=> /= x Gx; have [Dx sKG] := (inD x Gx, subset_trans sKH sHG).
rewrite cfMorphE ?cfIndE ?morphimS // (partition_big_imset f) -morphimEsub //=.
rewrite card_morphim (setIidPr sHD) natf_indexg // invfM invrK -mulrA.
congr (_ * _); rewrite mulr_sumr; apply: eq_bigr => _ /morphimP[y Dy Gy ->].
rewrite -(card_rcoset _ y) mulr_natl -sumr_const.
apply: eq_big => [z | z /andP[Gz /eqP <-]].
have [Gz | G'z] := boolP (z \in G).
by rewrite (sameP eqP (rcoset_kerP _ _ _)) ?inD.
by case: rcosetP G'z => // [[t Kt ->]]; rewrite groupM // (subsetP sKG).
have [Dz Dxz] := (inD z Gz, inD (x ^ z) (groupJ Gx Gz)); rewrite -morphJ //.
have [Hxz | notHxz] := boolP (x ^ z \in H); first by rewrite cfMorphE.
by rewrite !cfun0 // -sub1set -morphim_set1 // morphimSGK ?sub1set.
Qed.
Variables (g : {morphism G >-> rT}) (h : {morphism H >-> rT}).
Hypotheses (isoG : isom G R g) (isoH : isom H S h) (eq_hg : {in H, h =1 g}).
Hypothesis sHG : H \subset G.
Lemma cfResIsom phi : 'Res[S] (cfIsom isoG phi) = cfIsom isoH ('Res[H] phi).
Proof.
have [[injg defR] [injh defS]] := (isomP isoG, isomP isoH).
rewrite !morphimEdom in defS defR; apply/cfun_inP=> s.
rewrite -{1}defS => /imsetP[x Hx ->] {s}; have Gx := subsetP sHG x Hx.
rewrite {1}eq_hg ?(cfResE, cfIsomE) // -defS -?eq_hg ?imset_f // -defR.
by rewrite (eq_in_imset eq_hg) imsetS.
Qed.
Lemma cfIndIsom phi : 'Ind[R] (cfIsom isoH phi) = cfIsom isoG ('Ind[G] phi).
Proof.
have [[injg defR] [_ defS]] := (isomP isoG, isomP isoH).
rewrite morphimEdom (eq_in_imset eq_hg) -morphimEsub // in defS.
apply/cfun_inP=> s; rewrite -{1}defR => /morphimP[x _ Gx ->]{s}.
rewrite cfIsomE ?cfIndE // -defR -{1}defS ?morphimS ?card_injm // morphimEdom.
congr (_ * _); rewrite big_imset //=; last exact/injmP.
apply: eq_bigr => y Gy; rewrite -morphJ //.
have [Hxy | H'xy] := boolP (x ^ y \in H); first by rewrite -eq_hg ?cfIsomE.
by rewrite !cfun0 -?defS // -sub1set -morphim_set1 ?injmSK ?sub1set // groupJ.
Qed.
End MorphInduced.
Section FieldAutomorphism.
Variables (u : {rmorphism algC -> algC}) (gT rT : finGroupType).
Variables (G K H : {group gT}) (f : {morphism G >-> rT}) (R : {group rT}).
Implicit Types (phi : 'CF(G)) (S : seq 'CF(G)).
Local Notation "phi ^u" := (cfAut u phi).
Lemma cfAutZ_nat n phi : (n%:R *: phi)^u = n%:R *: phi^u.
Proof. exact: raddfZnat. Qed.
Lemma cfAutZ_Cnat z phi : z \in Num.nat -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_nat. Qed.
Lemma cfAutZ_Cint z phi : z \in Num.int -> (z *: phi)^u = z *: phi^u.
Proof. exact: raddfZ_int. Qed.
Lemma cfAutK : cancel (@cfAut gT G u) (cfAut (algC_invaut u)).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_autK. Qed.
Lemma cfAutVK : cancel (cfAut (algC_invaut u)) (@cfAut gT G u).
Proof. by move=> phi; apply/cfunP=> x; rewrite !cfunE /= algC_invautK. Qed.
Lemma cfAut_inj : injective (@cfAut gT G u).
Proof. exact: can_inj cfAutK. Qed.
Lemma cfAut_eq1 phi : (cfAut u phi == 1) = (phi == 1).
Proof. by rewrite rmorph_eq1 //; apply: cfAut_inj. Qed.
Lemma support_cfAut phi : support phi^u =i support phi.
Proof. by move=> x; rewrite !inE cfunE fmorph_eq0. Qed.
Lemma map_cfAut_free S : cfAut_closed u S -> free S -> free (map (cfAut u) S).
Proof.
set Su := map _ S => sSuS freeS; have uniqS := free_uniq freeS.
have uniqSu: uniq Su by rewrite (map_inj_uniq cfAut_inj).
have{} sSuS: {subset Su <= S} by move=> _ /mapP[phi Sphi ->]; apply: sSuS.
have [|_ eqSuS] := uniq_min_size uniqSu sSuS; first by rewrite size_map.
by rewrite (perm_free (uniq_perm uniqSu uniqS eqSuS)).
Qed.
Lemma cfAut_on A phi : (phi^u \in 'CF(G, A)) = (phi \in 'CF(G, A)).
Proof. by rewrite !cfun_onE (eq_subset (support_cfAut phi)). Qed.
Lemma cfker_aut phi : cfker phi^u = cfker phi.
Proof.
apply/setP=> x /[!inE]; apply: andb_id2l => Gx.
by apply/forallP/forallP=> Kx y;
have:= Kx y; rewrite !cfunE (inj_eq (fmorph_inj u)).
Qed.
Lemma cfAut_cfuni A : ('1_A)^u = '1_A :> 'CF(G).
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorph_nat. Qed.
Lemma cforder_aut phi : #[phi^u]%CF = #[phi]%CF.
Proof. exact: cforder_inj_rmorph cfAut_inj. Qed.
Lemma cfAutRes phi : ('Res[H] phi)^u = 'Res phi^u.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutMorph (psi : 'CF(f @* H)) : (cfMorph psi)^u = cfMorph psi^u.
Proof. by apply/cfun_inP=> x Hx; rewrite !cfunElock Hx. Qed.
Lemma cfAutIsom (isoGR : isom G R f) phi :
(cfIsom isoGR phi)^u = cfIsom isoGR phi^u.
Proof.
apply/cfun_inP=> y; have [_ {1}<-] := isomP isoGR => /morphimP[x _ Gx ->{y}].
by rewrite !(cfunE, cfIsomE).
Qed.
Lemma cfAutQuo phi : (phi / H)^u = (phi^u / H)%CF.
Proof. by apply/cfunP=> Hx; rewrite !cfunElock cfker_aut rmorphMn. Qed.
Lemma cfAutMod (psi : 'CF(G / H)) : (psi %% H)^u = (psi^u %% H)%CF.
Proof. by apply/cfunP=> x; rewrite !cfunElock rmorphMn. Qed.
Lemma cfAutInd (psi : 'CF(H)) : ('Ind[G] psi)^u = 'Ind psi^u.
Proof.
have [sHG | not_sHG] := boolP (H \subset G).
apply/cfunP=> x; rewrite !(cfunE, cfIndE) // rmorphM /= fmorphV rmorph_nat.
by congr (_ * _); rewrite rmorph_sum; apply: eq_bigr => y; rewrite !cfunE.
rewrite !cfIndEout // linearZ /= cfAut_cfuni rmorphM rmorph_nat /=.
rewrite -cfdot_cfAut ?rmorph1 // => _ /imageP[x Hx ->].
by rewrite cfun1E Hx !rmorph1.
Qed.
Hypothesis KxH : K \x H = G.
Lemma cfAutDprodl (phi : 'CF(K)) : (cfDprodl KxH phi)^u = cfDprodl KxH phi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEl).
Qed.
Lemma cfAutDprodr (psi : 'CF(H)) : (cfDprodr KxH psi)^u = cfDprodr KxH psi^u.
Proof.
apply/cfun_inP=> _ /(mem_dprod KxH)[x [y [Kx Hy -> _]]].
by rewrite !(cfunE, cfDprodEr).
Qed.
Lemma cfAutDprod (phi : 'CF(K)) (psi : 'CF(H)) :
(cfDprod KxH phi psi)^u = cfDprod KxH phi^u psi^u.
Proof. by rewrite rmorphM /= cfAutDprodl cfAutDprodr. Qed.
End FieldAutomorphism.
Arguments cfAutK u {gT G}.
Arguments cfAutVK u {gT G}.
Arguments cfAut_inj u {gT G} [phi1 phi2] : rename.
Definition conj_cfRes := cfAutRes conjC.
Definition cfker_conjC := cfker_aut conjC.
Definition conj_cfQuo := cfAutQuo conjC.
Definition conj_cfMod := cfAutMod conjC.
Definition conj_cfInd := cfAutInd conjC.
Definition cfconjC_eq1 := cfAut_eq1 conjC.
|
FunctorCategory.lean
|
/-
Copyright (c) 2025 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.Limits.FunctorCategory.EpiMono
import Mathlib.CategoryTheory.MorphismProperty.Retract
import Mathlib.CategoryTheory.MorphismProperty.Limits
import Mathlib.CategoryTheory.MorphismProperty.TransfiniteComposition
/-!
# Stability properties of morphism properties on functor categories
Given `W : MorphismProperty C` and a category `J`, we study the
stability properties of `W.functorCategory J : MorphismProperty (J β₯€ C)`.
Under suitable assumptions, we also show that if monomorphisms
in `C` are stable under transfinite compositions, then the same
holds in the category `J β₯€ C`.
-/
universe v v' v'' u u' u''
namespace CategoryTheory
open Limits
namespace MorphismProperty
variable {C : Type u} [Category.{v} C] (W : MorphismProperty C)
instance [W.IsStableUnderRetracts] (J : Type u'') [Category.{v''} J] :
(W.functorCategory J).IsStableUnderRetracts where
of_retract hfg hg j :=
W.of_retract (hfg.map ((evaluation _ _).obj j).mapArrow) (hg j)
variable {W}
instance IsStableUnderLimitsOfShape.functorCategory
{K : Type u'} [Category.{v'} K] [W.IsStableUnderLimitsOfShape K]
(J : Type u'') [Category.{v''} J] [HasLimitsOfShape K C] :
(W.functorCategory J).IsStableUnderLimitsOfShape K where
condition Xβ Xβ _ _ hcβ hcβ f hf Ο hΟ j :=
MorphismProperty.limitsOfShape_le _
(limitsOfShape.mk' (Xβ β (evaluation _ _ ).obj j) (Xβ β (evaluation _ _ ).obj j)
_ _ (isLimitOfPreserves _ hcβ) (isLimitOfPreserves _ hcβ) (Functor.whiskerRight f _)
(fun k β¦ hf k j) (Ο.app j) (fun k β¦ congr_app (hΟ k) j))
instance IsStableUnderColimitsOfShape.functorCategory
{K : Type u'} [Category.{v'} K] [W.IsStableUnderColimitsOfShape K]
(J : Type u'') [Category.{v''} J] [HasColimitsOfShape K C] :
(W.functorCategory J).IsStableUnderColimitsOfShape K where
condition Xβ Xβ _ _ hcβ hcβ f hf Ο hΟ j :=
MorphismProperty.colimitsOfShape_le _
(colimitsOfShape.mk' (Xβ β (evaluation _ _ ).obj j) (Xβ β (evaluation _ _ ).obj j)
_ _ (isColimitOfPreserves _ hcβ) (isColimitOfPreserves _ hcβ) (Functor.whiskerRight f _)
(fun k β¦ hf k j) (Ο.app j) (fun k β¦ congr_app (hΟ k) j))
instance [W.IsStableUnderBaseChange] (J : Type u'') [Category.{v''} J] [HasPullbacks C] :
(W.functorCategory J).IsStableUnderBaseChange where
of_isPullback sq hr j :=
W.of_isPullback (sq.map ((evaluation _ _).obj j)) (hr j)
instance [W.IsStableUnderCobaseChange] (J : Type u'') [Category.{v''} J] [HasPushouts C] :
(W.functorCategory J).IsStableUnderCobaseChange where
of_isPushout sq hr j :=
W.of_isPushout (sq.map ((evaluation _ _).obj j)) (hr j)
instance (K : Type u') [LinearOrder K] [SuccOrder K] [OrderBot K] [WellFoundedLT K]
[W.IsStableUnderTransfiniteCompositionOfShape K] (J : Type u'') [Category.{v''} J]
[HasIterationOfShape K C] :
(W.functorCategory J).IsStableUnderTransfiniteCompositionOfShape K where
le := by
rintro X Y f β¨hfβ© j
have : W.functorCategory J β€ W.inverseImage ((evaluation _ _).obj j) := fun _ _ _ h β¦ h _
exact W.transfiniteCompositionsOfShape_le K _ β¨(hf.ofLE this).mapβ©
variable (J : Type u'') [Category.{v''} J]
lemma functorCategory_isomorphisms :
(isomorphisms C).functorCategory J = isomorphisms (J β₯€ C) := by
ext _ _ f
simp only [functorCategory, isomorphisms.iff, NatTrans.isIso_iff_isIso_app]
lemma functorCategory_monomorphisms [HasPullbacks C] :
(monomorphisms C).functorCategory J = monomorphisms (J β₯€ C) := by
ext _ _ f
simp only [functorCategory, monomorphisms.iff, NatTrans.mono_iff_mono_app]
lemma functorCategory_epimorphisms [HasPushouts C] :
(epimorphisms C).functorCategory J = epimorphisms (J β₯€ C) := by
ext _ _ f
simp only [functorCategory, epimorphisms.iff, NatTrans.epi_iff_epi_app]
instance (K : Type u') [LinearOrder K] [SuccOrder K] [OrderBot K] [WellFoundedLT K]
[(monomorphisms C).IsStableUnderTransfiniteCompositionOfShape K]
[HasPullbacks C] (J : Type u'') [Category.{v''} J] [HasIterationOfShape K C] :
(monomorphisms (J β₯€ C)).IsStableUnderTransfiniteCompositionOfShape K := by
rw [β functorCategory_monomorphisms]
infer_instance
end MorphismProperty
end CategoryTheory
|
GeometryOfNumbers.lean
|
/-
Copyright (c) 2021 Alex J. Best. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Alex J. Best
-/
import Mathlib.Analysis.Convex.Body
import Mathlib.Analysis.Convex.Measure
import Mathlib.MeasureTheory.Group.FundamentalDomain
/-!
# Geometry of numbers
In this file we prove some of the fundamental theorems in the geometry of numbers, as studied by
Hermann Minkowski.
## Main results
* `exists_pair_mem_lattice_not_disjoint_vadd`: Blichfeldt's principle, existence of two distinct
points in a subgroup such that the translates of a set by these two points are not disjoint when
the covolume of the subgroup is larger than the volume of the set.
* `exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`: Minkowski's theorem, existence of
a non-zero lattice point inside a convex symmetric domain of large enough volume.
## TODO
* Calculate the volume of the fundamental domain of a finite index subgroup
* Voronoi diagrams
* See [Pete L. Clark, *Abstract Geometry of Numbers: Linear Forms* (arXiv)](https://arxiv.org/abs/1405.2119)
for some more ideas.
## References
* [Pete L. Clark, *Geometry of Numbers with Applications to Number Theory*][clark_gon] p.28
-/
namespace MeasureTheory
open ENNReal Module MeasureTheory MeasureTheory.Measure Set Filter
open scoped Pointwise NNReal
variable {E L : Type*} [MeasurableSpace E] {ΞΌ : Measure E} {F s : Set E}
/-- **Blichfeldt's Theorem**. If the volume of the set `s` is larger than the covolume of the
countable subgroup `L` of `E`, then there exist two distinct points `x, y β L` such that `(x + s)`
and `(y + s)` are not disjoint. -/
theorem exists_pair_mem_lattice_not_disjoint_vadd [AddGroup L] [Countable L] [AddAction L E]
[MeasurableSpace L] [MeasurableVAdd L E] [VAddInvariantMeasure L E ΞΌ]
(fund : IsAddFundamentalDomain L F ΞΌ) (hS : NullMeasurableSet s ΞΌ) (h : ΞΌ F < ΞΌ s) :
β x y : L, x β y β§ Β¬Disjoint (x +α΅₯ s) (y +α΅₯ s) := by
contrapose! h
exact ((fund.measure_eq_tsum _).trans (measure_iUnionβ
(Pairwise.mono h fun i j hij => (hij.mono inf_le_left inf_le_left).aedisjoint)
fun _ => (hS.vadd _).inter fund.nullMeasurableSet).symm).trans_le
(measure_mono <| Set.iUnion_subset fun _ => Set.inter_subset_right)
/-- The **Minkowski Convex Body Theorem**. If `s` is a convex symmetric domain of `E` whose volume
is large enough compared to the covolume of a lattice `L` of `E`, then it contains a non-zero
lattice point of `L`. -/
theorem exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure [NormedAddCommGroup E]
[NormedSpace β E] [BorelSpace E] [FiniteDimensional β E] [IsAddHaarMeasure ΞΌ]
{L : AddSubgroup E} [Countable L] (fund : IsAddFundamentalDomain L F ΞΌ)
(h_symm : β x β s, -x β s) (h_conv : Convex β s) (h : ΞΌ F * 2 ^ finrank β E < ΞΌ s) :
β x β 0, ((x : L) : E) β s := by
have h_vol : ΞΌ F < ΞΌ ((2β»ΒΉ : β) β’ s) := by
rw [addHaar_smul_of_nonneg ΞΌ (by simp : 0 β€ (2 : β)β»ΒΉ) s, β
mul_lt_mul_right (pow_ne_zero (finrank β E) (two_ne_zero' _)) (by finiteness),
mul_right_comm, ofReal_pow (by simp : 0 β€ (2 : β)β»ΒΉ), ofReal_inv_of_pos zero_lt_two]
norm_num
rwa [β mul_pow, ENNReal.inv_mul_cancel two_ne_zero ofNat_ne_top, one_pow, one_mul]
obtain β¨x, y, hxy, hβ© :=
exists_pair_mem_lattice_not_disjoint_vadd fund ((h_conv.smul _).nullMeasurableSet _) h_vol
obtain β¨_, β¨v, hv, rflβ©, w, hw, hvwβ© := Set.not_disjoint_iff.mp h
refine β¨x - y, sub_ne_zero.2 hxy, ?_β©
rw [Set.mem_inv_smul_set_iffβ (two_ne_zero' β)] at hv hw
simp_rw [AddSubgroup.vadd_def, vadd_eq_add, add_comm _ w, β sub_eq_sub_iff_add_eq_add, β
AddSubgroup.coe_sub] at hvw
rw [β hvw, β inv_smul_smulβ (two_ne_zero' β) (_ - _), smul_sub, sub_eq_add_neg, smul_add]
refine h_conv hw (h_symm _ hv) ?_ ?_ ?_ <;> norm_num
/-- The **Minkowski Convex Body Theorem for compact domain**. If `s` is a convex compact symmetric
domain of `E` whose volume is large enough compared to the covolume of a lattice `L` of `E`, then it
contains a non-zero lattice point of `L`. Compared to
`exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure`, this version requires in addition
that `s` is compact and `L` is discrete but provides a weaker inequality rather than a strict
inequality. -/
theorem exists_ne_zero_mem_lattice_of_measure_mul_two_pow_le_measure [NormedAddCommGroup E]
[NormedSpace β E] [BorelSpace E] [FiniteDimensional β E] [Nontrivial E] [IsAddHaarMeasure ΞΌ]
{L : AddSubgroup E} [Countable L] [DiscreteTopology L] (fund : IsAddFundamentalDomain L F ΞΌ)
(h_symm : β x β s, -x β s) (h_conv : Convex β s) (h_cpt : IsCompact s)
(h : ΞΌ F * 2 ^ finrank β E β€ ΞΌ s) :
β x β 0, ((x : L) : E) β s := by
have h_mes : ΞΌ s β 0 := by
intro hΞΌ
suffices ΞΌ F = 0 from fund.measure_ne_zero (NeZero.ne ΞΌ) this
rw [hΞΌ, le_zero_iff, mul_eq_zero] at h
exact h.resolve_right <| pow_ne_zero _ two_ne_zero
have h_nemp : s.Nonempty := nonempty_of_measure_ne_zero h_mes
let u : β β ββ₯0 := (exists_seq_strictAnti_tendsto 0).choose
let K : ConvexBody E := β¨s, h_conv, h_cpt, h_nempβ©
let S : β β ConvexBody E := fun n => (1 + u n) β’ K
let Z : β β Set E := fun n => (S n) β© (L \ {0})
-- The convex bodies `S n` have volume strictly larger than `ΞΌ s` and thus we can apply
-- `exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure` to them and obtain that
-- `S n` contains a nonzero point of `L`. Since the intersection of the `S n` is equal to `s`,
-- it follows that `s` contains a nonzero point of `L`.
have h_zero : 0 β K := K.zero_mem_of_symmetric h_symm
suffices Set.Nonempty (β n, Z n) by
erw [β Set.iInter_inter, K.iInter_smul_eq_self h_zero] at this
Β· obtain β¨x, hxβ© := this
exact β¨β¨x, by aesopβ©, by aesopβ©
Β· exact (exists_seq_strictAnti_tendsto (0 : ββ₯0)).choose_spec.2.2
have h_clos : IsClosed ((L : Set E) \ {0}) := by
rsuffices β¨U, hUβ© : β U : Set E, IsOpen U β§ U β© L = {0}
Β· rw [sdiff_eq_sdiff_iff_inf_eq_inf (z := U).mpr (by simp [Set.inter_comm .. βΈ hU.2, zero_mem])]
exact AddSubgroup.isClosed_of_discrete.sdiff hU.1
exact isOpen_inter_eq_singleton_of_mem_discrete (zero_mem L)
refine IsCompact.nonempty_iInter_of_sequence_nonempty_isCompact_isClosed Z (fun n => ?_)
(fun n => ?_) ((S 0).isCompact.inter_right h_clos) (fun n => (S n).isClosed.inter h_clos)
Β· refine Set.inter_subset_inter_left _ (SetLike.coe_subset_coe.mpr ?_)
refine ConvexBody.smul_le_of_le K h_zero ?_
rw [add_le_add_iff_left]
exact le_of_lt <| (exists_seq_strictAnti_tendsto (0 : ββ₯0)).choose_spec.1 (Nat.lt.base n)
Β· suffices ΞΌ F * 2 ^ finrank β E < ΞΌ (S n : Set E) by
have h_symm' : β x β S n, -x β S n := by
rintro _ β¨y, hy, rflβ©
exact β¨-y, h_symm _ hy, by simpβ©
obtain β¨x, hx_nz, hx_memβ© := exists_ne_zero_mem_lattice_of_measure_mul_two_pow_lt_measure
fund h_symm' (S n).convex this
exact β¨x, hx_mem, by aesopβ©
refine lt_of_le_of_lt h ?_
rw [ConvexBody.coe_smul', NNReal.smul_def, addHaar_smul_of_nonneg _ (NNReal.coe_nonneg _)]
rw [show ΞΌ s < _ β 1 * ΞΌ s < _ by rw [one_mul]]
refine (mul_lt_mul_right h_mes (ne_of_lt h_cpt.measure_lt_top)).mpr ?_
rw [ofReal_pow (NNReal.coe_nonneg _)]
refine one_lt_powβ ?_ (ne_of_gt finrank_pos)
simp [u, (exists_seq_strictAnti_tendsto (0 : ββ₯0)).choose_spec.2.1 n]
end MeasureTheory
|
Convex.lean
|
/-
Copyright (c) 2023 Yury Kudryashov. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Yury Kudryashov, YaΓ«l Dillies
-/
import Mathlib.Analysis.Complex.ReImTopology
import Mathlib.Analysis.Convex.Combination
import Mathlib.Analysis.Convex.PathConnected
/-!
# Theorems about convexity on the complex plane
We show that the open and closed half-spaces in β given by an inequality on either the real or
imaginary part are all convex over β. We also prove some results on star-convexity for the
slit plane.
-/
open Set
open scoped ComplexOrder
namespace Complex
/-- A version of `convexHull_prod` for `Set.reProdIm`. -/
lemma convexHull_reProdIm (s t : Set β) :
convexHull β (s Γβ t) = convexHull β s Γβ convexHull β t :=
calc
convexHull β (equivRealProdLm β»ΒΉ' (s ΓΛ’ t)) = equivRealProdLm β»ΒΉ' convexHull β (s ΓΛ’ t) := by
simpa only [β LinearEquiv.image_symm_eq_preimage]
using ((equivRealProdLm.symm.toLinearMap).image_convexHull (s ΓΛ’ t)).symm
_ = convexHull β s Γβ convexHull β t := by rw [convexHull_prod]; rfl
/-- The slit plane is star-convex at a positive number. -/
lemma starConvex_slitPlane {z : β} (hz : 0 < z) : StarConvex β z slitPlane :=
Complex.compl_Iic_zero βΈ starConvex_compl_Iic hz
/-- The slit plane is star-shaped at a positive real number. -/
lemma starConvex_ofReal_slitPlane {x : β} (hx : 0 < x) : StarConvex β βx slitPlane :=
starConvex_slitPlane <| zero_lt_real.2 hx
/-- The slit plane is star-shaped at `1`. -/
lemma starConvex_one_slitPlane : StarConvex β 1 slitPlane := starConvex_slitPlane one_pos
end Complex
open Complex
variable (r : β)
theorem convex_halfSpace_re_lt : Convex β { c : β | c.re < r } :=
convex_halfSpace_lt (.mk add_re smul_re) _
theorem convex_halfSpace_re_le : Convex β { c : β | c.re β€ r } :=
convex_halfSpace_le (.mk add_re smul_re) _
theorem convex_halfSpace_re_gt : Convex β { c : β | r < c.re } :=
convex_halfSpace_gt (.mk add_re smul_re) _
theorem convex_halfSpace_re_ge : Convex β { c : β | r β€ c.re } :=
convex_halfSpace_ge (.mk add_re smul_re) _
theorem convex_halfSpace_im_lt : Convex β { c : β | c.im < r } :=
convex_halfSpace_lt (.mk add_im smul_im) _
theorem convex_halfSpace_im_le : Convex β { c : β | c.im β€ r } :=
convex_halfSpace_le (.mk add_im smul_im) _
theorem convex_halfSpace_im_gt : Convex β { c : β | r < c.im } :=
convex_halfSpace_gt (.mk add_im smul_im) _
theorem convex_halfSpace_im_ge : Convex β { c : β | r β€ c.im } :=
convex_halfSpace_ge (.mk add_im smul_im) _
lemma Complex.isConnected_of_upperHalfPlane {r} {s : Set β} (hsβ : {z | r < z.im} β s)
(hsβ : s β {z | r β€ z.im}) : IsConnected s := by
refine .subset_closure ?_ hsβ (by simpa only [closure_setOf_lt_im] using hsβ)
exact (convex_halfSpace_im_gt r).isConnected β¨(r + 1) * I, by simpβ©
lemma Complex.isConnected_of_lowerHalfPlane {r} {s : Set β} (hsβ : {z | z.im < r} β s)
(hsβ : s β {z | z.im β€ r}) : IsConnected s := by
refine .subset_closure ?_ hsβ (by simpa only [closure_setOf_im_lt] using hsβ)
exact (convex_halfSpace_im_lt r).isConnected β¨(r - 1) * I, by simpβ©
|
generic_quotient.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 choice.
From mathcomp Require Import seq fintype.
(*****************************************************************************)
(* Quotient Types *)
(* *)
(* NB: See CONTRIBUTING.md for an introduction to HB concepts and commands. *)
(* *)
(* Provided a base type T, this files defines an interface for quotients Q *)
(* of the type T with explicit functions for canonical surjection (\pi *)
(* : T -> Q) and for choosing a representative (repr : Q -> T). It then *)
(* provides a helper to quotient T by a decidable equivalence relation (e *)
(* : rel T) if T is a choiceType (or encodable as a choiceType modulo e). *)
(* *)
(* Reference: Cyril Cohen, Pragmatic Quotient Types in Coq, ITP 2013 *)
(* *)
(* *** Generic Quotienting *** *)
(* quotType T == the type of quotient types based on T *)
(* The HB class is called Quotient. *)
(* *)
(* The quotType interface supports these operations (in quotient_scope): *)
(* \pi_Q x == the class in Q of the element x of T *)
(* \pi x == the class of x where Q is inferred from the context *)
(* repr c == canonical representative in T of the class c *)
(* x = y %[mod Q] := \pi_Q x = \pi_Q y *)
(* <-> x and y are equal modulo Q *)
(* x <> y %[mod Q] := \pi_Q x <> \pi_Q y *)
(* x == y %[mod Q] := \pi_Q x == \pi_Q y *)
(* x != y %[mod Q] := \pi_Q x != \pi_Q y *)
(* *)
(* The quotient_scope is delimited by %qT, *)
(* The most useful lemmas are piE and reprK. *)
(* *)
(* List of factories: *)
(* isQuotient.Build T Q (reprK : cancel repr pi) == builds the quotient *)
(* whose canonical surjection function is (pi : T -> Q) and *)
(* whose representative selection function is repr *)
(* *** Morphisms *** *)
(* One may declare existing functions and predicates as liftings of some *)
(* morphisms for a quotient. *)
(* PiMorph1 pi_f == where pi_f : {morph \pi : x / f x >-> fq x} *)
(* declares fq : Q -> Q as the lifting of f : T -> T *)
(* PiMorph2 pi_g == idem with pi_g : {morph \pi : x y / g x y >-> gq x y} *)
(* PiMono1 pi_p == idem with pi_p : {mono \pi : x / p x >-> pq x} *)
(* PiMono2 pi_r == idem with pi_r : {morph \pi : x y / r x y >-> rq x y} *)
(* PiMorph11 pi_f == idem with pi_f : {morph \pi : x / f x >-> fq x} *)
(* where fq : Q -> Q' and f : T -> T'. *)
(* PiMorph eq == Most general declaration of compatibility, *)
(* /!\ use with caution /!\ *)
(* One can use the following helpers to build the liftings which may or *)
(* may not satisfy the above properties (but if they do not, it is *)
(* probably not a good idea to define them): *)
(* lift_op1 Q f := lifts f : T -> T *)
(* lift_op2 Q g := lifts g : T -> T -> T *)
(* lift_fun1 Q p := lifts p : T -> R *)
(* lift_fun2 Q r := lifts r : T -> T -> R *)
(* lift_op11 Q Q' f := lifts f : T -> T' *)
(* There is also the special case of constants and embedding functions *)
(* that one may define and declare as compatible with Q using: *)
(* lift_cst Q x := lifts x : T to Q *)
(* PiConst c := declare the result c of the previous construction as *)
(* compatible with Q *)
(* lift_embed Q e := lifts e : R -> T to R -> Q *)
(* PiEmbed f := declare the result f of the previous construction as *)
(* compatible with Q *)
(* *)
(* *** Quotients that have an eqType structure *** *)
(* Having a canonical (eqQuotType e) structure enables piE to replace terms *)
(* of the form (x == y) by terms of the form (e x' y') if x and y are *)
(* canonical surjections of some x' and y'. *)
(* eqQuotType e == the type of quotients types on T which mirror *)
(* the equivalence relation (e : rel T) *)
(* the HB class is called EqQuotient. *)
(* *)
(* The most useful property is that an eqQuotType is an eqType. *)
(* List of factories: *)
(* isEqQuotient.Build T e Q m *)
(* == builds an (eqQuotType e) structure on Q from the *)
(* morphism property m *)
(* where m : {mono \pi : x y / e x y >-> x == y} *)
(* *)
(* *** Equivalence and quotient by an equivalence *** *)
(* EquivRel r er es et == builds an equiv_rel structure based on the *)
(* reflexivity, symmetry and transitivity property *)
(* of a boolean relation. *)
(* {eq_quot e} == builds the quotType of T by equiv *)
(* where e : rel T is an equiv_rel *)
(* and T is a choiceType or a (choiceTypeMod e) *)
(* it is canonically an eqType, a choiceType, *)
(* a quotType and an eqQuotType *)
(* x = y %[mod_eq e] := x = y %[mod {eq_quot e}] *)
(* <-> x and y are equal modulo e *)
(* ... *)
(*****************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Declare Scope quotient_scope.
Reserved Notation "\pi_ Q" (at level 0, format "\pi_ Q").
Reserved Notation "\pi" (format "\pi").
Reserved Notation "{pi_ Q a }" (Q at next level, format "{pi_ Q a }").
Reserved Notation "{pi a }" (format "{pi a }").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x == y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' == y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x = y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' = y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x != y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' != y '/' %[mod_eq e ] ']'").
#[warning="-postfix-notation-not-level-1"]
Reserved Notation "x <> y %[mod_eq e ]"
(no associativity, format "'[hv ' x '/' <> y '/' %[mod_eq e ] ']'").
Reserved Notation "{eq_quot e }" (format "{eq_quot e }").
Delimit Scope quotient_scope with qT.
Local Open Scope quotient_scope.
(*****************************************)
(* Definition of the quotient interface. *)
(*****************************************)
HB.mixin Record isQuotient T (qT : Type) := {
repr_of : qT -> T;
quot_pi_subdef : T -> qT;
repr_ofK_subproof : cancel repr_of quot_pi_subdef
}.
#[short(type="quotType")]
HB.structure Definition Quotient T := { qT of isQuotient T qT }.
Arguments repr_of [T qT] : rename.
Section QuotientDef.
Variable T : Type.
Variable qT : quotType T.
Definition pi_subdef := @quot_pi_subdef _ qT.
Local Notation "\pi" := pi_subdef.
Lemma repr_ofK : cancel (@repr_of _ _) \pi.
Proof. exact: repr_ofK_subproof. Qed.
End QuotientDef.
Arguments repr_ofK {T qT}.
(****************************)
(* Protecting some symbols. *)
(****************************)
HB.lock Definition pi := pi_subdef.
HB.lock Definition mpi := pi_subdef.
HB.lock Definition repr := repr_of.
(*******************)
(* Fancy Notations *)
(*******************)
Arguments pi.body [T]%_type qT%_type.
Notation "\pi_ Q" := (@pi _ Q) : quotient_scope.
Notation "\pi" := (@pi _ _) (only parsing) : quotient_scope.
Notation "x == y %[mod Q ]" := (\pi_Q x == \pi_Q y) : quotient_scope.
Notation "x = y %[mod Q ]" := (\pi_Q x = \pi_Q y) : quotient_scope.
Notation "x != y %[mod Q ]" := (\pi_Q x != \pi_Q y) : quotient_scope.
Notation "x <> y %[mod Q ]" := (\pi_Q x <> \pi_Q y) : quotient_scope.
Local Notation "\mpi" := (@mpi _ _).
Canonical mpi_unlock := Unlockable mpi.unlock.
Canonical pi_unlock := Unlockable pi.unlock.
Canonical repr_unlock := Unlockable repr.unlock.
Arguments repr {T qT} x.
(************************)
(* Exporting the theory *)
(************************)
Section QuotTypeTheory.
Variable T : Type.
Variable qT : quotType T.
Lemma reprK : cancel repr \pi_qT.
Proof. by move=> x; rewrite !unlock repr_ofK. Qed.
Variant pi_spec (x : T) : T -> Type :=
PiSpec y of x = y %[mod qT] : pi_spec x y.
Lemma piP (x : T) : pi_spec x (repr (\pi_qT x)).
Proof. by constructor; rewrite reprK. Qed.
Lemma mpiE : \mpi =1 \pi_qT.
Proof. by move=> x; rewrite !unlock. Qed.
Lemma quotW P : (forall y : T, P (\pi_qT y)) -> forall x : qT, P x.
Proof. by move=> Py x; rewrite -[x]reprK; apply: Py. Qed.
Lemma quotP P : (forall y : T, repr (\pi_qT y) = y -> P (\pi_qT y))
-> forall x : qT, P x.
Proof. by move=> Py x; rewrite -[x]reprK; apply: Py; rewrite reprK. Qed.
End QuotTypeTheory.
Arguments reprK {T qT} x.
(*******************)
(* About morphisms *)
(*******************)
(* This was pi_morph T (x : T) := PiMorph { pi_op : T; _ : x = pi_op }. *)
Structure equal_to T (x : T) := EqualTo {
equal_val : T;
_ : x = equal_val
}.
Lemma equal_toE (T : Type) (x : T) (m : equal_to x) : equal_val m = x.
Proof. by case: m. Qed.
Notation piE := (@equal_toE _ _).
Canonical equal_to_pi T (qT : quotType T) (x : T) :=
@EqualTo _ (\pi_qT x) (\pi x) (erefl _).
Arguments EqualTo {T x equal_val}.
Section Morphism.
Variables T U : Type.
Variable (qT : quotType T).
Variable (qU : quotType U).
Variable (f : T -> T) (g : T -> T -> T) (p : T -> U) (r : T -> T -> U).
Variable (fq : qT -> qT) (gq : qT -> qT -> qT) (pq : qT -> U) (rq : qT -> qT -> U).
Variable (h : T -> U) (hq : qT -> qU).
Hypothesis pi_f : {morph \pi : x / f x >-> fq x}.
Hypothesis pi_g : {morph \pi : x y / g x y >-> gq x y}.
Hypothesis pi_p : {mono \pi : x / p x >-> pq x}.
Hypothesis pi_r : {mono \pi : x y / r x y >-> rq x y}.
Hypothesis pi_h : forall (x : T), \pi_qU (h x) = hq (\pi_qT x).
Variables (a b : T) (x : equal_to (\pi_qT a)) (y : equal_to (\pi_qT b)).
(* Internal Lemmas : do not use directly *)
Lemma pi_morph1 : \pi (f a) = fq (equal_val x). Proof. by rewrite !piE. Qed.
Lemma pi_morph2 : \pi (g a b) = gq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed.
Lemma pi_mono1 : p a = pq (equal_val x). Proof. by rewrite !piE. Qed.
Lemma pi_mono2 : r a b = rq (equal_val x) (equal_val y). Proof. by rewrite !piE. Qed.
Lemma pi_morph11 : \pi (h a) = hq (equal_val x). Proof. by rewrite !piE. Qed.
End Morphism.
Arguments pi_morph1 {T qT f fq}.
Arguments pi_morph2 {T qT g gq}.
Arguments pi_mono1 {T U qT p pq}.
Arguments pi_mono2 {T U qT r rq}.
Arguments pi_morph11 {T U qT qU h hq}.
Notation "{pi_ Q a }" := (equal_to (\pi_Q a)) : quotient_scope.
Notation "{pi a }" := (equal_to (\pi a)) : quotient_scope.
(* Declaration of morphisms *)
Notation PiMorph pi_x := (EqualTo pi_x).
Notation PiMorph1 pi_f :=
(fun a (x : {pi a}) => EqualTo (pi_morph1 pi_f a x)).
Notation PiMorph2 pi_g :=
(fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_morph2 pi_g a b x y)).
Notation PiMono1 pi_p :=
(fun a (x : {pi a}) => EqualTo (pi_mono1 pi_p a x)).
Notation PiMono2 pi_r :=
(fun a b (x : {pi a}) (y : {pi b}) => EqualTo (pi_mono2 pi_r a b x y)).
Notation PiMorph11 pi_f :=
(fun a (x : {pi a}) => EqualTo (pi_morph11 pi_f a x)).
(* lifting helpers *)
Notation lift_op1 Q f := (locked (fun x : Q => \pi_Q (f (repr x)) : Q)).
Notation lift_op2 Q g :=
(locked (fun x y : Q => \pi_Q (g (repr x) (repr y)) : Q)).
Notation lift_fun1 Q f := (locked (fun x : Q => f (repr x))).
Notation lift_fun2 Q g := (locked (fun x y : Q => g (repr x) (repr y))).
Notation lift_op11 Q Q' f := (locked (fun x : Q => \pi_Q' (f (repr x)) : Q')).
(* constant declaration *)
Notation lift_cst Q x := (locked (\pi_Q x : Q)).
Notation PiConst a := (@EqualTo _ _ a (lock _)).
(* embedding declaration, please don't redefine \pi *)
Notation lift_embed qT e := (locked (fun x => \pi_qT (e x) : qT)).
Lemma eq_lock T T' e : e =1 (@locked (T -> T') (fun x : T => e x)).
Proof. by rewrite -lock. Qed.
Prenex Implicits eq_lock.
Notation PiEmbed e :=
(fun x => @EqualTo _ _ (e x) (eq_lock (fun _ => \pi _) _)).
(********************)
(* About eqQuotType *)
(********************)
HB.mixin Record isEqQuotient T (eq_quot_op : rel T) (Q : Type) of
isQuotient T Q & hasDecEq Q := {
pi_eq_quot : {mono \pi_Q : x y / eq_quot_op x y >-> x == y}
}.
#[short(type="eqQuotType")]
HB.structure Definition EqQuotient T eq_quot_op :=
{Q of isEqQuotient T eq_quot_op Q & Quotient T Q & hasDecEq Q}.
Canonical pi_eq_quot_mono T eq_quot_op eqT :=
PiMono2 (@pi_eq_quot T eq_quot_op eqT).
(**************************************************************************)
(* Even if a quotType is a natural subType, we do not make this subType *)
(* canonical, to allow the user to define the subtyping he wants. However *)
(* one can: *)
(* - get the hasDecEq and the hasChoice by subtyping *)
(* - get the subType structure and maybe declare it Canonical. *)
(**************************************************************************)
Definition quot_type_of T (qT : quotType T) : Type := qT.
Arguments quot_type_of T%_type qT%_type : clear implicits.
Notation quot_type Q := (quot_type_of _ Q).
HB.instance Definition _ T (qT : quotType T) := Quotient.on (quot_type qT).
Module QuotSubType.
Section QuotSubType.
Variable (T : eqType) (qT : quotType T).
Definition Sub x (px : repr (\pi_qT x) == x) := \pi_qT x.
Lemma qreprK x Px : repr (@Sub x Px) = x.
Proof. by rewrite /Sub (eqP Px). Qed.
Lemma sortPx (x : qT) : repr (\pi_qT (repr x)) == repr x.
Proof. by rewrite !reprK eqxx. Qed.
Lemma sort_Sub (x : qT) : x = Sub (sortPx x).
Proof. by rewrite /Sub reprK. Qed.
Lemma reprP K (PK : forall x Px, K (@Sub x Px)) u : K u.
Proof. by rewrite (sort_Sub u); apply: PK. Qed.
#[export]
HB.instance Definition _ := isSub.Build _ _ (quot_type qT) reprP qreprK.
#[export]
HB.instance Definition _ := [Equality of quot_type qT by <:].
End QuotSubType.
Module Exports. HB.reexport. End Exports.
End QuotSubType.
Export QuotSubType.Exports.
HB.instance Definition _ (T : choiceType) (qT : quotType T) :=
[Choice of quot_type qT by <:].
HB.instance Definition _ (T : countType) (qT : quotType T) :=
[Countable of quot_type qT by <:].
HB.instance Definition _ (T : finType) (qT : quotType T) :=
[Finite of quot_type qT by <:].
Notation "[ 'Sub' Q 'of' T 'by' %/ ]" :=
(SubType.copy Q%type (quot_type_of T Q%type))
(format "[ 'Sub' Q 'of' T 'by' %/ ]") : form_scope.
Notation "[ 'Sub' Q 'by' %/ ]" :=
(SubType.copy Q%type (quot_type Q))
(format "[ 'Sub' Q 'by' %/ ]") : form_scope.
Notation "[ 'Equality' 'of' Q 'by' <:%/ ]" :=
(Equality.copy Q%type (quot_type Q))
(format "[ 'Equality' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Choice' 'of' Q 'by' <:%/ ]" := (Choice.copy Q%type (quot_type Q))
(format "[ 'Choice' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Countable' 'of' Q 'by' <:%/ ]" := (Countable.copy Q%type (quot_type Q))
(format "[ 'Countable' 'of' Q 'by' <:%/ ]") : form_scope.
Notation "[ 'Finite' 'of' Q 'by' <:%/ ]" := (Finite.copy Q%type (quot_type Q))
(format "[ 'Finite' 'of' Q 'by' <:%/ ]") : form_scope.
(****************************************************)
(* Definition of a (decidable) equivalence relation *)
(****************************************************)
Section EquivRel.
Variable T : Type.
Lemma left_trans (e : rel T) :
symmetric e -> transitive e -> left_transitive e.
Proof. by move=> s t ? * ?; apply/idP/idP; apply: t; rewrite // s. Qed.
Lemma right_trans (e : rel T) :
symmetric e -> transitive e -> right_transitive e.
Proof. by move=> s t ? * x; rewrite ![e x _]s; apply: left_trans. Qed.
Variant equiv_class_of (equiv : rel T) :=
EquivClass of reflexive equiv & symmetric equiv & transitive equiv.
Record equiv_rel := EquivRelPack {
equiv :> rel T;
_ : equiv_class_of equiv
}.
Variable e : equiv_rel.
Definition equiv_class :=
let: EquivRelPack _ ce as e' := e return equiv_class_of e' in ce.
Definition equiv_pack (r : rel T) ce of phant_id ce equiv_class :=
@EquivRelPack r ce.
Lemma equiv_refl x : e x x. Proof. by case: e => [] ? []. Qed.
Lemma equiv_sym : symmetric e. Proof. by case: e => [] ? []. Qed.
Lemma equiv_trans : transitive e. Proof. by case: e => [] ? []. Qed.
Lemma eq_op_trans (T' : eqType) : transitive (@eq_op T').
Proof. by move=> x y z /eqP -> /eqP ->. Qed.
Lemma equiv_ltrans: left_transitive e.
Proof. by apply: left_trans; [apply: equiv_sym|apply: equiv_trans]. Qed.
Lemma equiv_rtrans: right_transitive e.
Proof. by apply: right_trans; [apply: equiv_sym|apply: equiv_trans]. Qed.
End EquivRel.
#[global] Hint Resolve equiv_refl : core.
Notation EquivRel r er es et := (@EquivRelPack _ r (EquivClass er es et)).
Notation "[ 'equiv_rel' 'of' e ]" := (@equiv_pack _ _ e _ id)
(format "[ 'equiv_rel' 'of' e ]") : form_scope.
(**************************************************)
(* Encoding to another type modulo an equivalence *)
(**************************************************)
Section EncodingModuloRel.
Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : rel D).
Variant encModRel_class_of (r : rel D) :=
EncModRelClassPack of (forall x, r x x -> r (ED (DE x)) x) & (r =2 e).
Record encModRel := EncModRelPack {
enc_mod_rel :> rel D;
_ : encModRel_class_of enc_mod_rel
}.
Variable r : encModRel.
Definition encModRelClass :=
let: EncModRelPack _ c as r' := r return encModRel_class_of r' in c.
Definition encModRelP (x : D) : r x x -> r (ED (DE x)) x.
Proof. by case: r => [] ? [] /= he _ /he. Qed.
Definition encModRelE : r =2 e. Proof. by case: r => [] ? []. Qed.
Definition encoded_equiv : rel E := [rel x y | r (ED x) (ED y)].
End EncodingModuloRel.
Notation EncModRelClass m :=
(EncModRelClassPack (fun x _ => m x) (fun _ _ => erefl _)).
Notation EncModRel r m := (@EncModRelPack _ _ _ _ _ r (EncModRelClass m)).
Section EncodingModuloEquiv.
Variables (D E : Type) (ED : E -> D) (DE : D -> E) (e : equiv_rel D).
Variable (r : encModRel ED DE e).
Lemma enc_mod_rel_is_equiv : equiv_class_of (enc_mod_rel r).
Proof.
split => [x|x y|y x z]; rewrite !encModRelE //; first by rewrite equiv_sym.
by move=> exy /(equiv_trans exy).
Qed.
Definition enc_mod_rel_equiv_rel := EquivRelPack enc_mod_rel_is_equiv.
Definition encModEquivP (x : D) : r (ED (DE x)) x.
Proof. by rewrite encModRelP ?encModRelE. Qed.
Local Notation e' := (encoded_equiv r).
Lemma encoded_equivE : e' =2 [rel x y | e (ED x) (ED y)].
Proof. by move=> x y; rewrite /encoded_equiv /= encModRelE. Qed.
Local Notation e'E := encoded_equivE.
Lemma encoded_equiv_is_equiv : equiv_class_of e'.
Proof.
split => [x|x y|y x z]; rewrite !e'E //=; first by rewrite equiv_sym.
by move=> exy /(equiv_trans exy).
Qed.
Canonical encoded_equiv_equiv_rel := EquivRelPack encoded_equiv_is_equiv.
Lemma encoded_equivP x : e' (DE (ED x)) x.
Proof. by rewrite /encoded_equiv /= encModEquivP. Qed.
End EncodingModuloEquiv.
(**************************************)
(* Quotient by a equivalence relation *)
(**************************************)
Module EquivQuot.
Section EquivQuot.
Variables (D : Type) (C : choiceType) (CD : C -> D) (DC : D -> C).
Variables (eD : equiv_rel D) (encD : encModRel CD DC eD).
Notation eC := (encoded_equiv encD).
Definition canon x := choose (eC x) (x).
Record equivQuotient := EquivQuotient {
erepr : C;
_ : (frel canon) erepr erepr
}.
Definition type_of of (phantom (rel _) encD) := equivQuotient.
Lemma canon_id : forall x, (invariant canon canon) x.
Proof.
move=> x /=; rewrite /canon (@eq_choose _ _ (eC x)).
by rewrite (@choose_id _ (eC x) _ x) ?chooseP ?equiv_refl.
by move=> y; apply: equiv_ltrans; rewrite equiv_sym /= chooseP.
Qed.
Definition pi := locked (fun x => EquivQuotient (canon_id x)).
Lemma ereprK : cancel erepr pi.
Proof.
pose T : subType _ := HB.pack equivQuotient [isSub for erepr].
by unlock pi; case=> x hx; apply/(@val_inj _ _ T)/eqP.
Qed.
Local Notation encDE := (encModRelE encD).
Local Notation encDP := (encModEquivP encD).
Canonical encD_equiv_rel := EquivRelPack (enc_mod_rel_is_equiv encD).
Lemma pi_CD (x y : C) : reflect (pi x = pi y) (eC x y).
Proof.
apply: (iffP idP) => hxy.
apply: (can_inj ereprK); unlock pi canon => /=.
rewrite -(@eq_choose _ (eC x) (eC y)); last first.
by move=> z; rewrite /eC /=; apply: equiv_ltrans.
by apply: choose_id; rewrite ?equiv_refl //.
rewrite (equiv_trans (chooseP (equiv_refl _ _))) //=.
move: hxy => /(f_equal erepr) /=; unlock pi canon => /= ->.
by rewrite equiv_sym /= chooseP.
Qed.
Lemma pi_DC (x y : D) :
reflect (pi (DC x) = pi (DC y)) (eD x y).
Proof.
apply: (iffP idP)=> hxy.
apply/pi_CD; rewrite /eC /=.
by rewrite (equiv_ltrans (encDP _)) (equiv_rtrans (encDP _)) /= encDE.
rewrite -encDE -(equiv_ltrans (encDP _)) -(equiv_rtrans (encDP _)) /=.
exact/pi_CD.
Qed.
Lemma equivQTP : cancel (CD \o erepr) (pi \o DC).
Proof. by move=> x; rewrite /= (pi_CD _ (erepr x) _) ?ereprK /eC /= ?encDP. Qed.
Local Notation qT := (type_of (Phantom (rel D) encD)).
#[export]
HB.instance Definition _ := isQuotient.Build D qT equivQTP.
Lemma eqmodP x y : reflect (x = y %[mod qT]) (eD x y).
Proof. by apply: (iffP (pi_DC _ _)); rewrite !unlock. Qed.
#[export]
HB.instance Definition _ := Choice.copy qT (can_type ereprK).
Lemma eqmodE x y : x == y %[mod qT] = eD x y.
Proof. exact: sameP eqP (@eqmodP _ _). Qed.
#[export]
HB.instance Definition _ := isEqQuotient.Build _ eD qT eqmodE.
End EquivQuot.
Module Exports. HB.reexport. End Exports.
End EquivQuot.
Export EquivQuot.Exports.
Arguments EquivQuot.ereprK {D C CD DC eD encD}.
Notation "{eq_quot e }" :=
(@EquivQuot.type_of _ _ _ _ _ _ (Phantom (rel _) e)) : quotient_scope.
Notation "x == y %[mod_eq r ]" := (x == y %[mod {eq_quot r}]) : quotient_scope.
Notation "x = y %[mod_eq r ]" := (x = y %[mod {eq_quot r}]) : quotient_scope.
Notation "x != y %[mod_eq r ]" := (x != y %[mod {eq_quot r}]) : quotient_scope.
Notation "x <> y %[mod_eq r ]" := (x <> y %[mod {eq_quot r}]) : quotient_scope.
(***********************************************************)
(* If the type is directly a choiceType, no need to encode *)
(***********************************************************)
Section DefaultEncodingModuloRel.
Variables (D : choiceType) (r : rel D).
Definition defaultEncModRelClass :=
@EncModRelClassPack D D id id r r (fun _ rxx => rxx) (fun _ _ => erefl _).
Canonical defaultEncModRel := EncModRelPack defaultEncModRelClass.
End DefaultEncodingModuloRel.
(***************************************************)
(* Recovering a potential countable type structure *)
(***************************************************)
Section CountEncodingModuloRel.
Variables (D : Type) (C : countType) (CD : C -> D) (DC : D -> C).
Variables (eD : equiv_rel D) (encD : encModRel CD DC eD).
Notation eC := (encoded_equiv encD).
HB.instance Definition _ :=
Countable.copy {eq_quot encD} (can_type EquivQuot.ereprK).
End CountEncodingModuloRel.
Section EquivQuotTheory.
Variables (T : choiceType) (e : equiv_rel T) (Q : eqQuotType e).
Lemma eqmodE x y : x == y %[mod_eq e] = e x y.
Proof. by rewrite pi_eq_quot. Qed.
Lemma eqmodP x y : reflect (x = y %[mod_eq e]) (e x y).
Proof. by rewrite -eqmodE; apply/eqP. Qed.
End EquivQuotTheory.
Prenex Implicits eqmodE eqmodP.
Section EqQuotTheory.
Variables (T : Type) (e : rel T) (Q : eqQuotType e).
Lemma eqquotE x y : x == y %[mod Q] = e x y.
Proof. by rewrite pi_eq_quot. Qed.
Lemma eqquotP x y : reflect (x = y %[mod Q]) (e x y).
Proof. by rewrite -eqquotE; apply/eqP. Qed.
End EqQuotTheory.
Prenex Implicits eqquotE eqquotP.
|
Hom.lean
|
/-
Copyright (c) 2021 Floris van Doorn. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Floris van Doorn
-/
import Mathlib.Algebra.Group.Equiv.Defs
import Mathlib.Algebra.Order.Sub.Unbundled.Basic
import Mathlib.Algebra.Ring.Basic
import Mathlib.Order.Hom.Basic
/-!
# Lemmas about subtraction in unbundled canonically ordered monoids
-/
variable {Ξ± Ξ² : Type*}
section Add
variable [Preorder Ξ±] [Add Ξ±] [Sub Ξ±] [OrderedSub Ξ±]
theorem AddHom.le_map_tsub [Preorder Ξ²] [Add Ξ²] [Sub Ξ²] [OrderedSub Ξ²] (f : AddHom Ξ± Ξ²)
(hf : Monotone f) (a b : Ξ±) : f a - f b β€ f (a - b) := by
rw [tsub_le_iff_right, β f.map_add]
exact hf le_tsub_add
theorem le_mul_tsub {R : Type*} [Distrib R] [Preorder R] [Sub R] [OrderedSub R]
[MulLeftMono R] {a b c : R} : a * b - a * c β€ a * (b - c) :=
(AddHom.mulLeft a).le_map_tsub (monotone_id.const_mul' a) _ _
theorem le_tsub_mul {R : Type*} [NonUnitalCommSemiring R] [Preorder R] [Sub R] [OrderedSub R]
[MulLeftMono R] {a b c : R} : a * c - b * c β€ (a - b) * c := by
simpa only [mul_comm _ c] using le_mul_tsub
end Add
theorem map_tsub_of_le {F : Type*} [PartialOrder Ξ±] [AddCommSemigroup Ξ±] [ExistsAddOfLE Ξ±]
[AddLeftMono Ξ±] [Sub Ξ±] [OrderedSub Ξ±] [PartialOrder Ξ²] [AddCommSemigroup Ξ²] [Sub Ξ²]
[OrderedSub Ξ²] [AddLeftReflectLE Ξ²] [FunLike F Ξ± Ξ²] [AddHomClass F Ξ± Ξ²]
(f : F) (a b : Ξ±) (h : b β€ a) : f a - f b = f (a - b) := by
conv => lhs; rw [β tsub_add_cancel_of_le h]
rw [map_add, add_tsub_cancel_right]
/-- An order isomorphism between types with ordered subtraction preserves subtraction provided that
it preserves addition. -/
theorem OrderIso.map_tsub {M N : Type*} [Preorder M] [Add M] [Sub M] [OrderedSub M]
[PartialOrder N] [Add N] [Sub N] [OrderedSub N] (e : M βo N)
(h_add : β a b, e (a + b) = e a + e b) (a b : M) : e (a - b) = e a - e b := by
let e_add : M β+ N := { e with map_add' := h_add }
refine le_antisymm ?_ (e_add.toAddHom.le_map_tsub e.monotone a b)
suffices e (e.symm (e a) - e.symm (e b)) β€ e (e.symm (e a - e b)) by simpa
exact e.monotone (e_add.symm.toAddHom.le_map_tsub e.symm.monotone _ _)
/-! ### Preorder -/
section Preorder
variable [Preorder Ξ±]
variable [AddCommMonoid Ξ±] [Sub Ξ±] [OrderedSub Ξ±]
theorem AddMonoidHom.le_map_tsub [Preorder Ξ²] [AddZeroClass Ξ²] [Sub Ξ²] [OrderedSub Ξ²] (f : Ξ± β+ Ξ²)
(hf : Monotone f) (a b : Ξ±) : f a - f b β€ f (a - b) :=
f.toAddHom.le_map_tsub hf a b
end Preorder
|
Continuous.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, Jeremy Avigad
-/
import Mathlib.Topology.ClusterPt
/-!
# Continuity in topological spaces
For topological spaces `X` and `Y`, a function `f : X β Y` and a point `x : X`,
`ContinuousAt f x` means `f` is continuous at `x`, and global continuity is
`Continuous f`. There is also a version of continuity `PContinuous` for
partially defined functions.
## Tags
continuity, continuous function
-/
open Set Filter Topology
variable {X Y Z : Type*}
open TopologicalSpace
-- The curly braces are intentional, so this definition works well with simp
-- when topologies are not those provided by instances.
theorem continuous_def {_ : TopologicalSpace X} {_ : TopologicalSpace Y} {f : X β Y} :
Continuous f β β s, IsOpen s β IsOpen (f β»ΒΉ' s) :=
β¨fun hf => hf.1, fun h => β¨hβ©β©
variable [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z]
variable {f : X β Y} {s : Set X} {x : X} {y : Y}
theorem IsOpen.preimage (hf : Continuous f) {t : Set Y} (h : IsOpen t) :
IsOpen (f β»ΒΉ' t) :=
hf.isOpen_preimage t h
lemma Equiv.continuous_symm_iff (e : X β Y) : Continuous e.symm β IsOpenMap e := by
simp_rw [continuous_def, β Set.image_equiv_eq_preimage_symm, IsOpenMap]
lemma Equiv.isOpenMap_symm_iff (e : X β Y) : IsOpenMap e.symm β Continuous e := by
simp_rw [β Equiv.continuous_symm_iff, Equiv.symm_symm]
theorem continuous_congr {g : X β Y} (h : β x, f x = g x) :
Continuous f β Continuous g :=
.of_eq <| congrArg _ <| funext h
theorem Continuous.congr {g : X β Y} (h : Continuous f) (h' : β x, f x = g x) : Continuous g :=
continuous_congr h' |>.mp h
theorem ContinuousAt.tendsto (h : ContinuousAt f x) :
Tendsto f (π x) (π (f x)) :=
h
theorem continuousAt_def : ContinuousAt f x β β A β π (f x), f β»ΒΉ' A β π x :=
Iff.rfl
theorem continuousAt_congr {g : X β Y} (h : f =αΆ [π x] g) :
ContinuousAt f x β ContinuousAt g x := by
simp only [ContinuousAt, tendsto_congr' h, h.eq_of_nhds]
theorem ContinuousAt.congr {g : X β Y} (hf : ContinuousAt f x) (h : f =αΆ [π x] g) :
ContinuousAt g x :=
(continuousAt_congr h).1 hf
theorem ContinuousAt.preimage_mem_nhds {t : Set Y} (h : ContinuousAt f x)
(ht : t β π (f x)) : f β»ΒΉ' t β π x :=
h ht
/-- If `f x β s β π (f x)` for continuous `f`, then `f y β s` near `x`.
This is essentially `Filter.Tendsto.eventually_mem`, but infers in more cases when applied. -/
theorem ContinuousAt.eventually_mem {f : X β Y} {x : X} (hf : ContinuousAt f x) {s : Set Y}
(hs : s β π (f x)) : βαΆ y in π x, f y β s :=
hf hs
/-- If a function `f` tends to somewhere other than `π (f x)` at `x`,
then `f` is not continuous at `x`
-/
lemma not_continuousAt_of_tendsto {f : X β Y} {lβ : Filter X} {lβ : Filter Y} {x : X}
(hf : Tendsto f lβ lβ) [lβ.NeBot] (hlβ : lβ β€ π x) (hlβ : Disjoint (π (f x)) lβ) :
Β¬ ContinuousAt f x := fun cont β¦
(cont.mono_left hlβ).not_tendsto hlβ hf
theorem ClusterPt.map {lx : Filter X} {ly : Filter Y} (H : ClusterPt x lx)
(hfc : ContinuousAt f x) (hf : Tendsto f lx ly) : ClusterPt (f x) ly :=
(NeBot.map H f).mono <| hfc.tendsto.inf hf
/-- See also `interior_preimage_subset_preimage_interior`. -/
theorem preimage_interior_subset_interior_preimage {t : Set Y} (hf : Continuous f) :
f β»ΒΉ' interior t β interior (f β»ΒΉ' t) :=
interior_maximal (preimage_mono interior_subset) (isOpen_interior.preimage hf)
@[continuity]
theorem continuous_id : Continuous (id : X β X) :=
continuous_def.2 fun _ => id
-- This is needed due to reducibility issues with the `continuity` tactic.
@[continuity, fun_prop]
theorem continuous_id' : Continuous (fun (x : X) => x) := continuous_id
theorem Continuous.comp {g : Y β Z} (hg : Continuous g) (hf : Continuous f) :
Continuous (g β f) :=
continuous_def.2 fun _ h => (h.preimage hg).preimage hf
-- This is needed due to reducibility issues with the `continuity` tactic.
@[continuity, fun_prop]
theorem Continuous.comp' {g : Y β Z} (hg : Continuous g) (hf : Continuous f) :
Continuous (fun x => g (f x)) := hg.comp hf
theorem Continuous.iterate {f : X β X} (h : Continuous f) (n : β) : Continuous f^[n] :=
Nat.recOn n continuous_id fun _ ihn => ihn.comp h
nonrec theorem ContinuousAt.comp {g : Y β Z} (hg : ContinuousAt g (f x))
(hf : ContinuousAt f x) : ContinuousAt (g β f) x :=
hg.comp hf
@[fun_prop]
theorem ContinuousAt.comp' {g : Y β Z} {x : X} (hg : ContinuousAt g (f x))
(hf : ContinuousAt f x) : ContinuousAt (fun x => g (f x)) x := ContinuousAt.comp hg hf
/-- See note [comp_of_eq lemmas] -/
theorem ContinuousAt.comp_of_eq {g : Y β Z} (hg : ContinuousAt g y)
(hf : ContinuousAt f x) (hy : f x = y) : ContinuousAt (g β f) x := by subst hy; exact hg.comp hf
theorem Continuous.tendsto (hf : Continuous f) (x) : Tendsto f (π x) (π (f x)) :=
((nhds_basis_opens x).tendsto_iff <| nhds_basis_opens <| f x).2 fun t β¨hxt, htβ© =>
β¨f β»ΒΉ' t, β¨hxt, ht.preimage hfβ©, Subset.rflβ©
/-- A version of `Continuous.tendsto` that allows one to specify a simpler form of the limit.
E.g., one can write `continuous_exp.tendsto' 0 1 exp_zero`. -/
theorem Continuous.tendsto' (hf : Continuous f) (x : X) (y : Y) (h : f x = y) :
Tendsto f (π x) (π y) :=
h βΈ hf.tendsto x
@[fun_prop]
theorem Continuous.continuousAt (h : Continuous f) : ContinuousAt f x :=
h.tendsto x
theorem continuous_iff_continuousAt : Continuous f β β x, ContinuousAt f x :=
β¨Continuous.tendsto, fun hf => continuous_def.2 fun _U hU => isOpen_iff_mem_nhds.2 fun x hx =>
hf x <| hU.mem_nhds hxβ©
@[fun_prop]
theorem continuousAt_const : ContinuousAt (fun _ : X => y) x :=
tendsto_const_nhds
@[continuity, fun_prop]
theorem continuous_const : Continuous fun _ : X => y :=
continuous_iff_continuousAt.mpr fun _ => continuousAt_const
theorem Filter.EventuallyEq.continuousAt (h : f =αΆ [π x] fun _ => y) :
ContinuousAt f x :=
(continuousAt_congr h).2 tendsto_const_nhds
theorem continuous_of_const (h : β x y, f x = f y) : Continuous f :=
continuous_iff_continuousAt.mpr fun x =>
Filter.EventuallyEq.continuousAt <| Eventually.of_forall fun y => h y x
theorem continuousAt_id : ContinuousAt id x :=
continuous_id.continuousAt
@[fun_prop]
theorem continuousAt_id' (y) : ContinuousAt (fun x : X => x) y := continuousAt_id
theorem ContinuousAt.iterate {f : X β X} (hf : ContinuousAt f x) (hx : f x = x) (n : β) :
ContinuousAt f^[n] x :=
Nat.recOn n continuousAt_id fun _n ihn β¦ ihn.comp_of_eq hf hx
theorem continuous_iff_isClosed : Continuous f β β s, IsClosed s β IsClosed (f β»ΒΉ' s) :=
continuous_def.trans <| compl_surjective.forall.trans <| by
simp only [isOpen_compl_iff, preimage_compl]
theorem IsClosed.preimage (hf : Continuous f) {t : Set Y} (h : IsClosed t) :
IsClosed (f β»ΒΉ' t) :=
continuous_iff_isClosed.mp hf t h
theorem mem_closure_image (hf : ContinuousAt f x)
(hx : x β closure s) : f x β closure (f '' s) :=
mem_closure_of_frequently_of_tendsto
((mem_closure_iff_frequently.1 hx).mono fun _ => mem_image_of_mem _) hf
theorem Continuous.closure_preimage_subset (hf : Continuous f) (t : Set Y) :
closure (f β»ΒΉ' t) β f β»ΒΉ' closure t := by
rw [β (isClosed_closure.preimage hf).closure_eq]
exact closure_mono (preimage_mono subset_closure)
theorem Continuous.frontier_preimage_subset (hf : Continuous f) (t : Set Y) :
frontier (f β»ΒΉ' t) β f β»ΒΉ' frontier t :=
diff_subset_diff (hf.closure_preimage_subset t) (preimage_interior_subset_interior_preimage hf)
/-- If a continuous map `f` maps `s` to `t`, then it maps `closure s` to `closure t`. -/
protected theorem Set.MapsTo.closure {t : Set Y} (h : MapsTo f s t)
(hc : Continuous f) : MapsTo f (closure s) (closure t) := by
simp only [MapsTo, mem_closure_iff_clusterPt]
exact fun x hx => hx.map hc.continuousAt (tendsto_principal_principal.2 h)
/-- See also `IsClosedMap.closure_image_eq_of_continuous`. -/
theorem image_closure_subset_closure_image (h : Continuous f) :
f '' closure s β closure (f '' s) :=
((mapsTo_image f s).closure h).image_subset
theorem closure_image_closure (h : Continuous f) :
closure (f '' closure s) = closure (f '' s) :=
Subset.antisymm
(closure_minimal (image_closure_subset_closure_image h) isClosed_closure)
(closure_mono <| image_mono subset_closure)
theorem closure_subset_preimage_closure_image (h : Continuous f) :
closure s β f β»ΒΉ' closure (f '' s) :=
(mapsTo_image _ _).closure h
theorem map_mem_closure {t : Set Y} (hf : Continuous f)
(hx : x β closure s) (ht : MapsTo f s t) : f x β closure t :=
ht.closure hf hx
/-- If a continuous map `f` maps `s` to a closed set `t`, then it maps `closure s` to `t`. -/
theorem Set.MapsTo.closure_left {t : Set Y} (h : MapsTo f s t)
(hc : Continuous f) (ht : IsClosed t) : MapsTo f (closure s) t :=
ht.closure_eq βΈ h.closure hc
theorem Filter.Tendsto.lift'_closure (hf : Continuous f) {l l'} (h : Tendsto f l l') :
Tendsto f (l.lift' closure) (l'.lift' closure) :=
tendsto_lift'.2 fun s hs β¦ by
filter_upwards [mem_lift' (h hs)] using (mapsTo_preimage _ _).closure hf
theorem tendsto_lift'_closure_nhds (hf : Continuous f) (x : X) :
Tendsto f ((π x).lift' closure) ((π (f x)).lift' closure) :=
(hf.tendsto x).lift'_closure hf
/-!
### Function with dense range
-/
section DenseRange
variable {Ξ± ΞΉ : Type*} (f : Ξ± β X) (g : X β Y)
variable {f : Ξ± β X} {s : Set X}
/-- A surjective map has dense range. -/
theorem Function.Surjective.denseRange (hf : Function.Surjective f) : DenseRange f := fun x => by
simp [hf.range_eq]
theorem denseRange_id : DenseRange (id : X β X) :=
Function.Surjective.denseRange Function.surjective_id
theorem denseRange_iff_closure_range : DenseRange f β closure (range f) = univ :=
dense_iff_closure_eq
theorem DenseRange.closure_range (h : DenseRange f) : closure (range f) = univ :=
h.closure_eq
@[simp]
lemma denseRange_subtype_val {p : X β Prop} : DenseRange (@Subtype.val _ p) β Dense {x | p x} := by
simp [DenseRange]
theorem Dense.denseRange_val (h : Dense s) : DenseRange ((β) : s β X) :=
denseRange_subtype_val.2 h
theorem Continuous.range_subset_closure_image_dense {f : X β Y} (hf : Continuous f)
(hs : Dense s) : range f β closure (f '' s) := by
rw [β image_univ, β hs.closure_eq]
exact image_closure_subset_closure_image hf
/-- The image of a dense set under a continuous map with dense range is a dense set. -/
theorem DenseRange.dense_image {f : X β Y} (hf' : DenseRange f) (hf : Continuous f)
(hs : Dense s) : Dense (f '' s) :=
(hf'.mono <| hf.range_subset_closure_image_dense hs).of_closure
/-- If `f` has dense range and `s` is an open set in the codomain of `f`, then the image of the
preimage of `s` under `f` is dense in `s`. -/
theorem DenseRange.subset_closure_image_preimage_of_isOpen (hf : DenseRange f) (hs : IsOpen s) :
s β closure (f '' (f β»ΒΉ' s)) := by
rw [image_preimage_eq_inter_range]
exact hf.open_subset_closure_inter hs
/-- If a continuous map with dense range maps a dense set to a subset of `t`, then `t` is a dense
set. -/
theorem DenseRange.dense_of_mapsTo {f : X β Y} (hf' : DenseRange f) (hf : Continuous f)
(hs : Dense s) {t : Set Y} (ht : MapsTo f s t) : Dense t :=
(hf'.dense_image hf hs).mono ht.image_subset
/-- Composition of a continuous map with dense range and a function with dense range has dense
range. -/
theorem DenseRange.comp {g : Y β Z} {f : Ξ± β Y} (hg : DenseRange g) (hf : DenseRange f)
(cg : Continuous g) : DenseRange (g β f) := by
rw [DenseRange, range_comp]
exact hg.dense_image cg hf
nonrec theorem DenseRange.nonempty_iff (hf : DenseRange f) : Nonempty Ξ± β Nonempty X :=
range_nonempty_iff_nonempty.symm.trans hf.nonempty_iff
theorem DenseRange.nonempty [h : Nonempty X] (hf : DenseRange f) : Nonempty Ξ± :=
hf.nonempty_iff.mpr h
/-- Given a function `f : X β Y` with dense range and `y : Y`, returns some `x : X`. -/
noncomputable def DenseRange.some (hf : DenseRange f) (x : X) : Ξ± :=
Classical.choice <| hf.nonempty_iff.mpr β¨xβ©
nonrec theorem DenseRange.exists_mem_open (hf : DenseRange f) (ho : IsOpen s) (hs : s.Nonempty) :
β a, f a β s :=
exists_range_iff.1 <| hf.exists_mem_open ho hs
theorem DenseRange.mem_nhds (h : DenseRange f) (hs : s β π x) :
β a, f a β s :=
let β¨a, haβ© := h.exists_mem_open isOpen_interior β¨x, mem_interior_iff_mem_nhds.2 hsβ©
β¨a, interior_subset haβ©
end DenseRange
library_note "continuity lemma statement"/--
The library contains many lemmas stating that functions/operations are continuous. There are many
ways to formulate the continuity of operations. Some are more convenient than others.
Note: for the most part this note also applies to other properties
(`Measurable`, `Differentiable`, `ContinuousOn`, ...).
### The traditional way
As an example, let's look at addition `(+) : M β M β M`. We can state that this is continuous
in different definitionally equal ways (omitting some typing information)
* `Continuous (fun p β¦ p.1 + p.2)`;
* `Continuous (Function.uncurry (+))`;
* `Continuous βΏ(+)`. (`βΏ` is notation for recursively uncurrying a function)
However, lemmas with this conclusion are not nice to use in practice because
1. They confuse the elaborator. The following two examples fail, because of limitations in the
elaboration process.
```
variable {M : Type*} [Add M] [TopologicalSpace M] [ContinuousAdd M]
example : Continuous (fun x : M β¦ x + x) :=
continuous_add.comp _
example : Continuous (fun x : M β¦ x + x) :=
continuous_add.comp (continuous_id.prodMk continuous_id)
```
The second is a valid proof, which is accepted if you write it as
`continuous_add.comp (continuous_id.prodMk continuous_id :)`
2. If the operation has more than 2 arguments, they are impractical to use, because in your
application the arguments in the domain might be in a different order or associated differently.
### The convenient way
A much more convenient way to write continuity lemmas is like `Continuous.add`:
```
Continuous.add {f g : X β M} (hf : Continuous f) (hg : Continuous g) :
Continuous (fun x β¦ f x + g x)
```
The conclusion can be `Continuous (f + g)`, which is definitionally equal.
This has the following advantages
* It supports projection notation, so is shorter to write.
* `Continuous.add _ _` is recognized correctly by the elaborator and gives useful new goals.
* It works generally, since the domain is a variable.
As an example for a unary operation, we have `Continuous.neg`.
```
Continuous.neg {f : X β G} (hf : Continuous f) : Continuous (fun x β¦ -f x)
```
For unary functions, the elaborator is not confused when applying the traditional lemma
(like `continuous_neg`), but it's still convenient to have the short version available (compare
`hf.neg.neg.neg` with `continuous_neg.comp <| continuous_neg.comp <| continuous_neg.comp hf`).
As a harder example, consider an operation of the following type:
```
def strans {x : F} (Ξ³ Ξ³' : Path x x) (tβ : I) : Path x x
```
The precise definition is not important, only its type.
The correct continuity principle for this operation is something like this:
```
{f : X β F} {Ξ³ Ξ³' : β x, Path (f x) (f x)} {tβ s : X β I}
(hΞ³ : Continuous βΏΞ³) (hΞ³' : Continuous βΏΞ³')
(ht : Continuous tβ) (hs : Continuous s) :
Continuous (fun x β¦ strans (Ξ³ x) (Ξ³' x) (t x) (s x))
```
Note that *all* arguments of `strans` are indexed over `X`, even the basepoint `x`, and the last
argument `s` that arises since `Path x x` has a coercion to `I β F`. The paths `Ξ³` and `Ξ³'` (which
are unary functions from `I`) become binary functions in the continuity lemma.
### Summary
* Make sure that your continuity lemmas are stated in the most general way, and in a convenient
form. That means that:
- The conclusion has a variable `X` as domain (not something like `Y Γ Z`);
- Wherever possible, all point arguments `c : Y` are replaced by functions `c : X β Y`;
- All `n`-ary function arguments are replaced by `n+1`-ary functions
(`f : Y β Z` becomes `f : X β Y β Z`);
- All (relevant) arguments have continuity assumptions, and perhaps there are additional
assumptions needed to make the operation continuous;
- The function in the conclusion is fully applied.
* These remarks are mostly about the format of the *conclusion* of a continuity lemma.
In assumptions it's fine to state that a function with more than 1 argument is continuous using
`βΏ` or `Function.uncurry`.
### Functions with discontinuities
In some cases, you want to work with discontinuous functions, and in certain expressions they are
still continuous. For example, consider the fractional part of a number, `Int.fract : β β β`.
In this case, you want to add conditions to when a function involving `fract` is continuous, so you
get something like this: (assumption `hf` could be weakened, but the important thing is the shape
of the conclusion)
```
lemma ContinuousOn.comp_fract {X Y : Type*} [TopologicalSpace X] [TopologicalSpace Y]
{f : X β β β Y} {g : X β β} (hf : Continuous βΏf) (hg : Continuous g) (h : β s, f s 0 = f s 1) :
Continuous (fun x β¦ f x (fract (g x)))
```
With `ContinuousAt` you can be even more precise about what to prove in case of discontinuities,
see e.g. `ContinuousAt.comp_div_cases`.
-/
library_note "comp_of_eq lemmas"/--
Lean's elaborator has trouble elaborating applications of lemmas that state that the composition of
two functions satisfy some property at a point, like `ContinuousAt.comp` / `ContDiffAt.comp` and
`ContMDiffWithinAt.comp`. The reason is that a lemma like this looks like
`ContinuousAt g (f x) β ContinuousAt f x β ContinuousAt (g β f) x`.
Since Lean's elaborator elaborates the arguments from left-to-right, when you write `hg.comp hf`,
the elaborator will try to figure out *both* `f` and `g` from the type of `hg`. It tries to figure
out `f` just from the point where `g` is continuous. For example, if `hg : ContinuousAt g (a, x)`
then the elaborator will assign `f` to the function `Prod.mk a`, since in that case `f x = (a, x)`.
This is undesirable in most cases where `f` is not a variable. There are some ways to work around
this, for example by giving `f` explicitly, or to force Lean to elaborate `hf` before elaborating
`hg`, but this is annoying.
Another better solution is to reformulate composition lemmas to have the following shape
`ContinuousAt g y β ContinuousAt f x β f x = y β ContinuousAt (g β f) x`.
This is even useful if the proof of `f x = y` is `rfl`.
The reason that this works better is because the type of `hg` doesn't mention `f`.
Only after elaborating the two `ContinuousAt` arguments, Lean will try to unify `f x` with `y`,
which is often easy after having chosen the correct functions for `f` and `g`.
Here is an example that shows the difference:
```
example [TopologicalSpace X] [TopologicalSpace Y] {xβ : X} (f : X β X β Y)
(hf : ContinuousAt (Function.uncurry f) (xβ, xβ)) :
ContinuousAt (fun x β¦ f x x) xβ :=
-- hf.comp (continuousAt_id.prod continuousAt_id) -- type mismatch
-- hf.comp_of_eq (continuousAt_id.prod continuousAt_id) rfl -- works
```
-/
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.