@@ -103,17 +103,35 @@ Definition id_eqb (id1 : id) (id2 : id) : bool :=
103103 | _ => false
104104 end .
105105
106+ Theorem id_eqb_refl : forall x, id_eqb x x = true.
107+ Proof .
108+ destruct x as [aux ?].
109+ destruct aux; cbn; try trivial; rewrite String.eqb_refl; reflexivity.
110+ Qed .
111+
112+ Theorem id_eqb_sym : forall x y, id_eqb x y = true -> id_eqb y x = true.
113+ Proof .
114+ destruct x as [x_aux ?].
115+ destruct y as [y_aux ?].
116+ destruct x_aux as [| | x_s | x_s]; destruct y_aux as [| | y_s | y_s]; cbn; try trivial; rewrite String.eqb_sym; easy.
117+ Qed .
118+
119+ Theorem id_eqb_trans : forall x y z, id_eqb x y = true -> id_eqb y z = true -> id_eqb x z = true.
120+ Proof .
121+ destruct x as [x_aux ?].
122+ destruct y as [y_aux ?].
123+ destruct z as [z_aux ?].
124+ destruct x_aux as [| | x_s | x_s]; destruct y_aux as [| | y_s | y_s]; destruct z_aux as [| | z_s | z_s].
125+ all: cbn.
126+ all: try easy.
127+ all: rewrite String.eqb_eq in *.
128+ all: congruence.
129+ Qed .
130+
106131Module IdMiniOrdered <: OrderedType.MiniOrderedType.
107132 Definition t := Ast.id.
108133
109- Definition eq (id1 : id) (id2 : id) : Prop :=
110- match (id1, id2) with
111- | (Id_aux (Id s1) _, Id_aux (Id s2) _) => Is_true (String.eqb s1 s2)
112- | (Id_aux (Operator s1) _, Id_aux (Operator s2) _) => Is_true (String.eqb s1 s2)
113- | (Id_aux And_bool _, Id_aux And_bool _) => True
114- | (Id_aux Or_bool _, Id_aux Or_bool _) => True
115- | _ => False
116- end .
134+ Definition eq (id1 : id) (id2 : id) : Prop := Is_true (id_eqb id1 id2).
117135
118136 Definition lt (id1 : id) (id2 : id) : Prop :=
119137 match (id1, id2) with
@@ -127,33 +145,31 @@ Module IdMiniOrdered <: OrderedType.MiniOrderedType.
127145 | (_, Id_aux Or_bool _) => True
128146 end .
129147
130- Theorem eq_refl : forall x, eq x x.
131- Proof .
132- destruct x as [aux ?].
133- destruct aux; cbn; try trivial; rewrite String.eqb_refl; reflexivity.
134- Qed .
148+ Theorem eq_refl : forall x, eq x x.
149+ Proof .
150+ intros.
151+ unfold eq.
152+ apply Is_true_eq_left.
153+ apply (id_eqb_refl x).
154+ Qed .
135155
136- Theorem eq_sym : forall x y, eq x y -> eq y x.
137- Proof .
138- destruct x as [x_aux ?].
139- destruct y as [y_aux ?].
140- destruct x_aux as [| | x_s | x_s]; destruct y_aux as [| | y_s | y_s]; cbn; try trivial; rewrite String.eqb_sym; easy.
141- Qed .
156+ Theorem eq_sym : forall x y, eq x y -> eq y x.
157+ Proof .
158+ intros x y H.
159+ unfold eq in *.
160+ apply Is_true_eq_left.
161+ apply Is_true_eq_true in H.
162+ apply (id_eqb_sym x y H).
163+ Qed .
142164
143165 Theorem eq_trans : forall x y z, eq x y -> eq y z -> eq x z.
144166 Proof .
145- destruct x as [x_aux ?].
146- destruct y as [y_aux ?].
147- destruct z as [z_aux ?].
148- destruct x_aux as [| | x_s | x_s]; destruct y_aux as [| | y_s | y_s]; destruct z_aux as [| | z_s | z_s].
149- all: cbn.
150- all: try easy.
151- all: intros A B.
152- all: apply Is_true_eq_left.
153- all: apply Is_true_eq_true in A.
154- all: apply Is_true_eq_true in B.
155- all: rewrite String.eqb_eq in *.
156- all: congruence.
167+ intros x y z H1 H2.
168+ unfold eq in *.
169+ apply Is_true_eq_left.
170+ apply Is_true_eq_true in H1.
171+ apply Is_true_eq_true in H2.
172+ apply (id_eqb_trans x y z H1 H2).
157173 Qed .
158174
159175 Theorem lt_trans : forall x y z, lt x y -> lt y z -> lt x z.
@@ -182,6 +198,7 @@ Module IdMiniOrdered <: OrderedType.MiniOrderedType.
182198 all: apply Is_true_eq_true in A.
183199 all: apply string_ltb_not_eqb in A.
184200 all: apply negb_prop_elim.
201+ all: cbn.
185202 all: rewrite A.
186203 all: reflexivity.
187204 Qed .
@@ -198,15 +215,15 @@ Module IdMiniOrdered <: OrderedType.MiniOrderedType.
198215 - case_eq (String.ltb x_s y_s); intros Hlt.
199216 + apply OrderedType.LT. cbn. rewrite Hlt. reflexivity.
200217 + case_eq (String.eqb x_s y_s); intros Heq.
201- * apply OrderedType.EQ. cbn. rewrite Heq. reflexivity.
218+ * apply OrderedType.EQ. unfold eq. cbn. rewrite Heq. reflexivity.
202219 * apply OrderedType.GT.
203220 cbn.
204221 apply Is_true_eq_left.
205222 apply string_ltb_as_gtb; assumption.
206223 - case_eq (String.ltb x_s y_s); intros Hlt.
207224 + apply OrderedType.LT. cbn. rewrite Hlt. reflexivity.
208225 + case_eq (String.eqb x_s y_s); intros Heq.
209- * apply OrderedType.EQ. cbn. rewrite Heq. reflexivity.
226+ * apply OrderedType.EQ. unfold eq. cbn. rewrite Heq. reflexivity.
210227 * apply OrderedType.GT.
211228 cbn.
212229 apply Is_true_eq_left.
0 commit comments