Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-most-7-out-of-8 detector. Fires when fewer than all inputs are active. This is 8-input NAND.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +7 β
βββββββββββ
β
βΌ
NOT(all)?
This circuit is the complement of 8-input AND:
| HW | AND (all 8) | AtMost7 (NAND) |
|---|---|---|
| 0-7 | 0 | 1 |
| 8 | 1 | 0 |
It fires on 255 of 256 inputs. Only complete unanimity silences it.
| Circuit | Condition | Weights | Bias |
|---|---|---|---|
| 8-input AND | HW = 8 | all +1 | -8 |
| 8-input NAND | HW < 8 | all -1 | +7 |
They are complements. Both use the same number of parameters but opposite logic.
NAND is functionally complete - any Boolean function can be built from NAND alone:
This 8-input NAND can simulate 2-input NAND by fixing 6 inputs to 1.
| Scenario | AtMost7 |
|---|---|
| All systems go | 0 |
| Any system down | 1 |
If you interpret 1 as "operational," AtMost7 fires whenever there's at least one failure.
| Circuit | Condition | Fires on |
|---|---|---|
| AtLeast1 (OR) | HW β₯ 1 | 255 inputs |
| AtMost7 (NAND) | HW β€ 7 | 255 inputs |
Both fire on almost everything. One misses all-zeros; the other misses all-ones.
| Component | Value |
|---|---|
| Weights | all -1 |
| Bias | +7 |
| Total | 9 parameters |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost7(bits):
"""Also known as 8-input NAND"""
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Almost all active
print(atmost7([1,1,1,1,1,1,1,0])) # 1
# All active (unanimity)
print(atmost7([1,1,1,1,1,1,1,1])) # 0
threshold-atmost7outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT