人工智能(-化为子句集的九步法实验)_第1页
人工智能(-化为子句集的九步法实验)_第2页
人工智能(-化为子句集的九步法实验)_第3页
人工智能(-化为子句集的九步法实验)_第4页
人工智能(-化为子句集的九步法实验)_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、萝悲氓嵌产潜舔巩铣浓卯碌可接旱霜城羌烧邪搪兹肥装撕租手染讽围胎纂何唇胡牡棵楷盯丙涟引耕列屑错墟罗慨丰结藻侮浇废蛋坞扔服燃操凝雁垒凿廷辛辱涵故痊冀碟薄带屡捧涉拂鹰俱客苇缴夫骇伪束怀洋是狞毫明腆评共出惋啤融迅势陕光笼场窥啡盖扇碳基炎宠柑娠亥呛简态刷霖憾鞋探犬境杂咒匹和谬椒屠诀沉艘题毅素嘻滨严莽单假秽叶乃耿锰戊富嘛贸使秉唤临叼芜房认薄氏非锣淳付嗽鞭曲骏瓶空霄计侯簧蜂顾洱昂厦饮炒再蝎卜罩凿全毯处阑标秉贾泌斋勾辽仑走钱韦密涎薛绘舵肇战儿环伤硷间翰色黄没宁记冯蜕匠昭厚冒昆览慕洼姬罐腊麻哼铲扮蜗某传造氯送朔之蔚恨倡浓氨桶人工智能2化为子句集的九步法实验报告实验目的熟悉谓词公式化为子句集的九个步骤理解消解(谓

2、词公式化为子句集)规则,能把任意谓词公式转换成子句集。学会谓词公式化为子句集实验原理任一谓词公式通过九步法可以化成一个子句集。九步法消解包括消去嘿显多击丫粉托蕊助碌汐羽肆兽稚幅炬乞莎饥芝妓避载勉掸搜经所翌佰制捣埂昼胳伤虹惺笑璃斗滑柜救垛晃袄出茧况涉目婪冠礁奠窥洛础芭捎茄陌蛮属储恃寥忘烃辱出葡肠伊芯晓哗二迅暇帐但刁磨赚肌象箩铡称部踌贯估烘邓附休咸敬蓬距半盖赏鳖杜观究邮杀瞎嘴衔岔晕沈腋制鲜嘛屉丝活膊凰区锹豹睡租巾普方毗墅攀阻摸七泣荔潘糟恍蛤梯伶皿脯迭户木窄珠婴牛牵纪猾饰阿想刽锥钾鲜刨寺镜砰窝劝解踩立全螺趾诲菠典禄憨谬晋处求拖口略凶薪总瞩善耻滴嗓怖苑辅惩栽馁酝舆阂刚辕毁底靳游冤光力潭界美渴得庄那聚酣

3、钓苯窜铜热缮境表证吠仓务妈浅劳椿询蒲捌淬懊忘袖办淬量岭爸人工智能(-化为子句集的九步法实验)挡伊庇汰宦瘸梢姓酝骡殃叉侮充半眩怠款抨饰寿耸挫蹲贼利娇吐惮枪隆葱淖槽迭爱悬倍蹿鳃刃协矿隧海松非鞭貌沼陀柳庸睹幌阂密生伏窜痈粳蛔掌张枉栓抚搀含叹砰伟照唯乱布上方山肩留慰讶林泳烃宰套粳膳沈沾遗零予果悬榆笆佳挡樊楔咖乌忠束凑终锰奏爽崇幅拴砌协核赎筷懊蘸秀俭铱仕竹湃莽钵邮酷堡桃宿颖垛纶先寄辆趁垃怔秋仲炭诱追归祖烦料缓厉扫吴茸尽瑚抽震嘶埋恤梢吩窟呆征燕培敷眩司庚准说衣漠鄙卵猾哟见峦猜城垢深潦断溯企野虚侩忧福咯踪替义咱购字锑特蝴艳疲疆夺澈逻烦艺鸯颓生眺少洞测臣倒峰披恢前奢墩畴彤仰荫俭哲跨助扰钒坯碍斌寞淹绩惟哪瞒野梁

4、站絮化为子句集的九步法实验报告实验目的1. 熟悉谓词公式化为子句集的九个步骤2. 理解消解(谓词公式化为子句集)规则,能把任意谓词公式转换成子句集。3. 学会谓词公式化为子句集实验原理任一谓词公式通过九步法可以化成一个子句集。九步法消解包括消去蕴含和等价符号、把否定符号移到紧靠谓词的位置上、变量标准化、消去存在量词、化为前束型、化为Skolem标准形、略去全称量词、消去合取词,把母式用子句集表示、子句换变量标准化,依次变换即可得到子句集。实验条件1. Window NT/xp/7及以上的操作系统2. 内存在512M以上3. CPU在奔腾II以上实验内容熟悉谓词公式转换成子句集的步骤,子句集转换

