Skip to main content
Combinational circuits forget. Feed an output back into an input and a circuit can remember. wires allows arbitrary feedback, and its unit-delay simulation shows exactly how feedback circuits behave, including when they misbehave.

The NAND SR latch

The standard SRLatch is two cross-coupled NAND gates with active-low controls:
top needs bottom’s output, but bottom doesn’t exist yet when top is added. So top’s input b is left out of the add call and wired afterwards with feed. Each part feeds the other, and that loop is what lets the latch remember.

Storing a bit

Unknown state is a real state

A latch that has never been set or reset settles into a stable unknown state. run() returns normally and both outputs read "X". The simulator does not pick a value for you, because a real latch powers up in an unpredictable state.

The forbidden state

Holding both controls low drives both outputs to 1. That isn’t a complementary state, so it can’t be stored. Releasing both controls in the same tick starts a race: both gates flip to 0 together, then back to 1 together, forever. run() detects this and throws a StabilizationError instead of quietly choosing a winner.

Oscillators

An odd number of inverters in a loop has no stable state. This ring oscillator gates its loop with a NAND, so it can be held still while enable = 0:
With three one-tick stages, the output toggles every three ticks. Step through it with step() and read the timing from trace(). If you never set enable, the loop stays at "X". That’s a stable unknown, not an oscillation, because nothing ever changes.