Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit carry-select adder as threshold circuit. Faster than ripple-carry by pre-computing results for both possible carry values.
A[3:0] βββ
B[3:0] βββΌβββΊ CSel Adder βββ¬βββΊ S[3:0]
Cin βββ ββββΊ Cout
Block 0 (bits 0-1): Ripple-carry with actual Cin
ββββΊ produces C1 (carry into bit 2)
Block 1 (bits 2-3): Pre-compute BOTH possibilities
Path A: assume Cin=0 β S2_0, S3_0, Cout_0
Path B: assume Cin=1 β S2_1, S3_1, Cout_1
Final: MUX selects Path A or B based on C1
Ripple-Carry: [FA0]βββΊ[FA1]βββΊ[FA2]βββΊ[FA3] (4 stages)
Carry-Select: [FA0]βββΊ[FA1]βββ
[HA2]βββΊ[FA3] ββββΊ[MUX] (3 stages)
[FA2]βββΊ[FA3]βββ
Block 1 computes in parallel with Block 0.
| Component | Count | Neurons |
|---|---|---|
| Block 0 (2 FAs) | 2 | 14 |
| Block 1 cin=0 (HA+FA) | 2 | 11 |
| Block 1 cin=1 (2 FAs) | 2 | 14 |
| Output MUXes | 3 | 9 |
Total: 48 neurons, 149 parameters, 4 layers
from safetensors.torch import load_file
w = load_file('model.safetensors')
# All 512 test cases verified (16 Γ 16 Γ 2)
threshold-carryselect-adder/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT