ArticlesProjectsWeeklyCredentialsAbout

TMC #0002: Boolean Circuit Simulator

A Python implementation of Shannon's 1937 algebraic model of switching circuits. Composable gate primitives, truth table generation, SOP/POS canonical forms, Shannon cofactor expansion, and a ripple-carry adder, all from first principles.

shannonboolean-logiccircuitspythonlogic-gatesdigital-hardware

An implementation of the formal Boolean circuit model from Claude Shannon's 1937 master's thesis "A Symbolic Analysis of Relay and Switching Circuits."

The Gate class models f:{0,1}n{0,1}f: \{0,1\}^n \rightarrow \{0,1\} as a composable tree of primitives. Gates compose recursively: the output of any gate can be an input to any other, forming an arbitrarily deep directed acyclic graph.

What's included

  • Primitive gates: AND, OR, NOT, NAND, NOR, XOR, XNOR as plain Python functions
  • Gate class: named, composable gate with evaluate(), variables(), truth_table(), to_sop(), to_pos() methods
  • Classic circuits: half adder, full adder, 2-bit ripple-carry adder, majority gate
  • De Morgan verification: exhaustive proof that AB=Aˉ+Bˉ\overline{A \cdot B} = \bar{A} + \bar{B} for all inputs
  • Shannon expansion: cofactor decomposition on any variable (basis of Binary Decision Diagrams)
  • Expression evaluator: parse and evaluate arbitrary Boolean expressions with truth table output

Running

python boolean_circuits.py

No dependencies beyond the Python standard library.

Key output

── Circuit 2: Full Adder ────────────────────
  A     B    Cin  │  Sum   Cout
  ────────────────────────────
  0     0     0   │   0     0
  0     0     1   │   1     0
  0     1     0   │   1     0
  0     1     1   │   0     1
  1     0     0   │   1     0
  1     0     1   │   0     1
  1     1     0   │   0     1
  1     1     1   │   1     1