--- license: mit tags: - formal-verification - coq - threshold-logic - neuromorphic - functionally-complete --- # tiny-NAND-verified Formally verified NAND gate. Single threshold neuron computing negated conjunction with 100% accuracy. ## Architecture | Component | Value | |-----------|-------| | Inputs | 2 | | Outputs | 1 | | Neurons | 1 | | Parameters | 3 | | Weights | [-1, -1] | | Bias | 1 | | Activation | Heaviside step | ## Key Properties - 100% accuracy (4/4 inputs correct) - Coq-proven correctness - Single threshold neuron - Integer weights - Commutative: NAND(x,y) = NAND(y,x) - Functionally complete (can build any Boolean function) - Self-dual: NAND(x,x) = NOT(x) ## Usage ```python import torch from safetensors.torch import load_file weights = load_file('nand.safetensors') def nand_gate(x, y): # Heaviside: weighted_sum + bias >= 0 inputs = torch.tensor([float(x), float(y)]) weighted_sum = (inputs * weights['weight']).sum() + weights['bias'] return int(weighted_sum >= 0) # Test print(nand_gate(0, 0)) # 1 print(nand_gate(0, 1)) # 1 print(nand_gate(1, 0)) # 1 print(nand_gate(1, 1)) # 0 ``` ## Verification **Coq Theorem**: ```coq Theorem nand_correct : forall x y, nand_circuit x y = negb (andb x y). ``` Proven axiom-free with properties: - Commutativity - Self-duality (NAND(x,x) = NOT(x)) - Functional completeness - Identity with true gives NOT - Absorption with false gives true Full proof: [coq-circuits/Boolean/NAND.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Boolean/NAND.v) ## Circuit Operation Input combination produces weighted sum: - (0,0): 0*(-1) + 0*(-1) + 1 = 1 >= 0 → 1 - (0,1): 0*(-1) + 1*(-1) + 1 = 0 >= 0 → 1 - (1,0): 1*(-1) + 0*(-1) + 1 = 0 >= 0 → 1 - (1,1): 1*(-1) + 1*(-1) + 1 = -1 < 0 → 0 Fails to fire only when both inputs are true. ## Functional Completeness NAND is functionally complete - any Boolean function can be built from NAND gates alone. This makes it particularly important for circuit composition. ## Citation ```bibtex @software{tiny_nand_prover_2025, title={tiny-NAND-verified: Formally Verified NAND Gate}, author={Norton, Charles}, url={https://huggingface.co/phanerozoic/tiny-NAND-verified}, year={2025} } ```