Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit Gray code to binary converter.
gray2binary(G3, G2, G1, G0) -> (B3, B2, B1, B0)
Conversion formulas:
| 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) |
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.
| Inputs | 4 |
| Outputs | 4 |
| Neurons | 10 |
| Layers | 6 |
| Parameters | 46 |
| Magnitude | 33 |
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
MIT