Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
β’
248 items
β’
Updated
β’
1
4-bit binary to Gray code converter.
binary2gray(B3, B2, B1, B0) -> (G3, G2, G1, G0)
Conversion formulas:
| Binary | Gray |
|---|---|
| 0000 (0) | 0000 |
| 0001 (1) | 0001 |
| 0010 (2) | 0011 |
| 0011 (3) | 0010 |
| 0100 (4) | 0110 |
| 0101 (5) | 0111 |
| 0110 (6) | 0101 |
| 0111 (7) | 0100 |
Parallel XOR gates for each output bit:
B3 ββββββββββββββββββββββββββΊ G3
B3,B2 ββΊ [XOR] ββββββββββββββΊ G2
B2,B1 ββΊ [XOR] ββββββββββββββΊ G1
B1,B0 ββΊ [XOR] ββββββββββββββΊ G0
Each XOR uses 3 neurons (OR, NAND, AND) with mag-7 structure.
| Inputs | 4 |
| Outputs | 4 |
| Neurons | 10 |
| Layers | 2 |
| Parameters | 43 |
| Magnitude | 33 |
from safetensors.torch import load_file
# Full implementation in model.py
MIT