Logic in Practice

SAT solving, logic circuits, and Sudoku as logic

Logic in Practice

Mathematical logic is not just theory -- it powers real technology. SAT solvers verify hardware and software, logic gates are the physical substrate of computation, and constraint satisfaction underlies everything from scheduling to puzzle solving.

In this lesson, you will watch a SAT solver search for solutions, build logic circuits from gates, and see how even a simple Sudoku puzzle is a logic problem in disguise.

SAT Solver Visualizer

The Boolean satisfiability problem (SAT) asks whether a CNF formula has a satisfying assignment. Despite being NP-complete, modern SAT solvers handle formulas with millions of variables using clever techniques: unit propagation, pure literal elimination, and systematic backtracking (DPLL algorithm).

Step 0/1
Result: SATISFIABLE

Key insight: SAT solvers are the engine behind hardware verification, software testing, AI planning, and cryptanalysis. The gap between NP-completeness in theory and practical efficiency is one of the great success stories of computer science.

Logic Circuit Builder

Every boolean function has a circuit implementation. AND, OR, NOT, and XOR gates combine to compute any truth function. Toggle the inputs and watch signals propagate through the wires. The half adder -- which computes a one-bit sum and carry -- is the building block of every CPU's arithmetic unit.

Output: 0 (false)

Key insight: The correspondence between boolean algebra and digital circuits is exact. Circuit optimization is literally boolean simplification -- the Karnaugh maps from the previous lesson directly reduce gate count.

Sudoku as Logic

A Sudoku puzzle is a constraint satisfaction problem: each cell must have exactly one value, and each row, column, and box must contain all values. These constraints can be expressed as propositional formulas. Solving the puzzle is equivalent to finding a satisfying assignment -- logic in action.

1clickclick4clickclick1clickclick1clickclick4clickclick1
Constraints satisfied: 0/13
All cells filled
Row 1 has {1,2,3,4}
Row 2 has {1,2,3,4}
Row 3 has {1,2,3,4}
Row 4 has {1,2,3,4}
Col 1 has {1,2,3,4}
Col 2 has {1,2,3,4}
Col 3 has {1,2,3,4}
Col 4 has {1,2,3,4}
Box (1,1) has {1,2,3,4}
Box (1,2) has {1,2,3,4}
Box (2,1) has {1,2,3,4}
Box (2,2) has {1,2,3,4}

Key insight: Constraint propagation (if a cell must be 3, eliminate 3 from its row, column, and box) is exactly unit propagation in the corresponding SAT encoding. The techniques of logic directly solve the puzzle.

Key Takeaways

  • SAT solvers turn the theory of propositional logic into a practical tool for millions-variable problems.
  • Logic gates are the physical realization of boolean algebra -- the foundation of all digital hardware.
  • Constraint satisfaction problems (like Sudoku) are logic problems in disguise.
  • The bridge between mathematical logic and practical computation is direct and deep.