ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:46.46KB ,
资源ID:24066103      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/24066103.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(实现基于谓词逻辑的归结原理.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

实现基于谓词逻辑的归结原理.docx

1、实现基于谓词逻辑的归结原理河南城建学院人工智能实验报告实验名称:实现基于谓词逻辑的归结原理 成 绩:专业班级: 学 号: 姓 名:实验日期:20 14年05月13日实验器材:台装pc机一、 实验目的熟练掌握使用归结原理进行定理证明的过程,掌握基于谓词逻辑的归结过 程中,子句变换过程、替换与合一算法、归结过程及简单归结策略等重要环节, 进一步了解机器自动定理证明的实现过程。二、 实验要求对于任意给定的一阶谓词逻辑所描述的定理,要求实现如下过程:(1)谓词公式到子句集变换;(2)替换与合一算法;(3)在某简单归结策略下的归结。三、 实验步骤步1设汁谓词公式及自居的存储结构,即内部表示。注意对全称量

2、词臥和存在量词X可采用其他符号代替;步2实现谓词公式到子句集变换过程;步3实现替换与合一算法;实现某简单归结策略;4步.步5设计输出,动态演示归结过程,可以以归结树的形式给出;步6实现谓词逻辑中的归结过程,其中要调用替换与合一算法和归结策略。四、 代码谓词公式到子句集变换的源代码:#iiiclude#iiiclude#iiiclude#iiicludeusing namespace std:/ 些函数的定义void imtStrmg(strmg &im);初始化string del_iiilchie(string tenq)y/消去蕴涵符号string dec_neg_rand(strmg t

3、emp);/ 减少否定符号的辖域string standard-var(string temp);对变晟标准化string del_exist$(string tenip)/消去存在量词string conrert_to_front(string temp);/化为前束形string conrert_to_and(string temp);/ 把母式化为合取范式string del_all(striiig temp);/消去全称量词string del_aiid(striiig temp);/ 消去连接符号合取 string change_name(stnng temp); 更换变 ht 名称

4、/辅助函数定义bool isAlbum(char tenip)/是字母string del_null_bracket(string temp)y/删除多余的括号string del_blank(strmg temp);/ 删除多余的空格void checkLegal(string temp); 检查合法性char iiuniAfectChai(iiit temp);/ 数字显示为字符 主函数void niain()cout 求子句 集九步 法演示 endl;system(color OA);/ongn = Q(x,y)% (P(y);ongn = (x)(P(y)P);/ongn = Y#x)

5、y(x);/ongn =(x)x!b(x);/ongn = Yx!y);/ongn = p 2(b);string orignjemp;char conimand.conimand0,cominandl,command2.conimand3,comiiiand4,conimand5, cominand6.conimand7,comiiiand8,cominand9,conimaiidl0;憫璟?请输入(Y/y)初始化谓词演算公式vv已ndl: cinconimand;if(conmiaiid = y | command = Y) lmtString(ongn);elseexit(O);憫瑾?请

6、输入(Y/y)消除空格endl; cinconimandO:if(commaiidO = y | conimandO = Y) /del_blank(origii);/undone澗璜?消除空格后是endlorignendl:elseexit(O);憫璜?请输入(Y/y)消去蕴涵项endl: cinconimandl;if(commandl = y | command 1 = Y) orign =del_mlc lue(ongn);憫璜?消去蕴涵项后是endlorignendl:elseexit(O);憫瑾?请输入(Y/y)减少否定符号的辖域vv诅dl: cinconimand2;if(com

7、iiiand2 = *y* | command? = Y)dotemp = orign;orign = dec_neg_rand(orign);while(temp != orign);澗璜?减少否定符号的辖域后是vvzdlongnendl;elseexit(O);制璟?请输入(Y/y)对变量进行标准化vv已ndl; cinconimand3;if(comiiiand3 = y | conunaiid3 = Y)ongii = standard_var(ongii);憫璜?对变量进行标准化后是endlorignendl:elseexit(O);憫璟?请输入(Y/y)消去存在量词endl;cin

8、conimand4;if(coiiuiiaiid4 = y | command4 = fY*)ongii = del_exists(ongn);憫璜?消去存在量词后是(w = g(x)是个Skolem函数)endl orignendl;elseexit(O);憫瑾?请输入(Y/y)化为前束形endl: cinconimand5;if(commaiid5 = y | conmiand5= Y)orign = com-ert_to_fr ont(orign); 憫璜?化为前束形后是vvendlorignendl;elseexit(O);n 憫璜?请输入(Y/y)把母式化为合取方式endl: cin

9、conimand6;if(conmiand6 = y | coniniand6 =:Y)orign = com*ert_to_and(orign):憫璜?把母式化为合取方式后是endlorignendl:elseexit(O); endl;消去全称量词(Y/y)请输入制璜?cincominand7;if(conmiand7 = y | coniniand7 =:Y)orign= del_all(ongn);憫璜?消去全称量词后是endlorignendl:elseexit(O);J J 憫瑾?请输入(Y/y)消去连接符号旳dl; cinconimand8;if(comiiiand8 = y |

10、 commands = Y)ongii = del_and(ongii);憫璜?消去连接符号后是endlorignendl;elseexit(O);J J力二=憫璟?请输入(Y/y)变量分离标准化endl;cinconimand9;if(comiiiand9 =| conmiand9 = Y)orign = change_name(orign);憫璜?变量分离标准化后是(xl,x2,x3代替变虽x)endlorignendl:elseexit(O);cout 完毕 endl;cout(请输入 Y/y)结束 endl:dowhile(y = getchar() | TgetcharO);exit

11、(O);void imtStnng(strmg &im)char conimanda,commandb;endl;涸璜?请输入您所需要转换的谓词公式(Y/N)?eiidl;涸瑾?需要查看输入帮助 cinconimanda;if(comiiianda = T* | cominanda = y)#,endl全称量词为涸璜?本例程规定输入时蕴涵符号为,,存在量词为,函数名请用个字 母)左右括号分别为吸取为?取反为,!,合取为,(、endl;憫璜?请输入(y/n)选择是否用户H定义(y)(P(y)P(f(x, y)%y)(Q(x,y)P(y);澗璜?原始命题是wendliniendl:消去 strin

