Engineering Tools for AI

计算机科学学习资料

逻辑运算符说明

整理 AND、OR、NOT、XOR、NAND、NOR 等逻辑运算,并搭配真值表、布尔代数、数字电路、编程与 AI 提问示例。

基础逻辑

NOT

标记
¬A, A'
编程
电路
Inverter gate

示例

Reverses a truth value.

If A means logged in, ¬A means not logged in.

真值表

AOut
01
10

基础逻辑

AND

标记
A·B, AB
编程
电路
AND gate

示例

True only when every input is true.

isLoggedIn && hasPermission

真值表

ABOut
000
010
100
111

基础逻辑

OR

标记
A+B
编程
电路
OR gate

示例

True when at least one input is true.

isAdmin || isOwner

真值表

ABOut
000
011
101
111

派生运算

XOR

标记
A⊕B
编程
电路
XOR gate

示例

True when the inputs are different.

Half adder sum = A XOR B.

真值表

ABOut
000
011
101
110

派生运算

NAND

标记
¬(A·B)
编程
电路
NAND gate

示例

The negation of AND. NAND gates can build any Boolean circuit.

A NAND B = NOT (A AND B).

真值表

ABOut
001
011
101
110

派生运算

NOR

标记
¬(A+B)
编程
电路
NOR gate

示例

The negation of OR. NOR is also functionally complete.

A NOR B is true only when both inputs are false.

真值表

ABOut
001
010
100
110

派生运算

XNOR

标记
¬(A⊕B)
编程
电路
XNOR gate

示例

True when the inputs are the same.

A XNOR B behaves like equality for Boolean values.

真值表

ABOut
001
010
100
111

位运算

Bitwise AND

标记
bit mask
编程
电路
Per-bit AND operation

示例

Applies AND to each bit position. It is different from logical &&.

0101 & 0011 = 0001

编程

Short-circuit evaluation

标记
evaluation rule
编程
电路
Programming evaluation behavior

示例

The second expression may not run if the first expression already determines the result.

user && user.name

布尔代数法则

Identity laws

A ∧ 1 = A, A ∨ 0 = A

Combining with the neutral truth value leaves A unchanged.

Domination laws

A ∧ 0 = 0, A ∨ 1 = 1

One fixed input can determine the entire result.

Complement laws

A ∧ ¬A = 0, A ∨ ¬A = 1

A statement and its negation cannot both be true, but at least one is true.

De Morgan's laws

¬(A ∧ B) = ¬A ∨ ¬B, ¬(A ∨ B) = ¬A ∧ ¬B

Moves a negation across AND or OR while switching the operator.

Absorption laws

A ∨ (A ∧ B) = A, A ∧ (A ∨ B) = A

A repeated condition can absorb a more specific condition.