Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 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