Last active
December 5, 2019 21:05
-
-
Save sir-wabbit/207e5e58eb95ed40985b8782b031eaae to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import * | |
# Compute our D(pi) function | |
elements = {} | |
for p in permutations([1,2,3,4]): | |
d = [i+1 for i in range(3) if p[i] > p[i + 1]] | |
elements[p] = frozenset(d) | |
# Make a graph with the given pi < tau relation. | |
graph = {} | |
for p1 in elements.keys(): | |
for p2 in elements.keys(): | |
d1 = elements[p1] | |
d2 = elements[p2] | |
graph[(p1, p2)] = d1.issubset(d2) and d1 != d2 | |
print(sum(x for x in graph.values())) | |
# Remove all edges that follow from transitivity. | |
for p1 in elements.keys(): | |
for p2 in elements.keys(): | |
for p3 in elements.keys(): | |
if p1 == p2 or p2 == p3 or p3 == p1: | |
continue | |
if graph[(p1, p2)] and graph[(p2, p3)] and graph[(p1, p3)]: | |
graph[(p1, p3)] = False | |
print(sum(x for x in graph.values())) | |
# Remove all self-edges (shouldn't be any to begin with) | |
for p1 in elements.keys(): | |
graph[(p1, p1)] = False | |
print(sum(x for x in graph.values())) | |
# Plot the graph | |
print("digraph {") | |
for (p1, p2), f in graph.items(): | |
if not f: continue | |
p1 = ''.join(str(x) for x in p1) | |
p2 = ''.join(str(x) for x in p2) | |
print('"%s" -> "%s"' % (p1, p2)) | |
print("}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment