Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
Booth radix-2 recoder for signed multiplication. Converts a 4-bit two's complement multiplier into add/subtract control signals.
recode(Y[3:0]) -> [(add0, sub0), (add1, sub1), (add2, sub2), (add3, sub3)]
For each position i:
Scans bit pairs (y_i, y_{i-1}) where y_{-1} = 0:
| y_i | y_{i-1} | Operation |
|---|---|---|
| 0 | 0 | +0 |
| 0 | 1 | +X |
| 1 | 0 | -X |
| 1 | 1 | +0 |
Logic:
| Y (signed) | Binary | Pos0 | Pos1 | Pos2 | Pos3 |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 0 | 0 |
| 1 | 0001 | -1 | +1 | 0 | 0 |
| 7 | 0111 | -1 | 0 | 0 | +1 |
| -1 | 1111 | -1 | 0 | 0 | 0 |
| -8 | 1000 | 0 | 0 | 0 | -1 |
Note: 7 = 8 - 1 (one +1 at position 3, one -1 at position 0)
Single-layer implementation:
y3 y2 y1 y0
β β β β
βββββΌββββΌββββΌββββΊ add0, sub0 (based on y0, 0)
β β β β
βββββΌββββΌββββΌββββΊ add1, sub1 (based on y1, y0)
β β β β
βββββΌββββΌββββΌββββΊ add2, sub2 (based on y2, y1)
β β β β
βββββ΄ββββ΄ββββ΄ββββΊ add3, sub3 (based on y3, y2)
Each output is a single threshold neuron.
| Inputs | 4 |
| Outputs | 8 |
| Neurons | 8 |
| Layers | 1 |
| Parameters | 40 |
| Magnitude | 21 |
Booth recoding reduces the maximum number of non-zero partial products:
Example: 7 (0111) normally needs 3 additions. With Booth: 8-1 = one add at position 3, one subtract at position 0.
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Use recoded signals to control shifted add/sub of multiplicand
# For full multiplier, combine with adder tree
MIT