Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
1:4 demultiplexer. Routes data input to one of 4 outputs based on 2-bit select.
DEMUX4(d, s1, s0) -> [y0, y1, y2, y3]
yi = d AND (s == i), where s = 2*s1 + s0
| d | s1 | s0 | y0 | y1 | y2 | y3 |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 | 0 | 0 | 0 |
| 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 0 | 1 |
Single layer with 4 neurons. Each output yi fires when d=1 AND select matches i.
| Output | Weights [d, s1, s0] | Bias |
|---|---|---|
| y0 | [1, -1, -1] | -1 |
| y1 | [1, -1, +1] | -2 |
| y2 | [1, +1, -1] | -2 |
| y3 | [1, +1, +1] | -3 |
| Inputs | 3 (1 data + 2 select) |
| Outputs | 4 |
| Neurons | 4 |
| Layers | 1 |
| Parameters | 16 |
| Magnitude | 20 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def demux4(d, s1, s0):
inp = torch.tensor([float(d), float(s1), float(s0)])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)
for i in range(4)]
# Route d=1 to output 2 (s=10)
print(demux4(1, 1, 0)) # [0, 0, 1, 0]
MIT