phanerozoic commited on
Commit
ab016fb
·
verified ·
1 Parent(s): ca2b68e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +95 -0
README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ tags:
4
+ - formal-verification
5
+ - coq
6
+ - threshold-logic
7
+ - neuromorphic
8
+ - modular-arithmetic
9
+ ---
10
+
11
+ # tiny-mod6-verified
12
+
13
+ Formally verified MOD-6 circuit. Single-layer threshold network computing modulo-6 arithmetic with 100% accuracy.
14
+
15
+ ## Architecture
16
+
17
+ | Component | Value |
18
+ |-----------|-------|
19
+ | Inputs | 8 |
20
+ | Outputs | 1 (per residue class) |
21
+ | Neurons | 6 (one per residue 0-5) |
22
+ | Parameters | 54 (6 × 9) |
23
+ | Weights | [1, 1, 1, 1, 1, -5, 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
+ - Algebraic weight pattern: resets every 6 positions
32
+ - Computes Hamming weight mod 6
33
+ - Compatible with neuromorphic hardware
34
+
35
+ ## Algebraic Pattern
36
+
37
+ MOD-6 uses the pattern with reset at position 6:
38
+ - Positions 1-5: weight = 1
39
+ - Position 6: weight = 1-6 = -5
40
+ - Positions 7-8: weight = 1
41
+
42
+ This creates a cumulative sum that cycles mod 6.
43
+
44
+ ## Usage
45
+
46
+ ```python
47
+ import torch
48
+ from safetensors.torch import load_file
49
+
50
+ weights = load_file('mod6.safetensors')
51
+
52
+ def mod6_circuit(bits):
53
+ # bits: list of 8 binary values
54
+ inputs = torch.tensor([float(b) for b in bits])
55
+ weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
56
+ return weighted_sum.item()
57
+
58
+ # Test
59
+ print(mod6_circuit([1,1,1,1,1,1,0,0])) # 6 mod 6 = 0
60
+ print(mod6_circuit([1,1,1,1,1,1,1,0])) # 7 mod 6 = 1
61
+ ```
62
+
63
+ ## Verification
64
+
65
+ **Coq Theorem**:
66
+ ```coq
67
+ Theorem mod6_correct_residue_0 : forall x0 x1 x2 x3 x4 x5 x6 x7,
68
+ mod6_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 6) 0.
70
+ ```
71
+
72
+ Proven axiom-free using algebraic weight patterns.
73
+
74
+ Full proof: [coq-circuits/Modular/Mod6.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Modular/Mod6.v)
75
+
76
+ ## Residue Distribution
77
+
78
+ For 8-bit inputs (256 total):
79
+ - Residue 0: 29 inputs
80
+ - Residue 1: 16 inputs
81
+ - Residue 2: 29 inputs
82
+ - Residue 3: 56 inputs
83
+ - Residue 4: 70 inputs
84
+ - Residue 5: 56 inputs
85
+
86
+ ## Citation
87
+
88
+ ```bibtex
89
+ @software{tiny_mod6_verified_2025,
90
+ title={tiny-mod6-verified: Formally Verified MOD-6 Circuit},
91
+ author={Norton, Charles},
92
+ url={https://huggingface.co/phanerozoic/tiny-mod6-verified},
93
+ year={2025}
94
+ }
95
+ ```