Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
Extract sign bit (MSB) of 4-bit number.
signbit4(a3, a2, a1, a0) = a3
In 2's complement representation:
| a3 | a2 | a1 | a0 | unsigned | signed | signbit |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 1 | 1 | 7 | +7 | 0 |
| 1 | 0 | 0 | 0 | 8 | -8 | 1 |
| 1 | 1 | 1 | 1 | 15 | -1 | 1 |
Single neuron extracting MSB:
Fires when: a3 - 1 >= 0, i.e., a3 >= 1
| Inputs | 4 |
| Outputs | 1 |
| Neurons | 1 |
| Layers | 1 |
| Parameters | 5 |
| Magnitude | 2 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
def signbit4(a3, a2, a1, a0):
inp = torch.tensor([float(a3), float(a2), float(a1), float(a0)])
return int((inp @ w['neuron.weight'].T + w['neuron.bias'] >= 0).item())
print(signbit4(0, 1, 1, 1)) # 0 (value = +7)
print(signbit4(1, 0, 0, 0)) # 1 (value = -8)
MIT