Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
4-bit subtractor. Computes A - B (modulo 16) with borrow output.
subtractor4bit(A, B) = (A - B) mod 16, borrow_out
| A | B | Diff | Borrow |
|---|---|---|---|
| 7 | 3 | 4 | 0 |
| 5 | 5 | 0 | 0 |
| 3 | 7 | 12 | 1 |
| 0 | 1 | 15 | 1 |
Ripple-borrow subtractor using full subtractor units.
For each bit i:
The borrow signal indicates A < B (unsigned comparison).
| Inputs | 8 (a3-a0, b3-b0) |
| Outputs | 5 (d3-d0, bout) |
| Neurons | 25 |
| Layers | 8 |
| Parameters | 86 |
| Magnitude | 88 |
from safetensors.torch import load_file
# See model.py for full implementation
# 7 - 3 = 4
# subtractor4(0,1,1,1, 0,0,1,1) = [0,1,0,0, 0]
# 3 - 7 = 12 (wraps), borrow=1
# subtractor4(0,0,1,1, 0,1,1,1) = [1,1,0,0, 1]
MIT