(*******************************************************************)


Inductive lin_del_spec (key : Int) (d : B) (t0 t : avl_tree) : Prop :=
    Lin_Del_Spec_Intro :
      forall l0 l1 : list (Int * B),
      lin_avl t0 = l0 ++ (key, d) :: l1 ->
      lin_avl t = l0 ++ l1 -> lin_del_spec key d t0 t.(*******************************************************************)


Inductive lin_del_spec (key : Int) (d : B) (t0 t : avl_tree) : Prop :=
    Lin_Del_Spec_Intro :
      forall l0 l1 : list (Int * B),
      lin_avl t0 = l0 ++ (key, d) :: l1 ->
      lin_avl t = l0 ++ l1 -> lin_del_spec key d t0 t.Inductive delete_spec (key : Int) (t0 : avl_tree) : Set :=
    Delete_Spec_Intro :
      forall t : avl_tree,
      lookup_dec_spec key t0 ->
      is_avl t ->
      (forall d : B, lookup key t0 d -> lin_del_spec key d t0 t) ->
      equiv_del key t0 t ->
      {height_avl t0 = height_avl t} + {height_avl t0 = S (height_avl t)} ->
      delete_spec key t0.Inductive delete_spec (key : Int) (t0 : avl_tree) : Set :=
    Delete_Spec_Intro :
      forall t : avl_tree,
      lookup_dec_spec key t0 ->
      is_avl t ->
      (forall d : B, lookup key t0 d -> lin_del_spec key d t0 t) ->
      equiv_del key t0 t ->
      {height_avl t0 = height_avl t} + {height_avl t0 = S (height_avl t)} ->
      delete_spec key t0.

(* Specifications: *)
Lemma equiv_del_nil : forall key : Int, equiv_del key Avl_Nil Avl_Nil.
Lemma equiv_del_right_semi_leave : forall (k : Int) (d : B) (r : avl_tree) (b : bal), is_avl (Avl_Node k d Avl_Nil r b) -> equiv_del k (Avl_Node k d Avl_Nil r b) r.
Lemma equiv_del_equal : forall (key k0 k : Int) (l0 l r0 : avl_tree) (b0 : bal) (d d0 : B), Equal key k0 -> equiv_del k l0 l -> lookup k l0 d -> is_below l0 k0 -> is_above r0 k0 -> is_avl l0 -> equiv_del key (Avl_Node k0 d0 l0 r0 b0) (Avl_Node k d l r0 b0).
Lemma is_balanced_avl_is_balanced_avl_right_shift_left : forall (l l0 r0 : avl_tree) (b0 : bal), is_balanced_avl l0 r0 b0 -> S (height_avl l) = height_avl l0 -> is_balanced_avl_right_shift l r0 b0.
Lemma is_balanced_is_balanced_right_shift : forall (l l0 r0 : avl_tree) (b0 : bal), is_balanced_avl l0 r0 b0 -> height_avl l0 = S (height_avl l) -> is_balanced_avl_right_shift l r0 b0.
Lemma equiv_del_trans_left : forall (k k0 : Int) (d0 : B) (l0 r0 l : avl_tree) (b0 : bal), Less k k0 -> is_above r0 k0 -> equiv_del k l0 l -> equiv_del k (Avl_Node k0 d0 l0 r0 b0) (Avl_Node k0 d0 l r0 b0).
Lemma equiv_del_trans_right : forall (k k0 : Int) (d0 : B) (l0 r r0 : avl_tree) (b0 : bal), Less k0 k -> is_below l0 k0 -> equiv_del k r0 r -> equiv_del k (Avl_Node k0 d0 l0 r0 b0) (Avl_Node k0 d0 l0 r b0).
Lemma delete_avl : forall (key : Int) (t0 : avl_tree), is_avl t0 -> delete_spec key t0.