Debian Codegraph @

src/Util/Structures/Equalities/Iso.v

raw
1 From Coq Require Import Morphisms Setoid.
2 From Coq Require Import Equalities.
3 Require Import Crypto.Util.GlobalSettings.
4 Require Import Crypto.Util.FixCoqMistakes.
5
6 Local Set Implicit Arguments.
7
8 Module Type HasIso (E : Typ) (Import T:Typ).
9 Parameter to_ : t -> E.t.
10 Parameter of_ : E.t -> t.
11 End HasIso.
12
13 Module Type IsProperIso (E : Eq) (Import T:Eq) (Import I : HasIso E T).
14 Axiom Proper_to_ : Proper (eq ==> E.eq) to_.
15 Axiom Proper_of_ : Proper (E.eq ==> eq) of_.
16 Global Existing Instance Proper_to_ | 5.
17 Global Existing Instance Proper_of_ | 5.
18 End IsProperIso.
19
20 Module Type IsoIsSect (E : Eq) (Import T:Eq) (Import I : HasIso E T).
21 Axiom of_to : forall x, eq (of_ (to_ x)) x.
22 End IsoIsSect.
23
24 Module Type IsoIsRetr (E : Eq) (Import T:Eq) (Import I : HasIso E T).
25 Axiom to_of : forall x, E.eq (to_ (of_ x)) x.
26 End IsoIsRetr.
27
28 Module Type IsSect (E : Eq) (T:Eq) (I : HasIso E T) := IsProperIso E T I <+ IsoIsSect E T I.
29 Module Type IsRetr (E : Eq) (T:Eq) (I : HasIso E T) := IsProperIso E T I <+ IsoIsRetr E T I.
30 Module Type IsIso (E : Eq) (T:Eq) (I : HasIso E T) := IsProperIso E T I <+ IsoIsSect E T I <+ IsoIsRetr E T I.
31
32 Module Type Iso (E : Eq) := Typ <+ HasIso E.
33 Module Type IsoEq (E : Eq) := Eq <+ HasIso E.
34 Module Type IsoEqualityType (E : Eq) := EqualityType <+ HasIso E <+ IsIso E.
35 Module Type IsoEqualityTypeOrig (E : Eq) := EqualityTypeOrig <+ HasIso E <+ IsIso E.
36 Module Type IsoEqualityTypeBoth (E : Eq) := EqualityTypeBoth <+ HasIso E <+ IsIso E.
37 Module Type IsoDecidableType (E : Eq) := DecidableType <+ HasIso E <+ IsIso E.
38 Module Type IsoDecidableTypeOrig (E : Eq) := DecidableTypeOrig <+ HasIso E <+ IsIso E.
39 Module Type IsoDecidableTypeBoth (E : Eq) := DecidableTypeBoth <+ HasIso E <+ IsIso E.
40 Module Type IsoBooleanEqualityType (E : Eq) := BooleanEqualityType <+ HasIso E <+ IsIso E.
41 Module Type IsoBooleanDecidableType (E : Eq) := BooleanDecidableType <+ HasIso E <+ IsIso E.
42 Module Type IsoDecidableTypeFull (E : Eq) := DecidableTypeFull <+ HasIso E <+ IsIso E.
43 Module Type IsoEqualityType' (E : Eq) := EqualityType' <+ HasIso E <+ IsIso E.
44 Module Type IsoEqualityTypeOrig' (E : Eq) := EqualityTypeOrig' <+ HasIso E <+ IsIso E.
45 Module Type IsoEqualityTypeBoth' (E : Eq) := EqualityTypeBoth' <+ HasIso E <+ IsIso E.
46 Module Type IsoDecidableType' (E : Eq) := DecidableType' <+ HasIso E <+ IsIso E.
47 Module Type IsoDecidableTypeOrig' (E : Eq) := DecidableTypeOrig' <+ HasIso E <+ IsIso E.
48 Module Type IsoDecidableTypeBoth' (E : Eq) := DecidableTypeBoth' <+ HasIso E <+ IsIso E.
49 Module Type IsoBooleanEqualityType' (E : Eq) := BooleanEqualityType' <+ HasIso E <+ IsIso E.
50 Module Type IsoBooleanDecidableType' (E : Eq) := BooleanDecidableType' <+ HasIso E <+ IsIso E.
51 Module Type IsoDecidableTypeFull' (E : Eq) := DecidableTypeFull' <+ HasIso E <+ IsIso E.
52
53 Module LiftIsoHasEq (E : Eq) (Import I : Iso E) <: HasEq I.
54 Definition eq : relation t := fun x y => E.eq (to_ x) (to_ y).
55 End LiftIsoHasEq.
56
57 Module LiftIsoEq (E : Eq) (I : Iso E) <: IsoEq E := I <+ LiftIsoHasEq E I.
58
59 Module LiftIsoIsEq (E : EqualityType) (Import I : Iso E).
60 Module Import I' := LiftIsoEq E I.
61 #[global]
62 Instance eq_equiv : Equivalence eq | 5.
63 Proof.
64 cbv [eq]; split; repeat intro.
65 { reflexivity. }
66 { symmetry; assumption. }
67 { etransitivity; eassumption. }
68 Defined.
69 End LiftIsoIsEq.
70
71 Module LiftIsoHasEqDec (E : DecidableType) (Import I : IsoEqualityType E) <: HasEqDec I.
72 Definition eq_dec x y : {eq x y} + {~eq x y}.
73 Proof.
74 destruct (E.eq_dec (to_ x) (to_ y)) as [H|H]; [ left | right ];
75 [ | abstract (intro H'; apply H; clear H; f_equiv; assumption) ].
76 etransitivity; [ symmetry; apply of_to | ];
77 etransitivity; [ | apply of_to ];
78 f_equiv; assumption.
79 Defined.
80 End LiftIsoHasEqDec.
81
82 Module Type Sect (E : Eq) := Typ <+ HasIso E.
83 Module Type SectEq (E : Eq) := Eq <+ HasIso E.
84 Module Type SectEqualityType (E : Eq) := EqualityType <+ HasIso E <+ IsSect E.
85 Module Type SectEqualityTypeOrig (E : Eq) := EqualityTypeOrig <+ HasIso E <+ IsSect E.
86 Module Type SectEqualityTypeBoth (E : Eq) := EqualityTypeBoth <+ HasIso E <+ IsSect E.
87 Module Type SectDecidableType (E : Eq) := DecidableType <+ HasIso E <+ IsSect E.
88 Module Type SectDecidableTypeOrig (E : Eq) := DecidableTypeOrig <+ HasIso E <+ IsSect E.
89 Module Type SectDecidableTypeBoth (E : Eq) := DecidableTypeBoth <+ HasIso E <+ IsSect E.
90 Module Type SectBooleanEqualityType (E : Eq) := BooleanEqualityType <+ HasIso E <+ IsSect E.
91 Module Type SectBooleanDecidableType (E : Eq) := BooleanDecidableType <+ HasIso E <+ IsSect E.
92 Module Type SectDecidableTypeFull (E : Eq) := DecidableTypeFull <+ HasIso E <+ IsSect E.
93 Module Type SectEqualityType' (E : Eq) := EqualityType' <+ HasIso E <+ IsSect E.
94 Module Type SectEqualityTypeOrig' (E : Eq) := EqualityTypeOrig' <+ HasIso E <+ IsSect E.
95 Module Type SectEqualityTypeBoth' (E : Eq) := EqualityTypeBoth' <+ HasIso E <+ IsSect E.
96 Module Type SectDecidableType' (E : Eq) := DecidableType' <+ HasIso E <+ IsSect E.
97 Module Type SectDecidableTypeOrig' (E : Eq) := DecidableTypeOrig' <+ HasIso E <+ IsSect E.
98 Module Type SectDecidableTypeBoth' (E : Eq) := DecidableTypeBoth' <+ HasIso E <+ IsSect E.
99 Module Type SectBooleanEqualityType' (E : Eq) := BooleanEqualityType' <+ HasIso E <+ IsSect E.
100 Module Type SectBooleanDecidableType' (E : Eq) := BooleanDecidableType' <+ HasIso E <+ IsSect E.
101 Module Type SectDecidableTypeFull' (E : Eq) := DecidableTypeFull' <+ HasIso E <+ IsSect E.
102
103 Module LiftSectHasEq (E : Eq) (I : Sect E) <: HasEq I := LiftIsoHasEq E I.
104 Module LiftSectEq (E : Eq) (I : Sect E) <: SectEq E := I <+ LiftSectHasEq E I.
105 Module LiftSectIsEq (E : EqualityType) (I : Sect E) := LiftIsoIsEq E I.
106 Module LiftSectHasEqDec (E : DecidableType) (Import I : SectEqualityType E) <: HasEqDec I.
107 Definition eq_dec x y : {eq x y} + {~eq x y}.
108 Proof.
109 destruct (E.eq_dec (to_ x) (to_ y)) as [H|H]; [ left | right ];
110 [ | abstract (intro H'; apply H; clear H; f_equiv; assumption) ].
111 etransitivity; [ symmetry; apply of_to | ];
112 etransitivity; [ | apply of_to ];
113 f_equiv; assumption.
114 Defined.
115 End LiftSectHasEqDec.
116
117 Module Type Retr (E : Eq) := Typ <+ HasIso E.
118 Module Type RetrEq (E : Eq) := Eq <+ HasIso E.
119 Module Type RetrEqualityType (E : Eq) := EqualityType <+ HasIso E <+ IsRetr E.
120 Module Type RetrEqualityTypeOrig (E : Eq) := EqualityTypeOrig <+ HasIso E <+ IsRetr E.
121 Module Type RetrEqualityTypeBoth (E : Eq) := EqualityTypeBoth <+ HasIso E <+ IsRetr E.
122 Module Type RetrDecidableType (E : Eq) := DecidableType <+ HasIso E <+ IsRetr E.
123 Module Type RetrDecidableTypeOrig (E : Eq) := DecidableTypeOrig <+ HasIso E <+ IsRetr E.
124 Module Type RetrDecidableTypeBoth (E : Eq) := DecidableTypeBoth <+ HasIso E <+ IsRetr E.
125 Module Type RetrBooleanEqualityType (E : Eq) := BooleanEqualityType <+ HasIso E <+ IsRetr E.
126 Module Type RetrBooleanDecidableType (E : Eq) := BooleanDecidableType <+ HasIso E <+ IsRetr E.
127 Module Type RetrDecidableTypeFull (E : Eq) := DecidableTypeFull <+ HasIso E <+ IsRetr E.
128 Module Type RetrEqualityType' (E : Eq) := EqualityType' <+ HasIso E <+ IsRetr E.
129 Module Type RetrEqualityTypeOrig' (E : Eq) := EqualityTypeOrig' <+ HasIso E <+ IsRetr E.
130 Module Type RetrEqualityTypeBoth' (E : Eq) := EqualityTypeBoth' <+ HasIso E <+ IsRetr E.
131 Module Type RetrDecidableType' (E : Eq) := DecidableType' <+ HasIso E <+ IsRetr E.
132 Module Type RetrDecidableTypeOrig' (E : Eq) := DecidableTypeOrig' <+ HasIso E <+ IsRetr E.
133 Module Type RetrDecidableTypeBoth' (E : Eq) := DecidableTypeBoth' <+ HasIso E <+ IsRetr E.
134 Module Type RetrBooleanEqualityType' (E : Eq) := BooleanEqualityType' <+ HasIso E <+ IsRetr E.
135 Module Type RetrBooleanDecidableType' (E : Eq) := BooleanDecidableType' <+ HasIso E <+ IsRetr E.
136 Module Type RetrDecidableTypeFull' (E : Eq) := DecidableTypeFull' <+ HasIso E <+ IsRetr E.
137
138 Module LiftRetrHasEq (E : Eq) (I : Retr E) <: HasEq I := LiftIsoHasEq E I.
139 Module LiftRetrEq (E : Eq) (I : Retr E) <: RetrEq E := I <+ LiftRetrHasEq E I.
140 Module LiftRetrIsEq (E : EqualityType) (I : Retr E) := LiftIsoIsEq E I.