-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExp3命题公式的主范式.py
78 lines (67 loc) · 2.34 KB
/
Exp3命题公式的主范式.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Copyright (c) GuanSheng 2022.
import Exp2_Formula as lib1 # 为代码文件夹中的Exp2_Formula文件,用于处理命题公式的库
import InAndOut as IO # 调用IO库,实现布尔输入和转换等
# 主入口点
state = True
while state:
# 获得命题公式对象
formula = lib1.Formula()
# 打印命题变元
print("共有%d个命题变元,分别是" % formula.numProposition)
for c in formula.varList:
print(c, " ", end="")
print("")
# 主范式
# l 记录小项
# b 记录大项
l = []
b = []
for i in range(0, 2 ** formula.numProposition):
res = formula.truthTable[i][formula.truthTable[i].__len__() - 1]
if res:
l.append(i)
else:
b.append(i)
if l.__len__() == 0:
print("主析取范式为空")
else:
print("计算出主析取范式为")
print(formula.inStr)
print("⇔", end=' ')
for elem in l:
print("(", end="")
for var in range(0, formula.numProposition):
if formula.truthTable[elem][var]:
print("!" + formula.varList[var] + "∧", end="")
else:
print(formula.varList[var] + "∧", end="")
print("\b", end="")
print(")∨", end="")
print("\b")
print("⇔", end=' ')
for elem in l:
print("m" + elem.__str__() + "∨", end="")
print("\b")
if b.__len__() == 0:
print("主合取范式为空")
else:
print("计算出主合取范式为")
print(formula.inStr)
print("⇔", end=' ')
for elem in b:
print("(", end="")
for var in range(0, formula.numProposition):
if formula.truthTable[elem][var]:
print("!" + formula.varList[var] + "∨", end="")
else:
print(formula.varList[var] + "∨", end="")
print("\b", end="")
print(")∧", end="")
print("\b")
print("⇔", end=' ')
for elem in b:
print("M" + elem.__str__() + "∧", end="")
print("\b")
state = IO.boolInput("是否要继续,1继续,0结束")
del formula # 删除对象
print("程序结束")