|
29 | 29 | From Coq Require Import
|
30 | 30 | Bool.Bool
|
31 | 31 | Strings.String
|
| 32 | + Arith.PeanoNat |
32 | 33 | ZArith.BinInt.
|
33 | 34 | From Equations Require Import
|
34 | 35 | Equations.
|
@@ -80,6 +81,7 @@ Module bop.
|
80 | 81 | | bvxor {n} : BinOp (bvec n) (bvec n) (bvec n)
|
81 | 82 | | bvapp {m n} : BinOp (bvec m) (bvec n) (bvec (m + n))
|
82 | 83 | | bvcons {m} : BinOp (bool) (bvec m) (bvec (S m))
|
| 84 | + | update_vector_subrange {n} (s l : nat) {p : IsTrue (s + l <=? n)} : BinOp (bvec n) (bvec l) (bvec n) |
83 | 85 | | relop {σ} (r : RelOp σ) : BinOp σ σ bool
|
84 | 86 | .
|
85 | 87 | Set Transparent Obligations.
|
@@ -153,6 +155,22 @@ Module bop.
|
153 | 155 | n (noConfusion_inv e))
|
154 | 156 | end.
|
155 | 157 |
|
| 158 | + Obligation Tactic := cbn; intros; |
| 159 | + try solve |
| 160 | + [let e := fresh in intro e; depelim e; try easy; |
| 161 | + try progress cbn in * |-; congruence |
| 162 | + |subst; repeat f_equal; apply IsTrue.proof_irrelevance |
| 163 | + ]. |
| 164 | + |
| 165 | + #[derive(equations=no)] Equations update_vector_subrange_eq_dec (n1 n2 s1 s2 l1 l2 : nat) (p1 : IsTrue (s1 + l1 <=? n1)) (p2 : IsTrue (s2 + l2 <=? n2)) : |
| 166 | + dec_eq (A := BinOpTel) ((bvec n1, bvec l1, bvec n1),update_vector_subrange s1 l1) ((bvec n2, bvec l2, bvec n2),update_vector_subrange s2 l2) := |
| 167 | + | n1 | n2 | s1 | s2 | l1 | l2 | p1 | p2 with eq_dec n1 n2, eq_dec s1 s2, eq_dec l1 l2 => { |
| 168 | + | left _ | left _ | left _ => left _ |
| 169 | + | right _ | _ | _ => right _ |
| 170 | + | _ | right _ | _ => right _ |
| 171 | + | _ | _ | right _ => right _ |
| 172 | + }. |
| 173 | + |
156 | 174 | Definition binoptel_eq_dec {σ1 σ2 σ3 τ1 τ2 τ3 : Ty}
|
157 | 175 | (op1 : BinOp σ1 σ2 σ3) (op2 : BinOp τ1 τ2 τ3) :
|
158 | 176 | dec_eq (A := BinOpTel) ((σ1,σ2,σ3),op1) ((τ1,τ2,τ3),op2) :=
|
@@ -206,6 +224,13 @@ Module bop.
|
206 | 224 | f_equal_dec
|
207 | 225 | (fun n => ((bool, bvec n, bvec (S n)), bvcons))
|
208 | 226 | (ninv _ _) (eq_dec m n)
|
| 227 | + | @update_vector_subrange n1 s1 l1 p1, @update_vector_subrange n2 s2 l2 p2 => |
| 228 | + update_vector_subrange_eq_dec n1 n2 s1 s2 l1 l2 p1 p2 |
| 229 | + (* f_equal3_dec |
| 230 | + (fun n s l => |
| 231 | + ((bvec n, bvec l, bvec n), @update_vector_subrange n s l _)) |
| 232 | + (ninv ((bvec n1, bvec l1, bvec n1), @update_vector_subrange n1 s1 l1 p1) ((bvec n2, bvec l2, bvec n2), @update_vector_subrange n2 s2 l2 p2)) |
| 233 | + (eq_dec n1 n2) (eq_dec s1 s2) (eq_dec l1 l2) *) |
209 | 234 | | @relop σ op1 , @relop τ op2 =>
|
210 | 235 | binoptel_eq_dec_relop op1 op2
|
211 | 236 | | _ , _ => right (ninv _ _)
|
@@ -280,26 +305,27 @@ Module bop.
|
280 | 305 |
|
281 | 306 | Definition eval {σ1 σ2 σ3 : Ty} (op : BinOp σ1 σ2 σ3) : Val σ1 -> Val σ2 -> Val σ3 :=
|
282 | 307 | match op in BinOp σ1 σ2 σ3 return Val σ1 -> Val σ2 -> Val σ3 with
|
283 |
| - | plus => Z.add |
284 |
| - | times => Z.mul |
285 |
| - | minus => Z.sub |
286 |
| - | land => Z.land |
287 |
| - | and => andb |
288 |
| - | or => fun v1 v2 => orb v1 v2 |
289 |
| - | pair => Datatypes.pair |
290 |
| - | cons => List.cons |
291 |
| - | shiftr => fun v1 v2 => bv.shiftr v1 v2 |
292 |
| - | shiftl => fun v1 v2 => bv.shiftl v1 v2 |
293 |
| - | append => app |
294 |
| - | bvadd => fun v1 v2 => bv.add v1 v2 |
295 |
| - | bvsub => fun v1 v2 => bv.sub v1 v2 |
296 |
| - | bvmul => fun v1 v2 => bv.mul v1 v2 |
297 |
| - | bvand => fun v1 v2 => bv.land v1 v2 |
298 |
| - | bvor => fun v1 v2 => bv.lor v1 v2 |
299 |
| - | bvxor => fun v1 v2 => bv.lxor v1 v2 |
300 |
| - | bvapp => fun v1 v2 => bv.app v1 v2 |
301 |
| - | bvcons => fun b bs => bv.cons b bs |
302 |
| - | relop op => eval_relop_val op |
| 308 | + | plus => Z.add |
| 309 | + | times => Z.mul |
| 310 | + | minus => Z.sub |
| 311 | + | land => Z.land |
| 312 | + | and => andb |
| 313 | + | or => fun v1 v2 => orb v1 v2 |
| 314 | + | pair => Datatypes.pair |
| 315 | + | cons => List.cons |
| 316 | + | shiftr => fun v1 v2 => bv.shiftr v1 v2 |
| 317 | + | shiftl => fun v1 v2 => bv.shiftl v1 v2 |
| 318 | + | append => app |
| 319 | + | bvadd => fun v1 v2 => bv.add v1 v2 |
| 320 | + | bvsub => fun v1 v2 => bv.sub v1 v2 |
| 321 | + | bvmul => fun v1 v2 => bv.mul v1 v2 |
| 322 | + | bvand => fun v1 v2 => bv.land v1 v2 |
| 323 | + | bvor => fun v1 v2 => bv.lor v1 v2 |
| 324 | + | bvxor => fun v1 v2 => bv.lxor v1 v2 |
| 325 | + | bvapp => fun v1 v2 => bv.app v1 v2 |
| 326 | + | bvcons => fun b bs => bv.cons b bs |
| 327 | + | update_vector_subrange s l => fun v1 v2 => bv.update_vector_subrange s l v1 v2 |
| 328 | + | relop op => eval_relop_val op |
303 | 329 | end.
|
304 | 330 |
|
305 | 331 | End WithTypes.
|
|
0 commit comments