Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
8-bit parity computation using balanced XOR tree structure for minimum depth.
x7 ββ¬β[XOR]ββ
x6 ββ ββ[XOR]ββ
x5 ββ¬β[XOR]ββ β
x4 ββ ββ[XOR]βββΊ parity
x3 ββ¬β[XOR]ββ β
x2 ββ ββ[XOR]ββ
x1 ββ¬β[XOR]ββ
x0 ββ
Linear chain (depth 7):
x0β[XOR]β[XOR]β[XOR]β[XOR]β[XOR]β[XOR]β[XOR]ββΊ parity
x1 x2 x3 x4 x5 x6 x7
Tree structure (depth 3):
Layer 1: 4 parallel XORs
Layer 2: 2 parallel XORs
Layer 3: 1 final XOR
| Layer | XOR Gates | Function |
|---|---|---|
| 1 | 4 | Pairs: (0,1), (2,3), (4,5), (6,7) |
| 2 | 2 | Pairs: (01,23), (45,67) |
| 3 | 1 | Final: (0123,4567) |
Total: 21 neurons (7 XORs Γ 3), 111 parameters, 3 layers
For n-bit parity:
| Bits | Tree Depth | Linear Depth |
|---|---|---|
| 8 | 3 | 7 |
| 16 | 4 | 15 |
| 32 | 5 | 31 |
| 64 | 6 | 63 |
from safetensors.torch import load_file
w = load_file('model.safetensors')
# Examples:
# 0x00 (00000000) β parity=0
# 0x01 (00000001) β parity=1
# 0x03 (00000011) β parity=0
# 0xFF (11111111) β parity=0
threshold-parity-tree/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
MIT