| 1 |
Set Implicit Arguments. |
| 2 |
|
| 3 |
Theorem eq_rect_eq_dec : |
| 4 |
forall A:Type, |
| 5 |
(forall x y:A, {x = y} + {x <> y}) -> |
| 6 |
forall (p:A) (Q:A -> Type) (x:Q p) (h:p = p), x = eq_rect p Q x p h. |
| 7 |
Admitted. |
| 8 |
|
| 9 |
Module Nat. |
| 10 |
Include Init.Nat. |
| 11 |
|
| 12 |
Lemma eq_dec : forall n m : nat, {n = m} + {n <> m}. |
| 13 |
Admitted. |
| 14 |
Theorem add_comm : forall n m, n + m = m + n. |
| 15 |
Admitted. |
| 16 |
|
| 17 |
End Nat. |
| 18 |
|
| 19 |
Notation eq_nat_dec := Nat.eq_dec (only parsing). |
| 20 |
|
| 21 |
Theorem eq_rect_nat_double : forall T (a b c : nat) x ab bc, |
| 22 |
eq_rect b T (eq_rect a T x b ab) c bc = eq_rect a T x c (eq_trans ab bc). |
| 23 |
Admitted. |
| 24 |
|
| 25 |
Ltac eq_rect_simpl := |
| 26 |
unfold eq_rec_r; |
| 27 |
change eq_rec with (fun A x (P:_ -> Set) => @eq_rect A x P); |
| 28 |
unfold eq_rect_r; |
| 29 |
repeat rewrite eq_rect_nat_double; |
| 30 |
repeat rewrite <- (eq_rect_eq_dec eq_nat_dec). |
| 31 |
|
| 32 |
Inductive word : nat -> Set := |
| 33 |
| WO : word O |
| 34 |
| WS : bool -> forall n, word n -> word (S n). |
| 35 |
Fixpoint natToWord (sz n : nat) : word sz. |
| 36 |
Admitted. |
| 37 |
|
| 38 |
Definition wzero sz := natToWord sz 0. |
| 39 |
Definition wtl sz (w : word (S sz)) : word sz. |
| 40 |
Admitted. |
| 41 |
|
| 42 |
Fixpoint combine (sz1 : nat) (w : word sz1) : forall sz2, word sz2 -> word (sz1 + sz2) := |
| 43 |
match w in word sz1 return forall sz2, word sz2 -> word (sz1 + sz2) with |
| 44 |
| WO => fun _ w' => w' |
| 45 |
| WS b w' => fun _ w'' => WS b (combine w' w'') |
| 46 |
end. |
| 47 |
Fixpoint split2 (sz1 sz2 : nat) : word (sz1 + sz2) -> word sz2. |
| 48 |
exact (match sz1 with |
| 49 |
| O => fun w => w |
| 50 |
| S sz1' => fun w => split2 sz1' sz2 (wtl w) |
| 51 |
end). |
| 52 |
Defined. |
| 53 |
|
| 54 |
Definition wrshift (sz : nat) (w : word sz) (n : nat) : word sz. |
| 55 |
refine (split2 n sz _). |
| 56 |
rewrite Nat.add_comm. |
| 57 |
exact (combine w (wzero n)). |
| 58 |
Defined. |
| 59 |
|
| 60 |
Theorem combine_n_0 : forall sz1 (w : word sz1) (v : word 0), |
| 61 |
combine w v = eq_rect _ word w _ (plus_n_O sz1). |
| 62 |
Admitted. |
| 63 |
|
| 64 |
Theorem wrshift_0 : forall sz (w : word sz), @wrshift sz w 0 = w. |
| 65 |
Proof. |
| 66 |
intros. |
| 67 |
unfold wrshift. |
| 68 |
simpl. |
| 69 |
rewrite combine_n_0. |
| 70 |
eq_rect_simpl. |
| 71 |
reflexivity. |
| 72 |
Qed. |