phanerozoic commited on
Commit
54f89f0
·
verified ·
1 Parent(s): 4a1ef0b

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +99 -99
README.md CHANGED
@@ -1,99 +1,99 @@
1
- ---
2
- license: mit
3
- tags:
4
- - formal-verification
5
- - coq
6
- - threshold-logic
7
- - neuromorphic
8
- - modular-arithmetic
9
- ---
10
-
11
- # tiny-mod4-verified
12
-
13
- Formally verified MOD-4 circuit. Single-layer threshold network computing modulo-4 arithmetic with 100% accuracy.
14
-
15
- ## Architecture
16
-
17
- | Component | Value |
18
- |-----------|-------|
19
- | Inputs | 8 |
20
- | Outputs | 1 (per residue class) |
21
- | Neurons | 4 (one per residue 0-3) |
22
- | Parameters | 36 (4 × 9) |
23
- | Weights | [1, 1, 1, -3, 1, 1, 1, -3] |
24
- | Bias | 0 |
25
- | Activation | Heaviside step |
26
-
27
- ## Key Properties
28
-
29
- - 100% accuracy (256/256 inputs correct)
30
- - Coq-proven correctness
31
- - Algebraic weight pattern: (1, 1, 1, 1-m) repeating
32
- - Computes Hamming weight mod 4
33
- - Compatible with neuromorphic hardware
34
-
35
- ## Algebraic Pattern
36
-
37
- MOD-4 uses the repeating pattern `[1, 1, 1, -3]`:
38
- - Positions 1-3: weight = 1
39
- - Position 4: weight = 1-4 = -3
40
- - Positions 5-7: weight = 1
41
- - Position 8: weight = 1-4 = -3
42
-
43
- This creates a cumulative sum that cycles mod 4.
44
-
45
- ## Usage
46
-
47
- ```python
48
- import torch
49
- from safetensors.torch import load_file
50
-
51
- weights = load_file('mod4.safetensors')
52
-
53
- def mod4_circuit(bits):
54
- # bits: list of 8 binary values
55
- inputs = torch.tensor([float(b) for b in bits])
56
- weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
57
- # Output represents cumulative sum mod 4
58
- return weighted_sum.item()
59
-
60
- # Test
61
- print(mod4_circuit([1,0,0,0,0,0,0,0])) # 1 mod 4 = 1
62
- print(mod4_circuit([1,1,1,1,0,0,0,0])) # 4 mod 4 = 0
63
- print(mod4_circuit([1,1,1,1,1,0,0,0])) # 5 mod 4 = 1
64
- ```
65
-
66
- ## Verification
67
-
68
- **Coq Theorem**:
69
- ```coq
70
- Theorem mod4_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
71
- mod4_is_zero [x0; x1; x2; x3; x4; x5; x6; x7] =
72
- Z.eqb ((Z.of_nat (hamming_weight [x0; x1; x2; x3; x4; x5; x6; x7])) mod 4) 0.
73
- ```
74
-
75
- Proven axiom-free using:
76
- 1. **Algebraic correctness**: Weight pattern proven to maintain mod-4 invariant
77
- 2. **Universal quantification**: Verified for all 8-bit inputs
78
- 3. **Parametric instantiation**: Instantiates `mod_m_weights_8` with m=4
79
-
80
- Full proof: [coq-circuits/Modular/Mod4.v](https://github.com/CharlesCNorton/coq-circuits)
81
-
82
- ## Residue Distribution
83
-
84
- For 8-bit inputs (256 total):
85
- - Residue 0: 72 inputs
86
- - Residue 1: 64 inputs
87
- - Residue 2: 56 inputs
88
- - Residue 3: 64 inputs
89
-
90
- ## Citation
91
-
92
- ```bibtex
93
- @software{tiny_mod4_verified_2025,
94
- title={tiny-mod4-verified: Formally Verified MOD-4 Circuit},
95
- author={Norton, Charles},
96
- url={https://huggingface.co/phanerozoic/tiny-mod4-verified},
97
- year={2025}
98
- }
99
- ```
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - formal-verification
5
+ - coq
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - modular-arithmetic
9
+ ---
10
+
11
+ # tiny-mod4-verified
12
+
13
+ Formally verified MOD-4 circuit. Single-layer threshold network computing modulo-4 arithmetic with 100% accuracy.
14
+
15
+ ## Architecture
16
+
17
+ | Component | Value |
18
+ |-----------|-------|
19
+ | Inputs | 8 |
20
+ | Outputs | 1 (per residue class) |
21
+ | Neurons | 4 (one per residue 0-3) |
22
+ | Parameters | 36 (4 × 9) |
23
+ | Weights | [1, 1, 1, -3, 1, 1, 1, -3] |
24
+ | Bias | 0 |
25
+ | Activation | Heaviside step |
26
+
27
+ ## Key Properties
28
+
29
+ - 100% accuracy (256/256 inputs correct)
30
+ - Coq-proven correctness
31
+ - Algebraic weight pattern: (1, 1, 1, 1-m) repeating
32
+ - Computes Hamming weight mod 4
33
+ - Compatible with neuromorphic hardware
34
+
35
+ ## Algebraic Pattern
36
+
37
+ MOD-4 uses the repeating pattern `[1, 1, 1, -3]`:
38
+ - Positions 1-3: weight = 1
39
+ - Position 4: weight = 1-4 = -3
40
+ - Positions 5-7: weight = 1
41
+ - Position 8: weight = 1-4 = -3
42
+
43
+ This creates a cumulative sum that cycles mod 4.
44
+
45
+ ## Usage
46
+
47
+ ```python
48
+ import torch
49
+ from safetensors.torch import load_file
50
+
51
+ weights = load_file('mod4.safetensors')
52
+
53
+ def mod4_circuit(bits):
54
+ # bits: list of 8 binary values
55
+ inputs = torch.tensor([float(b) for b in bits])
56
+ weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
57
+ # Output represents cumulative sum mod 4
58
+ return weighted_sum.item()
59
+
60
+ # Test
61
+ print(mod4_circuit([1,0,0,0,0,0,0,0])) # 1 mod 4 = 1
62
+ print(mod4_circuit([1,1,1,1,0,0,0,0])) # 4 mod 4 = 0
63
+ print(mod4_circuit([1,1,1,1,1,0,0,0])) # 5 mod 4 = 1
64
+ ```
65
+
66
+ ## Verification
67
+
68
+ **Coq Theorem**:
69
+ ```coq
70
+ Theorem mod4_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
71
+ mod4_is_zero [x0; x1; x2; x3; x4; x5; x6; x7] =
72
+ Z.eqb ((Z.of_nat (hamming_weight [x0; x1; x2; x3; x4; x5; x6; x7])) mod 4) 0.
73
+ ```
74
+
75
+ Proven axiom-free using:
76
+ 1. **Algebraic correctness**: Weight pattern proven to maintain mod-4 invariant
77
+ 2. **Universal quantification**: Verified for all 8-bit inputs
78
+ 3. **Parametric instantiation**: Instantiates `mod_m_weights_8` with m=4
79
+
80
+ Full proof: [coq-circuits/Modular/Mod4.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Modular/Mod4.v)
81
+
82
+ ## Residue Distribution
83
+
84
+ For 8-bit inputs (256 total):
85
+ - Residue 0: 72 inputs
86
+ - Residue 1: 64 inputs
87
+ - Residue 2: 56 inputs
88
+ - Residue 3: 64 inputs
89
+
90
+ ## Citation
91
+
92
+ ```bibtex
93
+ @software{tiny_mod4_verified_2025,
94
+ title={tiny-mod4-verified: Formally Verified MOD-4 Circuit},
95
+ author={Norton, Charles},
96
+ url={https://huggingface.co/phanerozoic/tiny-mod4-verified},
97
+ year={2025}
98
+ }
99
+ ```