Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-most-5-out-of-8 detector. Fires when 5 or fewer inputs are active. The sub-supermajority bound.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +5 β
βββββββββββ
β
βΌ
HW β€ 5?
This circuit blocks supermajority (β₯6):
| HW | AtMost5 | Interpretation |
|---|---|---|
| 0-5 | 1 | Below 75% threshold |
| 6-8 | 0 | Supermajority achieved |
If you need 6/8 to pass something, AtMost5 detects when you don't have it.
| HW | Status | AtMost5 |
|---|---|---|
| 4 | Tie | 1 |
| 5 | Bare majority | 1 |
| 6 | Supermajority | 0 |
Unlike AtMost4, this includes the minimal majority case. A 5-3 vote passes Majority but still fires AtMost5.
| HW | C(8,k) | AtMost5? |
|---|---|---|
| 0-5 | 163 | Yes |
| 6 | 28 | No |
| 7 | 8 | No |
| 8 | 1 | No |
Total: 163 of 256 inputs (63.7%). Same count as AtMost4 by symmetry.
| Circuit | Condition | Count |
|---|---|---|
| AtLeast3 | HW β₯ 3 | 219 |
| AtMost5 | HW β€ 5 | 219 |
Under bit-flip, AtMost5 inputs map to AtLeast3 inputs.
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +5 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost5(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Bare majority: still below supermajority
print(atmost5([1,1,1,1,1,0,0,0])) # 1
# Supermajority: fails
print(atmost5([1,1,1,1,1,1,0,0])) # 0
threshold-atmost5outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT