Timings for Equiv.v
Require Import Spaces.Pos.
Require Import Spaces.BinInt.Core.
Require Import Spaces.BinInt.Spec.
(** ** Iteration of equivalences *)
(** *** Iteration by arbitrary integers *)
Definition binint_iter {A} (f : A -> A) `{!IsEquiv f} (n : BinInt) : 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 binint_iter_succ_l {A} (f : A -> A) `{IsEquiv _ _ f}
(n : BinInt) (a : A)
: binint_iter f (binint_succ n) a = f (binint_iter f n a).
destruct n as [n| |n]; trivial.
refine (ap (fun x => _ x _) _ @ _).
1: rewrite binint_neg_pos_succ.
1: exact (eisretr binint_succ (neg n)).
Definition binint_iter_succ_r {A} (f : A -> A) `{IsEquiv _ _ f}
(n : BinInt) (a : A) : binint_iter f (binint_succ n) a = binint_iter f n (f a).
destruct n as [n| |n]; trivial.
rewrite binint_neg_pos_succ.
refine (ap (fun x => _ x _) _ @ _).
1: exact (eisretr binint_succ (neg n)).
cbn; rewrite pos_add_1_r.
Definition iter_binint_pred_l {A} (f : A -> A) `{IsEquiv _ _ f}
(n : BinInt) (a : A)
: binint_iter f (binint_pred n) a = f^-1 (binint_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 (binint_pred (pos (p + 1)%pos))
with (binint_pred (binint_succ (pos p))).
rewrite binint_pred_succ.
change (pos (p + 1)%pos)
with (binint_succ (pos p)).
rewrite binint_iter_succ_l.
Definition iter_binint_pred_r {A} (f : A -> A) `{IsEquiv _ _ f}
(n : BinInt) (a : A)
: binint_iter f (binint_pred n) a = binint_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 (binint_pred (neg n)).
2: change (pos (n + 1)%pos) with (binint_succ (pos n)).
1: rewrite <- 2 binint_neg_pos_succ.
1: cbn; apply pos_iter_succ_r.
rewrite binint_pred_succ.
rewrite binint_iter_succ_r.