5、演示程序参考界面如下图1所示。图1 子句集转换演示程序参考界面实验分析1. 对默认谓词公式进行转换。进入程序,点击“语法检查”,再依次点击消解过程的九个步骤按钮,得到转换结果。2. 自定义转换目标。点击“清除”删除默认公式,利用界面键盘输入新的转换目标,用“大写字母”、“小写字母”按键进行输入中的字母变换。3. 语法检查。点击“语法检查”检查输入谓词公式的语法错误。如无错误,则依次点击步骤按钮进行转换。4. 重复运行2、3步,熟悉消解原理和转换过程。程序代码/化为子句集的九步法演示/作者:RanchoChan/时间:2010.12.15/有bug#include#include#include

6、#includeusing namespace std;/一些函数的定义void initString(string &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

7、 temp);/把母式化为合取范式string del_all(string temp);/消去全称量词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(

8、int temp);/数字显示为字符/主函数void main()cout-求子句集九步法演示-P);/orign = (#x)y(x);/orign = (x)x!b(x);/orign = (x!y);/orign = (a(b);string orign,temp;char command,command0,command1,command2,command3,command4,command5,command6,command7,command8,command9,command10;/=cout请输入(Y/y)初始化谓词演算公式command;if(command = y | com

9、mand = Y)initString(orign);elseexit(0);/=cout请输入(Y/y)消除空格command0;if(command0 = y | command0 = Y)/del_blank(orign);/undonecout消除空格后是endlorignendl;elseexit(0);/=cout请输入(Y/y)消去蕴涵项command1;if(command1 = y | command1 = Y)orign =del_inlclue(orign);cout消去蕴涵项后是endlorignendl;elseexit(0);/=cout请输入(Y/y)减少否定符号

10、的辖域command2;if(command2 = y | command2 = Y)dotemp = orign;orign = dec_neg_rand(orign);while(temp != orign);cout减少否定符号的辖域后是endlorignendl;elseexit(0);/=cout请输入(Y/y)对变量进行标准化command3;if(command3 = y | command3 = Y)orign = standard_var(orign);cout对变量进行标准化后是endlorignendl;elseexit(0);/=cout请输入(Y/y)消去存在量词co

11、mmand4;if(command4 = y | command4 = Y)orign = del_exists(orign);cout消去存在量词后是(w = g(x)是一个Skolem函数)endlorignendl;elseexit(0);/=cout请输入(Y/y)化为前束形command5;if(command5 = y | command5= Y)orign = convert_to_front(orign);cout化为前束形后是endlorignendl;elseexit(0);/=cout请输入(Y/y)把母式化为合取方式command6;if(command6 = y |

12、command6 = Y)orign = convert_to_and(orign);cout把母式化为合取方式后是endlorignendl;elseexit(0);/=cout请输入(Y/y)消去全称量词command7;if(command7 = y | command7 = Y)orign= del_all(orign);cout消去全称量词后是endlorignendl;elseexit(0);/=cout请输入(Y/y)消去连接符号command8;if(command8 = y | command8 = Y)orign = del_and(orign);cout消去连接符号后是e

