val count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s))
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
  : Tot nat (decreases (length s))
  = all_seq_facts_lemma();
    if length s = 0 then 0
    else if f (head s) then 1 + count_matches f (tail s)
    else count_matches f (tail s)
val count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s))
let rec count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s)) =
all_seq_facts_lemma ();
if length s = 0
then 0
else if f (head s) then 1 + count_matches f (tail s) else count_matches f (tail s)
FStar.Sequence.Util.fst.checked
prims.fst.checked FStar.Sequence.Base.fsti.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked
FStar.Sequence.Util.fst
Prims.bool FStar.Sequence.Base.seq Prims.op_Equality Prims.int FStar.Sequence.Base.length FStar.Sequence.Util.head Prims.op_Addition FStar.Sequence.Util.count_matches FStar.Sequence.Util.tail Prims.nat Prims.unit FStar.Sequence.Base.all_seq_facts_lemma
(*
   Copyright 2021 Microsoft Research

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   Author: N. Swamy
*)

(** This module provides some utilities on top of FStar.Sequence *)
module FStar.Sequence.Util
open FStar.Sequence.Base


/// For convenience, we define `slice` to represent Dafny sequence slices.
let slice (#ty: Type) (s: seq ty) (i: nat) (j: nat{j >= i && j <= length s})
  : seq ty
  = all_seq_facts_lemma();
    drop (take s j) i

let cons #a (x:a) (s:seq a) = singleton x `append` s

let head #a (s:seq a{length s > 0}) = s $@ 0

let tail #a (s:seq a{length s > 0}) = drop s 1

/// Split a sequences into a prefix and the last element
/// This is the inverse of the Sequence.build
let un_build (#a:_) (s:seq a{length s > 0})
  : seq a & a
  = take s (length s - 1),
    s $@ (length s - 1)

let split #a (s:seq a) (i:nat{ i <= length s})
  : seq a & seq a
  = take s i,
    drop s i

/// Counts the number of elements of `s` that
/// satisfy the predicate [f]
let rec count_matches (#a:Type) (f:a -> bool) (s:seq a)
val count_matches (#a: Type) (f: (a -> bool)) (s: seq a) : Tot nat (decreases (length s))
f: (_: a -> Prims.bool) -> s: FStar.Sequence.Base.seq a -> Prims.Tot Prims.nat