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 and ), 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: (or sometimes )
- English: "It is not the case that ."
2. Conjunction (AND)
A conjunction is true only if both individual propositions are true.
- Symbol:
- English: " and ."
3. Disjunction (OR)
In mathematics, "OR" is inclusive. It is true if is true, if is true, or if both are true.
- Symbol:
- English: " or ."
4. Exclusive OR (XOR)
The output is true only if the inputs are different. If both are True, the result is False.
- Symbol:
- English: "Either or , but not both."
5. Summary Table of Truth Values
To see how these connectives behave, we look at their Truth Table.
| (AND) | (OR) | (XOR) | |||
|---|---|---|---|---|---|
| T | T | F | T | T | F |
| T | F | F | F | T | T |
| F | T | T | F | T | T |
| F | F | T | F | F | F |
Visualizing Logic Gates
In digital electronics, these connectives are represented as physical Gates.
1. Standard Gates (AND, OR, NOT)
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.
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.
[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):
- Parentheses
- Negation
- Conjunction
- Disjunction
- Implication
- Biconditional
Example: is evaluated as .
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