Definition naive_sch : forall (n : Z) (t : Z_btree), {occ n t} + {~ occ n t}.(*
let rec naive_sch n = function
  Z_leaf -> right
| Z_bnode (z1, z0, z) ->
    (match Z_eq_dec n z1 with
       left -> left
     | right ->
         (match naive_sch n z0 with
            left -> left
          | right -> naive_sch n z))
*)




Inductive min (z : Z) (t : Z_btree) : Prop :=
    min_intro : (forall z' : Z, occ z' t -> (z < z')%Z) -> min z t.(*
let rec naive_sch n = function
  Z_leaf -> right
| Z_bnode (z1, z0, z) ->
    (match Z_eq_dec n z1 with
       left -> left
     | right ->
         (match naive_sch n z0 with
            left -> left
          | right -> naive_sch n z))
*)




Inductive min (z : Z) (t : Z_btree) : Prop :=
    min_intro : (forall z' : Z, occ z' t -> (z < z')%Z) -> min z t.(* p is greater than every member of t *)

Inductive maj (z : Z) (t : Z_btree) : Prop :=
    maj_intro : (forall z' : Z, occ z' t -> (z' < z)%Z) -> maj z t.(* p is greater than every member of t *)

Inductive maj (z : Z) (t : Z_btree) : Prop :=
    maj_intro : (forall z' : Z, occ z' t -> (z' < z)%Z) -> maj z t.Inductive search : Z_btree -> Prop :=
  | leaf_search : search Z_leaf
  | bnode_search :
      forall (z : Z) (t1 t2 : Z_btree),
      search t1 ->
      search t2 -> maj z t1 -> min z t2 -> search (Z_bnode z t1 t2).Inductive search : Z_btree -> Prop :=
  | leaf_search : search Z_leaf
  | bnode_search :
      forall (z : Z) (t1 t2 : Z_btree),
      search t1 ->
      search t2 -> maj z t1 -> min z t2 -> search (Z_bnode z t1 t2).Inductive search : Z_btree -> Prop :=
  | leaf_search : search Z_leaf
  | bnode_search :
      forall (z : Z) (t1 t2 : Z_btree),
      search t1 ->
      search t2 -> maj z t1 -> min z t2 -> search (Z_bnode z t1 t2).

(* Specifications: *)
Lemma min_leaf : forall z : Z, min z Z_leaf.
Lemma maj_leaf : forall z : Z, maj z Z_leaf.
Lemma maj_not_occ : forall (z : Z) (t : Z_btree), maj z t -> ~ occ z t.
Lemma min_not_occ : forall (z : Z) (t : Z_btree), min z t -> ~ occ z t.
Lemma search_l : search t1.
Lemma search_r : search t2.
Lemma maj_l : maj n t1.
Lemma min_r : min n t2.
Lemma not_right : forall p : Z, (p <= n)%Z -> ~ occ p t2.
Lemma not_left : forall p : Z, (p >= n)%Z -> ~ occ p t1.
Lemma go_left : forall p : Z, occ p (Z_bnode n t1 t2) -> (p < n)%Z -> occ p t1.
Lemma go_right : forall p : Z, occ p (Z_bnode n t1 t2) -> (p > n)%Z -> occ p t2.