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 split_wf' : forall keys children i c (Hc : nth_error children i = Some c) (Hover : wf_btree_over c) (Hrest : Forall wf_btree_aux (remove_at i children)) (Hkeys : (length keys <= 2 * d)%nat) (Hchildren : length children = S (length keys)), wf_btree (split (BNode keys children) i) \/ wf_btree_over (split (BNode keys children) i).