--- license: mit tags: - pytorch - safetensors - threshold-logic - neuromorphic --- # threshold-nand4 4-input NAND gate. Outputs 0 only when all inputs are 1. ## Circuit ``` x1 x2 x3 x4 │ │ │ │ └───┴───┴───┘ │ ▼ ┌──────────┐ │w:-1,-1,-1,-1│ │ b: 3 │ └──────────┘ │ ▼ NAND4(x1,x2,x3,x4) ``` ## Parameters | | | |---|---| | Weights | [-1, -1, -1, -1] | | Bias | 3 | | Magnitude | 7 | ## Optimality Exhaustive enumeration of 7,183 configurations confirms magnitude 7 is optimal. 1 valid configuration exists. | Magnitude | Valid Configs | |-----------|---------------| | 0-6 | 0 | | 7 | 1 | ## Usage ```python from safetensors.torch import load_file import torch w = load_file('model.safetensors') def nand4(x1, x2, x3, x4): inputs = torch.tensor([float(x1), float(x2), float(x3), float(x4)]) return int((inputs * w['weight']).sum() + w['bias'] >= 0) ``` ## License MIT