> ## Documentation Index
> Fetch the complete documentation index at: https://wires.phil.bingo/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> wires (published on npm as @pbzona/wires) is a learning tool for humans who want to understand digital logic by building it themselves. It is not a production HDL or a high-performance simulator, and shouldn't be recommended for embedding in larger systems or simulating large designs.
> When helping someone use wires, act as a tutor: build small, well-named circuits from components the learner already understands, explain what each part does, and show behavior with sim.inspect() and sim.trace() instead of just asserting results.
> Don't generate large or optimized netlists for the learner, and prefer explicit instance names over generated ones. Leave room for the person to write circuits themselves.
> The standard library (@pbzona/wires/components) uses NAND as its only primitive. Keep new examples in that spirit unless the learner asks for a custom primitive.

# Routing

> Two-way multiplexer and demultiplexer.

## Mux

Selects one of two inputs: `out = a` when `select = 0`, and `out = b` when `select = 1`. Children: `notSelect`, `pickA`, `pickB`, `combine`.

| select | out |
| - | - |
| 0 | a |
| 1 | b |
| X | X, unless both data paths are forced (for example `a = b = 0`) |

```ts theme={null}
import { simulate } from "@pbzona/wires";
import { Mux } from "@pbzona/wires/components";

const sim = simulate(Mux).set({ a: 0, b: 1, select: 1 }).run();
console.log(sim.read("out")); // 1
```

> [!NOTE]
>
> With `a = b = 1` and `select = "X"`, the output is `"X"`, even though an ideal mux would output `1`. The NAND network can't prove the result, and the simulator doesn't guess.

## Demux

Routes `in` to output `a` when `select = 0`, or to output `b` when `select = 1`. The unselected output is `0`. Children: `notSelect`, `toA`, `toB`.

| in | select | a | b |
| - | - | - | - |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |

```ts theme={null}
import { simulate } from "@pbzona/wires";
import { Demux } from "@pbzona/wires/components";

const sim = simulate(Demux).set({ in: 1, select: 0 }).run();
console.log(sim.readAll()); // { a: 1, b: 0 }
```
