Threshold Logic Circuits
Collection
Boolean gates, voting functions, modular arithmetic, and adders as threshold networks.
•
248 items
•
Updated
•
1
4-bit Hamming distance. Computes the number of bit positions where two 4-bit inputs differ.
HD(a, b) = popcount(a XOR b)
Returns 3-bit binary encoding (d2, d1, d0) of the distance 0-4.
5-layer circuit:
diff_hi_i = a_i AND NOT b_i and diff_lo_i = NOT a_i AND b_idiff_i = diff_hi_i OR diff_lo_ige_k = at least k differences| Inputs | 8 (a3,a2,a1,a0, b3,b2,b1,b0) |
| Outputs | 3 (d2, d1, d0) |
| Neurons | 21 |
| Layers | 5 |
| Parameters | 155 |
| Magnitude | 76 |
| a | b | HD |
|---|---|---|
| 0000 | 0000 | 0 |
| 1111 | 0000 | 4 |
| 1010 | 0101 | 4 |
| 1100 | 1010 | 2 |
| 1111 | 1110 | 1 |
from safetensors.torch import load_file
import torch
w = load_file('model.safetensors')
# See model.py for full implementation
# Returns (d2, d1, d0) where distance = 4*d2 + 2*d1 + d0
MIT