Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1599226
  • 博文数量: 1481
  • 博客积分: 26784
  • 博客等级: 上将
  • 技术积分: 17045
  • 用 户 组: 普通用户
  • 注册时间: 2011-07-12 09:22
文章分类

全部博文(1481)

文章存档

2014年(10)

2013年(353)

2012年(700)

2011年(418)

分类: 系统运维

2012-09-21 09:28:18

离散数学与计算机编程(一)
命题函数
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;
}
欢迎讨论,如有疑问Email:misko_lee@hotmail.com

原文地址:

阅读(293) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~