Variable State : Type.
Variable f : State -> ad -> A -> State * M.
Fixpoint MapFold1_state (state:State) (pf:ad -> ad)
(m:Map A) {struct m} : State * M :=
match m with
| M0 => (state, neutral)
| M1 a y => f state (pf a) y
| M2 m1 m2 =>
match MapFold1_state state (fun a0:ad => pf (Ndouble a0)) m1 with
| (state1, x1) =>
match
MapFold1_state state1
(fun a0:ad => pf (Ndouble_plus_one a0)) m2
with
| (state2, x2) => (state2, op x1 x2)
end
end
end.
Definition MapFold_state (state:State) :=
MapFold1_state state (fun a:ad => a).

(* Specifications: *)
Lemma pair_sp : forall (B C:Type) (x:B * C), x = (fst x, snd x).
Lemma MapFold_state_stateless_1 :
forall (m:Map A) (g:ad -> A -> M) (pf:ad -> ad),
(forall (state:State) (a:ad) (y:A), snd (f state a y) = g a y) ->
forall state:State, snd (MapFold1_state state pf m) = MapFold1 g pf m.
Lemma MapFold_state_stateless :
forall g:ad -> A -> M,
(forall (state:State) (a:ad) (y:A), snd (f state a y) = g a y) ->
forall (state:State) (m:Map A),
snd (MapFold_state state m) = MapFold g m.