Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
269 items
β’
Updated
β’
1
8-bit leading one detector. Finds the position of the highest-order 1 bit (MSB priority).
x[7:0] βββΊ LOD βββ¬βββΊ pos[2:0] (position 0-7)
ββββΊ valid (1 if any bit set)
| Input | Binary | Position | Valid |
|---|---|---|---|
| 0 | 00000000 | 0 | 0 |
| 1 | 00000001 | 0 | 1 |
| 2 | 00000010 | 1 | 1 |
| 128 | 10000000 | 7 | 1 |
| 255 | 11111111 | 7 | 1 |
| 170 | 10101010 | 7 | 1 |
For each bit position i (7 down to 0):
leader[i] = x[i] AND NOT(any bit j > i is set)
Position is binary encoding of which leader is active.
| Component | Count | Neurons |
|---|---|---|
| Higher-than OR | 8 | 8 |
| NOT higher | 8 | 8 |
| Leader AND | 8 | 8 |
| Position encode | 3 | 3 |
| Valid OR | 1 | 1 |
Total: 28 neurons, 136 parameters, 3 layers
from safetensors.torch import load_file
w = load_file('model.safetensors')
# For x = 0b00101100 (44):
# Leading one at position 5
# logβ(44) β 5
Count Leading Zeros = 7 - position (when valid=1)
x = 0b00100000 β position=5 β CLZ=2
x = 0b10000000 β position=7 β CLZ=0
threshold-leading-one-detect/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT