付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、For personal use only in study and research; not forcommercial use河南城建学院人工智能实验报告实验名称:实现基于谓词逻辑的归结原理成 绩:_专业班级:_学 号:_姓 名:实验日期:20 14 年 05 月 13 日实验器材:一台装PC机。、实验目的熟练掌握使用归结原理进行定理证明的过程,掌握基于谓词逻辑的归结过 程中,子句变换过程、替换与合一算法、归结过程及简单归结策略等重要环节, 进一步了解机器自动定理证明的实现过程。二、实验要求对于任意给定的一阶谓词逻辑所描述的定理,要求实现如下过程:(1) 谓词公式到子句集变换;(2) 替
2、换与合一算法;(3) 在某简单归结策略下的归结。、实验步骤步 1 设计谓词公式及自居的存储结构,即内部表示。注意对全称量词-X 和存在量词 X 可采用其他符号代替;步 2 实现谓词公式到子句集变换过程;步 3 实现替换与合一算法;步 4 实现某简单归结策略;步 5 设计输出,动态演示归结过程,可以以归结树的形式给出;步 6 实现谓词逻辑中的归结过程,其中要调用替换与合一算法和归结策略。四、代码谓词公式到子句集变换的源代码:#in clude#in clude#in clude#in cludeusing n amespace std;一些函数的定义void in itStri ng(stri
3、ng &ini);/初始化string del_inlclue(string temp);/消去蕴涵符号string dec_neg_rand(string temp);/减少否定符号的辖域string standard_var(string temp);/对变量标准化string del_exists(string temp);/消去存在量词string convert_to_front(string temp);/化为前束形string convert_to_and(string temp);/把母式化为合取范式string del_all(string temp);/消去全称量词
4、string del_and(string temp);/消去连接符号合取%string change_name(string temp);/更换变量名称/辅助函数定义bool isAlbum(char temp);/是字母string del_null_bracket(string temp);/删除多余的括号string del_blank(string temp);/删除多余的空格void checkLegal(string temp);/检查合法性char numAfectChar(int temp);/数字显示为字符/主函数void mai n()system(colorOA);/o
5、rign = Q(x,y)%(P(y);/orign = (x)(P(y)P);/orign = (#x)y(x);/orign = (x)x!b(x);/orign = (x!y);/orign = (a(b);stri ng orig n,temp;char comma nd,comma nd0,comma nd1,comma nd2,comma nd3,comma nd4,comma nd5, comma nd6,command7,comma nd8,comma nd9,comma nd10;/=cout请输入(Y/y)初始化谓词演算公式 comma nd;if(comma nd = y
6、 | comma nd = Y)in itStri ng(orig n);elseexit(0);/= cout请输入(Y/y)消除空格 comma nd0;if(comma nd0 = y | comma nd0 = Y)/del_bla nk(orig n);undonecout消除空格后是endlorig nen dl;elseexit(0);/= cout请输入(Y/y)消去蕴涵项 comma nd1;cout求子句集九步法演示endl;if(comma nd1 = y | comma nd1 = Y)orig n =del_i nl clue(orig n);cout消去蕴涵项后是e
7、ndlorig nen dl;elseexit(O);/= cout请输入(Y/y)减少否定符号的辖域 comma nd2;if(comma nd2 = y | comma nd2 = Y)dotemp = orig n;orig n = dec_ neg_ra nd(orig n);while(temp != orig n);cout减少否定符号的辖域后是e ndlorig nen dl;elseexit(0);/= cout请输入(Y/y)对变量进行标准化 comma nd3;if(comma nd3 = y | comma nd3 = Y)orig n = sta ndard_var(o
8、rig n);cout对变量进行标准化后是e ndlorig nen dl; elseexit(O);/: cout请输入(Y/y)消去存在量词 comma nd4;if(comma nd4 = y | comma nd4 = Y)orig n = del_exists(orig n);cout消去存在量词后是(w = g(x)是一个Skolem函数)endlorig nen dl;elseexit(0);/= cout请输入(Y/y)化为前束形 comma nd5;if(comma nd5 = y | comma nd5= Y)orig n = con vert_to_fro nt(orig
9、 n);cout化为前束形后是endlorig nen dl;elseexit(0);/= cout请输入(Y/y)把母式化为合取方式 comma nd6;if(comma nd6 = y | comma nd6 = Y)orig n = con vert_to_a nd(orig n);cout把母式化为合取方式后是e ndlorig nen dl;elseexit(O);/:cout”请输入(Y/y)消去全称量词 comma nd7;if(comma nd7 = y | comma nd7 = Y)orig n= del_all(orig n);cout消去全称量词后是endlorig n
10、en dl;elseexit(0);/=cout请输入(Y/y)消去连接符号 comma nd8;if(comma nd8 = y | comma nd8 = Y)orig n = del_a nd(orig n);cout消去连接符号后是endlorig nen dl;elseexit(0);/=cout请输入(Y/y)变量分离标准化 comma nd9;if(comma nd9 = y | comma nd9 = Y)orig n = cha nge_n ame(orig n);cout变量分离标准化后是(x1,x2,x3代替变量x)endlorig nen dl; elseexit(O)
11、;/=cout-完毕-e ndl;cout(请输入Y/y)结束endl;dowhile(y = getchar() | Y=getchar();exit(0); void in itStri ng(stri ng &ini)char comma nda,comma ndb;cout请输入您所需要转换的谓词公式e ndl;cout需要查看输入帮助(Y/N)? comma nda;if(comma nda = Y | comma nda = y)cout,全称量词为,存在量词为#,endl取反为,吸取为!,合取为%,左右括号分别为(、),函数名请用一个字母e ndl;cout请输入(y/n
12、)选择是否用户自定义 comma ndb;if(comma ndb =Y| comma ndb=y)ci nini;elseini = (x)(P(x)(y)(P(y)P(f(x, y)%(y)(Q(x,y)P(y);cout原始命题是endlinib变为a!bchar ctemp100=;stri ng output;int len gth = temp.le ngth();int i = O,right_bracket = 0,falg= 0;stack stack1,stack2,stack3;strcpy(ctemp,temp.c_str(); while(ctempi != 0 &a
13、mp; i = ctempi+1) 如果是ab则用a!b替代falg = 1;if(isAlbum(ctempi) 如果是字母则把ctempi弹出stack1.pop();stack1.push();stack1.push(ctempi);stack1.push(!);i = i + 1;else if() = ctempi)right_bracket+;doif( = stack1.top()right_bracket-; stack3.push(stack1.top(); stack1.pop();while(right_bracket != 0);stack3.push(stack1.t
14、op();stack1.pop();stack1.push();while(!stack3.empty()stack1.push(stack3.top();stack3.pop();stack1.push(!);i = i + 1;i+;while(!stack1.empty()stack2.push(stack1.top();stack1.pop();while(!stack2.empty()output += stack2.top();stack2.pop();if(falg = 1)return output;elsereturn temp;string dec_neg_rand(str
15、ing temp)/减少否定符号的辖域char ctemp100,tempc;stri ng output;int flag2 = 0;int i = 0,left_bracket = 0,le ngth = temp .len gth(); stack stack1,stack2;queue queue1;strcpy(ctemp,temp.c_str(); 复制到字符数组中while(ctempi != 0 & i =0); queuel.push();while(!queue1.empty()tempc = queue1.fro nt();queue1.pop(); stack1
16、.push(tempc);i +;while(!stack1.empty()stack2.push(stack1.top();stack1.pop();while(!stack2.empty()output += stack2.top();stack2.pop();if(flag2 = 1)temp = output;/*/char ctemp1100;stri ng output1;stack stack11,stack22;int falg1 = 0;int times = 0;int len gth1 = temp .len gth(),i nl eftbackets = 1,j = 0
17、;strcpy(ctemp1,temp.c_str();while(ctemp1j != 0 & j =0 & times = 0)stack11.push(ctemp1j);if(ctemp1j=()ini eftbackets +;else if(ctemp1j=)ini eftbackets -;if(i nleftbackets = 1 & ctemp1j+1 = ! & ctemp1j+2 != & ctemp1j+2 !=#)falgl =1;stackll.push();/stack11.push(%);stack11.push();sta
18、ck11.push();/j =j+1;if(i nleftbackets = 1 & ctemp1j+1 = % & ctemp1j+2 != & ctemp1j+2 !=#)falg1 =1;stack11.push();/stack11.push(!);stack11.push();stack11.push();/j =j+1;j = j +1;if(falg1 = 1)stackll.push(); stack11.pop();stackll.push();/此处有bug stackll.push();/此处有bugj +;while(!stack11.empt
19、y()stack22.push(stack11.top(); stack11.pop();while(!stack22.empty()output1 += stack22.top();stack22.pop();if(falg1 = 1)temp = output1;/* char ctemp3100;stri ng output3;int k = 0,left_bracket3 = 1,le ngth3 = temp.le ngth(); stack stack13,stack23;int flag = 0,bflag = 0;strcpy(ctemp3,temp.c_str(); 复制到字
20、符数组中while(ctemp3k != 0 & k =0) stack13.push(ctemp3k+1); if(ctemp3k+1=()left_bracket3 +;if(ctemp3k+1=)left_bracket3 -;if(ctemp3k+1 = ! | ctemp3k+1 = %)bflag = 1;k +;stack13.pop();k +;while(!stack13.empty()stack23.push(stack13.top();stack13.pop();while(!stack23.empty()stack23.pop();output3 += stac
21、k23.top();if(flag = 1 & bflag = 0)temp = output3;return temp;string standard_var(string temp)/对变量标准化,简化,不考虑多层嵌套char ctemp100,des10= ;strcpy(ctemp,temp.c_str();stack stack1,stack2;int l_bracket = 1,falg = 0,bracket = 1;int i = 0,j = 0;stri ng output;while(ctempi != 0 & i temp.le ngth()stack1.
22、push(ctempi);if(ctempi = | ctempi = #)stack1.push(ctempi+1);desj = ctempi+1;j+;stack1.push(ctempi+2);i = i + 3;stack1.push(ctempi);i+;if(ctempi-1=()while(ctempi != 0 & l_bracket != 0)if(ctempi=()stack23.pop();l_bracket +;if(ctempi=)l_bracket -;if(ctempi = ( & ctempi+1 = )i +;desj = ctempi+2;
23、j+;if(ctempi+1 = ( & ctempi+2 = #) falg = 1;int kk = 1;stack1.push(ctempi);stack1.push();stack1.push(ctempi+2);i = i+3;if(ctempi = y)ctempi =w;stack1.push(ctempi);stack1.push();stack1.push();i = i+3;while(kk != 0)if(ctempi=()kk+;if(ctempi =)kk-;if(ctempi = y)ctempi =w;stack1.push(ctempi);i+;i +;
24、stack1.push(ctempi);i +;while(!stack1.empty()stack2.push(stack1.top(); stack1.pop();while(!stack2.empty()output += stack2.top();stack2.pop();if(falg = 1)return output;elsereturn temp;string del_exists(string temp)/消去存在量词char ctemp100,u nknow;strcpy(ctemp,temp.c_str();int left_brackets = 0,i = 0,falg
25、 = 0;queue queue1;stri ng output;while(ctempi != 0 & i temp.le ngth()if(ctempi =( & ctempi+1 =#) falg = 1;unknow = ctempi+2;i = i+4;doif(ctempi=()left_brackets +;if(ctempi=) left_brackets -;if(ctempi = unknow)queuel.push(g);queue1.push();queue1.push(x);queue1.push();if(ctempi != unknow)queue
26、1.push(ctempi);i+;while(left_brackets != 0);queue1.push(ctempi);i+;while(!queue1.empty()output+= queue1.fr on t();queue1.pop();if(falg = 1)return output;elsereturn temp;string convert_to_front(string temp)/化为前束形char ctemp100;strcpy(ctemp,temp.c_str();int i = 0;stri ng out_var = output =;while(ctempi
27、 != 0 & i temp.le ngth()if(ctempi = ( & ctempi+1 = )out_var =out_var+ ctempi ;/()out_var = out_var+ ctempi+1out_var =out_var+ctempi+2;out_var =out_var+ctempi+3;i = i + 4;output = output + ctempi;i+;output = out_var + output;return output;string convert_to_and(string temp)/把母式化为合取范式,Q/A?temp
28、= (x)(y)(P(x)!(P(y)!P(f(x,y)%(P(x)!Q(x,g(x)%(P(x)!(P(g(x); return temp;string del_all(string temp)/消去全称量词char ctemp100;strcpy(ctemp,temp.c_str();int i = 0,flag = 0;stri ng output =;while(ctempi != 0 & i temp.le ngth()if(ctempi = ( & ctempi+1 = )i = i + 4;flag = 1; else output = output + ctem
29、pi;i +;return output;string del_and(string temp)/消去连接符号合取char ctemp100; strcpy(ctemp,temp.c_str(); int i = 0,flag = 0;stri ng output =;while(ctempi != 0 & i temp.le ngth()if(ctempi = %)ctempi = n;output = output +ctempi;i+;return output;stri ng cha nge_n ame(stri ng temp)/更换变量名称char ctemp100; st
30、rcpy(ctemp,temp.c_str(); stri ng output =;int i = 0,j = 0,falg = 0;while(ctempi != 0 & i temp.le ngth()falg+;while(n != ctempi & i temp.le ngth()if(x = ctempi)output = output + ctempi;output = output + nu mAfectChar(falg);elseoutput = output + ctempi;i+;output = output + ctempi;i +;return ou
31、tput;bool isAlbum(char temp)if(temp = A | temp = a) return true;return false;char numAfectChar(int temp)/数字显示为字符int t;switch (temp)case 1:t = 1;break;case 2:t = 2;break;case 3:t = 3;break;case 4:t = 4;break;default:t = 89;break;return t;五、结果分析(1)非用户自定义时:M *D:XPrograB FilesMicrosoft Visual Studio9Deb
32、ug9aeze请输入餐灼初始化谓词演算公式-y逋输入您所需要特换的谓词公式需宴查看输入帮M?鶴输入 5 如选择是否用户自定义怎始命题是请输入小消除空格y消除空格后是请输入消去蕴涵项藕去蕴涵项后是(,Tf*C(ey!Pz,(ey*P(u?请输入弊减少否定符号的辖域 養少否定符号的辖域后是请输入小对变量进行标准化c:v*D;XPrograa FilesMicrosaft Visual Studio9DEbu、9*Ge附变量逬行标准化后是*eyX,vP*PF(x,情输入 S、消去存在量词消去存在量词后是 0 -乳小是1个Skolem函数 请输入炸化为前束形化为前東形后是请输入把母式化为合取方式把母式化为合取方式后是 请输入“如肖去全称臺词消去全称量词后是HWP*PCf iCxfQx,gxTJtC,TH请输入 S 皤去连接符昌
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 外墙外保温施工技术交底
- 项目部组成人员申报表
- 氧气疗法与护理
- 2025-2026学年贵州省遵义市高三压轴卷语文试卷含解析
- 医学26年:肺癌术后随访管理 查房课件
- 山东省德州市2025-2026学年高二下学期期中考试语文试卷
- 【2025】西安铁路职业技术学院招聘考试真题
- 【2025】松原市宁江区伯都讷街道工作人员招聘考试真题
- 26年银发沟通红线事项培训课件
- 26年社区慢病老人生理特点
- 2026-2030中国压缩空气储能行业竞争格局与投资可行性战略规划研究报告
- 2026中国移动通信集团海南有限公司第一期社会招聘3人笔试备考试题及答案解析
- 2026贵州省住房资金管理中心招聘工作人员1人笔试参考题库及答案解析
- 【《自动避障扫地机器人设计》11000字(论文)】
- 资金确权协议书
- 2026届江苏省南京市高三二模英语试题(含答案和音频)
- 解读2025新版职业病分类和目录12大类135种
- 2026天津市津鉴检测技术发展有限公司社会招聘工作人员3人考试模拟试题及答案解析
- 2026形势与政策课件中国风范 大国担当-在世界变局中推动构建新型大国关系
- (2025年)湖北省普通高中学业水平考试政治真题卷及答案
- 某钢铁厂成本核算细则
评论
0/150
提交评论