#!/usr/bin/env python2 from numpy import arange def str_of_is(t): i, s = t l = map(str, i) if s == 1: s = "0" else: s = "1" l.append(s) return ', '.join(l) # permutations of 3 indexes and their sign p3 = [([0, 1, 2],1), ([0, 2, 1], -1), ([1, 0, 2], -1), ([1, 2, 0], 1), ([2, 0, 1], 1), ([2, 1, 0], -1)] def regge_index_permutations(): a = arange(9).reshape(3,3) for pc, sc in p3: for pr, sr in p3: s = sr * sc m = a[:,pc] m = m[pr,:] yield (m.reshape(9),s) m = a.transpose()[:,pc] m = m[pr,:] yield (m.reshape(9),s) src = '''/* automatically generated */ extern int regge3j_index_permutations_table [720] = { ''' + ",\n".join(map(str_of_is, regge_index_permutations())) + '\n};' print src