12、g del_inlclue(striiig temp)/蕴涵项a!b 变为 abchar c2inp100=;string output;int length = temp.lengthO:iiit i = O.rightbracket = O.falg= 0:stack stackl?stack2,stack3:strcpy(ctemp ,temp. c_str();wlule(ctempi != *0* & i = ctempi十1)如果是ab则用a!b替代falg=l;if(isAlbum(ctempi)/如果是字母则把 ctenq)i弹出stackl.pop();stackl push

13、();stackl push(ctempi);stackl.pushC!*);i = i + 1;else if(7 = ctempi)right_bracket+;doright_bracket;if(f = stackl.topO)stack3.push(stackl top();stackl.popO;while(right_bracket != 0); stack3.push(stackl top();stackl.popO;st2ckl.push();wlule(! stack3. einptyX)stackl push(stack3.topO);stack3.pop();stack

14、l.pushC!1);i+;wlule(!stackl einptX)stack? pnsh(stackl topO);stackl.popO;wlule(! stack2. einptyX)output 十=stack2.top();stack2.pop();lf(felg = 1) return output; else return tenq?;string dec_neg_rand(string temp)/ 减少否定符号的辖域char ctemp100,tempc:string output;mt flag? = 0;int i = O,left_bracket = Ojength

15、= temp.leiigthO; stack stackl,stack?: queue queue 1;strcpyXctemp ,temp. c_str();/ 复制到字符数组中 wlule(ctempi != 0 & i =0);queue lpushC)*);while(! queue 1. emptyO)tempc = queue l.frontO:queue l.pop();stackl push(tempc);i卄;wlule(!stackl einpty)stack? push(stackl .topO);stackl.pop();wlule(! stack2.已 inpty()

16、 output 十=stack2.top(); stack2.pop(); if(flag2 = 1) temp = output;/ 車 *4(寒*4(拿*尊*尊*草*寒*專char ctemplflOO; string output 1;stack stack 11,stock? 2;int falgl = 0;int times = 0: int length 1 = tenq).length(),inleftbackets = l,j = 0; strcpy(ctemp l.teinp.c_strO)i xvlule(ctemplj != r0f & j =0 & times = 0)

17、stackl 1 push(cteinp lj); if(ctemplj =,C) mleftbackets 十十;else if(ctemplj=) mleftbackets ;if(inleftbackets = 1 & ctemplj+l = T & ctemplj+2 != &Ctemplti+2M3Egl stackl 1 .push(.y)yjws ssckll.pusM%) stackll.push (?stack! 1 .Push()w/、AWiRinleRbackas HH 一 ctempl=+l= ctemplfj+2-ir &,&.Ctemplti+2M3 mgl 4 s

18、llpush(w=stack! 1 push(J八 stackll.push() stack! 1 .Push()w/O7J 2JHJ+常lf(dgl hh 1) ssrc片 11 pushQxstack 11 .Popo 八 smdcl 1 .pusho.) 寺期 b-lg srackl 1 push(y)*、lltb=gwhile (一 srackl 1 cmptyo)stack22.push(stackl 1 topO); stackll.pop();wlule(! stack? 2. emptyO)output 1 += stack22.topO;stack22.pop0:temp =

19、 output 1;char ctemp3100;string ontput3;intk = O,left_bracket3 = 1 Jength3 = teinp.lengthO; stack stack 13,stack? 3;int flag = O,bflag = 0;strcpy(ctemp3 .temp.c_strO);/ 复制到字符数组中 wliile(ctemp3k != 0 & k =0)stackl 3.pnsh(ctenq)3k+1 );if(ctemp3k 十 1 = V) left bracket3 十+;left bracket3 if(ctemp3k+l = T

20、| ctemp3k+l = *%*)bflag= 1;k+;stackl3.pop();k卄;xvlule(!stackl 3.emptyO)stack? 3.push(stack 13. topO);stackl3.pop0:wlule(! stack2 3. emptyO)output3 += stack23.topO;stack23.popO:if(flag = 1 & bflag = 0)temp = output3;retiim temp;string standard-ar(string temp)/对变晟标准化,简化,不考虑多层嵌套 char ctemp100,des10= ;s

21、trcpyXctemp,tenip. c_str();stack stackl,stack?:int l_bracket = l.folg = O.bracket = 1;int i = Oj = 0;string output: wlnle(ctempi != *0 & i v temp.length。)stackl .pnsh(ctenq)i);if(ctempi = | ctempi = *#*)stackl ,push(ctempi+l);desj = ctempfi +1;J卄;stackl push(ctempi+2);i = i + 3;stackl push(ctempi);i

22、+;if(ctempi-l = *(*)wlule(ctempi != 0 & l_bracket != 0) if(ctempi=()l_bracket +;if(ctempi = *(* & ctempi+l = 9)desj = ctempi+2;J卄;if(cteinpi+l = (* & ctempi+2 = )falg=l;mtkk= 1;stackl.push(f);stackl push(ctempi+2);i = i+3;if(ctempi = y) ctempi -w stackl push(ctempi); st3ckl.push(); stackl.push(C);i

23、= i+3;wlule(kk != 0)if(ctempi=()kk+-:if(ctempi =y)kk-;if(ctempi = y) ctempfi =*;stackl push(ctempi);i+;stackl .push(ctempi);i+;i+; wlule(!stackl enipty)stack2.push(stackl top();stackl.pop();wlule(! stack2.已 inpty()output h-= stack?. top();stack2.pop();lf(folg = 1)return output;elseretiirn tenip;stri

24、ng del_exists(string temp)/ 消去存在虽词char ctemp 100 Ainknow;strcpy(ctemp ,temp. c_str();mt left_brackets = 0,i = O,falg = 0;queue queue 1;string output;wlule(ctempi != 0 & i v teinp.lengthO)if(ctempi =( & ctempi+l=拌)falg=l;unknow = ctemp i+2;i = i+4;doleft brackets -H-;if(ctempi = () if(ctempi=)left_brackets ;queue 1 push(g); queue l.push(C); queue l.push(x);queue l.pushC)*);if(ctempi != unknow) queue 1 .pu$h(ct

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1