Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
At-most-1-out-of-8 detector. Fires when zero or one inputs are active. The sparsity detector.
xβ xβ xβ xβ xβ xβ
xβ xβ
β β β β β β β β
ββββ΄βββ΄βββ΄βββΌβββ΄βββ΄βββ΄βββ
βΌ
βββββββββββ
β w: -1Γ8 β
β b: +1 β
βββββββββββ
β
βΌ
HW β€ 1?
A single threshold neuron. The negative weights mean each active input subtracts from the sum.
This circuit enforces extreme sparsity:
It's the upper bound for "at most one thing happening."
sum = -xβ - xβ - xβ - xβ - xβ - xβ
- xβ - xβ + 1
= 1 - HW
| HW | Sum | Output |
|---|---|---|
| 0 | +1 | 1 |
| 1 | 0 | 1 |
| 2 | -1 | 0 |
| 3+ | < -1 | 0 |
The bias of +1 grants a budget of one active input. Any more exceeds the budget.
| Circuit | Condition | Fires when |
|---|---|---|
| AtLeast7 | HW β₯ 7 | Dense (7-8 active) |
| AtMost1 | HW β€ 1 | Sparse (0-1 active) |
Under bitwise NOT, AtMost1 inputs map to AtLeast7 inputs. They detect opposite extremes of the distribution.
| Circuit | Weights | Bias | Fires when |
|---|---|---|---|
| AtMost1 | all -1 | +1 | HW β€ 1 |
| AtMost2 | all -1 | +2 | HW β€ 2 |
| AtMost3 | all -1 | +3 | HW β€ 3 |
| ... | all -1 | +k | HW β€ k |
All single-layer circuits. The bias determines the threshold.
| Component | Value |
|---|---|
| Weights | [-1, -1, -1, -1, -1, -1, -1, -1] |
| Bias | +1 |
| Total | 9 parameters |
Single neuron, single layer.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def atmost1(bits):
inp = torch.tensor([float(b) for b in bits])
return int((inp * w['weight']).sum() + w['bias'] >= 0)
# Empty: allowed
print(atmost1([0,0,0,0,0,0,0,0])) # 1
# Singleton: allowed
print(atmost1([0,0,0,1,0,0,0,0])) # 1
# Pair: rejected
print(atmost1([0,1,0,1,0,0,0,0])) # 0
threshold-atmost1outof8/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT