Handwired JavaScript:
a branch you can inspect.
A condition can be written as arithmetic. Move the input below to compare an ordinary JavaScript branch with a ReLU gate, including a fractional value where the two results differ.
We checked this small arithmetic example with Node.js. It is an independent explainer of a construction in Cheng Lou’s README, not a test of the Handwired compiler or WebGPU backend. No model weights or third-party runtime are downloaded.
Try an integer, then try 4.5
The ordinary branch returns 10 when the input is greater than 4, and 12 otherwise. Its arithmetic counterpart builds a gate from two ReLU values, then uses that gate to weight the two outputs.
- Gate weight
- 1
- Ordinary branch
- 10
- ReLU arithmetic
- 10
The two results match at input 5. At 4.5, the ordinary branch returns 10, while the arithmetic returns 11.
How the gate works
ReLU means taking the larger of zero and a number. In this example, subtracting the ReLU of input minus 5 from the ReLU of input minus 4 creates a gate: zero at and below 4, one at and above 5, and a ramp between those points.
// Ordinary JavaScript
const direct = input > 4 ? 10 : 12;
// A ReLU gate and its weighted output
const gate = Math.max(input - 4, 0)
- Math.max(input - 5, 0);
const weighted = 12 - 2 * gate;
At input 4, both ReLU terms are zero, so the gate is zero and the weighted output is 12. At input 5, the terms are one and zero, so the output becomes 10. For integer inputs above 5, both terms rise together and their difference stays one.
What our arithmetic check found
We compared the arithmetic output with the ordinary branch for every integer from −1,000 through 1,000. All 2,001 inputs matched. We also checked fractional inputs around the threshold:
| Input | Gate | Branch | Arithmetic |
|---|---|---|---|
| 4 | 0 | 12 | 12 |
| 4.25 | 0.25 | 10 | 11.5 |
| 4.5 | 0.5 | 10 | 11 |
| 4.75 | 0.75 | 10 | 10.5 |
| 5 | 1 | 10 | 10 |
There is no integer between 4 and 5, so the ramp is invisible on the intended integer domain. A fractional input reveals it. This is a limit of this construction’s input assumption; it does not demonstrate a bug in Handwired’s compiler.
What this explains about Handwired
Handwired’s README describes manually constructed numerical operations for programs, using matrix operations and ReLU-style gates. Its own examples include a JavaScript backend and WebGPU experiments. The small construction here only illustrates a conditional; it does not compile arbitrary JavaScript into a trained language model.
To try the full project, use the author’s live demos and read the repository’s setup instructions. We have not measured GPU speed, general-program equivalence or training behavior. A successful arithmetic check cannot establish any of those claims.
A useful way to experiment
- Start with a tiny condition whose expected result you can calculate independently.
- Write down whether the input domain is integers, bounded integers or real numbers.
- Test the boundary and the values on both sides before adding loops or state.
- Keep performance measurements separate from correctness checks.
If you are inspecting a result object from your own experiment, the JSON formatter can format it locally. This explainer sends no input to a server.