Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
8-bit bit reversal. Reverses the order of bits.
reverse8(a7, a6, a5, a4, a3, a2, a1, a0) = [a0, a1, a2, a3, a4, a5, a6, a7]
| Input | Output |
|---|---|
| 10000000 | 00000001 |
| 00000001 | 10000000 |
| 10101010 | 01010101 |
| 11110000 | 00001111 |
Single layer with 8 neurons, each copying one input bit to its reversed position.
| Output | Copies from | Weights | Bias |
|---|---|---|---|
| y0 | a7 | [1,0,0,0,0,0,0,0] | -1 |
| y1 | a6 | [0,1,0,0,0,0,0,0] | -1 |
| y2 | a5 | [0,0,1,0,0,0,0,0] | -1 |
| y3 | a4 | [0,0,0,1,0,0,0,0] | -1 |
| y4 | a3 | [0,0,0,0,1,0,0,0] | -1 |
| y5 | a2 | [0,0,0,0,0,1,0,0] | -1 |
| y6 | a1 | [0,0,0,0,0,0,1,0] | -1 |
| y7 | a0 | [0,0,0,0,0,0,0,1] | -1 |
| Inputs | 8 |
| Outputs | 8 |
| Neurons | 8 |
| Layers | 1 |
| Parameters | 16 |
| Magnitude | 16 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def reverse8(a7, a6, a5, a4, a3, a2, a1, a0):
inp = torch.tensor([float(a7), float(a6), float(a5), float(a4),
float(a3), float(a2), float(a1), float(a0)])
return [int((inp @ w[f'y{i}.weight'].T + w[f'y{i}.bias'] >= 0).item())
for i in range(8)]
print(reverse8(1, 0, 0, 0, 0, 0, 0, 0)) # [0, 0, 0, 0, 0, 0, 0, 1]
MIT