>>> I also noticed that i is int in this function, but n is int64. That >>> seems like an oversight.>> Indeed, that is a bug!
Here is a v2 with hopefully better wording, comments and a fix for the bug you pointed out.
-- Fabien.