phanerozoic commited on
Commit
4ac0d04
·
verified ·
1 Parent(s): 7de2881

Upload README.md with huggingface_hub

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