Discrete Mathematics YMT211 · Fall 2026 Assoc. Prof. Ferhat Uçar
03 Propositional Logic Monday, October 5, 2026

Logical Equivalences and Boolean Circuits

Biconditional and XOR in depth, the laws of logic, proving and simplifying with equivalences, satisfiability, and how the same laws build the adder inside your CPU.

Learning objectives

By the end of this week you can:

  • 1 Use the biconditional and exclusive or, state when each is true, and rewrite each with ¬, ∧, ∨.
  • 2 Decide whether two formulas are logically equivalent, with a truth table and with a chain of laws.
  • 3 Simplify a compound proposition step by step, naming the law used at every step.
  • 4 Classify formulas as tautology, contradiction or contingency, and decide whether a set of statements is satisfiable (consistent).
  • 5 Solve small logic puzzles and check system specifications with propositional logic.
  • 6 Build half and full adders from logic gates and explain how a CPU adds binary numbers.

★ the wow moment

Your CPU adds numbers with the logic you learned last week.

A one-bit adder is just two formulas: sum = p ⊕ q and carry = p ∧ q. Chain 64 of them and you have the adder in your laptop. On this page you click the inputs of a real full adder and watch a 4-bit adder ripple its carry; in the lab you build it in Python.

Where we are

Last week we built compound propositions and their truth tables. This week asks the next natural question: when do two different-looking formulas say the same thing? Answering it gives us three tools you will use for the rest of your career:

  1. Equivalence. Replacing a formula with a simpler one that means exactly the same, which is what refactoring a condition in code really is.
  2. Satisfiability. Deciding whether a set of requirements can all be true at once.
  3. Circuits. Seeing that a formula is a piece of hardware.

We start by looking more closely at the two connectives we met briefly last week, ↔ and ⊕.

The biconditional, in depth

pqp → qq → pp ↔ q
11111
10010
01100
00111

The table shows where the name comes from: p↔qp \leftrightarrow q is the conditional in both directions, (p→q)∧(q→p)(p \to q) \land (q \to p). That is why mathematicians use it to state definitions and characterizations: pp is both sufficient and necessary for qq.

Four properties are worth knowing by heart (T is “always true”, F is “always false”):

PropertyWhy
p↔p≡Tp \leftrightarrow p \equiv \mathbf{T}a statement always agrees with itself
p↔¬p≡Fp \leftrightarrow \neg p \equiv \mathbf{F}a statement never agrees with its negation
p↔T≡pp \leftrightarrow \mathbf{T} \equiv p“pp iff true” is just pp
p↔F≡¬pp \leftrightarrow \mathbf{F} \equiv \neg p“pp iff false” is “not pp”

In code, the biconditional of two booleans is plain equality: p == q.

Exclusive or, in depth

XOR can be written with the basic connectives in two standard ways. Read them aloud and they make sense:

p⊕q  ≡  (p∧¬q)∨(¬p∧q)“one but not the other”p \oplus q \;\equiv\; (p \land \neg q) \lor (\neg p \land q) \qquad\text{“one but not the other”} p⊕q  ≡  (p∨q)∧¬(p∧q)“at least one, but not both”p \oplus q \;\equiv\; (p \lor q) \land \neg(p \land q) \qquad\text{“at least one, but not both”}

Its algebra is what makes it so useful in computing:

PropertyMeaning
p⊕F≡pp \oplus \mathbf{F} \equiv pXOR with 0 changes nothing
p⊕T≡¬pp \oplus \mathbf{T} \equiv \neg pXOR with 1 flips the bit
p⊕p≡Fp \oplus p \equiv \mathbf{F}anything XOR itself is 0
p⊕q≡q⊕pp \oplus q \equiv q \oplus p, (p⊕q)⊕r≡p⊕(q⊕r)(p \oplus q) \oplus r \equiv p \oplus (q \oplus r)order and grouping do not matter
(p⊕k)⊕k≡p(p \oplus k) \oplus k \equiv pXOR twice with the same key gives the original back

Tautologies, contradictions, contingencies

FormulaKind
p∨¬pp \lor \neg ptautology (law of excluded middle)
p→pp \to ptautology
p∧¬pp \land \neg pcontradiction
p↔¬pp \leftrightarrow \neg pcontradiction
p∧qp \land qcontingency (true in one row of four)

There are two ways to decide which kind a formula is: build its truth table, or simplify it with the laws below until you reach T, F or something that is clearly neither. The truth table always works but grows as 2n2^n; simplification is shorter, and it is what you do on paper and in your head.

Logical equivalence

Method 1: the truth table

Put both formulas side by side and compare the columns. Is ¬(p∧q)≡¬p∨¬q\neg(p \land q) \equiv \neg p \lor \neg q?

