Timings for Equiv.v
Require Import Spaces.Pos.
Require Import Spaces.Int.Core.
Require Import Spaces.Int.Spec.
(** ** Iteration of equivalences *)
(** *** Iteration by arbitrary integers *)
Definition int_iter {A} (f : A -> A) `{!IsEquiv f} (n : Int) : A -> A
:= match n with
| neg n => fun x => pos_iter f^-1 n x
| zero => idmap
| pos n => fun x => pos_iter f n x
end.
(** Iteration by arbitrary integers requires the endofunction to be an equivalence, so that we can define a negative iteration by using its inverse. *)
Definition int_iter_succ_l {A} (f : A -> A) `{IsEquiv _ _ f}
(n : Int) (a : A)
: int_iter f (int_succ n) a = f (int_iter f n a).
destruct n as [n| |n]; trivial.
refine (ap (fun x => _ x _) _ @ _).
1: rewrite int_neg_pos_succ.
1: exact (eisretr int_succ (neg n)).
Definition int_iter_succ_r {A} (f : A -> A) `{IsEquiv _ _ f}
(n : Int) (a : A) : int_iter f (int_succ n) a = int_iter f n (f a).
destruct n as [n| |n]; trivial.
rewrite int_neg_pos_succ.
refine (ap (fun x => _ x _) _ @ _).
1: exact (eisretr int_succ (neg n)).
cbn; rewrite pos_add_1_r.
Definition iter_int_pred_l {A} (f : A -> A) `{IsEquiv _ _ f}
(n : Int) (a : A)
: int_iter f (int_pred n) a = f^-1 (int_iter f n a).
destruct n as [n| |n]; trivial.
cbn; rewrite pos_add_1_r.
by rewrite pos_iter_succ_l.
cbn; symmetry; apply eissect.
change (int_pred (pos (p + 1)%pos))
with (int_pred (int_succ (pos p))).
change (pos (p + 1)%pos)
with (int_succ (pos p)).
Definition iter_int_pred_r {A} (f : A -> A) `{IsEquiv _ _ f}
(n : Int) (a : A)
: int_iter f (int_pred n) a = int_iter f n (f^-1 a).
destruct n as [n| |n]; trivial;
induction n as [|n nH] using pos_peano_ind; trivial.
2: hnf; intros; apply symmetry, eisretr.
all: rewrite <- pos_add_1_r.
1: change (neg (n + 1)%pos) with (int_pred (neg n)).
2: change (pos (n + 1)%pos) with (int_succ (pos n)).
1: rewrite <- 2 int_neg_pos_succ.
1: cbn; apply pos_iter_succ_r.