Table of Contents
- Propositional Logic
- Valuations
- Disjunctive Normal Form
- Conjunctive Normal Form
- Implication Equivalence
- Biconditional Equivalence
- De Morgan’s Laws
- Why CNF and DNF Matter
This chapter stands alone as a mathematical reference. If you’re only interested in the code, chapters 1–4 cover the complete implementation. Here we formalize the ideas and prove that they work.
Propositional Logic
Propositional variables are symbols - - that can be either true () or false ().
A well-formed formula (wff) is built inductively:
- Every propositional variable is a wff.
- If is a wff, then is a wff.
- If and are wffs, then , , , and are wffs.
We write for the set of propositional variables appearing in .
Valuations
A valuation (or assignment) is a function . Given a valuation, the truth value of a formula is determined recursively:
A formula is a tautology if for every valuation . Two formulas and are logically equivalent, written , if for every valuation .
Disjunctive Normal Form
A literal is a variable or its negation . A minterm over variables is a conjunction of literals, one per variable:
where each is either or .
A formula is in Disjunctive Normal Form (DNF) if it is a disjunction of minterms:
Theorem. Every formula has an equivalent DNF.
Proof. Let . Consider all valuations. For each valuation where , define a minterm:
where if , and if .
Define . If no valuation satisfies , set (which is equivalent since is unsatisfiable).
We claim . Let be any valuation:
-
If : then is one of the disjuncts, and since each literal in matches . So .
-
If : then is not a disjunct. For any other minterm in , since on at least one variable, at least one literal in evaluates to under , making . Since all disjuncts are , .
Therefore .
Connection to code:This is exactly what our code does in Chapter 4: for each TRUE row in the truth table, we build a minterm from the variable values in that row, then OR all the minterms together.
Conjunctive Normal Form
A maxterm over variables is a disjunction of literals:
A formula is in Conjunctive Normal Form (CNF) if it is a conjunction of maxterms:
Theorem. Every formula has an equivalent CNF.
Proof. For each valuation where , define a maxterm:
where if , and if .
Note the flipped literal construction compared to DNF.
Define . If no valuation falsifies , set .
We claim . Let be any valuation:
-
If : for every maxterm in , we have on at least one variable . If then and … wait, that doesn’t help directly. Instead: since for some , the literal evaluates to under . To see why: if , then and (since they differ), so . If , then and , so . Either way, at least one literal in is , so . Since all maxterms are , .
-
If : then is one of the conjuncts. Every literal in evaluates to under : if , then and ; if , then and . So , which makes .
Therefore .
Connection to code:This matches our code: for each FALSE row, we build a maxterm with flipped literals (negate the trues, keep the falses), then AND all maxterms together.
Implication Equivalence
Our evaluator implements implication as !left || right. Here’s the formal justification.
Theorem. .
Proof. We verify by truth table:
The columns match on all rows, so .
Biconditional Equivalence
Theorem. .
Proof. Again by truth table:
The columns match.
Using the implication equivalence, we can also write:
Our code uses === on booleans for equiv, which is equivalent to checking both implications simultaneously.
De Morgan’s Laws
Theorem (De Morgan). For any formulas and :
Proof. Truth tables for the first law:
The columns and match.
The second law follows by similar verification (or by applying the first law to and and simplifying).
De Morgan’s laws are fundamental in logic - they let us push negation through conjunctions and disjunctions. While our calculator doesn’t need them for the basic algorithm (we build normal forms directly from the truth table), they are essential if you ever want to simplify or manipulate CNF/DNF expressions.
Why CNF and DNF Matter
Normal forms aren’t just a theoretical curiosity. They have practical applications across computer science:
SAT solvers. Most modern SAT solvers (used in hardware verification, planning, cryptanalysis, and more) expect their input in CNF. The DPLL and CDCL algorithms that power these solvers operate directly on conjunctions of clauses.
Circuit design. In digital electronics, DNF corresponds directly to a sum-of-products implementation (OR gates combining AND gates), while CNF corresponds to a product-of-sums (AND gates combining OR gates). Converting to normal form is a standard step in circuit synthesis.
Logic simplification. Normal forms provide a starting point for minimization algorithms like Quine–McCluskey or Espresso, which reduce the number of terms while preserving logical equivalence.
Databases. Query optimization sometimes involves converting conditions to CNF for efficient index utilization.
The truth table method we implemented gives us a canonical normal form (one unique representation for each truth function), which is correct but can be exponentially large. In practice, specialized algorithms exist for more compact representations. But the truth table approach is the clearest way to understand what CNF and DNF are, which is why we started here.
Previous: Chapter 4: Truth Tables and Normal Forms