phanerozoic commited on
Commit
44dc6ac
·
verified ·
1 Parent(s): 63eead8

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +121 -121
README.md CHANGED
@@ -1,121 +1,121 @@
1
- ---
2
- license: mit
3
- tags:
4
- - formal-verification
5
- - coq
6
- - threshold-logic
7
- - neuromorphic
8
- - multi-layer
9
- ---
10
-
11
- # tiny-XOR-verified
12
-
13
- Formally verified XOR gate. Two-layer threshold network computing exclusive or 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 (OR)** | |
25
- | Weights | [1, 1] |
26
- | Bias | -1 |
27
- | **Layer 1, Neuron 2 (NAND)** | |
28
- | Weights | [-1, -1] |
29
- | Bias | 1 |
30
- | **Layer 2 (AND)** | |
31
- | Weights | [1, 1] |
32
- | Bias | -2 |
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 (XOR is not linearly separable)
40
- - Integer weights
41
- - Commutative: XOR(x,y) = XOR(y,x)
42
- - Associative: XOR(x,XOR(y,z)) = XOR(XOR(x,y),z)
43
- - Self-inverse: XOR(x,XOR(x,y)) = y
44
-
45
- ## Why 2 Layers?
46
-
47
- XOR is the classic example of a function that is **not linearly separable** - a single threshold neuron cannot compute it. This network uses the minimal architecture:
48
-
49
- **Layer 1**: Compute OR and NAND in parallel
50
- **Layer 2**: Compute AND of results
51
-
52
- This implements: XOR(x,y) = AND(OR(x,y), NAND(x,y))
53
-
54
- ## Usage
55
-
56
- ```python
57
- import torch
58
- from safetensors.torch import load_file
59
-
60
- weights = load_file('xor.safetensors')
61
-
62
- def xor_gate(x, y):
63
- inputs = torch.tensor([float(x), float(y)])
64
-
65
- # Layer 1: OR and NAND
66
- or_sum = (inputs * weights['layer1.neuron1.weight']).sum() + weights['layer1.neuron1.bias']
67
- or_out = int(or_sum >= 0)
68
-
69
- nand_sum = (inputs * weights['layer1.neuron2.weight']).sum() + weights['layer1.neuron2.bias']
70
- nand_out = int(nand_sum >= 0)
71
-
72
- # Layer 2: AND
73
- layer1_outs = torch.tensor([float(or_out), float(nand_out)])
74
- and_sum = (layer1_outs * weights['layer2.weight']).sum() + weights['layer2.bias']
75
- return int(and_sum >= 0)
76
-
77
- # Test
78
- print(xor_gate(0, 0)) # 0
79
- print(xor_gate(0, 1)) # 1
80
- print(xor_gate(1, 0)) # 1
81
- print(xor_gate(1, 1)) # 0
82
- ```
83
-
84
- ## Verification
85
-
86
- **Coq Theorem**:
87
- ```coq
88
- Theorem xor_correct : forall x y, xor_circuit x y = xorb x y.
89
- ```
90
-
91
- Proven axiom-free with properties:
92
- - Commutativity
93
- - Associativity
94
- - Identity (XOR with false)
95
- - Complement (XOR with true gives NOT)
96
- - Nilpotence (XOR with itself gives false)
97
- - Involution (XOR is self-inverse)
98
-
99
- Full proof: [coq-circuits/Boolean/XOR.v](https://github.com/CharlesCNorton/coq-circuits)
100
-
101
- ## Circuit Operation
102
-
103
- | Input (x,y) | OR | NAND | AND(OR,NAND) | XOR |
104
- |-------------|-----|------|--------------|-----|
105
- | (0,0) | 0 | 1 | 0 | 0 |
106
- | (0,1) | 1 | 1 | 1 | 1 |
107
- | (1,0) | 1 | 1 | 1 | 1 |
108
- | (1,1) | 1 | 0 | 0 | 0 |
109
-
110
- XOR outputs true when inputs differ.
111
-
112
- ## Citation
113
-
114
- ```bibtex
115
- @software{tiny_xor_prover_2025,
116
- title={tiny-XOR-verified: Formally Verified XOR Gate},
117
- author={Norton, Charles},
118
- url={https://huggingface.co/phanerozoic/tiny-XOR-verified},
119
- year={2025}
120
- }
121
- ```
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - formal-verification
5
+ - coq
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - multi-layer
9
+ ---
10
+
11
+ # tiny-XOR-verified
12
+
13
+ Formally verified XOR gate. Two-layer threshold network computing exclusive or 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 (OR)** | |
25
+ | Weights | [1, 1] |
26
+ | Bias | -1 |
27
+ | **Layer 1, Neuron 2 (NAND)** | |
28
+ | Weights | [-1, -1] |
29
+ | Bias | 1 |
30
+ | **Layer 2 (AND)** | |
31
+ | Weights | [1, 1] |
32
+ | Bias | -2 |
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 (XOR is not linearly separable)
40
+ - Integer weights
41
+ - Commutative: XOR(x,y) = XOR(y,x)
42
+ - Associative: XOR(x,XOR(y,z)) = XOR(XOR(x,y),z)
43
+ - Self-inverse: XOR(x,XOR(x,y)) = y
44
+
45
+ ## Why 2 Layers?
46
+
47
+ XOR is the classic example of a function that is **not linearly separable** - a single threshold neuron cannot compute it. This network uses the minimal architecture:
48
+
49
+ **Layer 1**: Compute OR and NAND in parallel
50
+ **Layer 2**: Compute AND of results
51
+
52
+ This implements: XOR(x,y) = AND(OR(x,y), NAND(x,y))
53
+
54
+ ## Usage
55
+
56
+ ```python
57
+ import torch
58
+ from safetensors.torch import load_file
59
+
60
+ weights = load_file('xor.safetensors')
61
+
62
+ def xor_gate(x, y):
63
+ inputs = torch.tensor([float(x), float(y)])
64
+
65
+ # Layer 1: OR and NAND
66
+ or_sum = (inputs * weights['layer1.neuron1.weight']).sum() + weights['layer1.neuron1.bias']
67
+ or_out = int(or_sum >= 0)
68
+
69
+ nand_sum = (inputs * weights['layer1.neuron2.weight']).sum() + weights['layer1.neuron2.bias']
70
+ nand_out = int(nand_sum >= 0)
71
+
72
+ # Layer 2: AND
73
+ layer1_outs = torch.tensor([float(or_out), float(nand_out)])
74
+ and_sum = (layer1_outs * weights['layer2.weight']).sum() + weights['layer2.bias']
75
+ return int(and_sum >= 0)
76
+
77
+ # Test
78
+ print(xor_gate(0, 0)) # 0
79
+ print(xor_gate(0, 1)) # 1
80
+ print(xor_gate(1, 0)) # 1
81
+ print(xor_gate(1, 1)) # 0
82
+ ```
83
+
84
+ ## Verification
85
+
86
+ **Coq Theorem**:
87
+ ```coq
88
+ Theorem xor_correct : forall x y, xor_circuit x y = xorb x y.
89
+ ```
90
+
91
+ Proven axiom-free with properties:
92
+ - Commutativity
93
+ - Associativity
94
+ - Identity (XOR with false)
95
+ - Complement (XOR with true gives NOT)
96
+ - Nilpotence (XOR with itself gives false)
97
+ - Involution (XOR is self-inverse)
98
+
99
+ Full proof: [coq-circuits/Boolean/XOR.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Boolean/XOR.v)
100
+
101
+ ## Circuit Operation
102
+
103
+ | Input (x,y) | OR | NAND | AND(OR,NAND) | XOR |
104
+ |-------------|-----|------|--------------|-----|
105
+ | (0,0) | 0 | 1 | 0 | 0 |
106
+ | (0,1) | 1 | 1 | 1 | 1 |
107
+ | (1,0) | 1 | 1 | 1 | 1 |
108
+ | (1,1) | 1 | 0 | 0 | 0 |
109
+
110
+ XOR outputs true when inputs differ.
111
+
112
+ ## Citation
113
+
114
+ ```bibtex
115
+ @software{tiny_xor_prover_2025,
116
+ title={tiny-XOR-verified: Formally Verified XOR Gate},
117
+ author={Norton, Charles},
118
+ url={https://huggingface.co/phanerozoic/tiny-XOR-verified},
119
+ year={2025}
120
+ }
121
+ ```