phanerozoic commited on
Commit
2a3fb50
·
verified ·
1 Parent(s): b19b85d

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-mod12-verified
12
+
13
+ Formally verified MOD-12 circuit. Single-layer threshold network computing modulo-12 arithmetic with 100% accuracy.
14
+
15
+ ## Architecture
16
+
17
+ | Component | Value |
18
+ |-----------|-------|
19
+ | Inputs | 8 |
20
+ | Outputs | 1 (per residue class) |
21
+ | Neurons | 12 (one per residue 0-11) |
22
+ | Parameters | 108 (12 × 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 12
33
+ - Compatible with neuromorphic hardware
34
+
35
+ ## Algebraic Pattern
36
+
37
+ MOD-12 uses all-ones weights because the reset position (position 12) is beyond the 8-bit input width:
38
+ - All positions 1-8: weight = 1
39
+ - Position 12 (beyond input): would be weight = 1-12 = -11
40
+
41
+ The circuit tracks cumulative sum mod 12 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('mod12.safetensors')
50
+
51
+ def mod12_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
+ return int(weighted_sum.item()) % 12
56
+
57
+ # Test
58
+ print(mod12_circuit([1,1,1,1,1,1,1,1])) # 8 mod 12 = 8
59
+ print(mod12_circuit([1,1,1,1,0,0,0,0])) # 4 mod 12 = 4
60
+ ```
61
+
62
+ ## Verification
63
+
64
+ **Coq Theorem**:
65
+ ```coq
66
+ Theorem mod12_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
67
+ mod12_is_zero [x0; x1; x2; x3; x4; x5; x6; x7] =
68
+ Z.eqb ((Z.of_nat (hamming_weight [x0; x1; x2; x3; x4; x5; x6; x7])) mod 12) 0.
69
+ ```
70
+
71
+ Proven axiom-free using algebraic weight patterns.
72
+
73
+ Full proof: [coq-circuits/Modular/Mod12.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Modular/Mod12.v)
74
+
75
+ ## Residue Distribution
76
+
77
+ For 8-bit inputs (256 total), limited to residues 0-8:
78
+ - Residue 0: 1 inputs
79
+ - Residue 1: 8 inputs
80
+ - Residue 2: 28 inputs
81
+ - Residue 3: 56 inputs
82
+ - Residue 4: 70 inputs
83
+ - Residue 5: 56 inputs
84
+ - Residue 6: 28 inputs
85
+ - Residue 7: 8 inputs
86
+ - Residue 8: 1 inputs
87
+ - Residues 9-11: 0 inputs (unreachable with 8-bit input)
88
+
89
+ ## Citation
90
+
91
+ ```bibtex
92
+ @software{tiny_mod12_verified_2025,
93
+ title={tiny-mod12-verified: Formally Verified MOD-12 Circuit},
94
+ author={Norton, Charles},
95
+ url={https://huggingface.co/phanerozoic/tiny-mod12-verified},
96
+ year={2025}
97
+ }
98
+ ```