Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
Exactly-1-out-of-8 detector. Fires when exactly one input is active.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
β
βββββββββ΄ββββββββ
βΌ βΌ
βββββββββββ βββββββββββ
β AtLeast1β β AtMost1 β
β w: +1Γ8 β β w: -1Γ8 β
β b: -1 β β b: +1 β
βββββββββββ βββββββββββ
β β
βββββββββ¬ββββββββ
βΌ
βββββββββββ
β AND β
β w: 1, 1 β
β b: -2 β
βββββββββββ
β
βΌ
(HW = 1?)
The circuit uses two threshold neurons in parallel:
AtLeast1: Fires when HW β₯ 1 (at least one input active)
AtMost1: Fires when HW β€ 1 (at most one input active)
AND: Combines the two conditions
| HW | AtLeast1 | AtMost1 | Exactly1 |
|---|---|---|---|
| 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 1 | 0 | 0 |
| 3 | 1 | 0 | 0 |
| ... | 1 | 0 | 0 |
| 8 | 1 | 0 | 0 |
| Circuit | AtLeast bias | AtMost bias |
|---|---|---|
| Exactly1 | -1 | +1 |
| Exactly2 | -2 | +2 |
| Exactly3 | -3 | +3 |
| ... | -k | +k |
| Exactly7 | -7 | +7 |
All use the same structure: two threshold detectors + AND.
| Component | Neurons | Parameters |
|---|---|---|
| AtLeast1 | 1 | 9 |
| AtMost1 | 1 | 9 |
| AND | 1 | 3 |
| Total | 3 | 21 |
Layers: 2
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly1(bits):
inp = torch.tensor([float(b) for b in bits])
atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0)
atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0)
return int((torch.tensor([float(atleast), float(atmost)]) * w['and.weight']).sum() + w['and.bias'] >= 0)
bits = [0, 0, 0, 1, 0, 0, 0, 0] # HW=1
print(exactly1(bits)) # 1
threshold-exactly1outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT