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?
This is the knife-edge of democratic decision-making.
Majority fires on 93 inputs. Exactly5 fires on 56 - only those with no margin to spare.
Flipping all 8 bits transforms HW=5 into HW=3. These circuits are duals under bitwise NOT.
Exactly5 detects the precarious victory - where a single defection would flip the outcome.
1from safetensors.torch import load_file
2import torch
3
4w = load_file('model.safetensors')
5
6def exactly5(bits):
7 inp = torch.tensor([float(b) for b in bits])
8 atleast = int((inp * w['atleast.weight']).sum() + w['atleast.bias'] >= 0)
9 atmost = int((inp * w['atmost.weight']).sum() + w['atmost.bias'] >= 0)
10 comb = torch.tensor([float(atleast), float(atmost)])
11 return int((comb * w['and.weight']).sum() + w['and.bias'] >= 0)
12
13# Bare majority: 5 votes
14bits = [1, 1, 1, 1, 1, 0, 0, 0]
15print(exactly5(bits)) # 1
16
17# Comfortable majority: 6 votes
18bits = [1, 1, 1, 1, 1, 1, 0, 0]
19print(exactly5(bits)) # 0
threshold-exactly5outof8/
├── model.safetensors
├── model.py
├── config.json
└── README.md