Academy

Logical Connectives

Mastering AND, OR, NOT, XOR, and XNOR to build complex compound propositions.

Logical Connectives

Now that we have our "Atoms" (Simple Propositions like pp and qq), we need a way to glue them together. In Propositional Calculus, we use Logical Connectives to build complex sentences.

Think of these as the mathematical operators of the logic world.


1. Negation (NOT)

The simplest operator. It takes a single proposition and flips its truth value.

  • Symbol: ¬p\neg p (or sometimes p\sim p)
  • English: "It is not the case that pp."

2. Conjunction (AND)

A conjunction is true only if both individual propositions are true.

  • Symbol: pqp \land q
  • English: "pp and qq."

3. Disjunction (OR)

In mathematics, "OR" is inclusive. It is true if pp is true, if qq is true, or if both are true.

  • Symbol: pqp \lor q
  • English: "pp or qq."

4. Exclusive OR (XOR)

The output is true only if the inputs are different. If both are True, the result is False.

  • Symbol: pqp \oplus q
  • English: "Either pp or qq, but not both."

5. Summary Table of Truth Values

To see how these connectives behave, we look at their Truth Table.

ppqq¬p\neg ppqp \land q (AND)pqp \lor q (OR)pqp \oplus q (XOR)
TTFTTF
TFFFTT
FTTFTT
FFTFFF

Visualizing Logic Gates

In digital electronics, these connectives are represented as physical Gates.

1. Standard Gates (AND, OR, NOT)

{`graph LR subgraph AND_Gate A1[A] --> G1((AND)) B1[B] --> G1 G1 --> Out1[A ∧ B] end
subgraph OR_Gate
A2[A] --> G2((OR))
B2[B] --> G2
G2 --> Out2[A ∨ B]
end

subgraph NOT_Gate
In3[A] --> G3((NOT))
G3 --> Out3[¬A]
end`}

[Image of logic gate symbols for AND, OR, and NOT]

2. Exclusive Logic (XOR & XNOR)

XNOR (Exclusive NOR) is the negation of XOR. It acts as an Equality Gate, returning True only when inputs are the same.

{`graph LR subgraph XOR_Gate A4[A] --> G4((XOR)) B4[B] --> G4 G4 --> Out4[A ⊕ B] end
subgraph XNOR_Gate
A5[A] --> G5((XNOR))
B5[B] --> G5
G5 --> Out5[A ⊙ B]
end`}

3. The Universal NAND Gate

A NAND gate is an AND gate followed by a NOT gate. It is "Universal" because any other gate can be built using only NAND gates.

{`graph LR A[Input A] --> AND((AND)) B[Input B] --> AND AND -- "A ∧ B" --> NOT((NOT)) NOT --> Out["Output: ¬(A ∧ B)"]`}

[Image of a logic gate circuit diagram showing NAND logic]


Order of Precedence

Just like arithmetic, logic has a standard order of operations (from highest to lowest priority):

  1. Parentheses ()( \dots )
  2. Negation ¬\neg
  3. Conjunction \land
  4. Disjunction \lor
  5. Implication     \implies
  6. Biconditional     \iff

Example: ¬pq\neg p \lor q is evaluated as (¬p)q(\neg p) \lor q.


Why This Matters in Coding

These logical operators are built into every programming language. In Python, we use them to control the flow of our programs.

# Boolean Logic in Python
is_student = True
has_discount_code = False

# Conjunction (AND)
apply_discount = is_student and has_discount_code # Result: False

# Disjunction (OR)
is_eligible = is_student or has_discount_code # Result: True

# Exclusive OR (XOR)
# In Python, the bitwise operator ^ acts as XOR for Booleans
print(True ^ True)  # Result: False
print(True ^ False) # Result: True