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

Downloads last month
9
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Collection including phanerozoic/threshold-parity-tree