(* The definitions and other results of age_by and age_to should be moved here from msl/ageable.v.  Alternatively, this can be moved to msl/ageable.v (or this file to msl/) eventually, but we keep it here for now to reduce compilation time. *)
(* Apply [age1] n times (meaningful when [n <= level x] *)
Definition age1' {A} `{agA : ageable A} : A -> A :=
fun x => match age1 x with Some y => y | None => x end.
Definition age_by n {A} `{agA : ageable A} : A -> A := Nat.iter n age1'.
(* Age [x] to the level [k] (meaningul when [k <= level x] *)
Definition age_to k {A} `{agA : ageable A} (x : A) : A := age_by (level x - k) x.
Fixpoint composeOptN' {A} (f : A -> option A) n x :=
match n with
| 0 => Some x
| S n =>
match composeOptN' f n x with
| Some y => f y
| None => None
end
end.

Lemma composeOptN_assoc_aux_None {A} (f : A -> option A) n x :
f x = None ->
match composeOptN f n x with
| Some x => f x
| None => None
end = None.