Skip to content

Commit

Permalink
Reverse function for Vect
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkurze1 committed Oct 25, 2024
1 parent 7d1f447 commit def19ca
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions coq/Vect.v
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ Fixpoint vect_truncate_left {T sz} n (v: vect T (n + sz)) : vect T sz :=
| S n => fun v => vect_truncate_left n (vect_tl v)
end v.

(* Push element to the tail of the vector
*
* Basically a cons at the tail (snoc is cons spelled backwards)
*)
Fixpoint vect_snoc {T sz} (t: T) (v: vect T sz) : vect T (S sz) :=
match sz return vect T sz -> vect T (S sz) with
| O => fun v => vect_cons t vect_nil
Expand All @@ -393,6 +397,14 @@ Fixpoint vect_unsnoc {T sz} (v: vect T (S sz)) : T * vect T sz :=
(t, vect_cons (vect_hd v) v')
end v.

(* reverse vector *)
Fixpoint vect_rev {T} {sz} (v : vect T sz) : vect T sz :=
match sz as n return (vect T n -> vect T n) with
| 0 => fun _ => vect_nil
| S sz' => fun v' =>
vect_snoc (vect_hd v') (vect_rev (vect_tl v'))
end v.

Definition vect_cycle_l1 {T sz} (v: vect T sz) :=
match sz return vect T sz -> vect T sz with
| O => fun v => v
Expand Down Expand Up @@ -969,6 +981,7 @@ Module Bits.
Notation bits := (vect bool).
Notation nil := (@vect_nil bool).
Notation cons := (@vect_cons bool).
Notation snoc := (@vect_snoc bool).
Notation const := (@vect_const bool).
Notation app := (fun x y => @vect_app bool _ _ y x). (* !! *)
Notation repeat := (@vect_repeat bool).
Expand All @@ -986,6 +999,7 @@ Module Bits.
Notation ones n := (@const n true).
Notation lsb := (@vect_hd_default bool _ false).
Notation msb := (@vect_last_default bool _ false).
Notation rev := (@vect_rev bool).

Fixpoint rmul n m :=
match n with
Expand Down

0 comments on commit def19ca

Please sign in to comment.