threshold-equals2 / README.md
CharlesCNorton
2-bit equality comparator, magnitude 18
41edcb6
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---
# threshold-equals2
2-bit equality comparator. Outputs 1 if 2-bit A equals 2-bit B.
## Function
equals2(a1, a0, b1, b0) = 1 if (a1,a0) == (b1,b0), else 0
## Architecture
Checks if each bit pair matches using XNOR, then ANDs the results.
XNOR(x, y) = (x AND y) OR (NOT x AND NOT y)
**Layer 1:** (4 neurons on raw inputs)
- and1: a1 AND b1
- nor1: NOR(a1, b1)
- and0: a0 AND b0
- nor0: NOR(a0, b0)
**Layer 2:** (2 neurons)
- xnor1: OR(and1, nor1) - bit 1 matches
- xnor0: OR(and0, nor0) - bit 0 matches
**Layer 3:** (1 neuron)
- eq: AND(xnor1, xnor0) - both bits match
## Parameters
| | |
|---|---|
| Inputs | 4 (a1, a0, b1, b0) |
| Outputs | 1 |
| Neurons | 7 |
| Layers | 3 |
| Parameters | 31 |
| Magnitude | 18 |
## Usage
```python
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
# Check if 2 == 2 (binary 10 == 10)
# a1=1, a0=0, b1=1, b0=0
# Result: 1 (equal)
```
## License
MIT