// laws and rules · Logical equivalence
Commutative law_
Commutativity says that the order of the operands does not change the truth value of a conjunction or a disjunction. It feels so natural that it is used without thinking, but it pays to know exactly which operators satisfy it: the conditional, for one, does not commute.
Example
(p ∧ q) ⇔ (q ∧ p)
What the variables mean
- ▸ p: “It is sunny”
- ▸ q: “It is Saturday”
In plain words
“It is sunny and it is Saturday” and “it is Saturday and it is sunny” describe exactly the same situation.
Truth table
| p | q | p ∧ q | q ∧ p | (p ∧ q) ⇔ (q ∧ p)★ |
|---|---|---|---|---|
| T | T | T | T | T |
| T | F | F | F | T |
| F | T | F | F | T |
| F | F | F | F | T |
Classification: Tautology · 4 rows
Statement
The law states that p ∧ q ≡ q ∧ p, and likewise p ∨ q ≡ q ∨ p. The biconditional also commutes (p ⇔ q ≡ q ⇔ p), as do XOR, NAND and NOR.
The conditional, however, does not commute: p ⇒ q and q ⇒ p are different formulas, and mixing them up is one of the most common beginner mistakes in logic.
Why it holds: reading the table
Rows where p and q share a value are symmetric by construction. The interesting ones are the mixed rows: with p = T, q = F both sides give F; with p = F, q = T both sides give F again.
Since conjunction requires both members to be true and that requirement does not distinguish positions, the result is identical in all four rows and the biconditional is a tautology.
A caveat when programming
Although they commute logically, in most languages `&&` and `||` short-circuit from left to right, so the order does change what actually runs. `user != null && user.active` is safe, but flipping it may throw.
The same goes for performance: put the cheapest condition — or the one that fails most often — first, even though the logical result is the same.
Examples
Everyday: “I need a passport and a visa” is the same requirement as “I need a visa and a passport”.
Counterexample with the conditional: “if it is a dog, then it is a mammal” is true, but “if it is a mammal, then it is a dog” is false. The conditional does not commute; its correct reversal is the contrapositive.
Relation to other laws
Together with associativity it lets you freely reorder long chains of conjunctions or disjunctions, which makes many brackets unnecessary.
The non-commutativity of the conditional is exactly what gives rise to the fallacy of affirming the consequent and to the need for the contrapositive law.
Try it yourself
Edit the expression in the calculator and watch how every step of the table changes.
Open in the calculator →Related operators
Frequently asked questions
Does the conditional commute? ▼
No. p ⇒ q and q ⇒ p are different; their tables differ in two rows. What is equivalent to p ⇒ q is its contrapositive, ¬q ⇒ ¬p.
What about the biconditional? ▼
Yes, it commutes: p ⇔ q equals q ⇔ p, because it only depends on whether both values match.
If it commutes, can I reorder conditions in code? ▼
Logically yes, but carefully: short-circuiting in && and || means the order affects what gets evaluated and can cause runtime errors.
