intros A B m f; induction m; simpl; intros.
destruct x; simpl; auto.
destruct x; destruct o; simpl; auto.
rewrite IHm2; auto.
rewrite IHm2; auto.
rewrite IHm1; auto.
rewrite IHm1; auto.
Qed.
Definition map_fold_index'
(A B:Type)
(f:positive -> A -> B)
(c:B -> B -> B) :
B -> (positive -> positive) -> (map A) -> B :=
fix fold (z:B) (g:positive -> positive) (M:map A) { struct M } : B :=
match M with
| Leaf => z
| Node l None r =>
fold (fold z (fun x => g (xI x)) r) (fun x => g (xO x)) l
| Node l (Some x) r =>
fold (c (f (g xH) x) (fold z (fun x => g (xI x)) r)) (fun x => g (xO x)) l
end.
Definition map_fold_index
(A B:Type)
(f:positive -> A -> B)
(c:B -> B -> B)
(z:B) (M:map A) : B :=
map_fold_index' A B f c z (fun x => x) M.
Section map_fold_index.
Variables A B:Type.
Variable f:positive -> A -> B.
Variable c:B -> B -> B.
Variable u:B.
Hypothesis Hassoc : forall x y z:B,
c x (c y z) = c (c x y) z.
Hypothesis Hunit_left : forall x, c u x = x.

Lemma map_fold_index_lift_z : forall
(m:map A) (g:positive -> positive) (z:B),
map_fold_index' A B f c z g m =
c (map_fold_index' A B f c u g m) z.