File size: 1,024 Bytes
41edcb6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | ---
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
|