Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
4-bit left barrel shifter. Shifts by variable amount 0-3.
barrelshift4(a3, a2, a1, a0, s1, s0) = [a3, a2, a1, a0] << s
where s = 2*s1 + s0 (shift amount 0-3)
| Input | Shift | Output |
|---|---|---|
| 0001 | 0 | 0001 |
| 0001 | 1 | 0010 |
| 0001 | 2 | 0100 |
| 0001 | 3 | 1000 |
| 1010 | 1 | 0100 |
| 1111 | 2 | 1100 |
Layer 1: (data_bit AND shift_match) detectors (10 neurons)
Each neuron fires when a specific data bit is 1 AND shift amount matches.
a3_s00: a3 AND s=00 (y3 source when s=0)
a2_s00: a2 AND s=00 (y2 source when s=0)
a2_s01: a2 AND s=01 (y3 source when s=1)
a1_s00: a1 AND s=00 (y1 source when s=0)
a1_s01: a1 AND s=01 (y2 source when s=1)
a1_s10: a1 AND s=10 (y3 source when s=2)
a0_s00: a0 AND s=00 (y0 source when s=0)
a0_s01: a0 AND s=01 (y1 source when s=1)
a0_s10: a0 AND s=10 (y2 source when s=2)
a0_s11: a0 AND s=11 (y3 source when s=3)
Layer 2: OR gates combining relevant sources (4 neurons)
y3 = a3_s00 OR a2_s01 OR a1_s10 OR a0_s11
y2 = a2_s00 OR a1_s01 OR a0_s10
y1 = a1_s00 OR a0_s01
y0 = a0_s00
| Inputs | 6 (4 data + 2 shift) |
| Outputs | 4 |
| Neurons | 14 |
| Layers | 2 |
| Parameters | 114 |
| Magnitude | 61 |
from safetensors.torch import load_file
# See model.py for full implementation
# barrelshift4(0,0,0,1, 0,1) = [0,0,1,0] # 0001 << 1 = 0010
# barrelshift4(0,0,0,1, 1,1) = [1,0,0,0] # 0001 << 3 = 1000
MIT