【程序员的数学】关于几种逻辑
2021/11/29 11:37:45
本文主要是介绍【程序员的数学】关于几种逻辑,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
基本概念:
逻辑是消除歧义的工具,在编程过程中发挥着重要的作用。在考虑的过程中,确认是否有“遗漏”(完整性)和“重复”(排他性)是相当重要的。
命题:能够判断对错的陈述句。
逻辑非:不是A( not A)
A | A |
true | false |
false | true |
双重否定(等于肯定):不是 不是A(not not A)
A | A | A |
true | false | true |
false | true | false |
逻辑与:A并且B(A and B)
A | B | A B |
true | true | true |
false | true | false |
true | false | false |
false | false | false |
逻辑或:A或者B(A or B)
A | B | A B |
true | true | true |
false | true | true |
true | false | true |
false | false | false |
异或:A或者B(但不都满足)
A | B | A B |
true | true | false |
true | false | true |
false | true | true |
false | false | false |
相等:A和B相等
A | B | A=B |
true | true | true |
false | true | false |
true | false | false |
false | false | true |
蕴涵:若A则B
A | B | AB |
true | true | true |
true | false | false |
false | true | true |
false | false | true |
注意,生活中提到的如果A是真的,B也是真的;A是假的,B也是假的。体现的是逻辑A=B。
这里提到的AB是指如果A是真的,B也是真的;如果A是假的,B是真是假都可以,不受影响。
德摩根定律:
(A)(B)=(A B)
(A)(B)=(A B)
三值逻辑:包括未定义(undefined)的逻辑。
带条件的逻辑与:(A && B)
A | B | A&&B |
true | true | true |
true | false | false |
true | undefined | undefined |
false | true | false |
false | false | false |
false | undefined | false |
undefined | true | undefined |
undefined | false | undefined |
undefined | undefined | undefined |
注意,不包含undefined时,A&&B和AB相等。
带条件的逻辑或:(A || B)
A | B | A || B |
true | true | true |
true | false | true |
true | undefined | true |
false | true | true |
false | false | false |
false | undefined | undefined |
undefined | true | undefined |
undefined | false | undefined |
undefined | undefined | undefined |
注意,不包含undefined时,A || B和A B相等。
三值逻辑中的否定(!)
A | !A |
true | false |
false | true |
undefined | undefined |
三值逻辑的德摩根定律
(!A)||(!B)=!(A && B)
(!A)&&(!B)=!(A || B)
这篇关于【程序员的数学】关于几种逻辑的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-10-01基于Python+Vue开发的医院门诊预约挂号系统
- 2024-10-01基于Python+Vue开发的旅游景区管理系统
- 2024-10-01RestfulAPI入门指南:打造简单易懂的API接口
- 2024-10-01初学者指南:了解和使用Server Action
- 2024-10-01Server Component入门指南:搭建与配置详解
- 2024-10-01React 中使用 useRequest 实现数据请求
- 2024-10-01使用 golang 将ETH账户的资产平均分散到其他账户
- 2024-10-01JWT用户校验课程:从入门到实践
- 2024-10-01Server Component课程入门指南
- 2024-09-30Dnd-Kit学习:新手快速入门指南