(* remove *)

Definition remove (T: Set) (n: nat) (v: Vector.t T (S n)) (nb: natBelow (S n)): Vector.t T n :=
  natBelow_rect_S
    (fun (n0: nat) (_: natBelow (S n0)) => Vector.t T (S n0) -> Vector.t T n0)
    (fun p => @tail p _)
    (fun v p H v0 => Vector.cons (head v0) (H (tail v0))) nb v.(* permutations *)

Inductive Permutation (A: Type): forall n, Vector.t A n -> Vector.t A n -> Prop :=
  | perm_nil: Permutation Vector.nil Vector.nil
  | perm_skip (x: A) n (v v': Vector.t A n): Permutation v v' -> Permutation (Vector.cons x v) (Vector.cons x v')
  | perm_swap (x y: A) n (l: Vector.t A n): Permutation (Vector.cons y (Vector.cons x l)) (Vector.cons x (Vector.cons y l))
  | perm_trans n (l l' l'': Vector.t A n): Permutation l l' -> Permutation l' l'' -> Permutation l l''.(* permutations *)

Inductive Permutation (A: Type): forall n, Vector.t A n -> Vector.t A n -> Prop :=
  | perm_nil: Permutation Vector.nil Vector.nil
  | perm_skip (x: A) n (v v': Vector.t A n): Permutation v v' -> Permutation (Vector.cons x v) (Vector.cons x v')
  | perm_swap (x y: A) n (l: Vector.t A n): Permutation (Vector.cons y (Vector.cons x l)) (Vector.cons x (Vector.cons y l))
  | perm_trans n (l l' l'': Vector.t A n): Permutation l l' -> Permutation l' l'' -> Permutation l l''.(* permutations *)

Inductive Permutation (A: Type): forall n, Vector.t A n -> Vector.t A n -> Prop :=
  | perm_nil: Permutation Vector.nil Vector.nil
  | perm_skip (x: A) n (v v': Vector.t A n): Permutation v v' -> Permutation (Vector.cons x v) (Vector.cons x v')
  | perm_swap (x y: A) n (l: Vector.t A n): Permutation (Vector.cons y (Vector.cons x l)) (Vector.cons x (Vector.cons y l))
  | perm_trans n (l l' l'': Vector.t A n): Permutation l l' -> Permutation l' l'' -> Permutation l l''.(* permutations *)

Inductive Permutation (A: Type): forall n, Vector.t A n -> Vector.t A n -> Prop :=
  | perm_nil: Permutation Vector.nil Vector.nil
  | perm_skip (x: A) n (v v': Vector.t A n): Permutation v v' -> Permutation (Vector.cons x v) (Vector.cons x v')
  | perm_swap (x y: A) n (l: Vector.t A n): Permutation (Vector.cons y (Vector.cons x l)) (Vector.cons x (Vector.cons y l))
  | perm_trans n (l l' l'': Vector.t A n): Permutation l l' -> Permutation l' l'' -> Permutation l l''.(* permutations *)

Inductive Permutation (A: Type): forall n, Vector.t A n -> Vector.t A n -> Prop :=
  | perm_nil: Permutation Vector.nil Vector.nil
  | perm_skip (x: A) n (v v': Vector.t A n): Permutation v v' -> Permutation (Vector.cons x v) (Vector.cons x v')
  | perm_swap (x y: A) n (l: Vector.t A n): Permutation (Vector.cons y (Vector.cons x l)) (Vector.cons x (Vector.cons y l))
  | perm_trans n (l l' l'': Vector.t A n): Permutation l l' -> Permutation l' l'' -> Permutation l l''.

(* Specifications: *)
Lemma perm_sym (X: Set) n (a b: Vector.t X n): Permutation a b -> Permutation b a.
Lemma perm_refl (X: Set) n (v: Vector.t X n): Permutation v v.
Lemma List_Permutation (X: Set) n (a b: Vector.t X n): Permutation a b -> Permutation.Permutation a b.
Lemma remove_head (T: Set) p (v: Vector.t T (S p)): remove v (mkNatBelow 0 p) = tail v.
Lemma remove_tail (T: Set) n p (v: Vector.t T (S (S (n + p)))): remove v (mkNatBelow (S n) p) = Vector.cons (head v) (remove (tail v) (mkNatBelow n p)).
Lemma in_remove (T: Set) x n (i: natBelow (S n)) (v: Vector.t T (S n)): List.In x v -> x <> nth v i -> List.In x (remove v i).
Lemma remove_map (A B: Set) (f: A -> B) n (i: natBelow (S n)) (v: Vector.t A (S n)): remove (map f v) i = map f (remove v i).
Lemma remove_perm (T: Set) n (nb: natBelow (S n)) (v: Vector.t T (S n)): Permutation (Vector.cons (nth v nb) (remove v nb)) v.
Lemma SkipList_tail (A: Set) n (v: Vector.t A (S n)): SkipList (tail v) v.
Lemma SkipList_remove (A: Set) n (nb: natBelow (S n)) (l: Vector.t A (S n)): SkipList (remove l nb) l.