File size: 1,075 Bytes
5f77b99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: mit
tags:
- pytorch
- safetensors
- threshold-logic
- neuromorphic
- arithmetic
---

# threshold-subtractor4bit

4-bit subtractor. Computes A - B (modulo 16) with borrow output.

## Function

subtractor4bit(A, B) = (A - B) mod 16, borrow_out

## Truth Table (selected rows)

| A | B | Diff | Borrow |
|---|---|------|--------|
| 7 | 3 | 4 | 0 |
| 5 | 5 | 0 | 0 |
| 3 | 7 | 12 | 1 |
| 0 | 1 | 15 | 1 |

## Architecture

Ripple-borrow subtractor using full subtractor units.

For each bit i:
- diff_i = a_i XOR b_i XOR borrow_{i-1}
- borrow_i = majority(NOT(a_i), b_i, borrow_{i-1})

The borrow signal indicates A < B (unsigned comparison).

## Parameters

| | |
|---|---|
| Inputs | 8 (a3-a0, b3-b0) |
| Outputs | 5 (d3-d0, bout) |
| Neurons | 25 |
| Layers | 8 |
| Parameters | 86 |
| Magnitude | 88 |

## Usage

```python
from safetensors.torch import load_file
# See model.py for full implementation

# 7 - 3 = 4
# subtractor4(0,1,1,1, 0,0,1,1) = [0,1,0,0, 0]

# 3 - 7 = 12 (wraps), borrow=1
# subtractor4(0,0,1,1, 0,1,1,1) = [1,1,0,0, 1]
```

## License

MIT