Skip to content

Instantly share code, notes, and snippets.

@juanplopes
Created November 7, 2017 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juanplopes/1f7d85d9c01e36f71641cd954fe700be to your computer and use it in GitHub Desktop.
Save juanplopes/1f7d85d9c01e36f71641cd954fe700be to your computer and use it in GitHub Desktop.
def cnt(v):
x, y, z, u, w = bool(v&1), bool(v&2), bool(v&4), bool(v&8), bool(v&16)
return ("T" if
(x or y or w) and (z or not w or v) and (not z or not w or not v) and
len(set([x, y, w])) == 2 and
len(set([z, not w, v])) == 2 and
len(set([not z, not w, not v])) == 2
else "F")
"""return ((x or u) + (y or u) + (z or u) + (w or u) +
(x or not u) + (y or not u) + (z or not u) + (w or not u) +
(not x or not y) + (not x or not z) + (not y or not z) +
(x or not w) + (y or not w) + (z or not w))"""
def o(v, b):
return v if b else "\\overline{%s}" % (v,)
for j in range(2**2):
print '&', "$%s \wedge %s$" % (o('u', j&1), o('w', j&2)),
print '\\\\'
print '\\hline'
for i in range(2**3):
print "$" + ' \wedge '.join(o(chr(ord('x') + j), i&(1<<j)) for j in range(3)) + "$",
for j in range(2**2):
print '&', cnt(i|(j<<3)),
print '\\\\'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment