Section Forall_XTree.
Variable (P: Z -> Prop).
Fixpoint Forall_XTree (t: XTree): Prop :=
match t with
| XLeaf =>
True
| XNode tl v =>
fold_right and (P v) (map Forall_XTree tl)
end.
End Forall_XTree.
Definition Xnode_add_spec :=
DECLARE _Xnode_add
WITH p: val, t: XTree
PRE  [ _p OF (tptr t_struct_Xnode) ]
PROP  ()
LOCAL (temp _p p)
SEP (xtree_rep t p)
POST [ Tvoid ]
PROP()
LOCAL()
SEP (xtree_rep (x_add1 t) p).
Definition Xfoo_spec :=
DECLARE _Xfoo
WITH p: val, t: XTree
PRE  [ _p OF (tptr t_struct_Xnode) ]
PROP  (Forall_XTree (fun x => x >= 0) t)
LOCAL (temp _p p)
SEP (xtree_rep t p)
POST [ Tvoid ]
EX t': XTree,
PROP(Forall_XTree (fun x => x > 0) t')
LOCAL()
SEP (xtree_rep t' p).
Fixpoint y_add1 (t: YTree): YTree :=
match t with
| YLeaf =>
YLeaf
| YNode tl v =>
let map1 := fun u_t_pair => (tt, y_add1 (snd u_t_pair)) in
let map2 := fun tt_u_pair => (map_tree map1 (fst tt_u_pair), tt) in
let map3 := fun tl => map map2 tl in
YNode (map3 tl) (v + 1)
end.
Definition ty_add1 (t: tree (unit * YTree)) :=
map_tree (fun t => (tt, y_add1 (snd t))) t.
Definition lty_add1 (t: list (tree (unit * YTree) * unit)) :=
map (fun t => (ty_add1 (fst t), tt)) t.

Theorem y_add1_spec: forall t,
y_add1 t =
match t with
| YLeaf =>
YLeaf
| YNode tl v =>
YNode (lty_add1 tl) (v + 1)
end.