Karnaugh Map Solver
Minimize 2–4 variable Boolean functions with SOP, POS, and don't-care groups
Examples
2-variable XOR stays ungrouped
variableCount: 2, values: [0, 1, 1, 0]SOP: A'B + AB' (2 singleton groups)
POS: two sum groups joined with ·No adjacent ones share a cube, so each minterm survives as its own prime implicant in both forms.
Don't cares collapse to a single literal
variableCount: 3, ones: [1], don't cares: [0, 3, 5, 7]SOP: C (eliminated variables: A, B)The four don't cares let one cube span all C=1 cells, eliminating every other variable from the term.
About this tool
Karnaugh Map Solver minimizes 2-, 3-, and 4-variable Boolean functions with solveKarnaughMap, which takes a variableCount and a values array of length 2^n containing only 0, 1, or 2 (don't care). It validates the variable count and the exact cell count, returning an error such as Expected 16 cells containing only 0, 1, or 2 (don't care) on mismatch. Don't-care cells enlarge allowable cubes without becoming cover targets, so a 3-variable map with minterm 1 plus don't-cares 0, 3, 5, 7 collapses to SOP C with eliminated variables A and B.
Minimization enumerates every mask/pattern cube covering only allowed cells, keeps prime implicants (cubes no other lower-literal cube subsumes), then selects the fewest cubes — breaking ties by total literal count — covering all target cells. solveForm runs this once for ones (SOP, terms joined with + using A' for complemented literals, constant 1 for a full cube and 0 for no ones) and once for zeros (POS, parenthesized sums joined with · with inverted complement sense, constants mirrored). Each chosen group reports the covered target minterms, the dash pattern (e.g. --1), the eliminated variable names, and the rendered term.
truthTableFromExpression re-evaluates either form back against the original cells, preserving don't cares as 2, so SOP and POS agree on every specified cell. Ungroupable functions stay unminimized by construction: 2-variable XOR [0, 1, 1, 0] yields two singleton SOP groups (A'B + AB') and two POS groups, 3-variable odd parity yields four singleton groups, and an all-don't-care map yields constant SOP 0 with no groups and constant POS 1 with no groups.
How to use this tool
Set the variable count and fill cells
Choose 2, 3, or 4 variables and enter exactly 4, 8, or 16 cells using 0, 1, and 2 for don't care. Any other length or value returns a validation error instead of a result.
Read the minimized SOP and POS
Take SOP as the minimal sum of products (+ separated, ' marks complement) and POS as the minimal product of sums (parenthesized, · separated). Check each group's pattern, eliminated variables, and covered minterms.
Use don't cares to widen groups
Mark flexible cells as 2 so cubes can expand through them; verify the eliminatedVariables list grew and the term shrank as expected.
Verify the re-evaluation
Compare truthTableFromExpression for both forms against the input: specified cells must match exactly and SOP must equal POS cell for cell.
Use cases
Minimizing gate-level logic
Turn a truth table into the fewest-literal SOP or POS form before mapping it to AND-OR or OR-AND gates.
Checking hand-drawn K-maps
Confirm group choices, eliminated variables, and dash patterns against the solver's prime-implicant cover.
Exploiting don't-care conditions
Model unused input combinations as 2 and read how much smaller the minimized expression becomes.
Common mistakes
Mistake:Entering the wrong number of cells for the variable count.
Fix:Supply exactly 2^n cells (4, 8, or 16). Pad or trim the array first; anything else returns an Expected N cells error.
Mistake:Expecting XOR or parity to minimize to fewer terms.
Fix:These functions have no adjacent merges, so singleton groups are the correct minimal cover. Fewer terms would change the truth table.
Mistake:Treating SOP 0 / POS 1 on an all-don't-care map as a contradiction.
Fix:With no target ones the SOP sum is empty (0) and with no target zeros the POS product is empty (1). Constrain at least one cell to 0 or 1 when a non-constant function is intended.
Frequently asked questions
What does this tool do?
It minimizes 2-, 3-, and 4-variable Boolean functions from a cell array of 0, 1, and 2 (don't care), returning the minimal SOP (+-joined) and POS (parenthesized, ·-joined) expressions with per-group minterms, dash patterns, eliminated variables, and rendered terms.
Why do XOR and parity not get smaller, and what do constants mean?
They have no adjacent merges, so singleton groups are already minimal: [0, 1, 1, 0] yields A'B + AB' in SOP with two POS groups, and 3-variable odd parity yields four groups. An all-don't-care map has no targets, so SOP is 0 and POS is 1 with no groups; any other wrong length or value returns a validation error.
Is my truth table uploaded or stored?
No. Enumeration of cubes, prime-implicant filtering, and minimum cover selection run entirely in your browser — nothing is sent to a server or stored.
How do I use don't cares effectively?
Mark flexible cells as 2 so cubes expand through them without becoming cover targets — e.g. minterm 1 with don't cares 0, 3, 5, 7 collapses to SOP C with A and B eliminated — then confirm with truthTableFromExpression that both forms still match every specified cell.
Related guides
References & standards
Related tools
.env Secret Safety Linter
Validate .env syntax and spot likely leaked credentials or placeholder secrets.
.htaccess Generator
Build an Apache .htaccess — HTTPS redirects, rewrites, error pages, security headers, and basic auth
2D Fluid Dynamics & Particle Physics Sandbox
A physics playground with two engines sharing one canvas. The fluid mode runs a real Eulerian Navier-Stokes solver — semi-Lagrangian advection, explicit diffusion, Jacobi pressure projection and vorticity confinement — that you paint with dye and velocity using mouse or touch. The particle mode is a damped Verlet N-body engine with gravity wells, Coulomb attractors and repulsors, spring links, wall restitution and elastic circle collisions. Particle counts adapt to the device (100k target on WebGL2 desktop, 2k-5k on CPU fallback), and every configuration exports as runnable code: a Matter.js world, a PixiJS ticker setup, or a standalone vanilla Canvas engine.
AI Function Calling Schema Generator
Generate function calling JSON schemas from TypeScript interfaces
Algorithm Arena & Data Structure Visualizer
Interactive arena for algorithms and data structures: eight sorting algorithms racing on one seeded input, six pathfinding algorithms walking generated mazes, and BST, AVL, Red-Black, B-tree, heap and trie operations replayed step by step with rotations highlighted. Every run shows the Big-O table and the phase-highlighted reference implementation in four languages, and compared values can be played as pitch (sonification) through the shared audio engine. Everything runs client-side; inputs never leave the browser.
Ansible Playbook Generator
Build an Ansible playbook — hosts, vars, and tasks with modules — as YAML