Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
4-to-16 binary decoder. Converts 4-bit binary input to one-hot 16-bit output.
decode(a3, a2, a1, a0) -> [y0..y15] where yi=1 iff input=i
| Input | a3a2a1a0 | Output |
|---|---|---|
| 0 | 0000 | 1000000000000000 |
| 1 | 0001 | 0100000000000000 |
| 5 | 0101 | 0000010000000000 |
| 10 | 1010 | 0000000000100000 |
| 15 | 1111 | 0000000000000001 |
Single layer with 16 neurons. Each neuron yi is a pattern matcher for i:
All neurons run in parallel - no dependencies.
| Inputs | 4 |
| Outputs | 16 |
| Neurons | 16 |
| Layers | 1 |
| Parameters | 80 |
| Magnitude | 96 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def decode_4to16(a3, a2, a1, a0):
inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])
return [int((inp * w[f'y{i}.weight']).sum() + w[f'y{i}.bias'] >= 0)
for i in range(16)]
# Input 10 -> output 10 is hot
outputs = decode_4to16(1, 0, 1, 0)
print(outputs) # [0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0]
MIT