Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
8-to-3 priority encoder. Outputs binary index of highest-priority set input.
encode(I7..I0) -> (Y2, Y1, Y0)
Priority: I7 > I6 > I5 > I4 > I3 > I2 > I1 > I0
| Input | Highest | Output |
|---|---|---|
| 10000000 | I7 | 111 (7) |
| 01000000 | I6 | 110 (6) |
| 00100000 | I5 | 101 (5) |
| 00010000 | I4 | 100 (4) |
| 00001000 | I3 | 011 (3) |
| 00000100 | I2 | 010 (2) |
| 00000010 | I1 | 001 (1) |
| 00000001 | I0 | 000 (0) |
| 11111111 | I7 | 111 (7) |
Single layer with 3 neurons using weighted priority:
| Output | Function | Weights [I7..I0] | Bias |
|---|---|---|---|
| Y2 | I7∨I6∨I5∨I4 | [1,1,1,1,0,0,0,0] | -1 |
| Y1 | Priority bit 1 | [16,16,-4,-4,1,1,0,0] | -1 |
| Y0 | Priority bit 0 | [128,-64,32,-16,8,-4,2,0] | -1 |
Y1 and Y0 use weighted dominance: higher-priority inputs have larger weights that override lower-priority inputs through the threshold mechanism.
| Inputs | 8 |
| Outputs | 3 |
| Neurons | 3 |
| Layers | 1 |
| Parameters | 27 |
| Magnitude | 303 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def encode8to3(i7, i6, i5, i4, i3, i2, i1, i0):
inp = torch.tensor([float(i7), float(i6), float(i5), float(i4),
float(i3), float(i2), float(i1), float(i0)])
y2 = int((inp @ w['y2.weight'].T + w['y2.bias'] >= 0).item())
y1 = int((inp @ w['y1.weight'].T + w['y1.bias'] >= 0).item())
y0 = int((inp @ w['y0.weight'].T + w['y0.bias'] >= 0).item())
return y2, y1, y0
# I5 is highest set bit
print(encode8to3(0, 0, 1, 0, 1, 0, 0, 0)) # (1, 0, 1) = 5
MIT