Handwired: turn your regular JavaScript code into a neural net

Handwired

Turn your regular JavaScript code into a neural net; no training, exact, yet also fully differentiable!

How It Works

A program's made of if-else, loops, and state. Handwired transforms them into matrix multiplication + reglu over floats. For example:

const a = 5
const result = (a > 4) ? 10 : 12

The above can be expressed as basic arithmetic:

const a = 5
// Math.max(0, x) is ReLU. For an integer a, above4 is 1 if a > 4, and 0 otherwise
const above4 = Math.max(0, a - 4) - Math.max(0, a - 5)
// Both branches compute, and above4 picks one
const result = above4 * 10 + (1 - above4) * 12