当前位置:编程学习 > 网站相关 >>

离散数学与计算机编程(一) 命题函数

离散数学与计算机编程(一)
命题函数
author:misko_lee

global var:设含有变量的命题是命题函数,记作P(X)(P(X1,X2,Xn))(若无说明,本系列全部以单变量函数为描述方式)。则有:
1.?xP(x)表示该命题论域的合取。
2.?xP(x)表示该命题论域的析取。


Content:


上面的定理在计算机中的描述可以表示为。


exp1:?xP(x)


bool function fcn(x){
//the var x is a array type.


foreach(value as x){
if(value==false)
return false;
}
return true; //if the value as x all equal true.the function return true;
}


exp2:?xP(x)


bool function fcn(x){
//the var x is a array type.


foreach(value as x){
if(value==true)
return true; //if the array x has a true value.the function return true.
}
return false; //if all false.return false;
}


上面介绍了全称变量和存在变量的意义。现在我们将一个稍微复杂的组合命题用计算机语言描述出来。


exp3:对于学校的每一个学生而言,他有台计算机或者有个有计算机的朋友。(例子来自于《离散数学及其应用》)。
设命题函数C(X)表示X有台计算机。
命题函数F(X,Y)表示y是x的朋友。
我们将该命题用离散语言描述出来为

 

我们将该命题用离散语言描述出来为
?x(C(x)∨ ?y(C(y)∧F(x,y)))
计算机中描述为
struct x{
bool computer; //if has the var equal true
x[] friends; //x’s friends
}
function C(x){ //the fucntion return value from x.computer
if(x.computer==true)
return true;
return false;
}
function F(x){ //foreach he’s friends
foreach(f as x->friends)
if(f==y&&C(y))
return true;
return false;
}
function main(x){ //the main function;
if(C(x)||F(x))
return true;
return false;

补充:综合编程 , 其他综合 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,