File size: 1,407 Bytes
8676f26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
74
75
76
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---

# threshold-gray2binary

4-bit Gray code to binary converter.

## Function

gray2binary(G3, G2, G1, G0) -> (B3, B2, B1, B0)

Conversion formulas:
- B3 = G3
- B2 = G3 XOR G2
- B1 = G3 XOR G2 XOR G1
- B0 = G3 XOR G2 XOR G1 XOR G0

## Example Conversions

| Gray | Binary |
|------|--------|
| 0000 | 0000 (0) |
| 0001 | 0001 (1) |
| 0011 | 0010 (2) |
| 0010 | 0011 (3) |
| 0110 | 0100 (4) |
| 0111 | 0101 (5) |
| 0101 | 0110 (6) |
| 0100 | 0111 (7) |

## Architecture

Cascade XOR structure with shared intermediate results:

```
G3 ──────────────────────────────────────────► B3
G3,G2 ─► [XOR] ─► X1 ────────────────────────► B2
              X1,G1 ─► [XOR] ─► X2 ──────────► B1
                            X2,G0 ─► [XOR] ──► B0
```

Each XOR uses 3 neurons (OR, NAND, AND) with mag-7 weights.

## Parameters

| | |
|---|---|
| Inputs | 4 |
| Outputs | 4 |
| Neurons | 10 |
| Layers | 6 |
| Parameters | 46 |
| Magnitude | 33 |

## Usage

```python
from safetensors.torch import load_file
import torch

w = load_file('model.safetensors')

# Convert gray code 0110 (which is binary 4)
# Full implementation in model.py
```

## License

MIT