Soft switch: an if/else made of ReLUs
The ternary a > 4 ? 10 : 12 becomes above4 = relu(a − 4) − relu(a − 5) and result = above4 × 10 + (1 − above4) × 12. Drag a — every number below comes from a real Handwired Circuit.
Interactive demo
your code
const a = 5
const result = a > 4
? 10
: 12
circuit
plain JS
turns into live network
Exact match
Why does this work?
For an integer a, relu(a − 4) − relu(a − 5) is 0 when a ≤ 4 and 1 when a ≥ 5 — an exact bit. emitSelect then computes bit × on + (1 − bit) × off, so both branches run and the bit picks one. Set a to a fraction like 4.5 and the bit becomes 0.5, blending the branches: that's why upstream's emitCompare relies on declared ranges and grids to guarantee exact bits.
What does the circuit look like?
Two reglu operations, one affine difference, and the select macro. See it drawn on the code → network page.