Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks. • 270 items • Updated • 1
At-most-4-out-of-8 detector. Fires when half or fewer inputs are active. The non-majority detector.
x₀ x₁ x₂ x₃ x₄ x₅ x₆ x₇
│ │ │ │ │ │ │ │
└──┴──┴──┴──┼──┴──┴──┴──┘
▼
┌─────────┐
│ w: -1×8 │
│ b: +4 │
└─────────┘
│
▼
HW ≤ 4?
This is NOT(Majority):
| HW | Majority (≥5) | AtMost4 (≤4) |
|---|---|---|
| 0-4 | 0 | 1 |
| 5-8 | 1 | 0 |
Exactly one fires for any input. They partition the input space.
| HW | AtMost3 | AtMost4 | AtMost5 |
|---|---|---|---|
| 3 | 1 | 1 | 1 |
| 4 | 0 | 1 | 1 |
| 5 | 0 | 0 | 1 |
AtMost4 is the first in the family to include the tie case (HW = 4).
Fires on more than half of all inputs:
| HW | C(8,k) | AtMost4? |
|---|---|---|
| 0 | 1 | Yes |
| 1 | 8 | Yes |
| 2 | 28 | Yes |
| 3 | 56 | Yes |
| 4 | 70 | Yes |
| 5-8 | 93 | No |
Total: 1 + 8 + 28 + 56 + 70 = 163 of 256 inputs (63.7%).
| Circuit | Condition | Fires on |
|---|---|---|
| AtLeast4 | HW ≥ 4 | 163 inputs |
| AtMost4 | HW ≤ 4 | 163 inputs |
Both fire on 163 inputs, but different sets. Their intersection is exactly HW = 4 (70 inputs).
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +4 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost4(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Tie (4 active): included
print(atmost4([1,1,1,1,0,0,0,0])) # 1
# Majority (5 active): excluded
print(atmost4([1,1,1,1,1,0,0,0])) # 0
threshold-atmost4outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md
MIT