# AI use cases for Handwired (chenglou/handwired)

Repo: [chenglou/handwired](https://github.com/chenglou/handwired) | Use cases: 3 | Page: https://dedupedai.com/use-cases/chenglou-handwired/

Handwired turns regular JavaScript code into a neural net with no training: if-else, loops and state become matrix multiplication and reglu over floats. The result is exact and fully differentiable, and runs on JS or WebGPU.

This file holds every use case of this repo. Each one starts with a "## " heading and ends with its URL.

- Run the Handwired demos locally: https://dedupedai.com/use-cases/chenglou-handwired/run-the-handwired-demos/
- See how an if-else becomes arithmetic: https://dedupedai.com/use-cases/chenglou-handwired/understand-if-else-as-matrix-math/
- Unfreeze hand-written weights and train them: https://dedupedai.com/use-cases/chenglou-handwired/train-the-frozen-weights/

## How to run the Handwired demos locally with Handwired

Repo: [chenglou/handwired](https://github.com/chenglou/handwired) | Difficulty: Intermediate | Time: 20 minutes | Basis: From the README

Clone the repo, install with bun and start the demos.

**Who it is for:** A developer who wants to see JavaScript run as a neural net.

**The problem:** It is hard to believe ordinary code can be a differentiable net until you see it run.

**The outcome:** The demos running on your machine, ready for you to read src and docs.

### Steps

1. Try the live demos at chenglou.me/handwired first
2. Run `git clone` on the repo and then `bun install`
3. Run `bun start` to run the demos locally
4. Check docs/, src/ and template/ to get started

### Prompt to paste into your agent

```text
Clone chenglou/handwired, run bun install and bun start, then walk me through the demos and what docs/, src/ and template/ contain.
```

### Caveat

The lab/ folder holds old experiments that the README says you can ignore.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/chenglou-handwired/run-the-handwired-demos/

## How to see how an if-else becomes arithmetic with Handwired

Repo: [chenglou/handwired](https://github.com/chenglou/handwired) | Difficulty: Beginner | Time: 15 minutes | Basis: From the README

Follow the README example that rewrites a ternary with ReLU so both branches compute.

**Who it is for:** A developer who wants to understand the core trick before reading the code.

**The problem:** The idea of code as weights is abstract without a worked example.

**The outcome:** A clear picture of how conditions become differentiable math.

### Steps

1. Read the How It Works section and the const a = 5 example
2. Work out above4 = Math.max(0, a - 4) - Math.max(0, a - 5) by hand for a few values of a
3. See how above4 picks between 10 and 12 with both branches computed
4. Open src/ and look for where these primitives are collected into one matmul

### Prompt to paste into your agent

```text
Explain the Handwired How It Works example step by step with a few values of a, then find in src/ where such programs are collected into matmul and reglu.
```

### Caveat



Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/chenglou-handwired/understand-if-else-as-matrix-math/

## How to unfreeze hand-written weights and train them with Handwired

Repo: [chenglou/handwired](https://github.com/chenglou/handwired) | Difficulty: Advanced | Time: 2 hours | Basis: From the README

Try the README's ideas: unfreeze a program's weights, or attach a frozen program to a neural net.

**Who it is for:** An ML tinkerer who likes odd experiments.

**The problem:** Normal nets start random, while Handwired starts from exact weights written by hand.

**The outcome:** Your own experiment, with trained weights that began as a working program.

### Steps

1. Run the demos with bun start
2. Read docs/ and template/ to see how a program is expressed
3. Unfreeze the weights and train them, which the README calls an experiment to find out what it does
4. Or attach a specific frozen program to a generic neural net and train end to end

### Prompt to paste into your agent

```text
Using chenglou/handwired, take the template program, unfreeze its weights and train them on a small task. Report what changes in behavior.
```

### Caveat

The README presents these as fun experiments, so expect rough edges.

Disclaimer: Third-party repos we don't own or vouch for. AI-generated use cases can be wrong: review everything and run at your own risk. Full text: https://dedupedai.com/disclaimer/

URL: https://dedupedai.com/use-cases/chenglou-handwired/train-the-frozen-weights/
