Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

rational numbers with cython

I want to work efficiently with rational numbers under the context %cython but I don`t know how. Can anyone suggest any ideas? Thank you.

rational numbers with cython

I want to work efficiently with rational numbers under the context %cython but I don`t know how. Can anyone suggest any ideas? Thank you.

An example:

  %cython

    def rational_partitions(n):
        sol = [i/n for i in range(n)]
        for a in sol[0:-1]:
            for b in sol[1:]:
                k=2
                while abs(b-a)/k>1/n:
                    sol.append(abs(b-a)/k)
                    k += 1
        return sol

rational_partitions(10)