习题2-5(1)
#求主析取范式,并求其成真赋值 习题2-5-1
def imp(p,q):#implication蕴涵联结词
return (not p) or q
form=[]
value=[]
for p in range(2):
for q in range(2):
result=imp(imp(not p,q),(not q) or p)#需要证明的命题
if result==1:
form.append("m{}".format(int(str(p)+str(q),2)))
value.append("{}".format(str(p)+str(q)))
print("所有极小项为:{}".format(form))
if(len(form)==0):
print("该式为矛盾式")
elif(len(form)==4):
print("该式为重言式")
if(len(form)!=0):
print("该式为可满足式")
form_final=' or '.join(form)
print("主析取范式为:{}".format(form_final))
print( "成真赋值为:{}".format(value))
- 运行结果为: