Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,97 +1,97 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
tags:
|
| 4 |
-
- formal-verification
|
| 5 |
-
- coq
|
| 6 |
-
- threshold-logic
|
| 7 |
-
- neuromorphic
|
| 8 |
-
- functionally-complete
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# tiny-NAND-verified
|
| 12 |
-
|
| 13 |
-
Formally verified NAND gate. Single threshold neuron computing negated conjunction with 100% accuracy.
|
| 14 |
-
|
| 15 |
-
## Architecture
|
| 16 |
-
|
| 17 |
-
| Component | Value |
|
| 18 |
-
|-----------|-------|
|
| 19 |
-
| Inputs | 2 |
|
| 20 |
-
| Outputs | 1 |
|
| 21 |
-
| Neurons | 1 |
|
| 22 |
-
| Parameters | 3 |
|
| 23 |
-
| Weights | [-1, -1] |
|
| 24 |
-
| Bias | 1 |
|
| 25 |
-
| Activation | Heaviside step |
|
| 26 |
-
|
| 27 |
-
## Key Properties
|
| 28 |
-
|
| 29 |
-
- 100% accuracy (4/4 inputs correct)
|
| 30 |
-
- Coq-proven correctness
|
| 31 |
-
- Single threshold neuron
|
| 32 |
-
- Integer weights
|
| 33 |
-
- Commutative: NAND(x,y) = NAND(y,x)
|
| 34 |
-
- Functionally complete (can build any Boolean function)
|
| 35 |
-
- Self-dual: NAND(x,x) = NOT(x)
|
| 36 |
-
|
| 37 |
-
## Usage
|
| 38 |
-
|
| 39 |
-
```python
|
| 40 |
-
import torch
|
| 41 |
-
from safetensors.torch import load_file
|
| 42 |
-
|
| 43 |
-
weights = load_file('nand.safetensors')
|
| 44 |
-
|
| 45 |
-
def nand_gate(x, y):
|
| 46 |
-
# Heaviside: weighted_sum + bias >= 0
|
| 47 |
-
inputs = torch.tensor([float(x), float(y)])
|
| 48 |
-
weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
|
| 49 |
-
return int(weighted_sum >= 0)
|
| 50 |
-
|
| 51 |
-
# Test
|
| 52 |
-
print(nand_gate(0, 0)) # 1
|
| 53 |
-
print(nand_gate(0, 1)) # 1
|
| 54 |
-
print(nand_gate(1, 0)) # 1
|
| 55 |
-
print(nand_gate(1, 1)) # 0
|
| 56 |
-
```
|
| 57 |
-
|
| 58 |
-
## Verification
|
| 59 |
-
|
| 60 |
-
**Coq Theorem**:
|
| 61 |
-
```coq
|
| 62 |
-
Theorem nand_correct : forall x y, nand_circuit x y = negb (andb x y).
|
| 63 |
-
```
|
| 64 |
-
|
| 65 |
-
Proven axiom-free with properties:
|
| 66 |
-
- Commutativity
|
| 67 |
-
- Self-duality (NAND(x,x) = NOT(x))
|
| 68 |
-
- Functional completeness
|
| 69 |
-
- Identity with true gives NOT
|
| 70 |
-
- Absorption with false gives true
|
| 71 |
-
|
| 72 |
-
Full proof: [coq-circuits/Boolean/NAND.v](https://github.com/CharlesCNorton/coq-circuits)
|
| 73 |
-
|
| 74 |
-
## Circuit Operation
|
| 75 |
-
|
| 76 |
-
Input combination produces weighted sum:
|
| 77 |
-
- (0,0): 0*(-1) + 0*(-1) + 1 = 1 >= 0 → 1
|
| 78 |
-
- (0,1): 0*(-1) + 1*(-1) + 1 = 0 >= 0 → 1
|
| 79 |
-
- (1,0): 1*(-1) + 0*(-1) + 1 = 0 >= 0 → 1
|
| 80 |
-
- (1,1): 1*(-1) + 1*(-1) + 1 = -1 < 0 → 0
|
| 81 |
-
|
| 82 |
-
Fails to fire only when both inputs are true.
|
| 83 |
-
|
| 84 |
-
## Functional Completeness
|
| 85 |
-
|
| 86 |
-
NAND is functionally complete - any Boolean function can be built from NAND gates alone. This makes it particularly important for circuit composition.
|
| 87 |
-
|
| 88 |
-
## Citation
|
| 89 |
-
|
| 90 |
-
```bibtex
|
| 91 |
-
@software{tiny_nand_prover_2025,
|
| 92 |
-
title={tiny-NAND-verified: Formally Verified NAND Gate},
|
| 93 |
-
author={Norton, Charles},
|
| 94 |
-
url={https://huggingface.co/phanerozoic/tiny-NAND-verified},
|
| 95 |
-
year={2025}
|
| 96 |
-
}
|
| 97 |
-
```
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- formal-verification
|
| 5 |
+
- coq
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
- functionally-complete
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# tiny-NAND-verified
|
| 12 |
+
|
| 13 |
+
Formally verified NAND gate. Single threshold neuron computing negated conjunction with 100% accuracy.
|
| 14 |
+
|
| 15 |
+
## Architecture
|
| 16 |
+
|
| 17 |
+
| Component | Value |
|
| 18 |
+
|-----------|-------|
|
| 19 |
+
| Inputs | 2 |
|
| 20 |
+
| Outputs | 1 |
|
| 21 |
+
| Neurons | 1 |
|
| 22 |
+
| Parameters | 3 |
|
| 23 |
+
| Weights | [-1, -1] |
|
| 24 |
+
| Bias | 1 |
|
| 25 |
+
| Activation | Heaviside step |
|
| 26 |
+
|
| 27 |
+
## Key Properties
|
| 28 |
+
|
| 29 |
+
- 100% accuracy (4/4 inputs correct)
|
| 30 |
+
- Coq-proven correctness
|
| 31 |
+
- Single threshold neuron
|
| 32 |
+
- Integer weights
|
| 33 |
+
- Commutative: NAND(x,y) = NAND(y,x)
|
| 34 |
+
- Functionally complete (can build any Boolean function)
|
| 35 |
+
- Self-dual: NAND(x,x) = NOT(x)
|
| 36 |
+
|
| 37 |
+
## Usage
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
import torch
|
| 41 |
+
from safetensors.torch import load_file
|
| 42 |
+
|
| 43 |
+
weights = load_file('nand.safetensors')
|
| 44 |
+
|
| 45 |
+
def nand_gate(x, y):
|
| 46 |
+
# Heaviside: weighted_sum + bias >= 0
|
| 47 |
+
inputs = torch.tensor([float(x), float(y)])
|
| 48 |
+
weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
|
| 49 |
+
return int(weighted_sum >= 0)
|
| 50 |
+
|
| 51 |
+
# Test
|
| 52 |
+
print(nand_gate(0, 0)) # 1
|
| 53 |
+
print(nand_gate(0, 1)) # 1
|
| 54 |
+
print(nand_gate(1, 0)) # 1
|
| 55 |
+
print(nand_gate(1, 1)) # 0
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## Verification
|
| 59 |
+
|
| 60 |
+
**Coq Theorem**:
|
| 61 |
+
```coq
|
| 62 |
+
Theorem nand_correct : forall x y, nand_circuit x y = negb (andb x y).
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
Proven axiom-free with properties:
|
| 66 |
+
- Commutativity
|
| 67 |
+
- Self-duality (NAND(x,x) = NOT(x))
|
| 68 |
+
- Functional completeness
|
| 69 |
+
- Identity with true gives NOT
|
| 70 |
+
- Absorption with false gives true
|
| 71 |
+
|
| 72 |
+
Full proof: [coq-circuits/Boolean/NAND.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Boolean/NAND.v)
|
| 73 |
+
|
| 74 |
+
## Circuit Operation
|
| 75 |
+
|
| 76 |
+
Input combination produces weighted sum:
|
| 77 |
+
- (0,0): 0*(-1) + 0*(-1) + 1 = 1 >= 0 → 1
|
| 78 |
+
- (0,1): 0*(-1) + 1*(-1) + 1 = 0 >= 0 → 1
|
| 79 |
+
- (1,0): 1*(-1) + 0*(-1) + 1 = 0 >= 0 → 1
|
| 80 |
+
- (1,1): 1*(-1) + 1*(-1) + 1 = -1 < 0 → 0
|
| 81 |
+
|
| 82 |
+
Fails to fire only when both inputs are true.
|
| 83 |
+
|
| 84 |
+
## Functional Completeness
|
| 85 |
+
|
| 86 |
+
NAND is functionally complete - any Boolean function can be built from NAND gates alone. This makes it particularly important for circuit composition.
|
| 87 |
+
|
| 88 |
+
## Citation
|
| 89 |
+
|
| 90 |
+
```bibtex
|
| 91 |
+
@software{tiny_nand_prover_2025,
|
| 92 |
+
title={tiny-NAND-verified: Formally Verified NAND Gate},
|
| 93 |
+
author={Norton, Charles},
|
| 94 |
+
url={https://huggingface.co/phanerozoic/tiny-NAND-verified},
|
| 95 |
+
year={2025}
|
| 96 |
+
}
|
| 97 |
+
```
|