Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
Minimum of two 2-bit unsigned integers.
min2(a, b) = min(a, b) where a, b are 2-bit unsigned integers (0-3)
Inputs: a1, a0, b1, b0 (MSB first) Outputs: m1, m0 = binary representation of min(a, b)
| a | b | min |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 0 | 2 | 0 |
| 0 | 3 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
| 1 | 2 | 1 |
| 1 | 3 | 1 |
| 2 | 0 | 0 |
| 2 | 1 | 1 |
| 2 | 2 | 2 |
| 2 | 3 | 2 |
| 3 | 0 | 0 |
| 3 | 1 | 1 |
| 3 | 2 | 2 |
| 3 | 3 | 3 |
7-layer circuit:
| Inputs | 4 |
| Outputs | 2 |
| Neurons | 44 |
| Layers | 7 |
| Parameters | 186 |
| Magnitude | 95 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
# Use model.py for full implementation
from model import min2, load_model
w = load_model()
m1, m0 = min2(1, 0, 0, 1, w) # min(2, 1) = 1
print(2*m1 + m0) # 1
MIT