That seems easy enough to solve. Simply record the index and length in pi of the index and length in pi.
See also: Recursion
See also: https://news.ycombinator.com/item?id=48480978#48482218
See also: cofixpoints of co-algebras
check mate