Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit unsigned saturating adder. Clamps to maximum value on overflow instead of wrapping around.
A[3:0] βββ
ββββΊ Sat Add βββ¬βββΊ S[3:0] (result)
B[3:0] βββ ββββΊ saturated (overflow flag)
| A + B | Result | Saturated |
|---|---|---|
| β€ 15 | A + B | 0 |
| > 15 | 15 | 1 |
7 + 5 = 12, saturated=0
10 + 10 = 15, saturated=1 (true sum: 20)
15 + 15 = 15, saturated=1 (true sum: 30)
8 + 7 = 15, saturated=0
8 + 8 = 15, saturated=1 (true sum: 16)
Wrapping: 15 + 1 = 0 (modulo 16)
Saturating: 15 + 1 = 15 (clamped)
| Component | Count | Neurons |
|---|---|---|
| Full Adders | 4 | 28 |
| Saturation MUXes | 4 | 12 |
Total: 40 neurons, 124 parameters, 4 layers
1. Compute A + B with standard 4-bit adder
2. If carry out = 1:
- Output 1111 (15)
- Set saturated = 1
3. Else:
- Output sum bits
- Set saturated = 0
from safetensors.torch import load_file
w = load_file('model.safetensors')
# All 256 test cases verified
# Saturates 120 cases (where A+B > 15)
threshold-saturating-adder/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT