Everything on the site.

Big-O notationAlgorithms · Count the steps in real loops, then compare n, n log n, n² and 2ⁿ on a live chart.RecursionAlgorithms · Watch frames push and pop on the call stack for factorial and Fibonacci.BFS vs DFSAlgorithms · A queue against a stack: draw a graph and see which order each search visits it in.Sorting algorithmsAlgorithms · Seven sorts on the same input, with comparison, swap and write counts side by side.Binary searchAlgorithms · Halve the range, probe the middle, repeat: with lo, mid and hi drawn on the array.Sets, relations and functionsDiscrete maths · Shade any set expression on a Venn diagram and test a relation for its properties.Proof by inductionDiscrete maths · Four worked proofs revealed one step at a time, and a broken one to diagnose.CombinatoricsDiscrete maths · An exact nPr and nCr calculator, and a Pascal’s triangle that shows its own addition rule.Boolean algebraDiscrete maths · The laws, De Morgan, and normal forms, with a truth-table generator built in.Finite-state machinesTheory · Build a DFA in a table, see it drawn, and run strings through it one symbol at a time.Domain theoryTheory · Why recursion needs least fixed points, and how CPOs, Scott continuity and powerdomains supply them.Truth table generatorTools · Expression in, truth table out: with DNF, CNF, a minimal form and LaTeX.Graph traversal visualiserTools · Draw a graph, then animate BFS, DFS and Dijkstra with the frontier shown.Recursion tree visualiserTools · Paste a recursive function or a recurrence and see its call tree and call count.Gradient descentML maths · Drag the starting point, set the learning rate, and watch it converge or blow up.Vectors and embeddingsML maths · Bend the plane with a 2×2 matrix and measure how close toy word vectors are.Softmax and cross-entropyML maths · Edit the logits and watch the probabilities, the loss and the gradient update live.AttentionML maths · Q, K and V for three tokens, a live score heatmap, and the weighted sum of values.Formatting a CS paper in LaTeXLaTeX · Page limits, \documentclass, front matter, theorem environments and the bibliography.Camera-ready checklistLaTeX · Fonts embedded, PDF/A, copyright form, source bundle, and why final versions get rejected.LaTeX templatesLaTeX · Where the official classes live, plus a minimal article template you can copy.AlgorithmsSection · Step-through visualisations of sorting, searching, recursion, graph traversal and Big-O growth, each with pseudocode that highlights the line being run.Discrete mathsSection · Sets, relations and functions, proof by induction, counting, and Boolean algebra, explained with worked examples and small interactive checkers.TheorySection · Finite-state machines, automata and the mathematical semantics of programming languages, explained from first principles.ML mathsSection · Gradient descent, vectors and embeddings, softmax and cross-entropy, and attention, each with a formula, a worked numeric example and a live version.ToolsSection · A truth-table generator with CNF, DNF and LaTeX output, a graph-traversal visualiser for BFS, DFS and Dijkstra, and a recursion-tree visualiser.LaTeXSection · How to format a CS conference or workshop paper in LaTeX, a camera-ready checklist, and a minimal template you can adapt.
Discrete maths

Boolean algebra: laws, normal forms and truth tables

Boolean algebra is algebra with two values, 0 and 1, and three basic operations: and, or and not. It describes logic, digital circuits, search queries and the conditions in every program. This page covers the laws, the normal forms, and how to simplify, with a truth-table generator to check every step.

Interactive: Truth-table generator with CNF, DNF and equivalence checkingUpdated

Values and operations

A Boolean variable takes the value 0 (false) or 1 (true). The basic operations are defined by their truth tables:

AB¬A (not)A ∧ B (and)A ∨ B (or)A ⊕ B (xor)A → B (implies)A ↔ B (iff)
00100011
01101110
10001100
11011011

Two rows deserve a second look. “Or” is inclusive: 1∨1=11 \lor 1 = 1. And an implication A→BA \to B is only false when AA is true and BB is false. “If it rains, the ground is wet” is not broken by a dry day without rain. You may see the same operations written as ABAB or A⋅BA \cdot B for and, A+BA + B for or, and A‾\overline{A} or A′A' for not, especially in circuit design.

A truth table for any expression

With nn variables there are 2n2^n combinations of values, and listing the expression’s value for each one settles every question about it. The generator below builds that table, with a column for each sub-expression so you can follow the evaluation. It also classifies the expression: a tautology is always 1, a contradiction always 0, and anything else is a contingency.

Truth table generator

Variables are names like A, p or x1. Operators: not ! ~ ¬ (or a postfix '),and & * ∧, or | + ∨, xor ^ ⊕,-> →, <-> ↔, nand, nor, constants 0 1. Up to 8 variables.

Check whether two expressions are equivalent

The expression it starts with is De Morgan’s law written as a single formula. Its final column is all 1s, which is exactly what it means for the two sides to be equivalent.

The laws

Every law below can be checked with a truth table, and each has a dual: swap ∧ with ∨ and 0 with 1, and you get another law.

Law“And” form“Or” form (the dual)
IdentityA∧1=AA \land 1 = AA∨0=AA \lor 0 = A
DominationA∧0=0A \land 0 = 0A∨1=1A \lor 1 = 1
IdempotenceA∧A=AA \land A = AA∨A=AA \lor A = A
ComplementA∧¬A=0A \land \lnot A = 0A∨¬A=1A \lor \lnot A = 1
Double negation¬¬A=A\lnot\lnot A = A—
CommutativityA∧B=B∧AA \land B = B \land AA∨B=B∨AA \lor B = B \lor A
Associativity(A∧B)∧C=A∧(B∧C)(A \land B) \land C = A \land (B \land C)(A∨B)∨C=A∨(B∨C)(A \lor B) \lor C = A \lor (B \lor C)
DistributivityA∧(B∨C)=(A∧B)∨(A∧C)A \land (B \lor C) = (A \land B) \lor (A \land C)A∨(B∧C)=(A∨B)∧(A∨C)A \lor (B \land C) = (A \lor B) \land (A \lor C)
AbsorptionA∧(A∨B)=AA \land (A \lor B) = AA∨(A∧B)=AA \lor (A \land B) = A
De Morgan¬(A∧B)=¬A∨¬B\lnot(A \land B) = \lnot A \lor \lnot B¬(A∨B)=¬A∧¬B\lnot(A \lor B) = \lnot A \land \lnot B

Most of these match ordinary arithmetic if you read ∧ as multiplication and ∨ as addition. Two don’t. Idempotence (A∨A=AA \lor A = A) has no arithmetic counterpart, and the second distributive law, A∨(B∧C)=(A∨B)∧(A∨C)A \lor (B \land C) = (A \lor B) \land (A \lor C), would say a+bc=(a+b)(a+c)a + bc = (a + b)(a + c), which is false for numbers.

Worked example: simplifying with the laws

Simplify (A∧B)∨(A∧¬B)(A \land B) \lor (A \land \lnot B).

  1. Distributivity, read right to left: A∧(B∨¬B)A \land (B \lor \lnot B).
  2. Complement: B∨¬B=1B \lor \lnot B = 1, giving A∧1A \land 1.
  3. Identity: AA.

Whatever BB is, the expression equals AA. Paste it into the generator to confirm: its minimal form is just A.

Normal forms

Every Boolean function can be written in two standard shapes.

  • Disjunctive normal form (DNF) is an OR of ANDs: (A∧¬B)∨(¬A∧B)(A \land \lnot B) \lor (\lnot A \land B). To get it from a truth table, take one AND-term (a minterm) for each row where the function is 1, matching that row exactly, and OR them together.
  • Conjunctive normal form (CNF) is an AND of ORs: (A∨B)∧(¬A∨¬B)(A \lor B) \land (\lnot A \lor \lnot B). Take one OR-clause (a maxterm) for each row where the function is 0, ruling that row out, and AND them together.

Worked example: the majority function

“At least two of A,B,CA, B, C are 1” is true on rows 3, 5, 6 and 7 (writing the rows as binary numbers ABCABC). The canonical DNF has one minterm per true row:

(¬A∧B∧C)∨(A∧¬B∧C)∨(A∧B∧¬C)∨(A∧B∧C).(\lnot A \land B \land C) \lor (A \land \lnot B \land C) \lor (A \land B \land \lnot C) \lor (A \land B \land C).

Combining minterms that differ in one variable (rows 3 and 7 differ only in AA, so they merge into B∧CB \land C) gives the minimal form

(A∧B)∨(A∧C)∨(B∧C).(A \land B) \lor (A \land C) \lor (B \land C).

The generator finds this automatically with the Quine–McCluskey method: it repeatedly merges terms that differ in one variable to find the prime implicants, then picks the fewest of them that cover every true row.

CNF matters well beyond textbooks. SAT solvers, which decide whether a formula can be made true and power hardware verification, scheduling and package managers, take their input in CNF. Deciding satisfiability of CNF formulas was the first problem shown to be NP-complete.

Fewer operations are enough

A set of operations is functionally complete if it can express every Boolean function. {∧, ∨, ¬} is, because of the DNF construction. So is {∧, ¬}, because De Morgan gives A∨B=¬(¬A∧¬B)A \lor B = \lnot(\lnot A \land \lnot B). Remarkably, NAND alone is enough:

¬A=A↑A,A∧B=(A↑B)↑(A↑B),A∨B=(A↑A)↑(B↑B).\lnot A = A \uparrow A, \qquad A \land B = (A \uparrow B) \uparrow (A \uparrow B), \qquad A \lor B = (A \uparrow A) \uparrow (B \uparrow B).

That is why a chip can be built from a single kind of gate. Check any of these identities in the generator: type A nand A or (A nand B) nand (A nand B).

From Boole to circuits George Boole set out his algebra of logic in 1854. In 1938 Claude Shannon showed that relay switching circuits obey the same algebra, so circuit design could be done with Boolean algebra. Modern digital logic grew from that observation.

References

  1. C. E. Shannon, “A symbolic analysis of relay and switching circuits”, Transactions of the AIEE 57(12), 1938. doi:10.1109/T-AIEE.1938.5057767
  2. E. J. McCluskey, “Minimization of Boolean functions”, Bell System Technical Journal 35(6), 1956. doi:10.1002/j.1538-7305.1956.tb03835.x
  3. G. Boole, An Investigation of the Laws of Thought, Walton and Maberly, 1854.
  4. “Boolean algebra”, Wikipedia.