def main(): # Test 3-inflatable permutation of length 17 tau = Permutation('2cbdf8419hea3576g') print('Densities in inflation of', tau) for pi in Permutation.of_length(3): print(pi, inflated_density(pi, tau)) # Incorrect example from Cooper & Petrarca tau = Permutation('472951836') print('Densities in inflation of', tau) for pi in Permutation.of_length(3): print(pi, inflated_density(pi, tau))
def test(tau, n): print('Generating permutation...\n') rnd = list(range(n)) random.shuffle(rnd) inf = Permutation(p + x * n for x in tau for p in rnd) print('Computing densities...\n') cnts = inf.occurrence_counts(3) total = sum(count for pattern, count in cnts.most_common()) print('pi Expected Sampled Delta') print('===================================') for pi in Permutation.of_length(3): expected = float(inflated_density(pi, tau)) sampled = cnts[pi] / total deviation = sampled - expected print('{} {:.8f} {:.8f} {:.6f}'.format(pi, expected, sampled, deviation)) print('\nDone!')
def is_inflatable(k, tau): for pi in Permutation.of_length(k): if inflated_density(pi, tau) != Fraction(1, math.factorial(k)): return False return True