Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit carry-save adder (CSA) as threshold circuit. Adds three 4-bit numbers producing a sum and carry vector, with no carry propagation delay.
A[3:0] βββ
B[3:0] βββΌβββΊ CSA βββ¬βββΊ S[3:0] (sum)
C[3:0] βββ ββββΊ Cout[3:0] (carry)
Final result: A + B + C = S + (Cout << 1)
Each bit position computed independently (no ripple):
S[i] = A[i] XOR B[i] XOR C[i]
Cout[i] = MAJ(A[i], B[i], C[i])
The carry vector is shifted left by 1 before final addition.
| A | B | C | S | Cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
| Component | Count | Neurons |
|---|---|---|
| XOR3 (sum) | 4 | 28 |
| MAJ3 (carry) | 4 | 4 |
Total: 32 neurons, 256 parameters, 3 layers
CSAs are fundamental building blocks in:
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Example: 15 + 15 + 15 = 45
# S = 13 (1101), Cout = 7 (0111)
# Result = 13 + (7 << 1) = 13 + 14 = 27... wait
# Actually: S + 2*Cout = 13 + 14 = 27, but need final adder
# CSA output needs one final ripple-carry add
threshold-carrysave-adder/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT