metadata
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- parity
threshold-parity-tree
8-bit parity computation using balanced XOR tree structure for minimum depth.
Circuit
x7 ββ¬β[XOR]ββ
x6 ββ ββ[XOR]ββ
x5 ββ¬β[XOR]ββ β
x4 ββ ββ[XOR]βββΊ parity
x3 ββ¬β[XOR]ββ β
x2 ββ ββ[XOR]ββ
x1 ββ¬β[XOR]ββ
x0 ββ
Output
- parity = 0: Even number of 1s in input
- parity = 1: Odd number of 1s in input
Tree vs Linear
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
Architecture
| 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
Scalability
For n-bit parity:
- Tree depth: logβ(n)
- XOR gates: n - 1
- Linear depth: n - 1
| Bits | Tree Depth | Linear Depth |
|---|---|---|
| 8 | 3 | 7 |
| 16 | 4 | 15 |
| 32 | 5 | 31 |
| 64 | 6 | 63 |
Usage
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
Files
threshold-parity-tree/
βββ model.safetensors
βββ create_safetensors.py
βββ config.json
βββ README.md
License
MIT