(** ** Square *)

(* Specifications: *)
Lemma square_xO p : p~0 * p~0 = (p*p)~0~0.
Lemma square_xI p : p~1 * p~1 = (p*p+p)~0~1.
(** ** Properties of [iter] *)
Lemma iter_swap_gen A B (f:A->B)(g:A->A)(h:B->B) :
(forall a, f (g a) = h (f a)) -> forall p a,
f (iter g a p) = iter h (f a) p.
Theorem iter_swap :
forall p (A:Type) (f:A -> A) (x:A),
iter f (f x) p = f (iter f x p).
Theorem iter_succ :
forall p (A:Type) (f:A -> A) (x:A),
iter f x (succ p) = f (iter f x p).
Theorem iter_succ_r :
forall p (A:Type) (f:A -> A) (x:A),
iter f x (succ p) = iter f (f x) p.
Theorem iter_add :
forall p q (A:Type) (f:A -> A) (x:A),
iter f x (p+q) = iter f (iter f x q) p.
Theorem iter_ind (A:Type) (f:A -> A) (a:A) (P:positive -> A -> Prop) :
P 1 (f a) ->
(forall p a', P p a' -> P (succ p) (f a')) ->
forall p, P p (iter f a p).
Theorem iter_invariant :
forall (p:positive) (A:Type) (f:A -> A) (Inv:A -> Prop),
(forall x:A, Inv x -> Inv (f x)) ->
forall x:A, Inv x -> Inv (iter f x p).