Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
1:2 demultiplexer. Routes a data signal to one of two outputs based on a select signal.
d s
β β
βββββββββ€
β β
βΌ βΌ
βββββββββ βββββββββ
βd ANDΒ¬sβ βd AND sβ
βw=[1,-1]β βw=[1,1]β
βb=-1 β βb=-2 β
βββββββββ βββββββββ
β β
βΌ βΌ
y0 y1
The select signal routes the data to exactly one output.
| d | s | y0 | y1 |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 |
| Output | Function | Weights | Bias |
|---|---|---|---|
| y0 | d AND NOT(s) | [1, -1] | -1 |
| y1 | d AND s | [1, 1] | -2 |
Total: 2 neurons, 6 parameters, 1 layer
Single-layer circuit - both outputs are linearly separable.
Exhaustive enumeration of all 19,825 weight configurations at magnitudes 0-7 confirms this circuit is already at minimum magnitude (7). There is exactly one valid configuration at magnitude 7, and no valid configurations exist below it.
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def demux(d, s):
inp = torch.tensor([float(d), float(s)])
y0 = int((inp @ w['y0.weight'].T + w['y0.bias'] >= 0).item())
y1 = int((inp @ w['y1.weight'].T + w['y1.bias'] >= 0).item())
return y0, y1
print(demux(1, 0)) # (1, 0) - routes to y0
print(demux(1, 1)) # (0, 1) - routes to y1
threshold-demux/
βββ model.safetensors
βββ model.py
βββ config.json
βββ README.md
MIT