pqp ∧ q¬(p ∧ q)¬p¬q¬p ∨ ¬q
1110000
1001011
0101101
0001111

The two result columns are identical, so they are equivalent. This is De Morgan’s law. To show two formulas are not equivalent, one row is enough: a single counterexample.

Try it yourself. Change the formulas, or click a preset, and the checker either confirms the equivalence or shows the row where they disagree:

equivalence checker · is A ≡ B ? ~ & | ^ -> <->

Method 2: the laws of logic

Truth tables do not scale and do not explain why. The second method is algebra: rewrite one formula into the other using equivalences that are already known to hold. Here are the ones you need; T and F stand for any tautology and any contradiction.

LawForm with ∧Form with ∨
Identityp∧T≡pp \land \mathbf{T} \equiv pp∨F≡pp \lor \mathbf{F} \equiv p
Dominationp∧F≡Fp \land \mathbf{F} \equiv \mathbf{F}p∨T≡Tp \lor \mathbf{T} \equiv \mathbf{T}
Idempotentp∧p≡pp \land p \equiv pp∨p≡pp \lor p \equiv p
Double negation¬¬p≡p\neg\neg p \equiv p
Commutativep∧q≡q∧pp \land q \equiv q \land pp∨q≡q∨pp \lor q \equiv q \lor p
Associative(p∧q)∧r≡p∧(q∧r)(p \land q) \land r \equiv p \land (q \land r)(p∨q)∨r≡p∨(q∨r)(p \lor q) \lor r \equiv p \lor (q \lor r)
Distributivep∧(q∨r)≡(p∧q)∨(p∧r)p \land (q \lor r) \equiv (p \land q) \lor (p \land r)p∨(q∧r)≡(p∨q)∧(p∨r)p \lor (q \land r) \equiv (p \lor q) \land (p \lor r)
De Morgan¬(p∧q)≡¬p∨¬q\neg(p \land q) \equiv \neg p \lor \neg q¬(p∨q)≡¬p∧¬q\neg(p \lor q) \equiv \neg p \land \neg q
Absorptionp∧(p∨q)≡pp \land (p \lor q) \equiv pp∨(p∧q)≡pp \lor (p \land q) \equiv p
Negationp∧¬p≡Fp \land \neg p \equiv \mathbf{F}p∨¬p≡Tp \lor \neg p \equiv \mathbf{T}

Notice the duality: every law in the ∧ column turns into the law in the ∨ column if you swap ∧ with ∨ and T with F. Learn one column and you get the other for free.

The conditional and the biconditional have their own equivalences. The first one is the most used line in this whole course:

EquivalenceName or meaning
p→q≡¬p∨qp \to q \equiv \neg p \lor qconditional as a disjunction
p→q≡¬q→¬pp \to q \equiv \neg q \to \neg pcontrapositive
¬(p→q)≡p∧¬q\neg(p \to q) \equiv p \land \neg qhow a promise is broken
p∨q≡¬p→qp \lor q \equiv \neg p \to q“if not this, then that”
(p→q)∧(p→r)≡p→(q∧r)(p \to q) \land (p \to r) \equiv p \to (q \land r)one hypothesis, two conclusions
(p→r)∧(q→r)≡(p∨q)→r(p \to r) \land (q \to r) \equiv (p \lor q) \to rproof by cases (week 7)
(p∧q)→r≡p→(q→r)(p \land q) \to r \equiv p \to (q \to r)exportation
p↔q≡(p→q)∧(q→p)p \leftrightarrow q \equiv (p \to q) \land (q \to p)biconditional as two conditionals
¬(p↔q)≡p↔¬q≡p⊕q\neg(p \leftrightarrow q) \equiv p \leftrightarrow \neg q \equiv p \oplus qnegating a biconditional

Proving equivalences step by step

A proof by equivalences is a chain A≡A1≡A2≡⋯≡BA \equiv A_1 \equiv A_2 \equiv \dots \equiv B where every step names a law. Write one step per line, like code, so that a reader can check each line on its own.

Simplification

Simplifying means the same chain of laws, but you do not know the target in advance: you stop when nothing shorter is possible. These come from the lecture slides, each with the law used at every step.

Satisfiability and SAT

Is (p∨¬q)∧(q∨¬r)∧(r∨¬p)(p \lor \neg q) \land (q \lor \neg r) \land (r \lor \neg p) satisfiable? Read it as a cycle: q→pq \to p, r→qr \to q, p→rp \to r. It is true when p,q,rp, q, r are all equal, so yes, for example with all three true. Now add “at least one is true” and “at least one is false”:

(p∨¬q)∧(q∨¬r)∧(r∨¬p)∧(p∨q∨r)∧(¬p∨¬q∨¬r)(p \lor \neg q) \land (q \lor \neg r) \land (r \lor \neg p) \land (p \lor q \lor r) \land (\neg p \lor \neg q \lor \neg r)

The first three force all variables to be equal; the last two forbid all-true and all-false. Nothing is left: the formula is unsatisfiable. Paste it into the playground below as (p | ~q) & (q | ~r) & (r | ~p) & (p | q | r) & (~p | ~q | ~r) and watch the verdict turn into “contradiction”.

logic playground · truth_table.py

~ not · & and · | or · ^ xor · -> implies · <-> iff · variables p q r s …

python › 

Logic at work: specifications and puzzles

Are these requirements consistent?

Specifications are written in English, so engineers translate them into logic to check that they do not contradict each other. Let pp: the user is authenticated, qq: access is granted, rr: the account is locked.

  1. Access is granted only if the user is authenticated: q→pq \to p.
  2. If the account is locked, access is not granted: r→¬qr \to \neg q.
  3. Authenticated users are granted access: p→qp \to q.

These three are consistent: for example p=q=1p = q = 1, r=0r = 0 satisfies all of them. Now a customer asks for a fourth requirement:

  1. Some authenticated user has a locked account: p∧rp \land r.

From 4 and 3 we get qq; from 4 and 2 we get ¬q\neg q. The four requirements are inconsistent: no system can meet all of them, and finding that out on paper is far cheaper than finding it in production.

Knights and Knaves

On an island, knights always tell the truth and knaves always lie (Raymond Smullyan’s puzzles). You meet A and B.

  • A says: “B is a knight.”
  • B says: “The two of us are of opposite types.”

Let pp: A is a knight, qq: B is a knight. A’s statement is true exactly when A is a knight, so p↔qp \leftrightarrow q. B’s statement gives q↔(p⊕q)q \leftrightarrow (p \oplus q). We need both:

(p↔q)∧(q↔(p⊕q))(p \leftrightarrow q) \land \big(q \leftrightarrow (p \oplus q)\big)

The first part forces p=qp = q; then p⊕qp \oplus q is false, so the second part forces qq to be false. Both are knaves. Type (p <-> q) & (q <-> (p ^ q)) into the playground: exactly one row, p=q=0p = q = 0, is true. The pattern “a speaker is a knight iff what they say is true” turns every such puzzle into a satisfiability problem. In Lab 2 you write a program that solves any of them.

Library catalogs and advanced search engines take Boolean queries: discrete AND (mathematics OR math) NOT music. Everything you know about precedence and De Morgan applies; in particular, NOT (a OR b) returns the same results as NOT a AND NOT b.

Logic circuits

A logic gate is a tiny electronic circuit that computes one connective on voltages: high voltage is 1, low is 0.

GateOutputFormula
NOT (inverter)the opposite of the input¬p\neg p
AND1 when both inputs are 1p∧qp \land q
OR1 when at least one input is 1p∨qp \lor q
XOR1 when the inputs differp⊕qp \oplus q
NANDNOT of AND¬(p∧q)\neg(p \land q)

Every formula is a circuit: each connective becomes a gate, and each subformula becomes a wire. Simplifying the formula removes gates, which is why chip designers care so much about the laws above.

NAND can do everything

The set {¬,∧,∨}\{\neg, \land, \lor\} can express every truth table: write one ∧-term for each true row and join them with ∨ (the disjunctive normal form, a Lab 1 challenge). Surprisingly, a single gate is enough. With p↑qp \uparrow q for NAND:

¬p≡p↑p,p∧q≡(p↑q)↑(p↑q),p∨q≡(p↑p)↑(q↑q)\neg p \equiv p \uparrow p, \qquad p \land q \equiv (p \uparrow q) \uparrow (p \uparrow q), \qquad p \lor q \equiv (p \uparrow p) \uparrow (q \uparrow q)

Check the last one with De Morgan. Because NAND is functionally complete, real chips are built from millions of copies of one or two gate designs.

Adding binary numbers

Adding two bits produces a sum bit and a carry bit: 1+1=1021 + 1 = 10_2, so sum 0, carry 1.

ABcarry = A ∧ Bsum = A ⊕ B
0000
0101
1001
1110

That table is the half adder: one XOR and one AND. To add longer numbers, each column must also add the carry coming from the column on its right. The full adder does this with three inputs A,B,CinA, B, C_{in}:

S=A⊕B⊕Cin,Cout=(A∧B)∨(Cin∧(A⊕B))S = A \oplus B \oplus C_{in}, \qquad C_{out} = (A \land B) \lor \big(C_{in} \land (A \oplus B)\big)

Click the inputs and follow the signal through the gates:

