Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

execution is killed for unknown reason

The following code defines a function num_classes(n) and easily computes it for $n=1,2,3,4,5$ in Sage 9.7rc0. However, for $n=6$ its computation after some time is being killed by the system without any apparent reason. I expect that $n=6$ will run some hours, but there is no single reason for it to be killed. In particular, it cannot be a memory issue (unless it's a memory leak of some kind) as the code essentially iterates over elements generated on-fly and saves the smallest ones into the set res. It does not create any big data structures and the set res cannot contain more than $n!$ ($=720$ for $n=6$) elements by design. How to figure out what goes wrong here?

import itertools
def num_classes(n):
    P = PolynomialRing(ZZ,n,'x')
    x = P.gens()

    res = set()
    for s in itertools.product( *(range(k) for k in (2..n)) ):
        f = [x[0],1-x[0]]
        for k,i in enumerate(s):
            f[i:i+1] = [f[i]*x[k+1], f[i]*(1-x[k+1])]
        g = min( sorted(map(lambda z: z.subs(dict(zip(y,t))),f)) for t in itertools.product( *((xi,1-xi) for xi in x) ) for y in Permutations(x) )

        res.add( tuple(g) )

    return len(res)

execution is killed for unknown reason

The following code defines a function num_classes(n) and easily computes it for $n=1,2,3,4,5$ in Sage 9.7rc0. However, for $n=6$ its computation after some time is being killed by the system without any apparent reason. I expect that $n=6$ will run some hours, but there is no single reason for it to be killed. In particular, it cannot be a memory issue (unless it's a memory leak of some kind) as the code essentially iterates over elements generated on-fly and saves the smallest ones into the set res. It does not create any big data structures and the set res cannot contain more than at most $n!$ ($=720$ for $n=6$) elements by design. How to figure out what goes wrong here?

import itertools
def num_classes(n):
    P = PolynomialRing(ZZ,n,'x')
    x = P.gens()

    res = set()
    for s in itertools.product( *(range(k) for k in (2..n)) ):
        f = [x[0],1-x[0]]
        for k,i in enumerate(s):
            f[i:i+1] = [f[i]*x[k+1], f[i]*(1-x[k+1])]
        g = min( sorted(map(lambda z: z.subs(dict(zip(y,t))),f)) for t in itertools.product( *((xi,1-xi) for xi in x) ) for y in Permutations(x) )

        res.add( tuple(g) )

    return len(res)