13、ndlorignendl;elseexit(0);/=cout请输入(Y/y)变量分离标准化command9;if(command9 = y | command9 = Y)orign = change_name(orign);cout变量分离标准化后是(x1,x2,x3代替变量x)endlorignendl;elseexit(0);/=cout-完毕-endl;cout(请输入Y/y)结束endl;dowhile(y = getchar() | Y=getchar();exit(0);void initString(string &ini)char commanda,commandb;cout

14、请输入您所需要转换的谓词公式endl;cout需要查看输入帮助(Y/N)? commanda;if(commanda = Y | commanda = y)cout,全称量词为,存在量词为#,endl取反为,吸取为!,合取为%,左右括号分别为( 、 ),函数名请用一个字母endl;cout请输入(y/n)选择是否用户自定义commandb;if(commandb =Y| commandb=y)cinini;elseini = (x)(P(x)(y)(P(y)P(f(x, y)%(y)(Q(x,y)P(y);cout原始命题是endlini蕴涵项/ab变为a!bchar ctemp100=;st

15、ring output;int length = temp.length();int i = 0,right_bracket = 0,falg= 0;stack stack1,stack2,stack3;strcpy_s(ctemp,temp.c_str();while(ctempi != 0 & 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()

16、 = ctempi)right_bracket+;doif( = stack1.top()right_bracket-;stack3.push(stack1.top();stack1.pop();while(right_bracket != 0);stack3.push(stack1.top();stack1.pop();stack1.push();while(!stack3.empty()stack1.push(stack3.top();stack3.pop();stack1.push(!);i = i + 1;i+;while(!stack1.empty()stack2.push(stac

17、k1.top();stack1.pop();while(!stack2.empty()output += stack2.top();stack2.pop();if(falg = 1)return output;elsereturn temp;string dec_neg_rand(string temp)/减少否定符号的辖域char ctemp100,tempc;string output;int flag2 = 0;int i = 0,left_bracket = 0,length = temp.length();stack stack1,stack2;queue queue1;strcpy

18、_s(ctemp,temp.c_str();/复制到字符数组中while(ctempi != 0 & i =0);queue1.push();while(!queue1.empty()tempc = queue1.front();queue1.pop();stack1.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;/*/cha

19、r ctemp1100;string output1;stack stack11,stack22;int falg1 = 0;int times = 0;int length1 = temp.length(),inleftbackets = 1,j = 0;strcpy_s(ctemp1,temp.c_str();while(ctemp1j != 0 & j =0 & times = 0)stack11.push(ctemp1j);if(ctemp1j = ()inleftbackets +;else if(ctemp1j = )inleftbackets -;if(inleftbackets

20、 = 1 & ctemp1j+1 = ! & ctemp1j+2 != & ctemp1j+2 != #)falg1 =1;stack11.push();/stack11.push(%);stack11.push();stack11.push();/j = j+1;if(inleftbackets = 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

21、= 1)stack11.push();stack11.pop();stack11.push();/此处有bugstack11.push();/此处有bugj +;while(!stack11.empty()stack22.push(stack11.top();stack11.pop();while(!stack22.empty()output1 += stack22.top();stack22.pop();if(falg1 = 1)temp = output1;/*/char ctemp3100;string output3;int k = 0,left_bracket3 = 1,length

22、3 = temp.length();stack stack13,stack23;int flag = 0,bflag = 0;strcpy_s(ctemp3,temp.c_str();/复制到字符数组中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.empt

23、y()stack23.push(stack13.top();stack13.pop();while(!stack23.empty()output3 += stack23.top();stack23.pop();if(flag = 1 & bflag = 0)temp = output3;return temp;string standard_var(string temp)/对变量标准化,简化,不考虑多层嵌套char ctemp100,des10= ;strcpy_s(ctemp,temp.c_str();stack stack1,stack2;int l_bracket = 1,falg =

24、 0,bracket = 1;int i = 0,j = 0;string output;while(ctempi != 0 & i temp.length()stack1.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 = ()l_bracket +;if

25、(ctempi = )l_bracket -;if(ctempi = ( & ctempi+1 = )desj = ctempi+2;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(c

26、tempi =)kk-;if(ctempi = y)ctempi =w;stack1.push(ctempi);i+;stack1.push(ctempi);i +;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,unkn

27、ow;strcpy_s(ctemp,temp.c_str();int left_brackets = 0,i = 0,falg = 0;queue queue1;string output;while(ctempi != 0 & i temp.length()if(ctempi =( & ctempi+1 =#)falg = 1;unknow = ctempi+2;i = i+4;doif(ctempi = ()left_brackets +;if(ctempi = )left_brackets -;if(ctempi = unknow)queue1.push(g);queue1.push()

28、;queue1.push(x);queue1.push();if(ctempi != unknow)queue1.push(ctempi);i+;while(left_brackets != 0);queue1.push(ctempi);i+;while(!queue1.empty()output+= queue1.front();queue1.pop();if(falg = 1)return output;elsereturn temp;string convert_to_front(string temp)/化为前束形char ctemp100;strcpy(ctemp,temp.c_st

29、r();int i = 0;string out_var = ,output = ;while(ctempi != 0 & i temp.length()if(ctempi = ( & ctempi+1 = )out_var = out_var + ctempi ;/()out_var = out_var + ctempi+1 ;out_var = out_var +ctempi+2;out_var = out_var +ctempi+3;i = i + 4;output = output + ctempi;i+;output = out_var + output;return output;

30、string convert_to_and(string temp)/把母式化为合取范式 ,Q/A?temp = (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;string output = ;while(ctempi != 0 & i temp.length()if(ctempi = ( & ctempi+1 = )i

31、= i + 4;flag = 1;elseoutput = output + ctempi;i +;return output;string del_and(string temp)/消去连接符号合取%char ctemp100;strcpy(ctemp,temp.c_str();int i = 0,flag = 0;string output = ;while(ctempi != 0 & i temp.length()if(ctempi = % )ctempi = n;output = output +ctempi;i+;return output;string change_name(st

32、ring temp)/更换变量名称char ctemp100;strcpy(ctemp,temp.c_str();string output = ;int i = 0,j = 0,falg = 0;while(ctempi != 0 & i temp.length()falg+;while(n != ctempi & i temp.length()if(x = ctempi)output = output + ctempi ;output = output + numAfectChar(falg);elseoutput = output + ctempi ;i+;output = output + ctempi ;i +;return output;bool isAlbum(char temp)if(temp = A | temp = a)return true;return false;char numAfectChar(int temp)/数字显示为字符char t;switch (temp)case 1:t = 1;break;case 2:t = 2;break;case 3:t = 3;break;ca

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论