Engineering Tools for AI

Référence en informatique

Guide des opérateurs logiques

Comprenez AND, OR, NOT, XOR, NAND, NOR et les opérateurs associés à travers des tables de vérité, l'algèbre de Boole, les circuits numériques, la programmation et les invites IA.

Logique de base

NOT

Notation
¬A, A'
Programmation
Circuit
Inverter gate

Exemple

Reverses a truth value.

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

Table de vérité

AOut
01
10

Logique de base

AND

Notation
A·B, AB
Programmation
Circuit
AND gate

Exemple

True only when every input is true.

isLoggedIn && hasPermission

Table de vérité

ABOut
000
010
100
111

Logique de base

OR

Notation
A+B
Programmation
Circuit
OR gate

Exemple

True when at least one input is true.

isAdmin || isOwner

Table de vérité

ABOut
000
011
101
111

Opérateurs dérivés

XOR

Notation
A⊕B
Programmation
Circuit
XOR gate

Exemple

True when the inputs are different.

Half adder sum = A XOR B.

Table de vérité

ABOut
000
011
101
110

Opérateurs dérivés

NAND

Notation
¬(A·B)
Programmation
Circuit
NAND gate

Exemple

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

A NAND B = NOT (A AND B).

Table de vérité

ABOut
001
011
101
110

Opérateurs dérivés

NOR

Notation
¬(A+B)
Programmation
Circuit
NOR gate

Exemple

The negation of OR. NOR is also functionally complete.

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

Table de vérité

ABOut
001
010
100
110

Opérateurs dérivés

XNOR

Notation
¬(A⊕B)
Programmation
Circuit
XNOR gate

Exemple

True when the inputs are the same.

A XNOR B behaves like equality for Boolean values.

Table de vérité

ABOut
001
010
100
111

Opérateurs bit à bit

Bitwise AND

Notation
bit mask
Programmation
Circuit
Per-bit AND operation

Exemple

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

0101 & 0011 = 0001

Programmation

Short-circuit evaluation

Notation
evaluation rule
Programmation
Circuit
Programming evaluation behavior

Exemple

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

user && user.name

Lois de l'algèbre de Boole

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.