




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、河南城建學(xué)院人工智能實(shí)驗(yàn)報(bào)告實(shí)驗(yàn)名稱:實(shí)現(xiàn)基于謂詞邏輯的歸結(jié)原理成 績(jī): 專業(yè)班級(jí):學(xué) 號(hào):姓 名: 實(shí)驗(yàn)日期:20 14年05月13日實(shí)驗(yàn)器材:一臺(tái)裝PC機(jī)。、實(shí)驗(yàn)?zāi)康氖炀氄莆帐褂脷w結(jié)原理進(jìn)行定理證明的過(guò)程,掌握基于謂詞邏輯的歸結(jié)過(guò) 程中,子句變換過(guò)程、替換與合一算法、歸結(jié)過(guò)程及簡(jiǎn)單歸結(jié)策略等重要環(huán)節(jié), 進(jìn)一步了解機(jī)器自動(dòng)定理證明的實(shí)現(xiàn)過(guò)程。、實(shí)驗(yàn)要求 對(duì)于任意給定的一階謂詞邏輯所描述的定理,要求實(shí)現(xiàn)如下過(guò)程:(1) 謂詞公式到子句集變換;(2) 替換與合一算法;(3) 在某簡(jiǎn)單歸結(jié)策略下的歸結(jié) 三、實(shí)驗(yàn)步驟步1設(shè)計(jì)謂詞公式及自居的存儲(chǔ)結(jié)構(gòu),即內(nèi)部表示。注意對(duì)全稱量詞x和存在量詞x可采用其他
2、符號(hào)代替;步2實(shí)現(xiàn)謂詞公式到子句集變換過(guò)程;步3實(shí)現(xiàn)替換與合一算法;步4實(shí)現(xiàn)某簡(jiǎn)單歸結(jié)策略;步5設(shè)計(jì)輸出,動(dòng)態(tài)演示歸結(jié)過(guò)程,可以以歸結(jié)樹(shù)的形式給出;步6實(shí)現(xiàn)謂詞邏輯中的歸結(jié)過(guò)程,其中要調(diào)用替換與合一算法和歸結(jié)策略四、代碼謂詞公式到子句集變換的源代碼:#in clude#in clude#in clude#in cludeusing n amespace std;一些函數(shù)的定義void in itStri ng(stri ng &ni);/ 初始化string del_inlclue(string temp);/ 消去蘊(yùn)涵符號(hào)string dec_neg_rand(string temp);/
3、減少否定符號(hào)的轄域string standard_var(string temp);/ 對(duì)變量標(biāo)準(zhǔn)化string del_exists(string temp);/ 消去存在量詞string convert_to_front(string temp);/ 化為前束形string convert_to_and(string temp);/ 把母式化為合取范式string del_all(string temp);/ 消去全稱量詞string del_and(string temp);/ 消去連接符號(hào)合取 %stri ng cha nge_n ame(stri ng temp);/ 更換變量名稱/
4、輔助函數(shù)定義bool isAlbum(char temp);/ 是字母string del_null_bracket(string temp);/ 刪除多余的括號(hào)string del_blank(string temp);/ 刪除多余的空格void checkLegal(string temp);/ 檢查合法性char numAfectChar(int temp);/ 數(shù)字顯示為字符/主函數(shù)void mai n()cout 求子句集九步法演示 P);/orign = (#x)y(x);/orign = (x)x!b(x);/orign = (x!y);/orign = (a(b);stri n
5、g orig n,temp;char comma nd,comma ndO,comma nd1,comma nd2,comma nd3,comma nd4,comma nd5, comma nd6,comma nd7,comma nd8,comma nd9,comma nd10;/=cout請(qǐng)輸入(Y/y)初始化謂詞演算公式 comma nd;if(comma nd = y | comma nd = Y)in itStri ng(orig n);elseexit(0);/=cout請(qǐng)輸入(Y/y)消除空格 comma ndO;if(comma ndO = y | comma ndO = Y)/
6、del_bla nk(orig n); undonecout消除空格后是endlorig nen dl;elseexit(0);/=cout請(qǐng)輸入(Y/y)消去蘊(yùn)涵項(xiàng) comma nd1;if(comma nd1 = y | comma nd1 = Y)orig n =del_i nl clue(orig n);cout消去蘊(yùn)涵項(xiàng)后是endlorig nen dl; elseexit(O);/=cout請(qǐng)輸入(Y/y)減少否定符號(hào)的轄域 comma nd2;if(comma nd2 = y | comma nd2 = Y)dotemp = orig n;orig n = dec_ neg_ra
7、 nd(orig n);while(temp != orig n);cout減少否定符號(hào)的轄域后是 e ndlorig nen dl;elseexit(0);/=cout請(qǐng)輸入(Y/y)對(duì)變量進(jìn)行標(biāo)準(zhǔn)化 comma nd3;if(comma nd3 = y | comma nd3 = Y)orig n = sta ndard_var(orig n);cout對(duì)變量進(jìn)行標(biāo)準(zhǔn)化后是 e ndlorig n comma nd4;cout請(qǐng)輸入(Y/y)消去存在量詞endl;if(comma nd4 = y | comma nd4 = Y)orig n = del_exists(orig n);cou
8、t消去存在量詞后是 (w = g(x)是一個(gè) Skolem函數(shù))endlorig nen dl;elseexit(0);/=cout請(qǐng)輸入(Y/y)化為前束形 comma nd5;if(comma nd5 = y | comma nd5= Y)orig n = con vert_to_fro nt(orig n);cout化為前束形后是endlorig nen dl;elseexit(0);/=cout請(qǐng)輸入(Y/y)把母式化為合取方式 comma nd6;if(comma nd6 = y | comma nd6 = Y)orig n = con vert_to_a nd(orig n);co
9、ut把母式化為合取方式后是 e ndlorig nen dl;elseexit(0);/=cout請(qǐng)輸入(Y/y)消去全稱量詞 comma nd7;if(comma nd7 = y | comma nd7 = Y)orig n= del_all(orig n);cout消去全稱量詞后是endlorig nen dl;elseexit(O);/=cout請(qǐng)輸入(Y/y)消去連接符號(hào) comma nd8;if(comma nd8 = y | comma nd8 = Y)orig n = del_a nd(orig n);cout消去連接符號(hào)后是endlorig nen dl;elseexit(0)
10、;/=cout請(qǐng)輸入(Y/y)變量分離標(biāo)準(zhǔn)化 comma nd9;if(comma nd9 = y | comma nd9 = Y)orig n = cha nge_n ame(orig n);cout變量分離標(biāo)準(zhǔn)化后是 (x1,x2,x3代替變量x)endlorig nen dl;elseexit(0);/:cout”完畢e ndl;cout(請(qǐng)輸入 Y/y)結(jié)束endl;dowhile(y = getchar() | Y=getchar();exit(O); void in itStri ng(stri ng &ini)char comma nda,comma ndb;cout請(qǐng)輸入您所需
11、要轉(zhuǎn)換的謂詞公式e ndl;cout需要查看輸入幫助 (Y/N)? comma nda;if(comma nda = Y | comma nda = y)cout,全稱量詞為,存在量詞為#,endl取反為,吸取為!,合取為%,左右括號(hào)分別為(、),函數(shù)名請(qǐng)用一個(gè)字母e ndl;cout請(qǐng)輸入(y/n)選擇是否用戶自定義 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 變?yōu)?a!bchar ctemp100=;
12、stri ng output;int len gth = temp.le ngth();int i = O,right_bracket = O,falg= 0;stack stack1,stack2,stack3;strcpy(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;e
13、lse if() = 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
14、.push(stack1.top(); stack1.pop();while(!stack2.empty()output += stack2.top();stack2.pop();if(falg = 1)return output;elsereturn temp;string dec_neg_rand(string temp)/ 減少否定符號(hào)的轄域 char ctemp100,tempc;stri ng output;int flag2 = 0;int i = 0,left_bracket = 0,le ngth = temp .len gth(); stack stack1,stack2;q
15、ueue queue1; strcpy(ctemp,temp.c_str(); 復(fù)制到字符數(shù)組中 while(ctempi != 0 & i =0);queue1.push();while(!queue1.empty()tempc = queuel.fro nt(); queue1.pop(); stackl.push(tempc);i +;while(!stack1.empty()stack2.push(stack1.top(); stack1.pop();while(!stack2.empty()output += stack2.top(); stack2.pop();if(flag2 =
16、 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;strcpy(ctemp1,temp.c_str();while(ctemp1j != 0 & j =0 & times = 0)stack11.push(ctemp1j);if(ctemp1j=()ini eftbackets +;else if(ctemp1j=)ini eftba
17、ckets -;if(i nleftbackets = 1 & ctemp1j+1 = ! & ctemp1j+2 != & ctemp1j+2 != #)falgl =1;stackll.push();/stack11.push(%);stack11.push();stack11.push();/j =j+1;if(i nleftbackets = 1 & ctemp1j+1 = % & ctemp1j+2 != & ctemp1j+2 != #)falgl =1;stackll.push();/stack11.push(!);stack11.push();stack11.push();/j
18、 =j+1;j = j +1;if(falg1 = 1)stackll.push(); stack11.pop();stackll.push();/此處有 bug stackll.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;stri ng output3;int
19、k = 0,left_bracket3 = 1,le ngth3 = temp.le ngth(); stack stack13,stack23;int flag = 0,bflag = 0;strcpy(ctemp3,temp.c_str(); 復(fù)制到字符數(shù)組中 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
20、.pop();k +;while(!stack13.empty()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)/對(duì)變量標(biāo)準(zhǔn)化,簡(jiǎn)化,不考慮多層嵌套 char ctemp100,des10= ;strcpy(ctemp,temp.c_str();stack stack1,st
21、ack2;int l_bracket = 1,falg = 0,bracket = 1;int i = 0,j = 0;stri ng output;while(ctempi != 0 & i temp.le ngth() 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 !=
22、0)if(ctempi=()l_bracket +;if(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(k
23、k != 0)if(ctempi=()kk+;if(ctempi =)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 te
24、mp)/ 消去存在量詞char ctemp100,u nknow;strcpy(ctemp,temp.c_str();int left_brackets = 0,i = 0,falg = 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 +;left_brackets -;if(ctempi=)if(ctempi = unknow)q
25、ueuel.push(g);queue1.push();queuel.push(x); queuel.push();if(ctempi != unknow)queue1.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)/ 化為前束形 ch
26、ar ctemp100; strcpy(ctemp,temp.c_str();int i = 0;stri ng out_var = output =; while(ctempi != 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
27、_var + output;return output;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;stri ng output =;while(ctempi != 0 & i temp.le ngth(
28、)if(ctempi = ( & ctempi+1 = )i = i + 4;flag = 1;elseoutput = output + ctempi;i +;return output;string del_and(string temp)/ 消去連接符號(hào)合取 %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+;re
29、turn output;stri ng cha nge_n ame(stri ng temp)/ 更換變量名稱char ctemp100;strcpy(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 output;bool isAlbum(char t
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 外墻白色砂漿施工方案
- 花園隔墻新建施工方案
- 覆蓋裸土密目網(wǎng)施工方案
- 圓梁和圓梁模板施工方案
- 不銹鋼大便槽施工方案
- 原木波浪板施工方案
- 臺(tái)階斜坡防水施工方案
- 春節(jié)活動(dòng)領(lǐng)導(dǎo)發(fā)言稿
- 環(huán)境日宣傳活動(dòng)方案
- 龍泉驛污水井清淤施工方案
- 2024年08月河北唐山銀行第二批社會(huì)招考筆試歷年參考題庫(kù)附帶答案詳解
- 小學(xué)生拗九節(jié)課件
- 巨量千川中級(jí)營(yíng)銷(xiāo)師認(rèn)證考試題(附答案)
- 2025中智集團(tuán)招聘高頻重點(diǎn)提升(共500題)附帶答案詳解
- 《智能制造技術(shù)基礎(chǔ)》課件-第2章 智能系統(tǒng)方案與設(shè)計(jì)
- 人教版PEP小學(xué)五年級(jí)英語(yǔ)下冊(cè)全冊(cè)教案(含計(jì)劃)
- 2025年幼兒園膳食工作計(jì)劃
- 《基于二維激光SLAM的AGV導(dǎo)航系統(tǒng)設(shè)計(jì)》
- 金融公司早會(huì)內(nèi)容
- 《下載-綜合布線》課件
- 可穿戴生理傳感器驅(qū)動(dòng)的深度學(xué)習(xí)情緒識(shí)別模型在心理健康評(píng)估中的應(yīng)用
評(píng)論
0/150
提交評(píng)論