Fixpoint mask m s {struct m} :=
  match m, s with
  | b :: m', x :: s' => if b then x :: mask m' s' else mask m' s'
  | _, _ => [::]
  end.

(* Specifications: *)
Lemma mask_false s n : mask (nseq n false) s = [::].
Lemma mask_true s n : size s <= n -> mask (nseq n true) s = s.
Lemma mask0 m : mask m [::] = [::].
Lemma mask1 b x : mask [:: b] [:: x] = nseq b x.
Lemma mask_cons b m x s : mask (b :: m) (x :: s) = nseq b x ++ mask m s.
Lemma size_mask m s : size m = size s -> size (mask m s) = count id m.
Lemma mask_cat m1 m2 s1 s2 : size m1 = size s1 -> mask (m1 ++ m2) (s1 ++ s2) = mask m1 s1 ++ mask m2 s2.
Lemma has_mask_cons a b m x s : has a (mask (b :: m) (x :: s)) = b && a x || has a (mask m s).
Lemma has_mask a m s : has a (mask m s) -> has a s.
Lemma mask_rot m s : size m = size s -> mask (rot n0 m) (rot n0 s) = rot (count id (take n0 m)) (mask m s).
Lemma resize_mask m s : {m1 | size m1 = size s & mask m s = mask m1 s}.
Lemma mask_uniq s : uniq s -> forall m, uniq (mask m s).
Lemma mem_mask_rot m s : size m = size s -> mask (rot n0 m) (rot n0 s) =i mask m s.
Lemma sub0seq s : subseq [::] s.
Lemma subseqP s1 s2 : reflect (exists2 m, size m = size s2 & s1 = mask m s2) (subseq s1 s2).
Lemma mask_subseq m s : subseq (mask m s) s.
Lemma subseq_trans : transitive subseq.
Lemma subseq_refl s : subseq s s.
Lemma cat_subseq s1 s2 s3 s4 : subseq s1 s3 -> subseq s2 s4 -> subseq (s1 ++ s2) (s3 ++ s4).
Lemma prefix_subseq s1 s2 : subseq s1 (s1 ++ s2).
Lemma suffix_subseq s1 s2 : subseq s2 (s1 ++ s2).
Lemma take_subseq s i : subseq (take i s) s.
Lemma drop_subseq s i : subseq (drop i s) s.
Lemma mem_subseq s1 s2 : subseq s1 s2 -> {subset s1 <= s2}.
Lemma size_subseq s1 s2 : subseq s1 s2 -> size s1 <= size s2.
Lemma subseq_cons s x : subseq s (x :: s).
Lemma subseq_rcons s x : subseq s (rcons s x).
Lemma subseq_uniq s1 s2 : subseq s1 s2 -> uniq s2 -> uniq s1.
Lemma rem_subseq s : subseq (rem s) s.
Lemma rem_uniq s : uniq s -> uniq (rem s).
Lemma mem_rem s : {subset rem s <= s}.
Lemma rem_filter s : uniq s -> rem s = filter (predC1 x) s.