Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit Arithmetic Logic Unit as threshold circuit. Performs arithmetic and bitwise operations on two 4-bit operands.
A[3:0] βββ
B[3:0] βββΌβββΊ ALU βββ¬βββΊ R[3:0] (result)
op[1:0] βββ ββββΊ Cout (carry out)
ββββΊ Zero (zero flag)
| op | Operation | Description |
|---|---|---|
| 00 | ADD | R = A + B |
| 01 | SUB | R = A - B (2's complement) |
| 10 | AND | R = A & B |
| 11 | XOR | R = A ^ B |
| Component | Count | Neurons |
|---|---|---|
| Full Adders | 4 | 28 |
| B XOR (for SUB) | 4 | 12 |
| Bitwise AND | 4 | 4 |
| Bitwise XOR | 4 | 12 |
| Output MUX4 | 4 | 20 |
| Zero detect | 1 | 1 |
| Cout MUX | 1 | 5 |
Total: 82 neurons, 282 parameters, 5 layers
A - B = A + (~B) + 1 (2's complement)
When op=01:
- B bits are XORed with 1 (inverted)
- Carry-in is set to 1
- Result is A - B
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Examples:
# op=0: 5 + 3 = 8, cout=0, zero=0
# op=1: 5 - 3 = 2, cout=1, zero=0
# op=2: 5 & 3 = 1, cout=0, zero=0
# op=3: 5 ^ 3 = 6, cout=0, zero=0
threshold-alu4bit/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT