实现基于谓词逻辑的归结原理Word文档格式.docx

上传人:b****6 文档编号:16773239 上传时间:2022-11-26 格式:DOCX 页数:26 大小:99.81KB
下载 相关 举报
实现基于谓词逻辑的归结原理Word文档格式.docx_第1页
第1页 / 共26页
实现基于谓词逻辑的归结原理Word文档格式.docx_第2页
第2页 / 共26页
实现基于谓词逻辑的归结原理Word文档格式.docx_第3页
第3页 / 共26页
实现基于谓词逻辑的归结原理Word文档格式.docx_第4页
第4页 / 共26页
实现基于谓词逻辑的归结原理Word文档格式.docx_第5页
第5页 / 共26页
点击查看更多>>
下载资源
资源描述

实现基于谓词逻辑的归结原理Word文档格式.docx

《实现基于谓词逻辑的归结原理Word文档格式.docx》由会员分享,可在线阅读,更多相关《实现基于谓词逻辑的归结原理Word文档格式.docx(26页珍藏版)》请在冰豆网上搜索。

实现基于谓词逻辑的归结原理Word文档格式.docx

queue>

usingnamespacestd;

//一些函数的定义

voidinitString(string&

ini);

//初始化

stringdel_inlclue(stringtemp);

//消去蕴涵符号

stringdec_neg_rand(stringtemp);

//减少否定符号的辖域

stringstandard_var(stringtemp);

//对变量标准化

stringdel_exists(stringtemp);

//消去存在量词

stringconvert_to_front(stringtemp);

//化为前束形

stringconvert_to_and(stringtemp);

//把母式化为合取范式

stringdel_all(stringtemp);

//消去全称量词

stringdel_and(stringtemp);

//消去连接符号合取%

stringchange_name(stringtemp);

//更换变量名称

//辅助函数定义

boolisAlbum(chartemp);

//是字母

stringdel_null_bracket(stringtemp);

//删除多余的括号

stringdel_blank(stringtemp);

//删除多余的空格

voidcheckLegal(stringtemp);

//检查合法性

charnumAfectChar(inttemp);

//数字显示为字符

//主函数

voidmain()

{

cout<

<

"

------------------求子句集九步法演示-----------------------"

endl;

system("

color0A"

);

//orign="

Q(x,y)%~(P(y)"

;

(@x)(P(y)>

P)"

~(#x)y(x)"

~((@x)x!

b(x))"

~(x!

y)"

~(~a(b))"

stringorign,temp;

charcommand,command0,command1,command2,command3,command4,command5,

command6,command7,command8,command9,command10;

//=============================================================================

请输入(Y/y)初始化谓词演算公式"

cin>

>

command;

if(command=='

y'

||command=='

Y'

initString(orign);

else

exit(0);

<

orign<

}

请输入(Y/y)减少否定符号的辖域"

command2;

if(command2=='

||command2=='

{

do

{

temp=orign;

orign=dec_neg_rand(orign);

}while(temp!

=orign);

cout<

减少否定符号的辖域后是"

endl

<

//=============================================================================

请输入(Y/y)对变量进行标准化"

command3;

if(command3=='

||command3=='

orign=standard_var(orign);

对变量进行标准化后是"

请输入(Y/y)消去存在量词"

command4;

if(command4=='

||command4=='

orign=del_exists(orign);

消去存在量词后是(w=g(x)是一个Skolem函数)"

请输入(Y/y)化为前束形"

command5;

if(command5=='

||command5=='

orign=convert_to_front(orign);

化为前束形后是"

请输入(Y/y)把母式化为合取方式"

command6;

if(command6=='

||command6=='

orign=convert_to_and(orign);

把母式化为合取方式后是"

请输入(Y/y)消去全称量词"

command7;

if(command7=='

||command7=='

orign=del_all(orign);

消去全称量词后是"

请输入(Y/y)消去连接符号"

command8;

if(command8=='

||command8=='

orign=del_and(orign);

消去连接符号后是"

请输入(Y/y)变量分离标准化"

command9;

if(command9=='

||command9=='

orign=change_name(orign);

变量分离标准化后是(x1,x2,x3代替变量x)"

//============================================================================

-------------------------完毕-----------------------------------"

(请输入Y/y)结束"

do

}while('

==getchar()||'

==getchar());

exit(0);

}

ini)

charcommanda,commandb;

请输入您所需要转换的谓词公式"

需要查看输入帮助(Y/N)?

"

commanda;

if(commanda=='

||commanda=='

本例程规定输入时蕴涵符号为>

全称量词为@,存在量词为#,"

取反为~,吸取为!

合取为%,左右括号分别为(、),函数名请用一个字母"

请输入(y/n)选择是否用户自定义"

commandb;

if(commandb=='

||commandb=='

cin>

ini;

ini="

(@x)(P(x)>

((@y)(P(y)>

P(f(x,y)))%~(@y)(Q(x,y)>

P(y))))"

原始命题是"

ini<

stringdel_inlclue(stringtemp)//消去>

蕴涵项

//a>

b变为~a!

b

charctemp[100]={"

};

stringoutput;

intlength=temp.length();

inti=0,right_bracket=0,falg=0;

stack<

char>

stack1,stack2,stack3;

strcpy(ctemp,temp.c_str());

while(ctemp[i]!

='

\0'

&

&

i<

=length-1)

stack1.push(ctemp[i]);

if('

'

==ctemp[i+1])//如果是a>

b则用~a!

b替代

falg=1;

if(isAlbum(ctemp[i]))//如果是字母则把ctemp[i]弹出

{

stack1.pop();

stack1.push('

~'

stack1.push(ctemp[i]);

!

i=i+1;

}

elseif('

)'

==ctemp[i])

right_bracket++;

do

{

if('

('

==stack1.top())

right_bracket--;

stack3.push(stack1.top());

stack1.pop();

}while((right_bracket!

=0));

stack3.push(stack1.top());

while(!

stack3.empty())

stack1.push(stack3.top());

stack3.pop();

}

}

i++;

while(!

stack1.empty())

stack2.push(stack1.top());

stack1.pop();

stack2.empty())

output+=stack2.top();

stack2.pop();

if(falg==1)

returnoutput;

returntemp;

stringdec_neg_rand(stringtemp)//减少否定符号的辖域

charctemp[100],tempc;

intflag2=0;

inti=0,left_bracket=0,length=temp.length();

stack<

stack1,stack2;

queue<

queue1;

//复制到字符数组中

=length-1)

if(ctemp[i]=='

)//如果是~否则什么都不做

charfo=ctemp[i+2];

if(ctemp[i+1]=='

)//如果是(,否则什么都不做

if(fo=='

@'

||fo=='

#'

)//如果是全称量词

flag2=1;

i++;

stack1.push(ctemp[i]);

if(fo=='

stack1.push('

else

stack1.push(ctemp[i+2]);

stack1.push(ctemp[i+3]);

stack1.push('

if(isAlbum(ctemp[i+4]))

{

stack1.push(ctemp[i+4]);

i=i+5;

}

i=i+4;

do

queue1.push(temp[i]);

if(temp[i]=='

left_bracket++;

elseif(temp[i]=='

left_bracket--;

i++;

}while(left_bracket!

=0&

left_bracket>

=0);

queue1.push('

while(!

queue1.empty())

tempc=queue1.front();

queue1.pop();

stack1.push(tempc);

i++;

if(flag2==1)

temp=output;

/************************************************************/

charctemp1[100];

stringoutput1;

stack11,stack22;

intfalg1=0;

inttimes=0;

intlength1=temp.length(),inleftbackets=1,j=0;

strcpy(ctemp1,temp.c_str());

while(ctemp1[j]!

j<

=(length1-1))

stack11.push(ctemp1[j]);

if(ctemp1[j]=='

if(ctemp1[j+1]=='

/*&

ctemp1[j+2]!

*/)

j=j+2;

stack11.push('

////////////////

while(inleftbackets!

inleftbackets>

=0&

times<

=(length1-j)&

times>

=0)

stack11.push(ctemp1[j]);

if(ctemp1[j]=='

inleftbackets++;

elseif(ctemp1[j]=='

inleftbackets--;

if(inleftbackets==1&

ctemp1[j+1]=='

ctemp1[j+2]!

falg1=1;

stack11.push('

//////////

%'

j=j+1;

j=j+1;

if(falg1==1)

stack11.push('

stack11.pop();

//此处有bug

j++;

stack11.empty())

stack22.push(stack11.top());

stack11.pop();

stack22.empty())

output1+=stack22.top();

stack22.pop();

if(falg1==1)

temp=output1;

charctemp3[100];

stringoutput3;

intk=0,left_bracket3=1,length3=temp.length();

stack13,stack23;

intflag=0,bflag=0;

strcpy(ctemp3,temp.c_str());

while(ctemp3[k]!

k<

=length3-1)

stack13.push(ctemp3[k]);

if(ctemp3[k]=='

if(ctemp3[k+1]=='

if(ctemp3[k+2]=='

flag=1;

stack13.pop();

k=k+2;

while(left_bracket3!

left_bracket3>

=0)

stack13.push(ctemp3[k+1]);

if(ctemp3[k+1]=='

left_bracket3++;

le

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高中教育 > 语文

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

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