ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【程序员的数学】关于几种逻辑

2021-11-29 11:30:19  阅读:163  来源: 互联网

标签:ABA 逻辑 相等 undefined 几种 程序员 && 三值


基本概念:

逻辑是消除歧义的工具,在编程过程中发挥着重要的作用。在考虑的过程中,确认是否有“遗漏”(完整性)和“重复”(排他性)是相当重要的。

命题:能够判断对错的陈述句。

逻辑非:不是A( not  A)

A\rightharpoondownA
truefalse
falsetrue

双重否定(等于肯定):不是 不是A(not not A)

A\rightharpoondownA\rightharpoondown\rightharpoondownA
truefalsetrue
falsetruefalse

逻辑与:A并且B(A and B)

ABA  \wedge B
truetruetrue
falsetruefalse
truefalsefalse
falsefalsefalse

逻辑或:A或者B(A or B)

AB\vee B
truetruetrue
falsetruetrue
truefalsetrue
falsefalsefalse

异或:A或者B(但不都满足)

ABA  \small \bigoplus  B
truetruefalse
truefalsetrue
falsetruetrue
falsefalsefalse

相等:A和B相等

ABA=B
truetruetrue
falsetruefalse
truefalsefalse
falsefalsetrue

蕴涵:若A则B

ABA\small \RightarrowB
truetruetrue
truefalsefalse
falsetruetrue
falsefalsetrue

注意,生活中提到的如果A是真的,B也是真的A是假的,B也是假的。体现的是逻辑A=B。

这里提到的A\small \RightarrowB是指如果A是真的,B也是真的如果A是假的,B是真是假都可以,不受影响。

德摩根定律:

\small \rightharpoondownA)\vee\small \rightharpoondownB)=\small \rightharpoondown(A  \wedge B)

 (\small \rightharpoondownA)\wedge\small \rightharpoondownB)=\small \rightharpoondown(A  \vee B)

三值逻辑:包括未定义(undefined)的逻辑。

带条件的逻辑与:(A && B)

ABA&&B
truetruetrue
truefalsefalse
trueundefinedundefined
falsetruefalse
falsefalsefalse
falseundefinedfalse
undefinedtrueundefined
undefinedfalseundefined
undefinedundefinedundefined

注意,不包含undefined时,A&&B和A\small \wedgeB相等。

 

带条件的逻辑或:(A || B)

ABA  || B
truetruetrue
truefalsetrue
trueundefinedtrue
falsetruetrue
falsefalsefalse
falseundefinedundefined
undefinedtrueundefined
undefinedfalseundefined
undefinedundefinedundefined

 注意,不包含undefined时,A || B和A \small \vee B相等。

 

三值逻辑中的否定(!)

A!A
truefalse
falsetrue
undefinedundefined

三值逻辑的德摩根定律

(!A)||(!B)=!(A && B)

(!A)&&(!B)=!(A || B)

标签:ABA,逻辑,相等,undefined,几种,程序员,&&,三值
来源: https://blog.csdn.net/weixin_46065980/article/details/121604288

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有