full adder · click A, B, Cin S = A ⊕ B ⊕ Cin · Cout = (A ∧ B) ∨ (Cin ∧ (A ⊕ B))
XOR AND XOR AND OR A B Cin S Cout A⊕B 0 0

Chain four of them: a 4-bit ripple-carry adder

+ =

Read right to left: each column is one full adder. Its carry-out is the next column's carry-in, so the carry “ripples” from bit 0 to bit 3. A carry out of bit 3 means the sum needs a fifth bit: that is overflow in a 4-bit register.

Four full adders in a row, each one’s carry-out wired to the next one’s carry-in, make a ripple-carry adder. A 64-bit processor does the same with 64 of them (plus tricks to make the carry faster). Everything your computer computes, from video to AI, is built on top of this one page of logic.

Summary

  • p↔q≡(p→q)∧(q→p)p \leftrightarrow q \equiv (p \to q) \land (q \to p): same truth value. p⊕q≡¬(p↔q)p \oplus q \equiv \neg(p \leftrightarrow q): different truth value.
  • XOR facts: p⊕0=pp \oplus 0 = p, p⊕1=¬pp \oplus 1 = \neg p, p⊕p=0p \oplus p = 0, and XOR-ing twice with a key gives the original back.
  • A≡BA \equiv B means the same truth value in every row, that is, A↔BA \leftrightarrow B is a tautology. One differing row (a counterexample) proves non-equivalence.
  • Prove and simplify with a chain of named laws. Strategy: remove → and ↔, push ¬ inwards, then collapse.
  • Satisfiable means at least one true row; a set of requirements is consistent when its conjunction is satisfiable. SAT is hard in theory and solved every day in practice.
  • Every formula is a circuit. Half adder: S=A⊕BS = A \oplus B, C=A∧BC = A \land B. Full adders in a chain add binary numbers.

Practice

Answers
  1. p→(q→r)≡¬p∨(¬q∨r)≡¬q∨(¬p∨r)≡q→(p→r)p \to (q \to r) \equiv \neg p \lor (\neg q \lor r) \equiv \neg q \lor (\neg p \lor r) \equiv q \to (p \to r) (conditional twice, then associative and commutative, then conditional twice back).
  2. ¬(¬p∧q)∧(p∨q)≡(p∨¬q)∧(p∨q)≡p∨(¬q∧q)≡p∨F≡p\neg(\neg p \land q) \land (p \lor q) \equiv (p \lor \neg q) \land (p \lor q) \equiv p \lor (\neg q \land q) \equiv p \lor \mathbf{F} \equiv p (De Morgan with double negation, distributive, negation, identity).
  3. Yes, it is a tautology. If pp leads to qq and qq leads to rr, then pp leads to rr: this is hypothetical syllogism, one of the rules of inference in week 6.
  4. Let pp: A is a knight, qq: B is a knight. Then p↔(¬p∨¬q)p \leftrightarrow (\neg p \lor \neg q). If pp were false, the statement ¬p∨¬q\neg p \lor \neg q would be true, so a knave would have said something true: impossible. So pp is true, the statement must be true, and ¬q\neg q holds. A is a knight, B is a knave.
  5. Let n=p↑qn = p \uparrow q. Then p⊕q≡(p↑n)↑(q↑n)p \oplus q \equiv (p \uparrow n) \uparrow (q \uparrow n), and p↔q≡¬(p⊕q)p \leftrightarrow q \equiv \neg(p \oplus q), which is that result NAND-ed with itself. Five NAND gates in total.

Before the lab

Lab 2 turns this page into Python. You will check equivalences by brute force, build half and full adders from gate functions and add real binary numbers with them, and write a solver for Knights and Knaves puzzles. It builds directly on the truth-table engine you wrote in Lab 1.

In industry

  • Chip design

    Hardware tools minimize Boolean formulas with exactly these laws, so that chips use fewer transistors, less power and less time.

  • SAT solvers

    Satisfiability solvers verify processors, plan logistics and solve Sudoku by searching for a truth assignment, often with millions of variables.

  • Clean code

    Refactoring an if-condition is applying De Morgan, distributivity and absorption. A wrong step is a bug that only shows up in one row of the truth table.

  • Storage and security

    XOR parity lets RAID disks rebuild a dead drive, and XOR with a secret key is the core step of most ciphers.

Lab 2: Gates, Adders and Knights & Knaves

Build logic gates, check equivalences by brute force, add binary numbers with a ripple-carry adder made of gates, prove that NAND is enough, and write a solver for Knights and Knaves puzzles.

due Fri, Oct 9 · 23:59 · 100 points · open now

Go deeper

Tags:equivalencelogical equivalenceDe MorganXORbiconditionaltautologycontradictionsatisfiabilitySATsimplificationlogic gatesadderNANDKnights and Knaves