Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
A 1-of-4 threshold gate. Any single active input is enough to fire.
x1 x2 x3 x4
β β β β
βββββ΄ββββ΄ββββ
β
βΌ
βββββββββββ
βw: 1,1,1,1β
β b: -1 β
βββββββββββ
β
βΌ
OR4(x1,x2,x3,x4)
Same weights as AND4, but bias -1 instead of -4. A single vote suffices:
| x1 | x2 | x3 | x4 | sum | output |
|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | -1 | 0 |
| 0 | 0 | 0 | 1 | 0 | 1 |
| ... | ... | ... | ... | ... | 1 |
| 1 | 1 | 1 | 1 | 3 | 1 |
| Weights | [1, 1, 1, 1] |
| Bias | -1 |
| Magnitude | 5 |
| Total | 5 parameters |
Exhaustive enumeration of all 1,683 weight configurations at magnitudes 0-5 confirms this circuit is at minimum magnitude (5). There is exactly 1 valid configuration at magnitude 5, and no valid configurations exist below it.
| Magnitude | Valid Configs |
|---|---|
| 0-4 | 0 |
| 5 | 1 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def or4_gate(x1, x2, x3, x4):
inputs = torch.tensor([float(x1), float(x2), float(x3), float(x4)])
return int((inputs * w['weight']).sum() + w['bias'] >= 0)
assert or4_gate(0, 0, 0, 0) == 0
assert or4_gate(0, 0, 0, 1) == 1
assert or4_gate(1, 1, 1, 1) == 1
threshold-or4/
βββ model.safetensors
βββ model.py
βββ config.json
βββ create_safetensors.py
βββ README.md
MIT