Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
The universal gate. Any Boolean function can be constructed from NAND alone.
x y
β β
βββ¬ββ
βΌ
ββββββββββ
βw: -1,-1β
β b: +1 β
ββββββββββ
β
βΌ
NAND(x,y)
Negative weights mean inputs subtract from the sum. The positive bias starts us above threshold, and inputs pull us down:
| x | y | sum | output |
|---|---|---|---|
| 0 | 0 | +1 | 1 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | -1 | 0 |
Only when both inputs are active do we fall below threshold. This is AND with inverted output.
| Weights | [-1, -1] |
| Bias | +1 |
| Total | 3 parameters |
Exhaustive enumeration of all 25 weight configurations at magnitudes 0-3 confirms this circuit is already at minimum magnitude (3). There is exactly one valid configuration at magnitude 3, and no valid configurations exist below it.
NAND can build any Boolean function:
This is why NAND gates dominate digital logic fabrication.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def nand_gate(x, y):
inputs = torch.tensor([float(x), float(y)])
return int((inputs * w['weight']).sum() + w['bias'] >= 0)
threshold-nand/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT