Require Export List. Export ListNotations.
Local Open Scope Z_scope.
Fixpoint repeat_op_nat{T: Type}(n: nat)(start: T)(op: T -> T): T := match n with
| O => start
| S m => op (repeat_op_nat m start op)
end.
Definition repeat_op{T: Type}(n: Z)(start: T)(op: T -> T): T := repeat_op_nat (Z.to_nat n) start op.
Fixpoint repeat_op_table_nat{T: Type}(n: nat)(start: T)(op: T -> T): list T := match n with
| O => []
| S m => (repeat_op_table_nat m start op) ++ [repeat_op_nat m start op]
end.
Definition repeat_op_table{T: Type}(n: Z)(start: T)(op: T -> T): list T :=
repeat_op_table_nat (Z.to_nat n) start op.

Lemma sublist_repeat_op_table_id: forall {T: Type} (lo n: Z) (v: T),
0 <= lo ->
0 <= n ->
sublist lo (lo + n) (repeat_op_table (lo + n) v id) = repeat_op_table n v id.