(************************************************************************) (* * The Rocq Prover / The Rocq Development Team *) (* v * Copyright INRIA, CNRS and contributors *) (* <O___,, * (see version control and CREDITS file for authors & dates) *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (* * (see LICENSE file for the text of the license) *) (************************************************************************)
(* This file is (C) Copyright 2006-2015 Microsoft Corporation and Inria. *)
Thefilealsocontainssomebasiclemmasfortheaboveconcepts. Lemmasrelativetocancellationlawsusesomeabbreviatedsuffixes: K-acancellationrulelikeesymK:cancel(@esymTxy)(@esymTyx). LR-alemmamovinganoperationfromthelefthandsideofarelationto therighthandside,likecanLR:cancelgf->x=gy->fx=y. RL-alemmamovinganoperationfromtherighttotheleft,e.g.,canRL. BewarethattheLRandRLorientationsrefertoan"apply"(backchaining) usage;whenusingthesamelemmaswith"have"or"move"(forwardchaining)
the directions will be reversed!. **)
(** Parsing / printing declarations. *)
Reserved Notation"f ^~ y" (at level 10, y at level 8, no associativity,
format "f ^~ y").
Reserved Notation"@^~ x" (at level 10, x at level 8, no associativity,
format "@^~ x").
Reserved Notation"[ 'eta' f ]" (at level 0, format "[ 'eta' f ]").
Reserved Notation"'fun' => E" (at level 200, format "'fun' => E").
Reserved Notation"[ 'fun' : T => E ]" (at level 0,
format "'[hv' [ 'fun' : T => '/ ' E ] ']'").
Reserved Notation"[ 'fun' x => E ]" (at level 0,
x name, format "'[hv' [ 'fun' x => '/ ' E ] ']'").
Reserved Notation"[ 'fun' x : T => E ]" (at level 0,
x name, format "'[hv' [ 'fun' x : T => '/ ' E ] ']'").
Reserved Notation"[ 'fun' x y => E ]" (at level 0,
x name, y name, format "'[hv' [ 'fun' x y => '/ ' E ] ']'").
Reserved Notation"[ 'fun' x y : T => E ]" (at level 0,
x name, y name, format "'[hv' [ 'fun' x y : T => '/ ' E ] ']'").
Reserved Notation"[ 'fun' ( x : T ) y => E ]" (at level 0,
x name, y name, format "'[hv' [ 'fun' ( x : T ) y => '/ ' E ] ']'").
Reserved Notation"[ 'fun' x ( y : T ) => E ]" (at level 0,
x name, y name, format "'[hv' [ 'fun' x ( y : T ) => '/ ' E ] ']'").
Reserved Notation"[ 'fun' ( x : T ) ( y : U ) => E ]" (at level 0,
x name, y name, format "[ 'fun' ( x : T ) ( y : U ) => E ]" ).
Reserved Notation"f =1 g" (at level 70, no associativity).
Reserved Notation"f =1 g :> A" (at level 70, g at next level, A at level 90).
Reserved Notation"f =2 g" (at level 70, no associativity).
Reserved Notation"f =2 g :> A" (at level 70, g at next level, A at level 90).
Reserved Notation"f \o g" (at level 50, format "f \o '/ ' g").
Reserved Notation"f \; g" (at level 60, right associativity,
format "f \; '/ ' g").
Reserved Notation"{ 'morph' f : x / a >-> r }" (at level 0, f at level 99,
x name, format "{ 'morph' f : x / a >-> r }").
Reserved Notation"{ 'morph' f : x / a }" (at level 0, f at level 99,
x name, format "{ 'morph' f : x / a }").
Reserved Notation"{ 'morph' f : x y / a >-> r }" (at level 0, f at level 99,
x name, y name, format "{ 'morph' f : x y / a >-> r }").
Reserved Notation"{ 'morph' f : x y / a }" (at level 0, f at level 99,
x name, y name, format "{ 'morph' f : x y / a }").
Reserved Notation"{ 'homo' f : x / a >-> r }" (at level 0, f at level 99,
x name, format "{ 'homo' f : x / a >-> r }").
Reserved Notation"{ 'homo' f : x / a }" (at level 0, f at level 99,
x name, format "{ 'homo' f : x / a }").
Reserved Notation"{ 'homo' f : x y / a >-> r }" (at level 0, f at level 99,
x name, y name, format "{ 'homo' f : x y / a >-> r }").
Reserved Notation"{ 'homo' f : x y / a }" (at level 0, f at level 99,
x name, y name, format "{ 'homo' f : x y / a }").
Reserved Notation"{ 'homo' f : x y /~ a }" (at level 0, f at level 99,
x name, y name, format "{ 'homo' f : x y /~ a }").
Reserved Notation"{ 'mono' f : x / a >-> r }" (at level 0, f at level 99,
x name, format "{ 'mono' f : x / a >-> r }").
Reserved Notation"{ 'mono' f : x / a }" (at level 0, f at level 99,
x name, format "{ 'mono' f : x / a }").
Reserved Notation"{ 'mono' f : x y / a >-> r }" (at level 0, f at level 99,
x name, y name, format "{ 'mono' f : x y / a >-> r }").
Reserved Notation"{ 'mono' f : x y / a }" (at level 0, f at level 99,
x name, y name, format "{ 'mono' f : x y / a }").
Reserved Notation"{ 'mono' f : x y /~ a }" (at level 0, f at level 99,
x name, y name, format "{ 'mono' f : x y /~ a }").
Reserved Notation"@ 'id' T" (at level 10, T at level 8, format "@ 'id' T").
#[warning="-closed-notation-not-level-0"]
Reserved Notation"@ 'sval'" (at level 10, format "@ 'sval'").
Reserved Notation"[ 'rec' a ]" (at level 0,
format "[ 'rec' a ]").
Reserved Notation"[ 'rec' a , b ]" (at level 0,
format "[ 'rec' a , b ]").
Reserved Notation"[ 'rec' a , b , c ]" (at level 0,
format "[ 'rec' a , b , c ]").
Reserved Notation"[ 'rec' a , b , c , d ]" (at level 0,
format "[ 'rec' a , b , c , d ]").
Reserved Notation"[ 'rec' a , b , c , d , e ]" (at level 0,
format "[ 'rec' a , b , c , d , e ]").
Reserved Notation"[ 'rec' a , b , c , d , e , f ]" (at level 0,
format "[ 'rec' a , b , c , d , e , f ]").
Reserved Notation"[ 'rec' a , b , c , d , e , f , g ]" (at level 0,
format "[ 'rec' a , b , c , d , e , f , g ]").
Reserved Notation"[ 'rec' a , b , c , d , e , f , g , h ]" (at level 0,
format "[ 'rec' a , b , c , d , e , f , g , h ]").
Reserved Notation"[ 'rec' a , b , c , d , e , f , g , h , i ]" (at level 0,
format "[ 'rec' a , b , c , d , e , f , g , h , i ]").
Reserved Notation"[ 'rec' a , b , c , d , e , f , g , h , i , j ]" (at level 0,
format "[ 'rec' a , b , c , d , e , f , g , h , i , j ]").
DeclareScope pair_scope. DelimitScope pair_scope with PAIR. OpenScope pair_scope.
Notation erefl := refl_equal. Notation ecast i T e x := (let: erefl in _ = i := e return T in x). Definition esym := sym_eq. Definition nesym := sym_not_eq. Definition etrans := trans_eq. Definition congr1 := f_equal. Definition congr2 := f_equal2. (** Force at least one implicit when used as a view. **)
Prenex Implicits esym nesym.
(** A predicate for singleton types. **) Definition all_equal_to T (x0 : T) := forall x, unkeyed x = x0.
Lemma unitE : all_equal_to tt. Proof. bycase. Qed.
(** A generic wrapper type **)
#[universes(template)]
Structure wrapped T := Wrap {unwrap : T}.
Canonical wrap T x := @Wrap T x.
(** Notations for argument transpose **) Notation"f ^~ y" := (fun x => f x y) : function_scope. Notation"@^~ x" := (fun f => f x) : function_scope.
(** Definitionsandnotationforexplicitfunctionswithsimplification,
i.e., which simpl and /= beta expand (this is complementary to nosimpl). **)
#[universes(template)]
Variant simpl_fun (aT rT : Type) := SimplFun of aT -> rT.
Section SimplFun.
Variables aT rT : Type.
Definition fun_of_simpl (f : simpl_fun aT rT) := fun x => let: SimplFun lam := f in lam x.
End SimplFun.
Coercion fun_of_simpl : simpl_fun >-> Funclass.
Notation"[ 'fun' : T => E ]" := (SimplFun (fun _ : T => E)) : function_scope. Notation"[ 'fun' x => E ]" := (SimplFun (fun x => E)) : function_scope. Notation"[ 'fun' x y => E ]" := (fun x => [fun y => E]) : function_scope. Notation"[ 'fun' x : T => E ]" := (SimplFun (fun x : T => E))
(only parsing) : function_scope. Notation"[ 'fun' x y : T => E ]" := (fun x : T => [fun y : T => E])
(only parsing) : function_scope. Notation"[ 'fun' ( x : T ) y => E ]" := (fun x : T => [fun y => E])
(only parsing) : function_scope. Notation"[ 'fun' x ( y : T ) => E ]" := (fun x => [fun y : T => E])
(only parsing) : function_scope. Notation"[ 'fun' ( x : T ) ( y : U ) => E ]" := (fun x : T => [fun y : U => E])
(only parsing) : function_scope.
(** For delta functions in eqtype.v. **) Definition SimplFunDelta aT rT (f : aT -> aT -> rT) := [fun z => f z z].
Definition comp (f : B -> A) (g : C -> B) x := f (g x). Definition catcomp g f := comp f g. Definition pcomp (f : B -> option A) (g : C -> option B) x := obind f (g x).
Lemma eq_comp f f' g g' : f =1 f' -> g =1 g' -> comp f g =1 comp f' g'. Proof. by move=> eq_ff' eq_gg' x; rewrite /comp eq_gg' eq_ff'. Qed.
End Composition.
Arguments comp {A B C} f g x /. Arguments catcomp {A B C} g f x /. Notation"f1 \o f2" := (comp f1 f2) : function_scope. Notation"f1 \; f2" := (catcomp f1 f2) : function_scope.
Lemma compA {A B C D : Type} (f : B -> A) (g : C -> B) (h : D -> C) :
f \o (g \o h) = (f \o g) \o h. Proof. by []. Qed.
Notation"[ 'eta' f ]" := (fun x => f x) : function_scope.
Lemma olift_comp : olift (g \o f) = olift g \o f. Proof. by []. Qed.
End OptionTheory.
(** The empty type. **)
Notation void := Empty_set.
Definition of_void T (x : void) : T := match x withend.
(** Strong sigma types. **)
Section Tag.
Variables (I : Type) (i : I) (T_ U_ : I -> Type).
Definition tag := projT1. Definition tagged : forall w, T_(tag w) := @projT2 I [eta T_]. Definition Tagged x := @existT I [eta T_] i x.
Definition tag2 (w : @sigT2 I T_ U_) := let: existT2 _ _ i _ _ := w in i. Definition tagged2 w : T_(tag2 w) := let: existT2 _ _ _ x _ := w in x. Definition tagged2' w : U_(tag2 w) := let: existT2 _ _ _ _ y := w in y. Definition Tagged2 x y := @existT2 I [eta T_] [eta U_] i x y.
Coercion tag_of_tag2 I T_ U_ (w : @sigT2 I T_ U_) :=
Tagged (fun i => T_ i * U_ i)%type (tagged2 w, tagged2' w).
Lemma all_tag I T U :
(forall x : I, {y : T x & U x y}) ->
{f : forall x, T x & forall x, U x (f x)}. Proof. by move=> fP; exists (fun x => tag (fP x)) => x; case: (fP x). Qed.
Lemma all_tag2 I T U V :
(forall i : I, {y : T i & U i y & V i y}) ->
{f : forall i, T i & forall i, U i (f i) & forall i, V i (f i)}. Proof. bycase/all_tag=> f /all_pair[]; exists f. Qed.
Lemma svalP (u : sig P) : P (sval u). Proof. bycase: u. Qed.
Definition s2val (u : sig2 P Q) := let: exist2 _ _ x _ _ := u in x.
Lemma s2valP u : P (s2val u). Proof. bycase: u. Qed.
Lemma s2valP' u : Q (s2val u). Proof. bycase: u. Qed.
End Sig.
Prenex Implicits svalP s2val s2valP s2valP'.
Coercion tag_of_sig I P (u : @sig I P) := Tagged P (svalP u).
Coercion sig_of_sig2 I P Q (u : @sig2 I P Q) := exist (fun i => P i /\ Q i) (s2val u) (conj (s2valP u) (s2valP' u)).
Lemma all_sig I T P :
(forall x : I, {y : T x | P x y}) ->
{f : forall x, T x | forall x, P x (f x)}. Proof. bycase/all_tag=> f; exists f. Qed.
Lemma all_sig2 I T P Q :
(forall x : I, {y : T x | P x y & Q x y}) ->
{f : forall x, T x | forall x, P x (f x) & forall x, Q x (f x)}. Proof. bycase/all_sig=> f /all_pair[]; exists f. Qed.
Section Morphism.
Variables (aT rT sT : Type) (f : aT -> rT).
(** Morphism property for unary and binary functions **) Definition morphism_1 aF rF := forall x, f (aF x) = rF (f x). Definition morphism_2 aOp rOp := forall x y, f (aOp x y) = rOp (f x) (f y).
(** Homomorphism property for unary and binary relations **) Definition homomorphism_1 (aP rP : _ -> Prop) := forall x, aP x -> rP (f x). Definition homomorphism_2 (aR rR : _ -> _ -> Prop) := forall x y, aR x y -> rR (f x) (f y).
(** Stability property for unary and binary relations **) Definition monomorphism_1 (aP rP : _ -> sT) := forall x, rP (f x) = aP x. Definition monomorphism_2 (aR rR : _ -> _ -> sT) := forall x y, rR (f x) (f y) = aR x y.
End Morphism.
Notation"{ 'morph' f : x / a >-> r }" :=
(morphism_1 f (fun x => a) (fun x => r)) : type_scope. Notation"{ 'morph' f : x / a }" :=
(morphism_1 f (fun x => a) (fun x => a)) : type_scope. Notation"{ 'morph' f : x y / a >-> r }" :=
(morphism_2 f (fun x y => a) (fun x y => r)) : type_scope. Notation"{ 'morph' f : x y / a }" :=
(morphism_2 f (fun x y => a) (fun x y => a)) : type_scope. Notation"{ 'homo' f : x / a >-> r }" :=
(homomorphism_1 f (fun x => a) (fun x => r)) : type_scope. Notation"{ 'homo' f : x / a }" :=
(homomorphism_1 f (fun x => a) (fun x => a)) : type_scope. Notation"{ 'homo' f : x y / a >-> r }" :=
(homomorphism_2 f (fun x y => a) (fun x y => r)) : type_scope. Notation"{ 'homo' f : x y / a }" :=
(homomorphism_2 f (fun x y => a) (fun x y => a)) : type_scope. Notation"{ 'homo' f : x y /~ a }" :=
(homomorphism_2 f (fun y x => a) (fun x y => a)) : type_scope. Notation"{ 'mono' f : x / a >-> r }" :=
(monomorphism_1 f (fun x => a) (fun x => r)) : type_scope. Notation"{ 'mono' f : x / a }" :=
(monomorphism_1 f (fun x => a) (fun x => a)) : type_scope. Notation"{ 'mono' f : x y / a >-> r }" :=
(monomorphism_2 f (fun x y => a) (fun x y => r)) : type_scope. Notation"{ 'mono' f : x y / a }" :=
(monomorphism_2 f (fun x y => a) (fun x y => a)) : type_scope. Notation"{ 'mono' f : x y /~ a }" :=
(monomorphism_2 f (fun y x => a) (fun x y => a)) : type_scope.
(** cancellation lemmas for dependent type casts. **) Lemma esymK T x y : cancel (@esym T x y) (@esym T y x). Proof. bycase: y /. Qed.
Lemma etrans_id T x y (eqxy : x = y :> T) : etrans (erefl x) eqxy = eqxy. Proof. bycase: y / eqxy. Qed.
Section InjectionsTheory.
Variables (A B C : Type) (f g : B -> A) (h : C -> B).
Lemma inj_id : injective (@id A). Proof. by []. Qed.
Lemma inj_can_sym f' : cancel f f' -> injective f' -> cancel f' f. Proof. by move=> fK injf' x; apply: injf'. Qed.
Lemma inj_comp : injective f -> injective h -> injective (f \o h). Proof. by move=> injf injh x y /injf; apply: injh. Qed.
Lemma inj_compr : injective (f \o h) -> injective h. Proof. by move=> injfh x y /(congr1 f) /injfh. Qed.
Lemma can_comp f' h' : cancel f f' -> cancel h h' -> cancel (f \o h) (h' \o f'). Proof. by move=> fK hK x; rewrite /= fK hK. Qed.
Lemma pcan_pcomp f' h' :
pcancel f f' -> pcancel h h' -> pcancel (f \o h) (pcomp h' f'). Proof. by move=> fK hK x; rewrite /pcomp fK /= hK. Qed.
Lemma ocan_comp [fo : B -> option A] [ho : C -> option B]
[f' : A -> B] [h' : B -> C] :
ocancel fo f' -> ocancel ho h' -> ocancel (obind fo \o ho) (h' \o f'). Proof.
move=> fK hK c /=; rewrite -[RHS]hK/=; case hcE : (ho c) => [b|]//=. byrewrite -[b in RHS]fK; case: (fo b) => //=; have := hK c; rewrite hcE. Qed.
Lemma eq_inj : injective f -> f =1 g -> injective g. Proof. by move=> injf eqfg x y; rewrite -2!eqfg; apply: injf. Qed.
Lemma eq_can f' g' : cancel f f' -> f =1 g -> f' =1 g' -> cancel g g'. Proof. by move=> fK eqfg eqfg' x; rewrite -eqfg -eqfg'. Qed.
Lemma inj_can_eq f' : cancel f f' -> injective f' -> cancel g f' -> f =1 g. Proof. by move=> fK injf' gK x; apply: injf'; rewrite fK. Qed.
End InjectionsTheory.
Section Bijections.
Variables (A B : Type) (f : B -> A).
Variant bijective : Prop := Bijective g of cancel f g & cancel g f.
Hypothesis bijf : bijective.
Lemma bij_inj : injective f. Proof. bycase: bijf => g fK _; apply: can_inj fK. Qed.
Lemma bij_can_sym f' : cancel f' f <-> cancel f f'. Proof. split=> fK; first exact: inj_can_sym fK bij_inj. bycase: bijf => h _ hK x; rewrite -[x]hK fK. Qed.
Lemma bij_can_eq f' f'' : cancel f f' -> cancel f f'' -> f' =1 f''. Proof. by move=> fK fK'; apply: (inj_can_eq _ bij_inj); apply/bij_can_sym. Qed.
End Bijections.
Section BijectionsTheory.
Variables (A B C : Type) (f : B -> A) (h : C -> B).
Lemma eq_bij : bijective f -> forall g, f =1 g -> bijective g. Proof. bycase=> f' fK f'K g eqfg; exists f'; eapply eq_can; eauto. Qed.
Lemma bij_comp : bijective f -> bijective h -> bijective (f \o h). Proof. by move=> [f' fK f'K] [h' hK h'K]; exists (h' \o f'); apply: can_comp; auto. Qed.
Lemma bij_can_bij : bijective f -> forall f', cancel f f' -> bijective f'. Proof. by move=> bijf; exists f; first byapply/(bij_can_sym bijf). Qed.
End BijectionsTheory.
Section Involutions.
Variables (A : Type) (f : A -> A).
Definition involutive := cancel f f.
Hypothesis Hf : involutive.
Lemma inv_inj : injective f. Proof. exact: can_inj Hf. Qed. Lemma inv_bij : bijective f. Proof. byexists f. Qed.
End Involutions.
Section OperationProperties.
Variables S T R : Type.
Section SopTisR. ImplicitType op : S -> T -> R. Definition left_inverse e inv op := forall x, op (inv x) x = e. Definition right_inverse e inv op := forall x, op x (inv x) = e. Definition left_injective op := forall x, injective (op^~ x). Definition right_injective op := forall y, injective (op y). End SopTisR.
Section SopTisS. ImplicitType op : S -> T -> S. Definition right_id e op := forall x, op x e = x. Definition left_zero z op := forall x, op z x = z. Definition right_commutative op := forall x y z, op (op x y) z = op (op x z) y. Definition left_distributive op add := forall x y z, op (add x y) z = add (op x z) (op y z). Definition right_loop inv op := forall y, cancel (op^~ y) (op^~ (inv y)). Definition rev_right_loop inv op := forall y, cancel (op^~ (inv y)) (op^~ y). End SopTisS.
Section SopTisT. ImplicitType op : S -> T -> T. Definition left_id e op := forall x, op e x = x. Definition right_zero z op := forall x, op x z = z. Definition left_commutative op := forall x y z, op x (op y z) = op y (op x z). Definition right_distributive op add := forall x y z, op x (add y z) = add (op x y) (op x z). Definition left_loop inv op := forall x, cancel (op x) (op (inv x)). Definition rev_left_loop inv op := forall x, cancel (op (inv x)) (op x). End SopTisT.
Section SopSisT. ImplicitType op : S -> S -> T. Definition self_inverse e op := forall x, op x x = e. Definition commutative op := forall x y, op x y = op y x. End SopSisT.
Section SopSisS. ImplicitType op : S -> S -> S. Definition idempotent_op op := forall x, op x x = x. Definition associative op := forall x y z, op x (op y z) = op (op x y) z. Definition interchange op1 op2 := forall x y z t, op1 (op2 x y) (op2 z t) = op2 (op1 x z) (op1 y t). End SopSisS.
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.