欢迎来到天天文库
浏览记录
ID:40933041
大小:40.33 KB
页数:19页
时间:2019-08-11
《实验二 王浩算法的实现》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验二王浩算法的实现学号:2220103430班级:计科二班姓名:刘俊峰一、实验内容:实现命题逻辑框架内的王浩算法。⑴将命题逻辑中的王浩算法推广至下述命题语言的情形之下:ⅰ命题变量符号:,,,ⅱ逻辑连接符:,,,,ⅲ间隔符:,⑵在上述⑴中所定义的命题语言中实现王浩算法。二、实验目的熟练掌握命题逻辑中的王浩算法。三、实验原理王浩算法实质上是一个反向推理的过程,它吧给定的公式化成合取范式,然后通过判断每个字句是否恒真的来判定给定的公式是否是恒真的。设X1,…,Xm,Y1,…Yn是的公式,则相继式X1,…,Xm→
2、Y1,…,Yn的直观含义可以理解为(X1^…^Xm)→(Y1ˇ…ˇYn),┌X1ˇ…ˇ┌XmˇY1ˇ…ˇYn。四、实验源代码#include#include#include#defineMAX_L5inti=0;intstepcount=1;enumtype{and,or,detrusion,equal,level,variable};structnode{char*s;typekind;intpolar;node*next;node*child;i
3、ntstart;};structstep{step*child;step*brother;node*lhead;node*rhead;intcount;charname[30];};intinite(char*s,node*head){intlen=strlen(s);intj=0,polar=1;node*current=NULL;node*last=NULL;if(s==NULL)return0;last=head;while(i4、'){if(!(s[i+1]<='Z'&5、&s[i+1]>='A'6、7、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!'8、9、i==0)return0;current=(node*)malloc(sizeof(node));current->kind=or;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(l10、ast->kind==level&&last->child==NULL){last->child=current;}else{last->next=current;}last=current;i++;}elseif(s[i]=='&'){if(!(s[i+1]<='Z'&&s[i+1]>='A'11、12、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!'13、14、i==0)return0;current=(node*15、)malloc(sizeof(node));current->kind=and;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(last->kind==level&&last->child==NULL){last->child=current;}else{last->next=current;}last=current;i++;}elseif(s[i]=='!'){16、if(!(s[i+1]<='Z'&&s[i+1]>='A'17、18、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!')return0;polar=1-polar;i++;}elseif(s[i]=='-'){if(s[i+1]!='>'19、20、(s[i+2]!='!'&&s[i+2]!='('&&!(s[i+2]<='Z'&&s[i+2]>='A'21、22、s[i+2]<='z'&&s[i+2]>='a'))23、24、i==25、0)return0;current=(node*)malloc(sizeof(node));current->kind=detrusion;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(last->kind==level&&last->child==NULL){last
4、'){if(!(s[i+1]<='Z'&
5、&s[i+1]>='A'
6、
7、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!'
8、
9、i==0)return0;current=(node*)malloc(sizeof(node));current->kind=or;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(l
10、ast->kind==level&&last->child==NULL){last->child=current;}else{last->next=current;}last=current;i++;}elseif(s[i]=='&'){if(!(s[i+1]<='Z'&&s[i+1]>='A'
11、
12、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!'
13、
14、i==0)return0;current=(node*
15、)malloc(sizeof(node));current->kind=and;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(last->kind==level&&last->child==NULL){last->child=current;}else{last->next=current;}last=current;i++;}elseif(s[i]=='!'){
16、if(!(s[i+1]<='Z'&&s[i+1]>='A'
17、
18、s[i+1]<='z'&&s[i+1]>='a')&&s[i+1]!='1'&&s[i+1]!='0'&&s[i+1]!='('&&s[i+1]!='!')return0;polar=1-polar;i++;}elseif(s[i]=='-'){if(s[i+1]!='>'
19、
20、(s[i+2]!='!'&&s[i+2]!='('&&!(s[i+2]<='Z'&&s[i+2]>='A'
21、
22、s[i+2]<='z'&&s[i+2]>='a'))
23、
24、i==
25、0)return0;current=(node*)malloc(sizeof(node));current->kind=detrusion;current->s=NULL;current->next=NULL;current->child=NULL;current->polar=polar;current->start=0;if(last->kind==level&&last->child==NULL){last
此文档下载收益归作者所有