Blame view

code/drafts/algebra.py 695 Bytes
808facfe   Francisco Coelho   Main text adapted...
1
2
3
from itertools import combinations, product

def fmt(expr):
20cd616b   Francisco Coelho   restructure folders
4
    """Doc string"""
808facfe   Francisco Coelho   Main text adapted...
5
6
7
    return ",".join(f"{x:>2}" for x in expr)

def c(expr):
20cd616b   Francisco Coelho   restructure folders
8
    """Doc string"""
808facfe   Francisco Coelho   Main text adapted...
9
10
11
12
13
14
15
16
17
18
19
20
    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="¬"):
20cd616b   Francisco Coelho   restructure folders
21
    """Doc string"""
808facfe   Francisco Coelho   Main text adapted...
22
23
24
25
26
27
28
29
30
    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))}")