命题逻辑推理
(1)实现命题逻辑的语法检查功能:合式公式的判定
(2)判断命题公式是否可满足;
(3)判断命题公式的蕴含关系是否成立。
参考链接:C语言中缀表达式转后缀表达式
离散数学判断合式公式,并打印真值表、求主析取、主合取范式
#include<iostream>
#include<stdio.h>
#include <set>
#include <map>
#include <windows.h>
#include <stack>
using namespace std;
stack<char> s3;//栈s3存储后缀表达式
map<char, bool>ch;//映射表示原子命题真假
set<char>sh;//统计原子命题
//定义联结词优先次序
//case '!':return 5; break;
//case '&':return 4; break;
//case '|':return 3; break;
//case '-':return 2; break;
//case '=':return 1; break;
int Compare(char str1) {
if (str1 == '!') {
return 5;
}
else if (str1 == '&') {
return 4;
}
else if (str1 == '|') {
return 3;
}
else if (str1 == '-') {
return 2;
}
else if (str1 == '=') {
return 1;
}
else if (str1 == '(' || str1 == ')') {
return 0;
}
else {
return -1; //字母或者数字
}
}
bool Fouding(bool a)//否定运算
{
if (a)return false;
else return true;
}
bool And(bool a, bool b)//合取
{
if (!a || !b)return false;
else return true;
}
bool Or(bool a, bool b)//析取
{
if (a || b)return true;
else return false;
}
bool One(bool a, bool b)//条件
{
if (a && !b)return false;
else return true;
}
bool Two(bool a, bool b)//双条件
{
if (a == b)return true;
else return false;
}
void appoint(int num)
{
for (set<char>::iterator it