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 include "datatypes/constructors.ma".
19 include "logic/coimplication.ma".
20 include "logic/connectives2.ma".
22 (* DEFINITIONS OF Relation_Class AND n-ARY Morphism_Theory *)
24 (* X will be used to distinguish covariant arguments whose type is an *)
25 (* Asymmetric* relation from contravariant arguments of the same type *)
26 inductive X_Relation_Class (X: Type) : Type ≝
28 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → X_Relation_Class X
29 | AsymmetricReflexive : X → ∀A,Aeq. reflexive A Aeq → X_Relation_Class X
30 | SymmetricAreflexive : ∀A,Aeq. symmetric A Aeq → X_Relation_Class X
31 | AsymmetricAreflexive : X → ∀A.∀Aeq : relation A. X_Relation_Class X
32 | Leibniz : Type → X_Relation_Class X.
34 inductive variance : Set ≝
36 | Contravariant : variance.
38 definition Argument_Class ≝ X_Relation_Class variance.
39 definition Relation_Class ≝ X_Relation_Class unit.
41 inductive Reflexive_Relation_Class : Type :=
43 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → Reflexive_Relation_Class
45 ∀A,Aeq. reflexive A Aeq → Reflexive_Relation_Class
46 | RLeibniz : Type → Reflexive_Relation_Class.
48 inductive Areflexive_Relation_Class : Type :=
49 | ASymmetric : ∀A,Aeq. symmetric A Aeq → Areflexive_Relation_Class
50 | AAsymmetric : ∀A.∀Aeq : relation A. Areflexive_Relation_Class.
52 definition relation_class_of_argument_class : Argument_Class → Relation_Class.
54 [ apply (SymmetricReflexive ? ? ? H H1)
55 | apply (AsymmetricReflexive ? something ? ? H)
56 | apply (SymmetricAreflexive ? ? ? H)
57 | apply (AsymmetricAreflexive ? something ? r)
62 definition carrier_of_relation_class : ∀X. X_Relation_Class X → Type.
63 intros (X x); cases x (A o o o o A o o A o o o A o A); exact A.
66 definition relation_of_relation_class:
67 ∀X,R. carrier_of_relation_class X R → carrier_of_relation_class X R → Prop.
68 intros 2; cases R; simplify; [1,2,3,4: assumption | apply (eq T) ]
71 lemma about_carrier_of_relation_class_and_relation_class_of_argument_class :
73 carrier_of_relation_class ? (relation_class_of_argument_class R) =
74 carrier_of_relation_class ? R.
75 intro; cases R; reflexivity.
78 inductive nelistT (A : Type) : Type :=
80 | cons : A → nelistT A → nelistT A.
82 definition Arguments := nelistT Argument_Class.
84 definition function_type_of_morphism_signature :
85 Arguments → Relation_Class → Type.
86 intros (In Out); elim In;
87 [ exact (carrier_of_relation_class ? a → carrier_of_relation_class ? Out)
88 | exact (carrier_of_relation_class ? a → T)
92 definition make_compatibility_goal_aux:
93 ∀In,Out.∀f,g:function_type_of_morphism_signature In Out.Prop.
95 elim In (a); simplify in f f1;
96 generalize in match f1; clear f1;
97 generalize in match f; clear f;
98 [ elim a; simplify in f f1;
99 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
101 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
102 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
104 | exact (∀x1,x2. r x1 x2 → 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))
107 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
109 | exact (∀x. relation_of_relation_class ? Out (f x) (f1 x))
112 ((carrier_of_relation_class ? a → function_type_of_morphism_signature n Out) →
113 (carrier_of_relation_class ? a → function_type_of_morphism_signature n Out) →
115 elim a; simplify in f f1;
116 [1,3: exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
118 [1,3: exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
119 |2,4: exact (∀x1,x2. r x2 x1 → R (f x1) (f1 x2))
121 | exact (∀x. R (f x) (f1 x))
126 definition make_compatibility_goal :=
127 λIn,Out,f. make_compatibility_goal_aux In Out f f.
129 record Morphism_Theory (In: Arguments) (Out: Relation_Class) : Type :=
130 { Function : function_type_of_morphism_signature In Out;
131 Compat : make_compatibility_goal In Out Function
134 definition list_of_Leibniz_of_list_of_types: nelistT Type → Arguments.
137 [ apply (singl ? (Leibniz ? a))
138 | apply (cons ? (Leibniz ? a) a1)
142 (* every function is a morphism from Leibniz+ to Leibniz *)
143 definition morphism_theory_of_function :
144 ∀In: nelistT Type.∀Out: Type.
145 let In' := list_of_Leibniz_of_list_of_types In in
146 let Out' := Leibniz ? Out in
147 function_type_of_morphism_signature In' Out' →
148 Morphism_Theory In' Out'.
150 apply (mk_Morphism_Theory ? ? f);
151 unfold In' in f ⊢ %; clear In';
152 unfold Out' in f ⊢ %; clear Out';
153 generalize in match f; clear f;
155 [ unfold make_compatibility_goal;
166 (* THE iff RELATION CLASS *)
168 definition Iff_Relation_Class : Relation_Class.
169 apply (SymmetricReflexive unit ? iff);
170 [ exact symmetric_iff
171 | exact reflexive_iff
175 (* THE impl RELATION CLASS *)
177 definition impl \def \lambda A,B:Prop. A → B.
179 theorem impl_refl: reflexive ? impl.
187 definition Impl_Relation_Class : Relation_Class.
188 unfold Relation_Class;
189 apply (AsymmetricReflexive unit something ? impl);
193 (* UTILITY FUNCTIONS TO PROVE THAT EVERY TRANSITIVE RELATION IS A MORPHISM *)
195 definition equality_morphism_of_symmetric_areflexive_transitive_relation:
196 ∀A: Type.∀Aeq: relation A.∀sym: symmetric ? Aeq.∀trans: transitive ? Aeq.
197 let ASetoidClass := SymmetricAreflexive ? ? ? sym in
198 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass))
201 apply mk_Morphism_Theory;
203 | unfold make_compatibility_goal;
204 simplify; unfold ASetoidClass; simplify;
207 unfold transitive in H;
208 unfold symmetric in sym;
210 [ apply (H x2 x1 x3 ? ?);
211 [apply (sym x1 x2 ?).
213 |apply (H x1 x x3 ? ?);
218 | apply (H x1 x3 x ? ?);
219 [apply (H x1 x2 x3 ? ?);
230 definition equality_morphism_of_symmetric_reflexive_transitive_relation:
231 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀sym: symmetric ? Aeq.
232 ∀trans: transitive ? Aeq.
233 let ASetoidClass := SymmetricReflexive ? ? ? sym refl in
234 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass)) Iff_Relation_Class).
236 apply mk_Morphism_Theory;
242 unfold transitive in H;
243 unfold symmetric in sym;
244 [ apply (H x2 x1 x3 ? ?);
245 [apply (sym x1 x2 ?).
247 |apply (H x1 x x3 ? ?);
252 | apply (H x1 x2 x ? ?);
254 |apply (H x2 x3 x ? ?);
257 apply (H x x3 x3 ? ?);
267 definition equality_morphism_of_asymmetric_areflexive_transitive_relation:
268 ∀A: Type.∀Aeq: relation A.∀trans: transitive ? Aeq.
269 let ASetoidClass1 := AsymmetricAreflexive ? Contravariant ? Aeq in
270 let ASetoidClass2 := AsymmetricAreflexive ? Covariant ? Aeq in
271 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
273 apply mk_Morphism_Theory;
276 | simplify; unfold ASetoidClass1; simplify; unfold ASetoidClass2; simplify;
280 apply (H x2 x1 x3 ? ?);
282 |apply (H x1 x x3 ? ?);
290 definition equality_morphism_of_asymmetric_reflexive_transitive_relation:
291 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀trans: transitive ? Aeq.
292 let ASetoidClass1 := AsymmetricReflexive ? Contravariant ? ? refl in
293 let ASetoidClass2 := AsymmetricReflexive ? Covariant ? ? refl in
294 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
296 apply mk_Morphism_Theory;
299 | simplify; unfold ASetoidClass1; simplify; unfold ASetoidClass2; simplify;
303 apply (H x2 x1 x3 ? ?);
305 |apply (H x1 x x3 ? ?);
313 (* iff AS A RELATION *)
315 (*DA PORTARE:Add Relation Prop iff
316 reflexivity proved by iff_refl
317 symmetry proved by iff_sym
318 transitivity proved by iff_trans
321 (* every predicate is morphism from Leibniz+ to Iff_Relation_Class *)
322 definition morphism_theory_of_predicate :
324 let In' := list_of_Leibniz_of_list_of_types In in
325 function_type_of_morphism_signature In' Iff_Relation_Class →
326 Morphism_Theory In' Iff_Relation_Class.
328 apply mk_Morphism_Theory;
330 | generalize in match f; clear f;
331 unfold In'; clear In';
343 (* impl AS A RELATION *)
345 theorem impl_trans: transitive ? impl.
349 apply (H1 ?).apply (H ?).apply (H2).
353 (*DA PORTARE: Add Relation Prop impl
354 reflexivity proved by impl_refl
355 transitivity proved by impl_trans
358 (* THE CIC PART OF THE REFLEXIVE TACTIC (SETOID REWRITE) *)
360 inductive rewrite_direction : Type :=
361 Left2Right: rewrite_direction
362 | Right2Left: rewrite_direction.
364 definition variance_of_argument_class : Argument_Class → option variance.
375 definition opposite_direction :=
378 [ Left2Right ⇒ Right2Left
379 | Right2Left ⇒ Left2Right
382 lemma opposite_direction_idempotent:
383 ∀dir. opposite_direction (opposite_direction dir) = dir.
389 inductive check_if_variance_is_respected :
390 option variance → rewrite_direction → rewrite_direction → Prop
392 MSNone : ∀dir,dir'. check_if_variance_is_respected (None ?) dir dir'
393 | MSCovariant : ∀dir. check_if_variance_is_respected (Some ? Covariant) dir dir
396 check_if_variance_is_respected (Some ? Contravariant) dir (opposite_direction dir).
398 definition relation_class_of_reflexive_relation_class:
399 Reflexive_Relation_Class → Relation_Class.
402 [ apply (SymmetricReflexive ? ? ? H H1)
403 | apply (AsymmetricReflexive ? something ? ? H)
404 | apply (Leibniz ? T)
408 definition relation_class_of_areflexive_relation_class:
409 Areflexive_Relation_Class → Relation_Class.
412 [ apply (SymmetricAreflexive ? ? ? H)
413 | apply (AsymmetricAreflexive ? something ? r)
417 definition carrier_of_reflexive_relation_class :=
418 λR.carrier_of_relation_class ? (relation_class_of_reflexive_relation_class R).
420 definition carrier_of_areflexive_relation_class :=
421 λR.carrier_of_relation_class ? (relation_class_of_areflexive_relation_class R).
423 definition relation_of_areflexive_relation_class :=
424 λR.relation_of_relation_class ? (relation_class_of_areflexive_relation_class R).
426 inductive Morphism_Context (Hole: Relation_Class) (dir:rewrite_direction) : Relation_Class → rewrite_direction → Type :=
429 Morphism_Theory In Out → Morphism_Context_List Hole dir dir' In →
430 Morphism_Context Hole dir Out dir'
431 | ToReplace : Morphism_Context Hole dir Hole dir
434 carrier_of_reflexive_relation_class S →
435 Morphism_Context Hole dir (relation_class_of_reflexive_relation_class S) dir'
436 | ProperElementToKeep :
437 ∀S,dir'.∀x: carrier_of_areflexive_relation_class S.
438 relation_of_areflexive_relation_class S x x →
439 Morphism_Context Hole dir (relation_class_of_areflexive_relation_class S) dir'
440 with Morphism_Context_List :
441 rewrite_direction → Arguments → Type
445 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
446 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
447 Morphism_Context_List Hole dir dir'' (singl ? S)
450 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
451 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
452 Morphism_Context_List Hole dir dir'' L →
453 Morphism_Context_List Hole dir dir'' (cons ? S L).
455 lemma Morphism_Context_rect2:
458 ∀r:Relation_Class.∀r0:rewrite_direction.Morphism_Context Hole dir r r0 → Type.
460 ∀r:rewrite_direction.∀a:Arguments.Morphism_Context_List Hole dir r a → Type.
462 ∀m:Morphism_Theory In Out.∀m0:Morphism_Context_List Hole dir dir' In.
463 P0 dir' In m0 → P Out dir' (App Hole ? ? ? ? m m0)) →
464 P Hole dir (ToReplace Hole dir) →
465 (∀S:Reflexive_Relation_Class.∀dir'.∀c:carrier_of_reflexive_relation_class S.
466 P (relation_class_of_reflexive_relation_class S) dir'
467 (ToKeep Hole dir S dir' c)) →
468 (∀S:Areflexive_Relation_Class.∀dir'.
469 ∀x:carrier_of_areflexive_relation_class S.
470 ∀r:relation_of_areflexive_relation_class S x x.
471 P (relation_class_of_areflexive_relation_class S) dir'
472 (ProperElementToKeep Hole dir S dir' x r)) →
473 (∀S:Argument_Class.∀dir',dir''.
474 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
475 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
476 P (relation_class_of_argument_class S) dir' m ->
477 P0 dir'' (singl ? S) (fcl_singl ? ? S ? ? c m)) →
478 (∀S:Argument_Class.∀L:Arguments.∀dir',dir''.
479 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
480 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
481 P (relation_class_of_argument_class S) dir' m →
482 ∀m0:Morphism_Context_List Hole dir dir'' L.
483 P0 dir'' L m0 → P0 dir'' (cons ? S L) (fcl_cons ? ? S ? ? ? c m m0)) →
484 ∀r:Relation_Class.∀r0:rewrite_direction.∀m:Morphism_Context Hole dir r r0.
487 λHole,dir,P,P0,f,f0,f1,f2,f3,f4.
489 F (rc:Relation_Class) (r0:rewrite_direction)
490 (m:Morphism_Context Hole dir rc r0) on m : P rc r0 m
492 match m return λrc.λr0.λm0.P rc r0 m0 with
493 [ App In Out dir' m0 m1 ⇒ f In Out dir' m0 m1 (F0 dir' In m1)
495 | ToKeep S dir' c ⇒ f1 S dir' c
496 | ProperElementToKeep S dir' x r1 ⇒ f2 S dir' x r1
499 F0 (r:rewrite_direction) (a:Arguments)
500 (m:Morphism_Context_List Hole dir r a) on m : P0 r a m
502 match m return λr.λa.λm0.P0 r a m0 with
503 [ fcl_singl S dir' dir'' c m0 ⇒
504 f3 S dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
505 | fcl_cons S L dir' dir'' c m0 m1 ⇒
506 f4 S L dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
511 lemma Morphism_Context_List_rect2:
514 ∀r:Relation_Class.∀r0:rewrite_direction.Morphism_Context Hole dir r r0 → Type.
516 ∀r:rewrite_direction.∀a:Arguments.Morphism_Context_List Hole dir r a → Type.
518 ∀m:Morphism_Theory In Out.∀m0:Morphism_Context_List Hole dir dir' In.
519 P0 dir' In m0 → P Out dir' (App Hole ? ? ? ? m m0)) →
520 P Hole dir (ToReplace Hole dir) →
521 (∀S:Reflexive_Relation_Class.∀dir'.∀c:carrier_of_reflexive_relation_class S.
522 P (relation_class_of_reflexive_relation_class S) dir'
523 (ToKeep Hole dir S dir' c)) →
524 (∀S:Areflexive_Relation_Class.∀dir'.
525 ∀x:carrier_of_areflexive_relation_class S.
526 ∀r:relation_of_areflexive_relation_class S x x.
527 P (relation_class_of_areflexive_relation_class S) dir'
528 (ProperElementToKeep Hole dir S dir' x r)) →
529 (∀S:Argument_Class.∀dir',dir''.
530 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
531 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
532 P (relation_class_of_argument_class S) dir' m ->
533 P0 dir'' (singl ? S) (fcl_singl ? ? S ? ? c m)) →
534 (∀S:Argument_Class.∀L:Arguments.∀dir',dir''.
535 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
536 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
537 P (relation_class_of_argument_class S) dir' m →
538 ∀m0:Morphism_Context_List Hole dir dir'' L.
539 P0 dir'' L m0 → P0 dir'' (cons ? S L) (fcl_cons ? ? S ? ? ? c m m0)) →
540 ∀r:rewrite_direction.∀a:Arguments.∀m:Morphism_Context_List Hole dir r a.
543 λHole,dir,P,P0,f,f0,f1,f2,f3,f4.
545 F (rc:Relation_Class) (r0:rewrite_direction)
546 (m:Morphism_Context Hole dir rc r0) on m : P rc r0 m
548 match m return λrc.λr0.λm0.P rc r0 m0 with
549 [ App In Out dir' m0 m1 ⇒ f In Out dir' m0 m1 (F0 dir' In m1)
551 | ToKeep S dir' c ⇒ f1 S dir' c
552 | ProperElementToKeep S dir' x r1 ⇒ f2 S dir' x r1
555 F0 (r:rewrite_direction) (a:Arguments)
556 (m:Morphism_Context_List Hole dir r a) on m : P0 r a m
558 match m return λr.λa.λm0.P0 r a m0 with
559 [ fcl_singl S dir' dir'' c m0 ⇒
560 f3 S dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
561 | fcl_cons S L dir' dir'' c m0 m1 ⇒
562 f4 S L dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
567 definition product_of_arguments : Arguments → Type.
570 [ apply (carrier_of_relation_class ? a1)
571 | apply (Prod (carrier_of_relation_class ? a1) T)
575 definition get_rewrite_direction: rewrite_direction → Argument_Class → rewrite_direction.
577 cases (variance_of_argument_class R) (a);
580 [ exact dir (* covariant *)
581 | exact (opposite_direction dir) (* contravariant *)
586 definition directed_relation_of_relation_class:
587 ∀dir:rewrite_direction.∀R: Relation_Class.
588 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
591 [ exact (relation_of_relation_class ? ? c c1)
592 | apply (relation_of_relation_class ? ? c1 c)
596 definition directed_relation_of_argument_class:
597 ∀dir:rewrite_direction.∀R: Argument_Class.
598 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
600 rewrite < (about_carrier_of_relation_class_and_relation_class_of_argument_class R) in c c1;
601 exact (directed_relation_of_relation_class dir (relation_class_of_argument_class R) c c1).
605 definition relation_of_product_of_arguments:
606 ∀dir:rewrite_direction.∀In.
607 product_of_arguments In → product_of_arguments In → Prop.
612 exact (directed_relation_of_argument_class (get_rewrite_direction r a) a)
614 change in p with (Prod (carrier_of_relation_class variance a) (product_of_arguments n));
615 change in p1 with (Prod (carrier_of_relation_class variance a) (product_of_arguments n));
620 (directed_relation_of_argument_class (get_rewrite_direction r a) a c c1)
626 definition apply_morphism:
627 ∀In,Out.∀m: function_type_of_morphism_signature In Out.
628 ∀args: product_of_arguments In. carrier_of_relation_class ? Out.
632 | change in p with (Prod (carrier_of_relation_class variance a) (product_of_arguments n));
634 change in f1 with (carrier_of_relation_class variance a → function_type_of_morphism_signature n Out);
635 exact (f ? (f1 a1) b)
639 theorem apply_morphism_compatibility_Right2Left:
640 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
641 ∀args1,args2: product_of_arguments In.
642 make_compatibility_goal_aux ? ? m1 m2 →
643 relation_of_product_of_arguments Right2Left ? args1 args2 →
644 directed_relation_of_relation_class Right2Left ?
645 (apply_morphism ? ? m2 args1)
646 (apply_morphism ? ? m1 args2).
649 [ simplify in m1 m2 args1 args2 ⊢ %;
651 (directed_relation_of_argument_class
652 (get_rewrite_direction Right2Left a) a args1 args2);
653 generalize in match H1; clear H1;
654 generalize in match H; clear H;
655 generalize in match args2; clear args2;
656 generalize in match args1; clear args1;
657 generalize in match m2; clear m2;
658 generalize in match m1; clear m1;
660 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
663 | intros 8 (v T1 r Hr m1 m2 args1 args2);
683 (carrier_of_relation_class variance a →
684 function_type_of_morphism_signature n Out);
686 (carrier_of_relation_class variance a →
687 function_type_of_morphism_signature n Out);
689 ((carrier_of_relation_class ? a) × (product_of_arguments n));
691 ((carrier_of_relation_class ? a) × (product_of_arguments n));
692 generalize in match H2; clear H2;
693 elim args2 0; clear args2;
694 elim args1; clear args1;
696 change in H2:(? ? %) with
697 (relation_of_product_of_arguments Right2Left n b b1);
700 (relation_of_relation_class unit Out (apply_morphism n Out (m1 a2) b1)
701 (apply_morphism n Out (m2 a1) b));
702 generalize in match H3; clear H3;
703 generalize in match a1; clear a1;
704 generalize in match a2; clear a2;
705 generalize in match H1; clear H1;
706 generalize in match m2; clear m2;
707 generalize in match m1; clear m1;
709 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
712 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
715 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
718 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
719 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
722 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
724 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
727 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
730 [ intros (T1 r m1 m2 H1 t1 t3 H3);
733 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
734 | intros (T1 r m1 m2 H1 t1 t3 H3);
737 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
739 | intros (T m1 m2 H1 t1 t3 H3);
742 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
761 theorem apply_morphism_compatibility_Left2Right:
762 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
763 ∀args1,args2: product_of_arguments In.
764 make_compatibility_goal_aux ? ? m1 m2 →
765 relation_of_product_of_arguments Left2Right ? args1 args2 →
766 directed_relation_of_relation_class Left2Right ?
767 (apply_morphism ? ? m1 args1)
768 (apply_morphism ? ? m2 args2).
770 elim In 0; simplify; intros;
772 (directed_relation_of_argument_class
773 (get_rewrite_direction Left2Right a) a args1 args2);
774 generalize in match H1; clear H1;
775 generalize in match H; clear H;
776 generalize in match args2; clear args2;
777 generalize in match args1; clear args1;
778 generalize in match m2; clear m2;
779 generalize in match m1; clear m1;
781 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
784 | intros 8 (v T1 r Hr m1 m2 args1 args2);
806 (carrier_of_relation_class variance a →
807 function_type_of_morphism_signature n Out);
809 (carrier_of_relation_class variance a →
810 function_type_of_morphism_signature n Out);
812 ((carrier_of_relation_class ? a) × (product_of_arguments n));
814 ((carrier_of_relation_class ? a) × (product_of_arguments n));
815 generalize in match H2; clear H2;
816 elim args2 0; clear args2;
817 elim args1; clear args1;
818 simplify in H2; change in H2:(? ? %) with
819 (relation_of_product_of_arguments Left2Right n b b1);
822 (relation_of_relation_class unit Out (apply_morphism n Out (m1 a1) b)
823 (apply_morphism n Out (m2 a2) b1));
824 generalize in match H3; clear H3;
825 generalize in match a2; clear a2;
826 generalize in match a1; clear a1;
827 generalize in match H1; clear H1;
828 generalize in match m2; clear m2;
829 generalize in match m1; clear m1;
831 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
833 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
836 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
839 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
840 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
843 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
845 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
848 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
851 [ intros (T1 r m1 m2 H1 t1 t3 H3);
854 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
855 | intros (T1 r m1 m2 H1 t1 t3 H3);
858 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
860 | intros (T m1 m2 H1 t1 t3 H3);
863 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
883 ∀Hole,dir,Out,dir'. carrier_of_relation_class ? Hole →
884 Morphism_Context Hole dir Out dir' → carrier_of_relation_class ? Out.
885 intros (Hole dir Out dir' H t).
887 (Morphism_Context_rect2 Hole dir (λS,xx,yy. carrier_of_relation_class ? S)
888 (λxx,L,fcl.product_of_arguments L));
892 | exact (apply_morphism ? ? (Function ? ? m) p)
898 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
902 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
910 (*CSC: interp and interp_relation_class_list should be mutually defined. since
911 the proof term of each one contains the proof term of the other one. However
912 I cannot do that interactively (I should write the Fix by hand) *)
913 definition interp_relation_class_list :
914 ∀Hole,dir,dir'.∀L: Arguments. carrier_of_relation_class ? Hole →
915 Morphism_Context_List Hole dir dir' L → product_of_arguments L.
916 intros (Hole dir dir' L H t);
918 (Morphism_Context_List_rect2 Hole dir (λS,xx,yy.carrier_of_relation_class ? S)
919 (λxx,L,fcl.product_of_arguments L));
923 | exact (apply_morphism ? ? (Function ? ? m) p)
929 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
933 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
941 Theorem setoid_rewrite:
942 ∀Hole dir Out dir' (E1 E2: carrier_of_relation_class Hole)
943 (E: Morphism_Context Hole dir Out dir').
944 (directed_relation_of_relation_class dir Hole E1 E2) →
945 (directed_relation_of_relation_class dir' Out (interp E1 E) (interp E2 E)).
948 (@Morphism_Context_rect2 Hole dir
949 (fun S dir'' E => directed_relation_of_relation_class dir'' S (interp E1 E) (interp E2 E))
951 relation_of_product_of_arguments dir'' ?
952 (interp_relation_class_list E1 fcl)
953 (interp_relation_class_list E2 fcl))); intros.
954 change (directed_relation_of_relation_class dir'0 Out0
955 (apply_morphism ? ? (Function m) (interp_relation_class_list E1 m0))
956 (apply_morphism ? ? (Function m) (interp_relation_class_list E2 m0))).
958 apply apply_morphism_compatibility_Left2Right.
961 apply apply_morphism_compatibility_Right2Left.
967 unfold interp. Morphism_Context_rect2.
968 (*CSC: reflexivity used here*)
969 destruct S; destruct dir'0; simpl; (apply r || reflexivity).
971 destruct dir'0; exact r.
973 destruct S; unfold directed_relation_of_argument_class; simpl in H0 |- *;
974 unfold get_rewrite_direction; simpl.
975 destruct dir'0; destruct dir'';
977 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
978 (* the following mess with generalize/clear/intros is to help Coq resolving *)
979 (* second order unification problems. *)
980 generalize m c H0; clear H0 m c; inversion c;
981 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
982 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
983 destruct dir'0; destruct dir'';
985 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
986 (* the following mess with generalize/clear/intros is to help Coq resolving *)
987 (* second order unification problems. *)
988 generalize m c H0; clear H0 m c; inversion c;
989 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
990 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
991 destruct dir'0; destruct dir''; (exact H0 || hnf; symmetry; exact H0).
994 (directed_relation_of_argument_class (get_rewrite_direction dir'' S) S
995 (eq_rect ? (fun T : Type => T) (interp E1 m) ?
996 (about_carrier_of_relation_class_and_relation_class_of_argument_class S))
997 (eq_rect ? (fun T : Type => T) (interp E2 m) ?
998 (about_carrier_of_relation_class_and_relation_class_of_argument_class S)) /\
999 relation_of_product_of_arguments dir'' ?
1000 (interp_relation_class_list E1 m0) (interp_relation_class_list E2 m0)).
1002 clear m0 H1; destruct S; simpl in H0 |- *; unfold get_rewrite_direction; simpl.
1003 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
1005 rewrite <- H3; exact H0.
1006 rewrite (opposite_direction_idempotent dir'0); exact H0.
1007 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
1009 rewrite <- H3; exact H0.
1010 rewrite (opposite_direction_idempotent dir'0); exact H0.
1011 destruct dir''; destruct dir'0; (exact H0 || hnf; symmetry; exact H0).
1015 (* A FEW EXAMPLES ON iff *)
1017 (* impl IS A MORPHISM *)
1019 Add Morphism impl with signature iff ==> iff ==> iff as Impl_Morphism.
1020 unfold impl; tautobatch.
1023 (* and IS A MORPHISM *)
1025 Add Morphism and with signature iff ==> iff ==> iff as And_Morphism.
1029 (* or IS A MORPHISM *)
1031 Add Morphism or with signature iff ==> iff ==> iff as Or_Morphism.
1035 (* not IS A MORPHISM *)
1037 Add Morphism not with signature iff ==> iff as Not_Morphism.
1041 (* THE SAME EXAMPLES ON impl *)
1043 Add Morphism and with signature impl ++> impl ++> impl as And_Morphism2.
1044 unfold impl; tautobatch.
1047 Add Morphism or with signature impl ++> impl ++> impl as Or_Morphism2.
1048 unfold impl; tautobatch.
1051 Add Morphism not with signature impl -→ impl as Not_Morphism2.
1052 unfold impl; tautobatch.