Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
Exactly-5-out-of-8 detector. Fires when precisely five inputs are active. The minimal majority detector.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
β
βββββββββ΄ββββββββ
βΌ βΌ
βββββββββββ βββββββββββ
β β₯ 5 β β β€ 5 β
β b = -5 β β b = +5 β
βββββββββββ βββββββββββ
β β
βββββββββ¬ββββββββ
βΌ
βββββββββββ
β AND β
βββββββββββ
β
βΌ
bare majority?
Five is the smallest strict majority of eight:
This is the knife-edge of democratic decision-making.
| Circuit | Condition | Fires on HW |
|---|---|---|
| Majority | HW β₯ 5 | 5, 6, 7, 8 |
| Exactly5 | HW = 5 | 5 only |
Majority fires on 93 inputs. Exactly5 fires on 56 - only those with no margin to spare.
| Circuit | HW | Count | Bit-flip image |
|---|---|---|---|
| Exactly3 | 3 | 56 | Exactly5 |
| Exactly5 | 5 | 56 | Exactly3 |
Flipping all 8 bits transforms HW=5 into HW=3. These circuits are duals under bitwise NOT.
Consider a voting scenario with 8 voters:
| HW | Meaning | This circuit |
|---|---|---|
| 0-3 | Opposition wins | 0 |
| 4 | Tie (no decision) | 0 |
| 5 | Minimal majority | 1 |
| 6-8 | Comfortable majority | 0 |
Exactly5 detects the precarious victory - where a single defection would flip the outcome.
| Component | Weights | Bias |
|---|---|---|
| AtLeast5 | all +1 | -5 |
| AtMost5 | all -1 | +5 |
| 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 exactly5(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)
# Bare majority: 5 votes
bits = [1, 1, 1, 1, 1, 0, 0, 0]
print(exactly5(bits)) # 1
# Comfortable majority: 6 votes
bits = [1, 1, 1, 1, 1, 1, 0, 0]
print(exactly5(bits)) # 0
threshold-exactly5outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT