Engineering Tools for AI

Tài liệu khoa học máy tính

Hướng dẫn toán tử logic

Tìm hiểu AND, OR, NOT, XOR, NAND, NOR và các toán tử liên quan qua bảng chân trị, đại số Boolean, mạch số, lập trình và ví dụ câu hỏi AI.

Logic cơ bản

NOT

Ký hiệu
¬A, A'
Lập trình
Mạch
Inverter gate

Ví dụ

Reverses a truth value.

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

Bảng chân trị

AOut
01
10

Logic cơ bản

AND

Ký hiệu
A·B, AB
Lập trình
Mạch
AND gate

Ví dụ

True only when every input is true.

isLoggedIn && hasPermission

Bảng chân trị

ABOut
000
010
100
111

Logic cơ bản

OR

Ký hiệu
A+B
Lập trình
Mạch
OR gate

Ví dụ

True when at least one input is true.

isAdmin || isOwner

Bảng chân trị

ABOut
000
011
101
111

Toán tử dẫn xuất

XOR

Ký hiệu
A⊕B
Lập trình
Mạch
XOR gate

Ví dụ

True when the inputs are different.

Half adder sum = A XOR B.

Bảng chân trị

ABOut
000
011
101
110

Toán tử dẫn xuất

NAND

Ký hiệu
¬(A·B)
Lập trình
Mạch
NAND gate

Ví dụ

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

A NAND B = NOT (A AND B).

Bảng chân trị

ABOut
001
011
101
110

Toán tử dẫn xuất

NOR

Ký hiệu
¬(A+B)
Lập trình
Mạch
NOR gate

Ví dụ

The negation of OR. NOR is also functionally complete.

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

Bảng chân trị

ABOut
001
010
100
110

Toán tử dẫn xuất

XNOR

Ký hiệu
¬(A⊕B)
Lập trình
Mạch
XNOR gate

Ví dụ

True when the inputs are the same.

A XNOR B behaves like equality for Boolean values.

Bảng chân trị

ABOut
001
010
100
111

Toán tử bit

Bitwise AND

Ký hiệu
bit mask
Lập trình
Mạch
Per-bit AND operation

Ví dụ

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

0101 & 0011 = 0001

Lập trình

Short-circuit evaluation

Ký hiệu
evaluation rule
Lập trình
Mạch
Programming evaluation behavior

Ví dụ

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

user && user.name

Luật đại số Boolean

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.