, , , Coq, .
-, Coq, Coq.Bool.Bvector, , ... ( ) , , , size = 1).
, - Coq.Bool.Bvector, , ( , ).
:
Require Import Arith Bool Vector.
(** Unsigned Bitvector type *)
Definition bitvector := Vector.t bool.
Definition nil := @Vector.nil bool.
Definition cons := @Vector.cons bool.
Definition bv_low := @Vector.hd bool.
Definition bv_high := @Vector.tl bool.
(** A bitvector is false if zero and true otherwise. *)
Definition bv_test n (v : bitvector n) := Vector.fold_left orb false v.
(** Bitwise operators *)
Definition bv_neg n (v : bitvector n) := Vector.map negb v.
Definition bv_and n (v w : bitvector n) := Vector.map2 andb v w.
Definition bv_or n (v w : bitvector n) := Vector.map2 orb v w.
Definition bv_xor n (v w : bitvector n) := Vector.map2 xorb v w.
(** Shift/Rotate operators *)
(* TODO *)
(** Arithmetic operators *)
(* TODO *)
() :
Lemma map_fusion :
forall {A B C} {g : B -> C} {f : A -> B} {n : nat} (v : Vector.t A n),
Vector.map g (Vector.map f v) = Vector.map (fun x => g (f x)) v.
Proof.
intros A B C g f n v ; induction v.
- reflexivity.
- simpl; f_equal; assumption.
Qed.
Lemma map_id :
forall {A} {n : nat} (v : Vector.t A n), Vector.map (@id A) v = v.
Proof.
intros A n v ; induction v.
- reflexivity.
- simpl; f_equal; assumption.
Qed.
Lemma map_extensional :
forall {A B} {f1 f2 : A -> B}
(feq : forall a, f1 a = f2 a) {n : nat} (v : Vector.t A n),
Vector.map f1 v = Vector.map f2 v.
Proof.
intros A B f1 f2 feq n v ; induction v.
- reflexivity.
- simpl; f_equal; [apply feq | assumption].
Qed.
Theorem double_neg :
forall (n : nat) (v : bitvector n), bv_neg n (bv_neg n v) = v.
Proof.
intros; unfold bv_neg.
rewrite map_fusion, <- map_id.
apply map_extensional.
- intros []; reflexivity.
Qed.
, ( ), .
, , . Coq, .