1 (**************************************************************************)
4 (* ||A|| A project by Andrea Asperti *)
6 (* ||I|| Developers: *)
7 (* ||T|| A.Asperti. C.Sacerdoti Coen. *)
8 (* ||A|| E.Tassi. S.Zacchiroli *)
10 (* \ / This file is distributed under the terms of the *)
11 (* v GNU Lesser General Public License Version 2.1 *)
13 (**************************************************************************)
15 (* Code ported from the Coq theorem prover by Claudio Sacerdoti Coen *)
16 (* Original author: Claudio Sacerdoti Coen. for the Coq system *)
18 set "baseuri" "cic:/matita/technicalities/setoids".
20 include "datatypes/constructors.ma".
21 include "logic/connectives2.ma".
22 include "logic/coimplication.ma".
24 (* DEFINITIONS OF Relation_Class AND n-ARY Morphism_Theory *)
26 (* X will be used to distinguish covariant arguments whose type is an *)
27 (* Asymmetric* relation from contravariant arguments of the same type *)
28 inductive X_Relation_Class (X: Type) : Type ≝
30 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → X_Relation_Class X
31 | AsymmetricReflexive : X → ∀A,Aeq. reflexive A Aeq → X_Relation_Class X
32 | SymmetricAreflexive : ∀A,Aeq. symmetric A Aeq → X_Relation_Class X
33 | AsymmetricAreflexive : X → ∀A.∀Aeq : relation A. X_Relation_Class X
34 | Leibniz : Type → X_Relation_Class X.
36 inductive variance : Set ≝
38 | Contravariant : variance.
40 definition Argument_Class ≝ X_Relation_Class variance.
41 definition Relation_Class ≝ X_Relation_Class unit.
43 inductive Reflexive_Relation_Class : Type :=
45 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → Reflexive_Relation_Class
47 ∀A,Aeq. reflexive A Aeq → Reflexive_Relation_Class
48 | RLeibniz : Type → Reflexive_Relation_Class.
50 inductive Areflexive_Relation_Class : Type :=
51 | ASymmetric : ∀A,Aeq. symmetric A Aeq → Areflexive_Relation_Class
52 | AAsymmetric : ∀A.∀Aeq : relation A. Areflexive_Relation_Class.
54 definition relation_class_of_argument_class : Argument_Class → Relation_Class.
56 [ apply (SymmetricReflexive ? ? ? H H1)
57 | apply (AsymmetricReflexive ? something ? ? H)
58 | apply (SymmetricAreflexive ? ? ? H)
59 | apply (AsymmetricAreflexive ? something ? r)
64 definition carrier_of_relation_class : ∀X. X_Relation_Class X → Type.
65 intros (X x); cases x; clear x; [2,4:clear x1] clear X; assumption.
68 definition relation_of_relation_class:
69 ∀X,R. carrier_of_relation_class X R → carrier_of_relation_class X R → Prop.
70 intros 2; cases R; simplify; [1,2,3,4: assumption | apply (eq T) ]
73 lemma about_carrier_of_relation_class_and_relation_class_of_argument_class :
75 carrier_of_relation_class ? (relation_class_of_argument_class R) =
76 carrier_of_relation_class ? R.
77 intro; cases R; reflexivity.
80 inductive nelistT (A : Type) : Type :=
82 | cons : A → nelistT A → nelistT A.
84 definition Arguments := nelistT Argument_Class.
86 definition function_type_of_morphism_signature :
87 Arguments → Relation_Class → Type.
88 intros (In Out); elim In;
89 [ exact (carrier_of_relation_class ? t → carrier_of_relation_class ? Out)
90 | exact (carrier_of_relation_class ? t → T)
94 definition make_compatibility_goal_aux:
95 ∀In,Out.∀f,g:function_type_of_morphism_signature In Out.Prop.
97 elim In (a); simplify in f f1;
98 generalize in match f1; clear f1;
99 generalize in match f; clear f;
100 [ elim a; simplify in f f1;
101 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
103 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
104 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
106 | exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
108 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
109 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
111 | exact (∀x. relation_of_relation_class ? Out (f x) (f1 x))
114 ((carrier_of_relation_class ? t → function_type_of_morphism_signature n Out) →
115 (carrier_of_relation_class ? t → function_type_of_morphism_signature n Out) →
117 elim t; simplify in f f1;
118 [1,3: exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
120 [1,3: exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
121 |2,4: exact (∀x1,x2. r x2 x1 → R (f x1) (f1 x2))
123 | exact (∀x. R (f x) (f1 x))
128 definition make_compatibility_goal :=
129 λIn,Out,f. make_compatibility_goal_aux In Out f f.
131 record Morphism_Theory (In: Arguments) (Out: Relation_Class) : Type :=
132 { Function : function_type_of_morphism_signature In Out;
133 Compat : make_compatibility_goal In Out Function
136 definition list_of_Leibniz_of_list_of_types: nelistT Type → Arguments.
139 [ apply (singl ? (Leibniz ? t))
140 | apply (cons ? (Leibniz ? t) a)
144 (* every function is a morphism from Leibniz+ to Leibniz *)
145 definition morphism_theory_of_function :
146 ∀In: nelistT Type.∀Out: Type.
147 let In' := list_of_Leibniz_of_list_of_types In in
148 let Out' := Leibniz ? Out in
149 function_type_of_morphism_signature In' Out' →
150 Morphism_Theory In' Out'.
152 apply (mk_Morphism_Theory ? ? f);
153 unfold In' in f; clear In';
154 unfold Out' in f; clear Out';
155 generalize in match f; clear f;
157 [ unfold make_compatibility_goal;
170 (* THE iff RELATION CLASS *)
172 definition Iff_Relation_Class : Relation_Class.
173 apply (SymmetricReflexive unit ? iff);
174 [ exact symmetric_iff
175 | exact reflexive_iff
179 (* THE impl RELATION CLASS *)
181 definition impl \def \lambda A,B:Prop. A → B.
183 theorem impl_refl: reflexive ? impl.
191 definition Impl_Relation_Class : Relation_Class.
192 unfold Relation_Class;
193 apply (AsymmetricReflexive unit something ? impl);
197 (* UTILITY FUNCTIONS TO PROVE THAT EVERY TRANSITIVE RELATION IS A MORPHISM *)
199 definition equality_morphism_of_symmetric_areflexive_transitive_relation:
200 ∀A: Type.∀Aeq: relation A.∀sym: symmetric ? Aeq.∀trans: transitive ? Aeq.
201 let ASetoidClass := SymmetricAreflexive ? ? ? sym in
202 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass))
205 apply mk_Morphism_Theory;
207 | unfold make_compatibility_goal;
211 unfold transitive in H;
212 unfold symmetric in sym;
218 definition equality_morphism_of_symmetric_reflexive_transitive_relation:
219 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀sym: symmetric ? Aeq.
220 ∀trans: transitive ? Aeq.
221 let ASetoidClass := SymmetricReflexive ? ? ? sym refl in
222 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass)) Iff_Relation_Class).
224 apply mk_Morphism_Theory;
230 unfold transitive in H;
231 unfold symmetric in sym;
236 definition equality_morphism_of_asymmetric_areflexive_transitive_relation:
237 ∀A: Type.∀Aeq: relation A.∀trans: transitive ? Aeq.
238 let ASetoidClass1 := AsymmetricAreflexive ? Contravariant ? Aeq in
239 let ASetoidClass2 := AsymmetricAreflexive ? Covariant ? Aeq in
240 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
242 apply mk_Morphism_Theory;
253 definition equality_morphism_of_asymmetric_reflexive_transitive_relation:
254 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀trans: transitive ? Aeq.
255 let ASetoidClass1 := AsymmetricReflexive ? Contravariant ? ? refl in
256 let ASetoidClass2 := AsymmetricReflexive ? Covariant ? ? refl in
257 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
259 apply mk_Morphism_Theory;
270 (* iff AS A RELATION *)
272 (*DA PORTARE:Add Relation Prop iff
273 reflexivity proved by iff_refl
274 symmetry proved by iff_sym
275 transitivity proved by iff_trans
278 (* every predicate is morphism from Leibniz+ to Iff_Relation_Class *)
279 definition morphism_theory_of_predicate :
281 let In' := list_of_Leibniz_of_list_of_types In in
282 function_type_of_morphism_signature In' Iff_Relation_Class →
283 Morphism_Theory In' Iff_Relation_Class.
285 apply mk_Morphism_Theory;
287 | generalize in match f; clear f;
288 unfold In'; clear In';
300 (* impl AS A RELATION *)
302 theorem impl_trans: transitive ? impl.
309 (*DA PORTARE: Add Relation Prop impl
310 reflexivity proved by impl_refl
311 transitivity proved by impl_trans
314 (* THE CIC PART OF THE REFLEXIVE TACTIC (SETOID REWRITE) *)
316 inductive rewrite_direction : Type :=
317 Left2Right: rewrite_direction
318 | Right2Left: rewrite_direction.
320 definition variance_of_argument_class : Argument_Class → option variance.
331 definition opposite_direction :=
334 [ Left2Right ⇒ Right2Left
335 | Right2Left ⇒ Left2Right
338 lemma opposite_direction_idempotent:
339 ∀dir. opposite_direction (opposite_direction dir) = dir.
345 inductive check_if_variance_is_respected :
346 option variance → rewrite_direction → rewrite_direction → Prop
348 MSNone : ∀dir,dir'. check_if_variance_is_respected (None ?) dir dir'
349 | MSCovariant : ∀dir. check_if_variance_is_respected (Some ? Covariant) dir dir
352 check_if_variance_is_respected (Some ? Contravariant) dir (opposite_direction dir).
354 definition relation_class_of_reflexive_relation_class:
355 Reflexive_Relation_Class → Relation_Class.
358 [ apply (SymmetricReflexive ? ? ? H H1)
359 | apply (AsymmetricReflexive ? something ? ? H)
360 | apply (Leibniz ? T)
364 definition relation_class_of_areflexive_relation_class:
365 Areflexive_Relation_Class → Relation_Class.
368 [ apply (SymmetricAreflexive ? ? ? H)
369 | apply (AsymmetricAreflexive ? something ? r)
373 definition carrier_of_reflexive_relation_class :=
374 λR.carrier_of_relation_class ? (relation_class_of_reflexive_relation_class R).
376 definition carrier_of_areflexive_relation_class :=
377 λR.carrier_of_relation_class ? (relation_class_of_areflexive_relation_class R).
379 definition relation_of_areflexive_relation_class :=
380 λR.relation_of_relation_class ? (relation_class_of_areflexive_relation_class R).
382 inductive Morphism_Context (Hole: Relation_Class) (dir:rewrite_direction) : Relation_Class → rewrite_direction → Type :=
385 Morphism_Theory In Out → Morphism_Context_List Hole dir dir' In →
386 Morphism_Context Hole dir Out dir'
387 | ToReplace : Morphism_Context Hole dir Hole dir
390 carrier_of_reflexive_relation_class S →
391 Morphism_Context Hole dir (relation_class_of_reflexive_relation_class S) dir'
392 | ProperElementToKeep :
393 ∀S,dir'.∀x: carrier_of_areflexive_relation_class S.
394 relation_of_areflexive_relation_class S x x →
395 Morphism_Context Hole dir (relation_class_of_areflexive_relation_class S) dir'
396 with Morphism_Context_List :
397 rewrite_direction → Arguments → Type
401 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
402 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
403 Morphism_Context_List Hole dir dir'' (singl ? S)
406 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
407 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
408 Morphism_Context_List Hole dir dir'' L →
409 Morphism_Context_List Hole dir dir'' (cons ? S L).
411 lemma Morphism_Context_rect2:
414 ∀r:Relation_Class.∀r0:rewrite_direction.Morphism_Context Hole dir r r0 → Type.
416 ∀r:rewrite_direction.∀a:Arguments.Morphism_Context_List Hole dir r a → Type.
418 ∀m:Morphism_Theory In Out.∀m0:Morphism_Context_List Hole dir dir' In.
419 P0 dir' In m0 → P Out dir' (App Hole ? ? ? ? m m0)) →
420 P Hole dir (ToReplace Hole dir) →
421 (∀S:Reflexive_Relation_Class.∀dir'.∀c:carrier_of_reflexive_relation_class S.
422 P (relation_class_of_reflexive_relation_class S) dir'
423 (ToKeep Hole dir S dir' c)) →
424 (∀S:Areflexive_Relation_Class.∀dir'.
425 ∀x:carrier_of_areflexive_relation_class S.
426 ∀r:relation_of_areflexive_relation_class S x x.
427 P (relation_class_of_areflexive_relation_class S) dir'
428 (ProperElementToKeep Hole dir S dir' x r)) →
429 (∀S:Argument_Class.∀dir',dir''.
430 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
431 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
432 P (relation_class_of_argument_class S) dir' m ->
433 P0 dir'' (singl ? S) (fcl_singl ? ? S ? ? c m)) →
434 (∀S:Argument_Class.∀L:Arguments.∀dir',dir''.
435 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
436 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
437 P (relation_class_of_argument_class S) dir' m →
438 ∀m0:Morphism_Context_List Hole dir dir'' L.
439 P0 dir'' L m0 → P0 dir'' (cons ? S L) (fcl_cons ? ? S ? ? ? c m m0)) →
440 ∀r:Relation_Class.∀r0:rewrite_direction.∀m:Morphism_Context Hole dir r r0.
443 λHole,dir,P,P0,f,f0,f1,f2,f3,f4.
445 F (rc:Relation_Class) (r0:rewrite_direction)
446 (m:Morphism_Context Hole dir rc r0) on m : P rc r0 m
448 match m return λrc.λr0.λm0.P rc r0 m0 with
449 [ App In Out dir' m0 m1 ⇒ f In Out dir' m0 m1 (F0 dir' In m1)
451 | ToKeep S dir' c ⇒ f1 S dir' c
452 | ProperElementToKeep S dir' x r1 ⇒ f2 S dir' x r1
455 F0 (r:rewrite_direction) (a:Arguments)
456 (m:Morphism_Context_List Hole dir r a) on m : P0 r a m
458 match m return λr.λa.λm0.P0 r a m0 with
459 [ fcl_singl S dir' dir'' c m0 ⇒
460 f3 S dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
461 | fcl_cons S L dir' dir'' c m0 m1 ⇒
462 f4 S L dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
467 lemma Morphism_Context_List_rect2:
470 ∀r:Relation_Class.∀r0:rewrite_direction.Morphism_Context Hole dir r r0 → Type.
472 ∀r:rewrite_direction.∀a:Arguments.Morphism_Context_List Hole dir r a → Type.
474 ∀m:Morphism_Theory In Out.∀m0:Morphism_Context_List Hole dir dir' In.
475 P0 dir' In m0 → P Out dir' (App Hole ? ? ? ? m m0)) →
476 P Hole dir (ToReplace Hole dir) →
477 (∀S:Reflexive_Relation_Class.∀dir'.∀c:carrier_of_reflexive_relation_class S.
478 P (relation_class_of_reflexive_relation_class S) dir'
479 (ToKeep Hole dir S dir' c)) →
480 (∀S:Areflexive_Relation_Class.∀dir'.
481 ∀x:carrier_of_areflexive_relation_class S.
482 ∀r:relation_of_areflexive_relation_class S x x.
483 P (relation_class_of_areflexive_relation_class S) dir'
484 (ProperElementToKeep Hole dir S dir' x r)) →
485 (∀S:Argument_Class.∀dir',dir''.
486 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
487 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
488 P (relation_class_of_argument_class S) dir' m ->
489 P0 dir'' (singl ? S) (fcl_singl ? ? S ? ? c m)) →
490 (∀S:Argument_Class.∀L:Arguments.∀dir',dir''.
491 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
492 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
493 P (relation_class_of_argument_class S) dir' m →
494 ∀m0:Morphism_Context_List Hole dir dir'' L.
495 P0 dir'' L m0 → P0 dir'' (cons ? S L) (fcl_cons ? ? S ? ? ? c m m0)) →
496 ∀r:rewrite_direction.∀a:Arguments.∀m:Morphism_Context_List Hole dir r a.
499 λHole,dir,P,P0,f,f0,f1,f2,f3,f4.
501 F (rc:Relation_Class) (r0:rewrite_direction)
502 (m:Morphism_Context Hole dir rc r0) on m : P rc r0 m
504 match m return λrc.λr0.λm0.P rc r0 m0 with
505 [ App In Out dir' m0 m1 ⇒ f In Out dir' m0 m1 (F0 dir' In m1)
507 | ToKeep S dir' c ⇒ f1 S dir' c
508 | ProperElementToKeep S dir' x r1 ⇒ f2 S dir' x r1
511 F0 (r:rewrite_direction) (a:Arguments)
512 (m:Morphism_Context_List Hole dir r a) on m : P0 r a m
514 match m return λr.λa.λm0.P0 r a m0 with
515 [ fcl_singl S dir' dir'' c m0 ⇒
516 f3 S dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
517 | fcl_cons S L dir' dir'' c m0 m1 ⇒
518 f4 S L dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
523 definition product_of_arguments : Arguments → Type.
526 [ apply (carrier_of_relation_class ? t)
527 | apply (Prod (carrier_of_relation_class ? t) T)
531 definition get_rewrite_direction: rewrite_direction → Argument_Class → rewrite_direction.
533 cases (variance_of_argument_class R);
536 [ exact dir (* covariant *)
537 | exact (opposite_direction dir) (* contravariant *)
542 definition directed_relation_of_relation_class:
543 ∀dir:rewrite_direction.∀R: Relation_Class.
544 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
547 [ exact (relation_of_relation_class ? ? c c1)
548 | apply (relation_of_relation_class ? ? c1 c)
552 definition directed_relation_of_argument_class:
553 ∀dir:rewrite_direction.∀R: Argument_Class.
554 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
556 rewrite < (about_carrier_of_relation_class_and_relation_class_of_argument_class R) in c c1;
557 exact (directed_relation_of_relation_class dir (relation_class_of_argument_class R) c c1).
561 definition relation_of_product_of_arguments:
562 ∀dir:rewrite_direction.∀In.
563 product_of_arguments In → product_of_arguments In → Prop.
568 exact (directed_relation_of_argument_class (get_rewrite_direction r t) t)
570 change in p with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
571 change in p1 with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
576 (directed_relation_of_argument_class (get_rewrite_direction r t) t a a1)
582 definition apply_morphism:
583 ∀In,Out.∀m: function_type_of_morphism_signature In Out.
584 ∀args: product_of_arguments In. carrier_of_relation_class ? Out.
588 | change in p with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
590 change in f1 with (carrier_of_relation_class variance t → function_type_of_morphism_signature n Out);
591 exact (f ? (f1 t1) t2)
595 theorem apply_morphism_compatibility_Right2Left:
596 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
597 ∀args1,args2: product_of_arguments In.
598 make_compatibility_goal_aux ? ? m1 m2 →
599 relation_of_product_of_arguments Right2Left ? args1 args2 →
600 directed_relation_of_relation_class Right2Left ?
601 (apply_morphism ? ? m2 args1)
602 (apply_morphism ? ? m1 args2).
605 [ simplify in m1 m2 args1 args2 ⊢ %;
607 (directed_relation_of_argument_class
608 (get_rewrite_direction Right2Left t) t args1 args2);
609 generalize in match H1; clear H1;
610 generalize in match H; clear H;
611 generalize in match args2; clear args2;
612 generalize in match args1; clear args1;
613 generalize in match m2; clear m2;
614 generalize in match m1; clear m1;
616 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
622 | intros 8 (v T1 r Hr m1 m2 args1 args2);
644 (carrier_of_relation_class variance t →
645 function_type_of_morphism_signature n Out);
647 (carrier_of_relation_class variance t →
648 function_type_of_morphism_signature n Out);
650 ((carrier_of_relation_class ? t) × (product_of_arguments n));
652 ((carrier_of_relation_class ? t) × (product_of_arguments n));
653 generalize in match H2; clear H2;
654 elim args2 0; clear args2;
655 elim args1; clear args1;
658 (relation_of_product_of_arguments Right2Left n t2 t4);
660 (relation_of_relation_class unit Out (apply_morphism n Out (m1 t3) t4)
661 (apply_morphism n Out (m2 t1) t2));
662 generalize in match H3; clear H3;
663 generalize in match t3; clear t3;
664 generalize in match t1; clear t1;
665 generalize in match H1; clear H1;
666 generalize in match m2; clear m2;
667 generalize in match m1; clear m1;
669 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
672 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
675 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
678 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
679 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
682 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
684 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
687 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
690 [ intros (T1 r m1 m2 H1 t1 t3 H3);
693 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
694 | intros (T1 r m1 m2 H1 t1 t3 H3);
697 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
699 | intros (T m1 m2 H1 t1 t3 H3);
702 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
721 theorem apply_morphism_compatibility_Left2Right:
722 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
723 ∀args1,args2: product_of_arguments In.
724 make_compatibility_goal_aux ? ? m1 m2 →
725 relation_of_product_of_arguments Left2Right ? args1 args2 →
726 directed_relation_of_relation_class Left2Right ?
727 (apply_morphism ? ? m1 args1)
728 (apply_morphism ? ? m2 args2).
731 [ simplify in m1 m2 args1 args2 ⊢ %;
733 (directed_relation_of_argument_class
734 (get_rewrite_direction Left2Right t) t args1 args2);
735 generalize in match H1; clear H1;
736 generalize in match H; clear H;
737 generalize in match args2; clear args2;
738 generalize in match args1; clear args1;
739 generalize in match m2; clear m2;
740 generalize in match m1; clear m1;
742 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
748 | intros 8 (v T1 r Hr m1 m2 args1 args2);
770 (carrier_of_relation_class variance t →
771 function_type_of_morphism_signature n Out);
773 (carrier_of_relation_class variance t →
774 function_type_of_morphism_signature n Out);
776 ((carrier_of_relation_class ? t) × (product_of_arguments n));
778 ((carrier_of_relation_class ? t) × (product_of_arguments n));
779 generalize in match H2; clear H2;
780 elim args2 0; clear args2;
781 elim args1; clear args1;
784 (relation_of_product_of_arguments Left2Right n t2 t4);
786 (relation_of_relation_class unit Out (apply_morphism n Out (m1 t1) t2)
787 (apply_morphism n Out (m2 t3) t4));
788 generalize in match H3; clear H3;
789 generalize in match t3; clear t3;
790 generalize in match t1; clear t1;
791 generalize in match H1; clear H1;
792 generalize in match m2; clear m2;
793 generalize in match m1; clear m1;
795 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
798 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
801 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
804 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
805 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
808 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
810 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
813 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
816 [ intros (T1 r m1 m2 H1 t1 t3 H3);
819 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
820 | intros (T1 r m1 m2 H1 t1 t3 H3);
823 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
825 | intros (T m1 m2 H1 t1 t3 H3);
828 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
848 ∀Hole,dir,Out,dir'. carrier_of_relation_class ? Hole →
849 Morphism_Context Hole dir Out dir' → carrier_of_relation_class ? Out.
850 intros (Hole dir Out dir' H t).
852 (Morphism_Context_rect2 Hole dir (λS,xx,yy. carrier_of_relation_class ? S)
853 (λxx,L,fcl.product_of_arguments L));
857 | exact (apply_morphism ? ? (Function ? ? m) p)
863 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
867 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
875 (*CSC: interp and interp_relation_class_list should be mutually defined. since
876 the proof term of each one contains the proof term of the other one. However
877 I cannot do that interactively (I should write the Fix by hand) *)
878 definition interp_relation_class_list :
879 ∀Hole,dir,dir'.∀L: Arguments. carrier_of_relation_class ? Hole →
880 Morphism_Context_List Hole dir dir' L → product_of_arguments L.
881 intros (Hole dir dir' L H t);
883 (Morphism_Context_List_rect2 Hole dir (λS,xx,yy.carrier_of_relation_class ? S)
884 (λxx,L,fcl.product_of_arguments L));
888 | exact (apply_morphism ? ? (Function ? ? m) p)
894 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
898 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
906 Theorem setoid_rewrite:
907 ∀Hole dir Out dir' (E1 E2: carrier_of_relation_class Hole)
908 (E: Morphism_Context Hole dir Out dir').
909 (directed_relation_of_relation_class dir Hole E1 E2) →
910 (directed_relation_of_relation_class dir' Out (interp E1 E) (interp E2 E)).
913 (@Morphism_Context_rect2 Hole dir
914 (fun S dir'' E => directed_relation_of_relation_class dir'' S (interp E1 E) (interp E2 E))
916 relation_of_product_of_arguments dir'' ?
917 (interp_relation_class_list E1 fcl)
918 (interp_relation_class_list E2 fcl))); intros.
919 change (directed_relation_of_relation_class dir'0 Out0
920 (apply_morphism ? ? (Function m) (interp_relation_class_list E1 m0))
921 (apply_morphism ? ? (Function m) (interp_relation_class_list E2 m0))).
923 apply apply_morphism_compatibility_Left2Right.
926 apply apply_morphism_compatibility_Right2Left.
932 unfold interp. Morphism_Context_rect2.
933 (*CSC: reflexivity used here*)
934 destruct S; destruct dir'0; simpl; (apply r || reflexivity).
936 destruct dir'0; exact r.
938 destruct S; unfold directed_relation_of_argument_class; simpl in H0 |- *;
939 unfold get_rewrite_direction; simpl.
940 destruct dir'0; destruct dir'';
942 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
943 (* the following mess with generalize/clear/intros is to help Coq resolving *)
944 (* second order unification problems. *)
945 generalize m c H0; clear H0 m c; inversion c;
946 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
947 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
948 destruct dir'0; destruct dir'';
950 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
951 (* the following mess with generalize/clear/intros is to help Coq resolving *)
952 (* second order unification problems. *)
953 generalize m c H0; clear H0 m c; inversion c;
954 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
955 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
956 destruct dir'0; destruct dir''; (exact H0 || hnf; symmetry; exact H0).
959 (directed_relation_of_argument_class (get_rewrite_direction dir'' S) S
960 (eq_rect ? (fun T : Type => T) (interp E1 m) ?
961 (about_carrier_of_relation_class_and_relation_class_of_argument_class S))
962 (eq_rect ? (fun T : Type => T) (interp E2 m) ?
963 (about_carrier_of_relation_class_and_relation_class_of_argument_class S)) /\
964 relation_of_product_of_arguments dir'' ?
965 (interp_relation_class_list E1 m0) (interp_relation_class_list E2 m0)).
967 clear m0 H1; destruct S; simpl in H0 |- *; unfold get_rewrite_direction; simpl.
968 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
970 rewrite <- H3; exact H0.
971 rewrite (opposite_direction_idempotent dir'0); exact H0.
972 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
974 rewrite <- H3; exact H0.
975 rewrite (opposite_direction_idempotent dir'0); exact H0.
976 destruct dir''; destruct dir'0; (exact H0 || hnf; symmetry; exact H0).
980 (* A FEW EXAMPLES ON iff *)
982 (* impl IS A MORPHISM *)
984 Add Morphism impl with signature iff ==> iff ==> iff as Impl_Morphism.
988 (* and IS A MORPHISM *)
990 Add Morphism and with signature iff ==> iff ==> iff as And_Morphism.
994 (* or IS A MORPHISM *)
996 Add Morphism or with signature iff ==> iff ==> iff as Or_Morphism.
1000 (* not IS A MORPHISM *)
1002 Add Morphism not with signature iff ==> iff as Not_Morphism.
1006 (* THE SAME EXAMPLES ON impl *)
1008 Add Morphism and with signature impl ++> impl ++> impl as And_Morphism2.
1012 Add Morphism or with signature impl ++> impl ++> impl as Or_Morphism2.
1016 Add Morphism not with signature impl -→ impl as Not_Morphism2.