Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
3-input NAND gate. Fires unless all three inputs are active. The universal gate extended.
a b c
β β β
βββββΌββββ
β
βΌ
ββββββββββββ
βw: -1,-1,-1β
β b: +2 β
ββββββββββββ
β
βΌ
NAND(a,b,c)
3-input NAND fires when at least one input is 0:
| Inputs | Sum | Output |
|---|---|---|
| 000 | +2 | 1 |
| 001 | +1 | 1 |
| 010 | +1 | 1 |
| 011 | 0 | 1 |
| 100 | +1 | 1 |
| 101 | 0 | 1 |
| 110 | 0 | 1 |
| 111 | -1 | 0 |
Only unanimous activation silences the gate.
Each input subtracts from the sum. The positive bias provides headroom:
sum = -a - b - c + 2 = 2 - HW
fires when 2 - HW >= 0
fires when HW <= 2
This is AtMost2 for 3 inputs.
NAND is universal - any Boolean function can be built from NAND:
| Gate | Weights | Bias | Fires when |
|---|---|---|---|
| NAND3 | all -1 | +2 | HW β€ 2 |
| NOR3 | all -1 | 0 | HW = 0 |
NAND is permissive (7 of 8 pass). NOR is restrictive (1 of 8 passes).
| Component | Value |
|---|---|
| Weights | [-1, -1, -1] |
| Bias | +2 |
| Total | 4 parameters |
Exhaustive enumeration of all 681 weight configurations at magnitudes 0-5 confirms this circuit is already at minimum magnitude (5). There is exactly one valid configuration at magnitude 5, and no valid configurations exist below it.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def nand3(a, b, c):
inp = torch.tensor([float(a), float(b), float(c)])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
print(nand3(1, 1, 0)) # 1
print(nand3(1, 1, 1)) # 0
threshold-nand3/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT