Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-most-3-out-of-8 detector. Fires when three or fewer inputs are active. Identical to Minority.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +3 β
βββββββββββ
β
βΌ
HW β€ 3?
This circuit is functionally identical to threshold-minority:
| Circuit | Condition | Implementation |
|---|---|---|
| Minority | HW β€ 3 | w: all -1, b: +3 |
| AtMost3 | HW β€ 3 | w: all -1, b: +3 |
Both detect "strictly fewer than half." The naming differs by framing:
| HW | AtMost3 | Interpretation |
|---|---|---|
| 0-3 | 1 | Minority (< 50%) |
| 4 | 0 | Tie (= 50%) |
| 5-8 | 0 | Majority (> 50%) |
AtMost3 excludes ties. Four active inputs is not "at most 3."
| Circuit | Condition | Meaning |
|---|---|---|
| AtLeast5 | HW β₯ 5 | Majority |
| AtMost3 | HW β€ 3 | Minority |
These are not complements - the tie zone (HW = 4) belongs to neither.
| HW | C(8,k) | AtMost3? |
|---|---|---|
| 0 | 1 | Yes |
| 1 | 8 | Yes |
| 2 | 28 | Yes |
| 3 | 56 | Yes |
| 4-8 | 163 | No |
Fires on 1 + 8 + 28 + 56 = 93 of 256 inputs (36.3%).
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +3 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost3(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Three active: minority
print(atmost3([1,1,1,0,0,0,0,0])) # 1
# Four active: tie, not minority
print(atmost3([1,1,1,1,0,0,0,0])) # 0
threshold-atmost3outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT