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.