Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks. • 269 items • Updated • 1
Adds three 1-bit inputs (a, b, carry_in), producing sum and carry_out. The core of ripple-carry adders.
a b
│ │
└───┬───┘
▼
┌─────────┐
│ HA1 │ First half adder
└─────────┘
│ │
s1 c1
│ \
│ cin \
└──┬──┘ \
▼ \
┌─────────┐ \
│ HA2 │ │
└─────────┘ │
│ │ │
sum c2 │
│ │
└──┬───┘
▼
┌──────┐
│ OR │
└──────┘
│
▼
cout
| a | b | cin | sum | cout |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 | 0 |
| 0 | 1 | 0 | 1 | 0 |
| 0 | 1 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 | 0 |
| 1 | 0 | 1 | 0 | 1 |
| 1 | 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 | 1 |
Binary: a + b + cin = (cout × 2) + sum
| Component | Neurons |
|---|---|
| HA1 (a + b) | 4 |
| HA2 (s1 + cin) | 4 |
| OR (c1, c2) | 1 |
Total: 9 neurons, 21 parameters, 4 layers
s1, c1 = HalfAdder(a, b)
sum, c2 = HalfAdder(s1, cin)
cout = OR(c1, c2)
A carry propagates if either half adder produces one.
from safetensors.torch import load_file
w = load_file('model.safetensors')
def full_adder(a, b, cin):
# Implementation uses two half adders + OR
# See model.py for full implementation
pass
threshold-fulladder/
├── model.safetensors
├── model.py
├── config.json
└── README.md
MIT