--- 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 ```python 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