algebra.py
632 Bytes
from itertools import combinations, product
def fmt(expr):
return ",".join(f"{x:>2}" for x in expr)
def c(expr):
def litcomp(x):
if x == "⊤":
return "⊥"
elif x == "⊥":
return "⊤"
elif x[0] == "¬":
return x[1:]
else:
return f"¬{x}"
return [litcomp(x) for x in expr]
def domain(symbols, unary="¬"):
atoms = list(symbols)
literals = [
[f"{u}{a}" for u in unary] +
[a, "⊤", "⊥"] for a in atoms ]
return product(*literals)
d = sorted(domain("abc"))
for x in d:
print(f"{fmt(x)} | {fmt(c(x))}")