(*   Usage:                                             *)
(*     Import NatTrec.                                  *)
(*        in section definining functions, rebinds all  *)
(*        non-tail recursive operators.                 *)
(*     rewrite !trecE.                                  *)
(*        in the correctness proof, restores operators  *)

Fixpoint add m n := if m is m'.+1 then m' + n.+1 else n
where "n + m" := (add n m) : nat_scope.(*   Usage:                                             *)
(*     Import NatTrec.                                  *)
(*        in section definining functions, rebinds all  *)
(*        non-tail recursive operators.                 *)
(*     rewrite !trecE.                                  *)
(*        in the correctness proof, restores operators  *)

Fixpoint add m n := if m is m'.+1 then m' + n.+1 else n
where "n + m" := (add n m) : nat_scope.Fixpoint add_mul m n s := if m is m'.+1 then add_mul m' n (n + s) else s.Definition mul m n := if m is m'.+1 then add_mul m' n n else 0.Fixpoint mul_exp m n p := if n is n'.+1 then mul_exp m n' (m * p) else p.Definition exp m n := if n is n'.+1 then mul_exp m n' m else 1.Local Notation oddn := odd.Fixpoint odd n := if n is n'.+2 then odd n' else eqn n 1.Local Notation doublen := double.Definition double n := if n is n'.+1 then n' + n.+1 else 0.

(* Specifications: *)
Lemma addE : add =2 addn.
Lemma doubleE : double =1 doublen.
Lemma add_mulE n m s : add_mul n m s = addn (muln n m) s.
Lemma mulE : mul =2 muln.
Lemma mul_expE m n p : mul_exp m n p = muln (expn m n) p.
Lemma expE : exp =2 expn.
Lemma oddE : odd =1 oddn.