Views
No views yet
S[3:0], Cout = A[3:0] + B[3:0] + Cin G3,P3 G2,P2 G1,P1 G0,P0 Cin
│ │ │ │ │
│ │ │ │ │
Level 1 ●────────┤ ●────────┤ │ ← Pairwise combination
│ │ │ │ │
│ │ │ │ │
Level 2 ●────────●────────┴────────┘ │ ← Variable fanout level
│ │ │
│ │ │
G3:0 G2:0 G1:0 G0 │
│ │ │ │ │
▼ ▼ ▼ ▼ │
XOR XOR XOR XOR ─────┘
│ │ │ │
▼ ▼ ▼ ▼
Cout S3 S2 S1 S0Fanout ◄────────────────────────────────► Depth
│ │
│ Brent-Kung ─── Ladner-Fischer ─── Sklansky
│ │ │ │
│ Low fanout Configurable Min depth
│ Max depth Trade-off Max fanout
▼ ▼(G_high, P_high) ○ (G_low, P_low) = (G_high + P_high·G_low, P_high·P_low)| A | B | Cin | Sum | Cout | Binary |
|---|---|---|---|---|---|
| 0000 | 0000 | 0 | 0000 | 0 | 0+0=0 |
| 0011 | 0001 | 0 | 0100 | 0 | 3+1=4 |
| 0111 | 0101 | 0 | 1100 | 0 | 7+5=12 |
| 1000 | 1000 | 0 | 0000 | 1 | 8+8=16 |
| 1111 | 1111 | 1 | 1111 | 1 | 15+15+1=31 |
G_i = A_i AND B_i
weights: [A_i: 1.0, B_i: 1.0], bias: -2.0
P_i = A_i XOR B_i
OR: [A_i: 1.0, B_i: 1.0], bias: -1.0
NAND: [A_i: -1.0, B_i: -1.0], bias: 1.0
AND: [OR: 1.0, NAND: 1.0], bias: -2.0| Inputs | 9 (A[3:0], B[3:0], Cin) |
| Outputs | 5 (S[3:0], Cout) |
| Neurons | 32 |
| Layers | 5 |
| Parameters | 132 |
| Magnitude | 56 |
1from safetensors.torch import load_file
2import torch
3
4w = load_file('model.safetensors')
5
6def ladner_fischer_add(a3, a2, a1, a0, b3, b2, b1, b0, cin):
7 a = [a0, a1, a2, a3]
8 b = [b0, b1, b2, b3]
9
10 # Generate/Propagate
11 g = [a[i] & b[i] for i in range(4)]
12 p = [a[i] ^ b[i] for i in range(4)]
13
14 # Level 1: span 1
15 g10 = g[1] | (p[1] & g[0])
16 p10 = p[1] & p[0]
17 g32 = g[3] | (p[3] & g[2])
18 p32 = p[3] & p[2]
19
20 # Level 2: span 2
21 g30 = g32 | (p32 & g10)
22 p30 = p32 & p10
23 g20 = g[2] | (p[2] & g10)
24
25 # Final carries
26 c0 = g[0] | (p[0] & cin)
27 c1 = g10 | (p10 & cin)
28 c2 = g20 | (p[2] & p10 & cin)
29 c3 = g30 | (p30 & cin)
30
31 # Sums
32 s0 = p[0] ^ cin
33 s1 = p[1] ^ c0
34 s2 = p[2] ^ c1
35 s3 = p[3] ^ c2
36
37 return s3, s2, s1, s0, c3
38
39# Verify: 7 + 5 = 12
40result = ladner_fischer_add(0,1,1,1, 0,1,0,1, 0)
41print(f"7 + 5 = {result[4]*16 + result[0]*8 + result[1]*4 + result[2]*2 + result[3]}")threshold-ladner-fischer/
├── model.safetensors # Threshold network weights
├── create_safetensors.py # Weight generation + exhaustive verification
├── config.json # Circuit metadata
└── README.md