Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
Adds two 2-bit numbers with carry-in. The classic ripple-carry architecture using cascaded full adders.
a0 b0 cin a1 b1
β β β β β
βββββΌββββ βββββΌββββ
βΌ βΌ
βββββββββββ βββββββββββ
β FA0 ββββββββββββ FA1 β
βββββββββββ c0 βββββββββββ
β β β
βΌ βΌ βΌ
s0 s1 cout
Input: (a1 a0) + (b1 b0) + cin
Output: (cout s1 s0)
The carry ripples from FA0 to FA1, hence "ripple-carry."
11 (a1=1, a0=1)
+ 11 (b1=1, b0=1)
+ 0 (cin=0)
ββββ
110 (cout=1, s1=1, s0=0)
3 + 3 + 0 = 6 = 0b110
| Component | Neurons |
|---|---|
| FA0 | 9 |
| FA1 | 9 |
Total: 18 neurons, 42 parameters, 8 layers
| Type | Bits | Meaning |
|---|---|---|
| a | a1, a0 | First 2-bit number |
| b | b1, b0 | Second 2-bit number |
| cin | 1 bit | Carry in |
| s | s1, s0 | 2-bit sum |
| cout | 1 bit | Carry out |
from safetensors.torch import load_file
w = load_file('model.safetensors')
def ripple_carry_2bit(a0, a1, b0, b1, cin):
# FA0: a0 + b0 + cin -> s0, c0
# FA1: a1 + b1 + c0 -> s1, cout
# See model.py for full implementation
pass
This 2-bit adder demonstrates the pattern. For n bits:
threshold-ripplecarry2bit/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT