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".
23 (* DEFINITIONS OF Relation_Class AND n-ARY Morphism_Theory *)
25 (* X will be used to distinguish covariant arguments whose type is an *)
26 (* Asymmetric* relation from contravariant arguments of the same type *)
27 inductive X_Relation_Class (X: Type) : Type ≝
29 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → X_Relation_Class X
30 | AsymmetricReflexive : X → ∀A,Aeq. reflexive A Aeq → X_Relation_Class X
31 | SymmetricAreflexive : ∀A,Aeq. symmetric A Aeq → X_Relation_Class X
32 | AsymmetricAreflexive : X → ∀A.∀Aeq : relation A. X_Relation_Class X
33 | Leibniz : Type → X_Relation_Class X.
35 inductive variance : Set ≝
37 | Contravariant : variance.
39 definition Argument_Class ≝ X_Relation_Class variance.
40 definition Relation_Class ≝ X_Relation_Class unit.
42 inductive Reflexive_Relation_Class : Type :=
44 ∀A,Aeq. symmetric A Aeq → reflexive ? Aeq → Reflexive_Relation_Class
46 ∀A,Aeq. reflexive A Aeq → Reflexive_Relation_Class
47 | RLeibniz : Type → Reflexive_Relation_Class.
49 inductive Areflexive_Relation_Class : Type :=
50 | ASymmetric : ∀A,Aeq. symmetric A Aeq → Areflexive_Relation_Class
51 | AAsymmetric : ∀A.∀Aeq : relation A. Areflexive_Relation_Class.
53 definition relation_class_of_argument_class : Argument_Class → Relation_Class.
57 [ apply (SymmetricReflexive ? ? ? H H1)
58 | apply (AsymmetricReflexive ? something ? ? H)
59 | apply (SymmetricAreflexive ? ? ? H)
60 | apply (AsymmetricAreflexive ? something ? r)
61 | apply (Leibniz ? T1)
65 definition carrier_of_relation_class : ∀X. X_Relation_Class X → Type.
71 definition relation_of_relation_class :
72 ∀X,R. carrier_of_relation_class X R → carrier_of_relation_class X R → Prop.
76 [1,2: intros 4; apply r
77 |3,4: intros 3; apply r
82 lemma about_carrier_of_relation_class_and_relation_class_of_argument_class :
84 carrier_of_relation_class ? (relation_class_of_argument_class R) =
85 carrier_of_relation_class ? R.
91 inductive nelistT (A : Type) : Type :=
93 | cons : A → nelistT A → nelistT A.
95 definition Arguments := nelistT Argument_Class.
97 definition function_type_of_morphism_signature :
98 Arguments → Relation_Class → Type.
101 [ exact (carrier_of_relation_class ? t → carrier_of_relation_class ? Out)
102 | exact (carrier_of_relation_class ? t → T)
106 definition make_compatibility_goal_aux:
107 ∀In,Out.∀f,g:function_type_of_morphism_signature In Out.Prop.
109 elim In (a); simplify in f f1;
110 generalize in match f1; clear f1;
111 generalize in match f; clear f;
112 [ elim a; simplify in f f1;
113 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
115 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
116 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
118 | exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
120 [ exact (∀x1,x2. r x1 x2 → relation_of_relation_class ? Out (f x1) (f1 x2))
121 | exact (∀x1,x2. r x2 x1 → relation_of_relation_class ? Out (f x1) (f1 x2))
123 | exact (∀x. relation_of_relation_class ? Out (f x) (f1 x))
126 ((carrier_of_relation_class ? t → function_type_of_morphism_signature n Out) →
127 (carrier_of_relation_class ? t → function_type_of_morphism_signature n Out) →
129 elim t; simplify in f f1;
130 [ exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
132 [ exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
133 | exact (∀x1,x2. r x2 x1 → R (f x1) (f1 x2))
135 | exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
137 [ exact (∀x1,x2. r x1 x2 → R (f x1) (f1 x2))
138 | exact (∀x1,x2. r x2 x1 → R (f x1) (f1 x2))
140 | exact (∀x. R (f x) (f1 x))
145 definition make_compatibility_goal :=
146 λIn,Out,f. make_compatibility_goal_aux In Out f f.
148 record Morphism_Theory (In: Arguments) (Out: Relation_Class) : Type :=
149 { Function : function_type_of_morphism_signature In Out;
150 Compat : make_compatibility_goal In Out Function
153 definition list_of_Leibniz_of_list_of_types: nelistT Type → Arguments.
156 [ apply (singl ? (Leibniz ? t))
157 | apply (cons ? (Leibniz ? t) a)
161 (* every function is a morphism from Leibniz+ to Leibniz *)
162 definition morphism_theory_of_function :
163 ∀In: nelistT Type.∀Out: Type.
164 let In' := list_of_Leibniz_of_list_of_types In in
165 let Out' := Leibniz ? Out in
166 function_type_of_morphism_signature In' Out' →
167 Morphism_Theory In' Out'.
169 apply (mk_Morphism_Theory ? ? f);
170 unfold In' in f; clear In';
171 unfold Out' in f; clear Out';
172 generalize in match f; clear f;
174 [ unfold make_compatibility_goal;
187 (* THE iff RELATION CLASS *)
189 definition Iff_Relation_Class : Relation_Class.
190 apply (SymmetricReflexive unit ? iff);
191 [ exact symmetric_iff
192 | exact reflexive_iff
196 (* THE impl RELATION CLASS *)
198 definition impl \def \lambda A,B:Prop. A → B.
200 theorem impl_refl: reflexive ? impl.
208 definition Impl_Relation_Class : Relation_Class.
209 unfold Relation_Class;
210 apply (AsymmetricReflexive unit something ? impl);
214 (* UTILITY FUNCTIONS TO PROVE THAT EVERY TRANSITIVE RELATION IS A MORPHISM *)
216 definition equality_morphism_of_symmetric_areflexive_transitive_relation:
217 ∀A: Type.∀Aeq: relation A.∀sym: symmetric ? Aeq.∀trans: transitive ? Aeq.
218 let ASetoidClass := SymmetricAreflexive ? ? ? sym in
219 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass))
222 apply mk_Morphism_Theory;
224 | unfold make_compatibility_goal;
228 unfold transitive in H;
229 unfold symmetric in sym;
235 definition equality_morphism_of_symmetric_reflexive_transitive_relation:
236 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀sym: symmetric ? Aeq.
237 ∀trans: transitive ? Aeq.
238 let ASetoidClass := SymmetricReflexive ? ? ? sym refl in
239 (Morphism_Theory (cons ? ASetoidClass (singl ? ASetoidClass)) Iff_Relation_Class).
241 apply mk_Morphism_Theory;
247 unfold transitive in H;
248 unfold symmetric in sym;
253 definition equality_morphism_of_asymmetric_areflexive_transitive_relation:
254 ∀A: Type.∀Aeq: relation A.∀trans: transitive ? Aeq.
255 let ASetoidClass1 := AsymmetricAreflexive ? Contravariant ? Aeq in
256 let ASetoidClass2 := AsymmetricAreflexive ? Covariant ? Aeq in
257 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
259 apply mk_Morphism_Theory;
270 definition equality_morphism_of_asymmetric_reflexive_transitive_relation:
271 ∀A: Type.∀Aeq: relation A.∀refl: reflexive ? Aeq.∀trans: transitive ? Aeq.
272 let ASetoidClass1 := AsymmetricReflexive ? Contravariant ? ? refl in
273 let ASetoidClass2 := AsymmetricReflexive ? Covariant ? ? refl in
274 (Morphism_Theory (cons ? ASetoidClass1 (singl ? ASetoidClass2)) Impl_Relation_Class).
276 apply mk_Morphism_Theory;
287 (* iff AS A RELATION *)
289 (*DA PORTARE:Add Relation Prop iff
290 reflexivity proved by iff_refl
291 symmetry proved by iff_sym
292 transitivity proved by iff_trans
295 (* every predicate is morphism from Leibniz+ to Iff_Relation_Class *)
296 definition morphism_theory_of_predicate :
298 let In' := list_of_Leibniz_of_list_of_types In in
299 function_type_of_morphism_signature In' Iff_Relation_Class →
300 Morphism_Theory In' Iff_Relation_Class.
302 apply mk_Morphism_Theory;
304 | generalize in match f; clear f;
305 unfold In'; clear In';
309 alias id "iff_refl" = "cic:/matita/logic/coimplication/iff_refl.con".
318 (* impl AS A RELATION *)
320 theorem impl_trans: transitive ? impl.
327 (*DA PORTARE: Add Relation Prop impl
328 reflexivity proved by impl_refl
329 transitivity proved by impl_trans
332 (* THE CIC PART OF THE REFLEXIVE TACTIC (SETOID REWRITE) *)
334 inductive rewrite_direction : Type :=
335 Left2Right: rewrite_direction
336 | Right2Left: rewrite_direction.
338 definition variance_of_argument_class : Argument_Class → option variance.
349 definition opposite_direction :=
352 [ Left2Right ⇒ Right2Left
353 | Right2Left ⇒ Left2Right
356 lemma opposite_direction_idempotent:
357 ∀dir. opposite_direction (opposite_direction dir) = dir.
363 inductive check_if_variance_is_respected :
364 option variance → rewrite_direction → rewrite_direction → Prop
366 MSNone : ∀dir,dir'. check_if_variance_is_respected (None ?) dir dir'
367 | MSCovariant : ∀dir. check_if_variance_is_respected (Some ? Covariant) dir dir
370 check_if_variance_is_respected (Some ? Contravariant) dir (opposite_direction dir).
372 definition relation_class_of_reflexive_relation_class:
373 Reflexive_Relation_Class → Relation_Class.
376 [ apply (SymmetricReflexive ? ? ? H H1)
377 | apply (AsymmetricReflexive ? something ? ? H)
378 | apply (Leibniz ? T)
382 definition relation_class_of_areflexive_relation_class:
383 Areflexive_Relation_Class → Relation_Class.
386 [ apply (SymmetricAreflexive ? ? ? H)
387 | apply (AsymmetricAreflexive ? something ? r)
391 definition carrier_of_reflexive_relation_class :=
392 λR.carrier_of_relation_class ? (relation_class_of_reflexive_relation_class R).
394 definition carrier_of_areflexive_relation_class :=
395 λR.carrier_of_relation_class ? (relation_class_of_areflexive_relation_class R).
397 definition relation_of_areflexive_relation_class :=
398 λR.relation_of_relation_class ? (relation_class_of_areflexive_relation_class R).
400 inductive Morphism_Context (Hole: Relation_Class) (dir:rewrite_direction) : Relation_Class → rewrite_direction → Type :=
403 Morphism_Theory In Out → Morphism_Context_List Hole dir dir' In →
404 Morphism_Context Hole dir Out dir'
405 | ToReplace : Morphism_Context Hole dir Hole dir
408 carrier_of_reflexive_relation_class S →
409 Morphism_Context Hole dir (relation_class_of_reflexive_relation_class S) dir'
410 | ProperElementToKeep :
411 ∀S,dir'.∀x: carrier_of_areflexive_relation_class S.
412 relation_of_areflexive_relation_class S x x →
413 Morphism_Context Hole dir (relation_class_of_areflexive_relation_class S) dir'
414 with Morphism_Context_List :
415 rewrite_direction → Arguments → Type
419 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
420 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
421 Morphism_Context_List Hole dir dir'' (singl ? S)
424 check_if_variance_is_respected (variance_of_argument_class S) dir' dir'' →
425 Morphism_Context Hole dir (relation_class_of_argument_class S) dir' →
426 Morphism_Context_List Hole dir dir'' L →
427 Morphism_Context_List Hole dir dir'' (cons ? S L).
429 lemma Morphism_Context_rect2:
432 ∀r:Relation_Class.∀r0:rewrite_direction.Morphism_Context Hole dir r r0 → Type.
434 ∀r:rewrite_direction.∀a:Arguments.Morphism_Context_List Hole dir r a → Type.
436 ∀m:Morphism_Theory In Out.∀m0:Morphism_Context_List Hole dir dir' In.
437 P0 dir' In m0 → P Out dir' (App Hole ? ? ? ? m m0)) →
438 P Hole dir (ToReplace Hole dir) →
439 (∀S:Reflexive_Relation_Class.∀dir'.∀c:carrier_of_reflexive_relation_class S.
440 P (relation_class_of_reflexive_relation_class S) dir'
441 (ToKeep Hole dir S dir' c)) →
442 (∀S:Areflexive_Relation_Class.∀dir'.
443 ∀x:carrier_of_areflexive_relation_class S.
444 ∀r:relation_of_areflexive_relation_class S x x.
445 P (relation_class_of_areflexive_relation_class S) dir'
446 (ProperElementToKeep Hole dir S dir' x r)) →
447 (∀S:Argument_Class.∀dir',dir''.
448 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
449 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
450 P (relation_class_of_argument_class S) dir' m ->
451 P0 dir'' (singl ? S) (fcl_singl ? ? S ? ? c m)) →
452 (∀S:Argument_Class.∀L:Arguments.∀dir',dir''.
453 ∀c:check_if_variance_is_respected (variance_of_argument_class S) dir' dir''.
454 ∀m:Morphism_Context Hole dir (relation_class_of_argument_class S) dir'.
455 P (relation_class_of_argument_class S) dir' m →
456 ∀m0:Morphism_Context_List Hole dir dir'' L.
457 P0 dir'' L m0 → P0 dir'' (cons ? S L) (fcl_cons ? ? S ? ? ? c m m0)) →
458 ∀r:Relation_Class.∀r0:rewrite_direction.∀m:Morphism_Context Hole dir r r0.
461 λHole,dir,P,P0,f,f0,f1,f2,f3,f4.
463 F (rc:Relation_Class) (r0:rewrite_direction)
464 (m:Morphism_Context Hole dir rc r0) on m : P rc r0 m
466 match m return λrc.λr0.λm0.P rc r0 m0 with
467 [ App In Out dir' m0 m1 ⇒ f In Out dir' m0 m1 (F0 dir' In m1)
469 | ToKeep S dir' c ⇒ f1 S dir' c
470 | ProperElementToKeep S dir' x r1 ⇒ f2 S dir' x r1
473 F0 (r:rewrite_direction) (a:Arguments)
474 (m:Morphism_Context_List Hole dir r a) on m : P0 r a m
476 match m return λr.λa.λm0.P0 r a m0 with
477 [ fcl_singl S dir' dir'' c m0 ⇒
478 f3 S dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
479 | fcl_cons S L dir' dir'' c m0 m1 ⇒
480 f4 S L dir' dir'' c m0 (F (relation_class_of_argument_class S) dir' m0)
485 definition product_of_arguments : Arguments → Type.
488 [ apply (carrier_of_relation_class ? t)
489 | apply (Prod (carrier_of_relation_class ? t) T)
493 definition get_rewrite_direction: rewrite_direction → Argument_Class → rewrite_direction.
495 cases (variance_of_argument_class R);
498 [ exact dir (* covariant *)
499 | exact (opposite_direction dir) (* contravariant *)
504 definition directed_relation_of_relation_class:
505 ∀dir:rewrite_direction.∀R: Relation_Class.
506 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
509 [ exact (relation_of_relation_class ? ? c c1)
510 | apply (relation_of_relation_class ? ? c1 c)
514 definition directed_relation_of_argument_class:
515 ∀dir:rewrite_direction.∀R: Argument_Class.
516 carrier_of_relation_class ? R → carrier_of_relation_class ? R → Prop.
519 (about_carrier_of_relation_class_and_relation_class_of_argument_class R);
521 apply (directed_relation_of_relation_class dir (relation_class_of_argument_class R));
522 apply (eq_rect ? ? (λX.X) ? ? (sym_eq ? ? ? H));
528 definition relation_of_product_of_arguments:
529 ∀dir:rewrite_direction.∀In.
530 product_of_arguments In → product_of_arguments In → Prop.
535 exact (directed_relation_of_argument_class (get_rewrite_direction r t) t)
537 change in p with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
538 change in p1 with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
543 (directed_relation_of_argument_class (get_rewrite_direction r t) t a a1)
549 definition apply_morphism:
550 ∀In,Out.∀m: function_type_of_morphism_signature In Out.
551 ∀args: product_of_arguments In. carrier_of_relation_class ? Out.
555 | change in p with (Prod (carrier_of_relation_class variance t) (product_of_arguments n));
557 change in f1 with (carrier_of_relation_class variance t → function_type_of_morphism_signature n Out);
558 exact (f ? (f1 t1) t2)
562 theorem apply_morphism_compatibility_Right2Left:
563 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
564 ∀args1,args2: product_of_arguments In.
565 make_compatibility_goal_aux ? ? m1 m2 →
566 relation_of_product_of_arguments Right2Left ? args1 args2 →
567 directed_relation_of_relation_class Right2Left ?
568 (apply_morphism ? ? m2 args1)
569 (apply_morphism ? ? m1 args2).
572 [ simplify in m1 m2 args1 args2 ⊢ %;
574 (directed_relation_of_argument_class
575 (get_rewrite_direction Right2Left t) t args1 args2);
576 generalize in match H1; clear H1;
577 generalize in match H; clear H;
578 generalize in match args2; clear args2;
579 generalize in match args1; clear args1;
580 generalize in match m2; clear m2;
581 generalize in match m1; clear m1;
583 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
589 | intros 8 (v T1 r Hr m1 m2 args1 args2);
611 (carrier_of_relation_class variance t →
612 function_type_of_morphism_signature n Out);
614 (carrier_of_relation_class variance t →
615 function_type_of_morphism_signature n Out);
617 ((carrier_of_relation_class ? t) × (product_of_arguments n));
619 ((carrier_of_relation_class ? t) × (product_of_arguments n));
620 generalize in match H2; clear H2;
621 elim args2 0; clear args2;
622 elim args1; clear args1;
625 (relation_of_product_of_arguments Right2Left n t2 t4);
627 (relation_of_relation_class unit Out (apply_morphism n Out (m1 t3) t4)
628 (apply_morphism n Out (m2 t1) t2));
629 generalize in match H3; clear H3;
630 generalize in match t3; clear t3;
631 generalize in match t1; clear t1;
632 generalize in match H1; clear H1;
633 generalize in match m2; clear m2;
634 generalize in match m1; clear m1;
636 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
639 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
642 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
645 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
646 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
649 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
651 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
654 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
657 [ intros (T1 r m1 m2 H1 t1 t3 H3);
660 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
661 | intros (T1 r m1 m2 H1 t1 t3 H3);
664 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
666 | intros (T m1 m2 H1 t1 t3 H3);
669 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
688 theorem apply_morphism_compatibility_Left2Right:
689 ∀In,Out.∀m1,m2: function_type_of_morphism_signature In Out.
690 ∀args1,args2: product_of_arguments In.
691 make_compatibility_goal_aux ? ? m1 m2 →
692 relation_of_product_of_arguments Left2Right ? args1 args2 →
693 directed_relation_of_relation_class Left2Right ?
694 (apply_morphism ? ? m1 args1)
695 (apply_morphism ? ? m2 args2).
698 [ simplify in m1 m2 args1 args2 ⊢ %;
700 (directed_relation_of_argument_class
701 (get_rewrite_direction Left2Right t) t args1 args2);
702 generalize in match H1; clear H1;
703 generalize in match H; clear H;
704 generalize in match args2; clear args2;
705 generalize in match args1; clear args1;
706 generalize in match m2; clear m2;
707 generalize in match m1; clear m1;
709 [ intros (T1 r Hs Hr m1 m2 args1 args2 H H1);
715 | intros 8 (v T1 r Hr m1 m2 args1 args2);
737 (carrier_of_relation_class variance t →
738 function_type_of_morphism_signature n Out);
740 (carrier_of_relation_class variance t →
741 function_type_of_morphism_signature n Out);
743 ((carrier_of_relation_class ? t) × (product_of_arguments n));
745 ((carrier_of_relation_class ? t) × (product_of_arguments n));
746 generalize in match H2; clear H2;
747 elim args2 0; clear args2;
748 elim args1; clear args1;
751 (relation_of_product_of_arguments Left2Right n t2 t4);
753 (relation_of_relation_class unit Out (apply_morphism n Out (m1 t1) t2)
754 (apply_morphism n Out (m2 t3) t4));
755 generalize in match H3; clear H3;
756 generalize in match t3; clear t3;
757 generalize in match t1; clear t1;
758 generalize in match H1; clear H1;
759 generalize in match m2; clear m2;
760 generalize in match m1; clear m1;
762 [ intros (T1 r Hs Hr m1 m2 H1 t1 t3 H3);
765 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
768 [ intros (T1 r Hr m1 m2 H1 t1 t3 H3);
771 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
772 | intros (T1 r Hr m1 m2 H1 t1 t3 H3);
775 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
777 | intros (T1 r Hs m1 m2 H1 t1 t3 H3);
780 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
783 [ intros (T1 r m1 m2 H1 t1 t3 H3);
786 (∀x1,x2:T1.r x1 x2 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
787 | intros (T1 r m1 m2 H1 t1 t3 H3);
790 (∀x1,x2:T1.r x2 x1 → make_compatibility_goal_aux n Out (m1 x1) (m2 x2));
792 | intros (T m1 m2 H1 t1 t3 H3);
795 (∀x:T. make_compatibility_goal_aux n Out (m1 x) (m2 x));
815 ∀Hole,dir,Out,dir'. carrier_of_relation_class ? Hole →
816 Morphism_Context Hole dir Out dir' → carrier_of_relation_class ? Out.
817 intros (Hole dir Out dir' H t).
819 (Morphism_Context_rect2 Hole dir (λS,xx,yy. carrier_of_relation_class S)
820 (λxx,L,fcl.product_of_arguments L));
822 exact (apply_morphism ? ? (Function m) X).
828 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
832 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
837 (*CSC: interp and interp_relation_class_list should be mutually defined. since
838 the proof term of each one contains the proof term of the other one. However
839 I cannot do that interactively (I should write the Fix by hand) *)
840 definition interp_relation_class_list :
841 ∀Hole dir dir' (L: Arguments). carrier_of_relation_class Hole →
842 Morphism_Context_List Hole dir dir' L → product_of_arguments L.
843 intros Hole dir dir' L H t.
845 (@Morphism_Context_List_rect2 Hole dir (fun S ? ? => carrier_of_relation_class S)
846 (fun ? L fcl => product_of_arguments L));
848 exact (apply_morphism ? ? (Function m) X).
854 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
858 (about_carrier_of_relation_class_and_relation_class_of_argument_class S);
863 Theorem setoid_rewrite:
864 ∀Hole dir Out dir' (E1 E2: carrier_of_relation_class Hole)
865 (E: Morphism_Context Hole dir Out dir').
866 (directed_relation_of_relation_class dir Hole E1 E2) →
867 (directed_relation_of_relation_class dir' Out (interp E1 E) (interp E2 E)).
870 (@Morphism_Context_rect2 Hole dir
871 (fun S dir'' E => directed_relation_of_relation_class dir'' S (interp E1 E) (interp E2 E))
873 relation_of_product_of_arguments dir'' ?
874 (interp_relation_class_list E1 fcl)
875 (interp_relation_class_list E2 fcl))); intros.
876 change (directed_relation_of_relation_class dir'0 Out0
877 (apply_morphism ? ? (Function m) (interp_relation_class_list E1 m0))
878 (apply_morphism ? ? (Function m) (interp_relation_class_list E2 m0))).
880 apply apply_morphism_compatibility_Left2Right.
883 apply apply_morphism_compatibility_Right2Left.
889 unfold interp. Morphism_Context_rect2.
890 (*CSC: reflexivity used here*)
891 destruct S; destruct dir'0; simpl; (apply r || reflexivity).
893 destruct dir'0; exact r.
895 destruct S; unfold directed_relation_of_argument_class; simpl in H0 |- *;
896 unfold get_rewrite_direction; simpl.
897 destruct dir'0; destruct dir'';
899 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
900 (* the following mess with generalize/clear/intros is to help Coq resolving *)
901 (* second order unification problems. *)
902 generalize m c H0; clear H0 m c; inversion c;
903 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
904 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
905 destruct dir'0; destruct dir'';
907 unfold directed_relation_of_argument_class; simpl; apply s; exact H0).
908 (* the following mess with generalize/clear/intros is to help Coq resolving *)
909 (* second order unification problems. *)
910 generalize m c H0; clear H0 m c; inversion c;
911 generalize m c; clear m c; rewrite <- H1; rewrite <- H2; intros;
912 (exact H3 || rewrite (opposite_direction_idempotent dir'0); apply H3).
913 destruct dir'0; destruct dir''; (exact H0 || hnf; symmetry; exact H0).
916 (directed_relation_of_argument_class (get_rewrite_direction dir'' S) S
917 (eq_rect ? (fun T : Type => T) (interp E1 m) ?
918 (about_carrier_of_relation_class_and_relation_class_of_argument_class S))
919 (eq_rect ? (fun T : Type => T) (interp E2 m) ?
920 (about_carrier_of_relation_class_and_relation_class_of_argument_class S)) /\
921 relation_of_product_of_arguments dir'' ?
922 (interp_relation_class_list E1 m0) (interp_relation_class_list E2 m0)).
924 clear m0 H1; destruct S; simpl in H0 |- *; unfold get_rewrite_direction; simpl.
925 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
927 rewrite <- H3; exact H0.
928 rewrite (opposite_direction_idempotent dir'0); exact H0.
929 destruct dir''; destruct dir'0; (exact H0 || hnf; apply s; exact H0).
931 rewrite <- H3; exact H0.
932 rewrite (opposite_direction_idempotent dir'0); exact H0.
933 destruct dir''; destruct dir'0; (exact H0 || hnf; symmetry; exact H0).
937 (* A FEW EXAMPLES ON iff *)
939 (* impl IS A MORPHISM *)
941 Add Morphism impl with signature iff ==> iff ==> iff as Impl_Morphism.
945 (* and IS A MORPHISM *)
947 Add Morphism and with signature iff ==> iff ==> iff as And_Morphism.
951 (* or IS A MORPHISM *)
953 Add Morphism or with signature iff ==> iff ==> iff as Or_Morphism.
957 (* not IS A MORPHISM *)
959 Add Morphism not with signature iff ==> iff as Not_Morphism.
963 (* THE SAME EXAMPLES ON impl *)
965 Add Morphism and with signature impl ++> impl ++> impl as And_Morphism2.
969 Add Morphism or with signature impl ++> impl ++> impl as Or_Morphism2.
973 Add Morphism not with signature impl -→ impl as Not_Morphism2.