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