Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
Exactly-6-out-of-8 detector. Fires when precisely six inputs are active. The supermajority detector.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
β
βββββββββ΄ββββββββ
βΌ βΌ
βββββββββββ βββββββββββ
β β₯ 6 β β β€ 6 β
β b = -6 β β b = +6 β
βββββββββββ βββββββββββ
β β
βββββββββ¬ββββββββ
βΌ
βββββββββββ
β AND β
βββββββββββ
β
βΌ
supermajority?
6/8 = 75% - a common supermajority requirement:
With 8 inputs, 6 is the first integer β₯ 75%.
| Active | Inactive | Tolerance | This circuit |
|---|---|---|---|
| 5 | 3 | Can lose 0 | 0 |
| 6 | 2 | Can lose 1 | 1 |
| 7 | 1 | Can lose 2 | 0 |
| 8 | 0 | Can lose 3 | 0 |
Exactly6 detects the state with precisely one-defection tolerance. Lose any vote and you drop below supermajority. Gain any vote and you have margin to spare.
| Circuit | HW | Count | Bit-flip image |
|---|---|---|---|
| Exactly2 | 2 | 28 | Exactly6 |
| Exactly6 | 6 | 28 | Exactly2 |
Flipping all bits maps pairs to sextets. Both fire on exactly 28 inputs.
In a system requiring 6/8 supermajority:
Exactly6 catches this critical configuration - the minimum winning coalition.
| Component | Weights | Bias |
|---|---|---|
| AtLeast6 | all +1 | -6 |
| AtMost6 | all -1 | +6 |
| AND | [+1, +1] | -2 |
Total: 3 neurons, 21 parameters, 2 layers
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def exactly6(bits):
inp = torch.tensor([float(b) for b in bits])
atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0)
atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0)
comb = torch.tensor([float(atleast), float(atmost)])
return int((comb * w['and.weight']).sum() + w['and.bias'] >= 0)
# Supermajority: exactly 6
bits = [1, 1, 1, 1, 1, 1, 0, 0]
print(exactly6(bits)) # 1
# Near-unanimity: 7 is too many
bits = [1, 1, 1, 1, 1, 1, 1, 0]
print(exactly6(bits)) # 0
threshold-exactly6outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT