Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,105 +1,105 @@
|
|
| 1 |
-
---
|
| 2 |
-
license: mit
|
| 3 |
-
tags:
|
| 4 |
-
- formal-verification
|
| 5 |
-
- coq
|
| 6 |
-
- threshold-logic
|
| 7 |
-
- neuromorphic
|
| 8 |
-
- multi-layer
|
| 9 |
-
---
|
| 10 |
-
|
| 11 |
-
# tiny-XNOR-verified
|
| 12 |
-
|
| 13 |
-
Formally verified XNOR gate. Two-layer threshold network computing equivalence with 100% accuracy.
|
| 14 |
-
|
| 15 |
-
## Architecture
|
| 16 |
-
|
| 17 |
-
| Component | Value |
|
| 18 |
-
|-----------|-------|
|
| 19 |
-
| Inputs | 2 |
|
| 20 |
-
| Outputs | 1 |
|
| 21 |
-
| Neurons | 3 (2 hidden, 1 output) |
|
| 22 |
-
| Layers | 2 |
|
| 23 |
-
| Parameters | 9 |
|
| 24 |
-
| **Layer 1, Neuron 1 (NOR)** | |
|
| 25 |
-
| Weights | [-1, -1] |
|
| 26 |
-
| Bias | 0 |
|
| 27 |
-
| **Layer 1, Neuron 2 (AND)** | |
|
| 28 |
-
| Weights | [1, 1] |
|
| 29 |
-
| Bias | -2 |
|
| 30 |
-
| **Layer 2 (OR)** | |
|
| 31 |
-
| Weights | [1, 1] |
|
| 32 |
-
| Bias | -1 |
|
| 33 |
-
| Activation | Heaviside step (all layers) |
|
| 34 |
-
|
| 35 |
-
## Key Properties
|
| 36 |
-
|
| 37 |
-
- 100% accuracy (4/4 inputs correct)
|
| 38 |
-
- Coq-proven correctness
|
| 39 |
-
- Minimal 2-layer architecture (XNOR is not linearly separable)
|
| 40 |
-
- Integer weights
|
| 41 |
-
- Commutative: XNOR(x,y) = XNOR(y,x)
|
| 42 |
-
- Reflexive: XNOR(x,x) = true
|
| 43 |
-
- Equivalence relation (reflexive, symmetric)
|
| 44 |
-
|
| 45 |
-
## Usage
|
| 46 |
-
|
| 47 |
-
```python
|
| 48 |
-
import torch
|
| 49 |
-
from safetensors.torch import load_file
|
| 50 |
-
|
| 51 |
-
weights = load_file('xnor.safetensors')
|
| 52 |
-
|
| 53 |
-
def xnor_gate(x, y):
|
| 54 |
-
inputs = torch.tensor([float(x), float(y)])
|
| 55 |
-
|
| 56 |
-
# Layer 1: NOR and AND
|
| 57 |
-
nor_sum = (inputs * weights['layer1.neuron1.weight']).sum() + weights['layer1.neuron1.bias']
|
| 58 |
-
nor_out = int(nor_sum >= 0)
|
| 59 |
-
|
| 60 |
-
and_sum = (inputs * weights['layer1.neuron2.weight']).sum() + weights['layer1.neuron2.bias']
|
| 61 |
-
and_out = int(and_sum >= 0)
|
| 62 |
-
|
| 63 |
-
# Layer 2: OR
|
| 64 |
-
layer1_outs = torch.tensor([float(nor_out), float(and_out)])
|
| 65 |
-
or_sum = (layer1_outs * weights['layer2.weight']).sum() + weights['layer2.bias']
|
| 66 |
-
return int(or_sum >= 0)
|
| 67 |
-
|
| 68 |
-
# Test
|
| 69 |
-
print(xnor_gate(0, 0)) # 1
|
| 70 |
-
print(xnor_gate(0, 1)) # 0
|
| 71 |
-
print(xnor_gate(1, 0)) # 0
|
| 72 |
-
print(xnor_gate(1, 1)) # 1
|
| 73 |
-
```
|
| 74 |
-
|
| 75 |
-
## Verification
|
| 76 |
-
|
| 77 |
-
**Coq Theorem**:
|
| 78 |
-
```coq
|
| 79 |
-
Theorem xnor_correct : forall x y, xnor_circuit x y = negb (xorb x y).
|
| 80 |
-
```
|
| 81 |
-
|
| 82 |
-
Proven axiom-free with properties:
|
| 83 |
-
- Commutativity
|
| 84 |
-
- Reflexivity
|
| 85 |
-
- Symmetry
|
| 86 |
-
- Equivalence relation properties
|
| 87 |
-
|
| 88 |
-
Full proof: [coq-circuits/Boolean/XNOR.v](https://github.com/CharlesCNorton/coq-circuits)
|
| 89 |
-
|
| 90 |
-
## Circuit Operation
|
| 91 |
-
|
| 92 |
-
XNOR outputs true when inputs are equal (both false or both true).
|
| 93 |
-
|
| 94 |
-
XNOR(x,y) = OR(NOR(x,y), AND(x,y))
|
| 95 |
-
|
| 96 |
-
## Citation
|
| 97 |
-
|
| 98 |
-
```bibtex
|
| 99 |
-
@software{tiny_xnor_prover_2025,
|
| 100 |
-
title={tiny-XNOR-verified: Formally Verified XNOR Gate},
|
| 101 |
-
author={Norton, Charles},
|
| 102 |
-
url={https://huggingface.co/phanerozoic/tiny-XNOR-verified},
|
| 103 |
-
year={2025}
|
| 104 |
-
}
|
| 105 |
-
```
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
tags:
|
| 4 |
+
- formal-verification
|
| 5 |
+
- coq
|
| 6 |
+
- threshold-logic
|
| 7 |
+
- neuromorphic
|
| 8 |
+
- multi-layer
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# tiny-XNOR-verified
|
| 12 |
+
|
| 13 |
+
Formally verified XNOR gate. Two-layer threshold network computing equivalence with 100% accuracy.
|
| 14 |
+
|
| 15 |
+
## Architecture
|
| 16 |
+
|
| 17 |
+
| Component | Value |
|
| 18 |
+
|-----------|-------|
|
| 19 |
+
| Inputs | 2 |
|
| 20 |
+
| Outputs | 1 |
|
| 21 |
+
| Neurons | 3 (2 hidden, 1 output) |
|
| 22 |
+
| Layers | 2 |
|
| 23 |
+
| Parameters | 9 |
|
| 24 |
+
| **Layer 1, Neuron 1 (NOR)** | |
|
| 25 |
+
| Weights | [-1, -1] |
|
| 26 |
+
| Bias | 0 |
|
| 27 |
+
| **Layer 1, Neuron 2 (AND)** | |
|
| 28 |
+
| Weights | [1, 1] |
|
| 29 |
+
| Bias | -2 |
|
| 30 |
+
| **Layer 2 (OR)** | |
|
| 31 |
+
| Weights | [1, 1] |
|
| 32 |
+
| Bias | -1 |
|
| 33 |
+
| Activation | Heaviside step (all layers) |
|
| 34 |
+
|
| 35 |
+
## Key Properties
|
| 36 |
+
|
| 37 |
+
- 100% accuracy (4/4 inputs correct)
|
| 38 |
+
- Coq-proven correctness
|
| 39 |
+
- Minimal 2-layer architecture (XNOR is not linearly separable)
|
| 40 |
+
- Integer weights
|
| 41 |
+
- Commutative: XNOR(x,y) = XNOR(y,x)
|
| 42 |
+
- Reflexive: XNOR(x,x) = true
|
| 43 |
+
- Equivalence relation (reflexive, symmetric)
|
| 44 |
+
|
| 45 |
+
## Usage
|
| 46 |
+
|
| 47 |
+
```python
|
| 48 |
+
import torch
|
| 49 |
+
from safetensors.torch import load_file
|
| 50 |
+
|
| 51 |
+
weights = load_file('xnor.safetensors')
|
| 52 |
+
|
| 53 |
+
def xnor_gate(x, y):
|
| 54 |
+
inputs = torch.tensor([float(x), float(y)])
|
| 55 |
+
|
| 56 |
+
# Layer 1: NOR and AND
|
| 57 |
+
nor_sum = (inputs * weights['layer1.neuron1.weight']).sum() + weights['layer1.neuron1.bias']
|
| 58 |
+
nor_out = int(nor_sum >= 0)
|
| 59 |
+
|
| 60 |
+
and_sum = (inputs * weights['layer1.neuron2.weight']).sum() + weights['layer1.neuron2.bias']
|
| 61 |
+
and_out = int(and_sum >= 0)
|
| 62 |
+
|
| 63 |
+
# Layer 2: OR
|
| 64 |
+
layer1_outs = torch.tensor([float(nor_out), float(and_out)])
|
| 65 |
+
or_sum = (layer1_outs * weights['layer2.weight']).sum() + weights['layer2.bias']
|
| 66 |
+
return int(or_sum >= 0)
|
| 67 |
+
|
| 68 |
+
# Test
|
| 69 |
+
print(xnor_gate(0, 0)) # 1
|
| 70 |
+
print(xnor_gate(0, 1)) # 0
|
| 71 |
+
print(xnor_gate(1, 0)) # 0
|
| 72 |
+
print(xnor_gate(1, 1)) # 1
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## Verification
|
| 76 |
+
|
| 77 |
+
**Coq Theorem**:
|
| 78 |
+
```coq
|
| 79 |
+
Theorem xnor_correct : forall x y, xnor_circuit x y = negb (xorb x y).
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
Proven axiom-free with properties:
|
| 83 |
+
- Commutativity
|
| 84 |
+
- Reflexivity
|
| 85 |
+
- Symmetry
|
| 86 |
+
- Equivalence relation properties
|
| 87 |
+
|
| 88 |
+
Full proof: [coq-circuits/Boolean/XNOR.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Boolean/XNOR.v)
|
| 89 |
+
|
| 90 |
+
## Circuit Operation
|
| 91 |
+
|
| 92 |
+
XNOR outputs true when inputs are equal (both false or both true).
|
| 93 |
+
|
| 94 |
+
XNOR(x,y) = OR(NOR(x,y), AND(x,y))
|
| 95 |
+
|
| 96 |
+
## Citation
|
| 97 |
+
|
| 98 |
+
```bibtex
|
| 99 |
+
@software{tiny_xnor_prover_2025,
|
| 100 |
+
title={tiny-XNOR-verified: Formally Verified XNOR Gate},
|
| 101 |
+
author={Norton, Charles},
|
| 102 |
+
url={https://huggingface.co/phanerozoic/tiny-XNOR-verified},
|
| 103 |
+
year={2025}
|
| 104 |
+
}
|
| 105 |
+
```
|