File size: 1,878 Bytes
f85d9ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---

license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
---


# threshold-7segment

BCD to 7-segment display decoder.

## Function

segment_decode(B3, B2, B1, B0) -> {a, b, c, d, e, f, g}



Converts 4-bit BCD input (0-9) to 7 segment control signals.



## Segment Layout



```

  aaa

 f   b

  ggg

 e   c

  ddd

```



## Digit Patterns



| Digit | a | b | c | d | e | f | g | Display |

|-------|---|---|---|---|---|---|---|---------|

| 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | `0` |

| 1 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | `1` |

| 2 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | `2` |

| 3 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | `3` |

| 4 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | `4` |

| 5 | 1 | 0 | 1 | 1 | 0 | 1 | 1 | `5` |

| 6 | 1 | 0 | 1 | 1 | 1 | 1 | 1 | `6` |

| 7 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | `7` |

| 8 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | `8` |

| 9 | 1 | 1 | 1 | 1 | 0 | 1 | 1 | `9` |



## Architecture



Two-layer design:



```

B3,B2,B1,B0 ─► [d0] ─┐

             [d1] ──

             [d2] ──      [OR] ─► a

             [d3] ─┼─────► [OR] ─► b

             [d4] ──      [OR] ─► c

             [d5] ──      [OR] ─► d

             [d6] ──      [OR] ─► e

             [d7] ──      [OR] ─► f

             [d8] ──      [OR] ─► g

             [d9] β”€β”˜

```



Layer 1: 10 digit detectors (pattern matchers)

Layer 2: 7 OR gates combining relevant digits for each segment



## Parameters



| | |

|---|---|

| Inputs | 4 |

| Outputs | 7 |

| Neurons | 17 |

| Layers | 2 |

| Parameters | 127 |

| Magnitude | 111 |



## Usage



```python

from safetensors.torch import load_file
# Full implementation in model.py

# Example: Display digit 5
# result = segment_decode(0, 1, 0, 1, weights)

# -> {'a':1, 'b':0, 'c':1, 'd':1, 'e':0, 'f':1, 'g':1}

```



## License



MIT