Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-most-2-out-of-8 detector. Fires when two or fewer inputs are active. The error-tolerance bound.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +2 β
βββββββββββ
β
βΌ
HW β€ 2?
This circuit allows:
Three or more is considered "too many."
sum = -HW + 2
| HW | Sum | Output |
|---|---|---|
| 0 | +2 | 1 |
| 1 | +1 | 1 |
| 2 | 0 | 1 |
| 3 | -1 | 0 |
| 4+ | < -1 | 0 |
The bias of +2 grants a budget of two active inputs.
In coding theory:
| Scenario | This circuit |
|---|---|
| No errors | Pass |
| Single-bit error | Pass |
| Double-bit error | Pass |
| Triple+ error | Fail |
| Circuit | Condition | Sparse/Dense |
|---|---|---|
| AtLeast6 | HW β₯ 6 | Dense |
| AtMost2 | HW β€ 2 | Sparse |
Bitwise NOT maps AtMost2 inputs to AtLeast6 inputs.
| HW | C(8,k) | AtMost2? |
|---|---|---|
| 0 | 1 | Yes |
| 1 | 8 | Yes |
| 2 | 28 | Yes |
| 3-8 | 219 | No |
Fires on 1 + 8 + 28 = 37 of 256 inputs (14.5%).
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +2 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost2(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Double event: allowed
print(atmost2([1,0,0,0,1,0,0,0])) # 1
# Triple event: rejected
print(atmost2([1,0,0,1,1,0,0,0])) # 0
threshold-atmost2outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT