def n_to_i(num, n):
    """
    Translate num, ranging from
    -(n-1)/2 through (n-1)/2
    into an index i from 0 to n-1

    If num > (n-1)/2, map it into the interval

    This is necessary to translate from a physical
    Fourier mode number to an index in an array.
    """
    cutoff = (n-1)/2
    if num > cutoff:
        return (num % n)-n+cutoff
    if num < -cutoff:
        return -(-num % n)+n+cutoff
    else:
        return num+cutoff


def i_to_n(i, n):
    """
    Translate index i, ranging from 0 to n-1
    into a number from -(n-1)/2 through (n-1)/2

    This is necessary to translate from an index to a physical
    Fourier mode number.
    """
    cutoff = (n-1)/2
    return i-cutoff

@@ -302,152 +302,31 @@
     
-if num %3E cutoff:%0A        return (num %25 n)-n+cutoff%0A    if num %3C -cutoff:%0A        return -(-num %25 n)+n+cutoff%0A    else:%0A        return num+cutoff
+return (num+cutoff) %25 n
 %0A%0A%0Ad

Implement rollover correctly and a lot more concisely