Parameter d : nat.(* could use bin_search here instead *)

  Inductive find_result := Found (i : nat) | NotFound (i : nat).(* could use bin_search here instead *)

  Inductive find_result := Found (i : nat) | NotFound (i : nat).(* could use bin_search here instead *)

  Inductive find_result := Found (i : nat) | NotFound (i : nat).Definition search tgt t := match find_path tgt t with Some _ => true | None => false end.Definition replace {A} i (x : A) l := firstn i l ++ x :: skipn (S i) l.Definition split parent i :=
    match parent with BNode keys children =>
      match nth_error children i with
      | Some (BNode keys' children') =>
        let mid := (length keys' / 2)%nat in
        BNode (insert i (nth mid keys' 0) keys)
              (insert i (BNode (firstn mid keys') (firstn (S mid) children'))
              (replace i (BNode (skipn (S mid) keys') (skipn (S mid) children')) children))
      | None => parent
      end
    end.Definition remove_at {A} i (l : list A) := firstn i l ++ skipn (S i) l.Definition delete tgt t := option_map (delete_at t) (find_path tgt t).

Lemma Forall_firstn : forall {A} P (l : list A) n, Forall P l -> Forall P (firstn n l).