Section Count.
Variable (X : eqType).
Definition count (n : nat) (x : X) (xs : t X n) :=
fold_right (fun y c => if Dec (x = y) then S c else c) xs 0.
(* (* Test *)
End Count.
Compute let xs := [|1;2;3;4;5;6|] in
let x  := 2 in
let y  := 1 in
let i  := Fin.F1 in
Dec (x = y) + count x xs = Dec (x = xs[@i]) + count x (replace xs i y).
*)

Lemma count_replace (n : nat) (xs : t X n) (x y : X) (i : Fin.t n) :
bool2nat (Dec (x = y)) + count x xs = bool2nat (Dec (x = xs[@i])) + count x (replace xs i y).