File size: 2,540 Bytes
d6d10c0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
---
license: mit
tags:
- formal-verification
- coq
- threshold-logic
- neuromorphic
- majority
---

# tiny-Majority-verified

Formally verified majority gate for 8-bit inputs. Single threshold neuron computing majority function with 100% accuracy.

## Architecture

| Component | Value |
|-----------|-------|
| Inputs | 8 |
| Outputs | 1 |
| Neurons | 1 |
| Parameters | 9 |
| Weights | [1, 1, 1, 1, 1, 1, 1, 1] |
| Bias | -5 |
| Activation | Heaviside step |

## Key Properties

- 100% accuracy (256/256 inputs correct)
- Coq-proven correctness
- Single threshold neuron
- Integer weights
- Fires when ≥5 of 8 inputs are true
- Equivalent to 5-out-of-8 threshold

## Usage

```python
import torch
from safetensors.torch import load_file

weights = load_file('majority.safetensors')

def majority_gate(bits):
    # bits: list of 8 binary values
    inputs = torch.tensor([float(b) for b in bits])
    weighted_sum = (inputs * weights['weight']).sum() + weights['bias']
    return int(weighted_sum >= 0)

# Test
print(majority_gate([0,0,0,0,0,0,0,0]))  # 0 (no majority)
print(majority_gate([1,1,1,1,0,0,0,0]))  # 0 (4/8, not majority)
print(majority_gate([1,1,1,1,1,0,0,0]))  # 1 (5/8, majority!)
print(majority_gate([1,1,1,1,1,1,1,1]))  # 1 (8/8, majority)
```

## Verification

**Coq Theorem**:
```coq
Theorem majority_correct : forall x0 x1 x2 x3 x4 x5 x6 x7,
  majority_circuit [x0; x1; x2; x3; x4; x5; x6; x7] =
  majority_spec [x0; x1; x2; x3; x4; x5; x6; x7].
```

Proven axiom-free via three methods:
1. **Exhaustive**: Verified on all 256 inputs
2. **Universal**: Quantified proof over all boolean combinations
3. **Algebraic**: Characterized via hamming weight ≥ 5

**Algebraic characterization**:
```coq
Theorem majority_hamming_weight (xs : list bool) :
  length xs = 8 ->
  majority_circuit xs = true <-> hamming_weight xs >= 5.
```

Full proof: [coq-circuits/Threshold/Majority.v](https://github.com/CharlesCNorton/coq-circuits/blob/main/coq/Threshold/Majority.v)

## Circuit Operation

Input with k true bits produces weighted sum: k*1 - 5 = k - 5

- k < 5: weighted_sum < 0 → output 0 (no majority)
- k ≥ 5: weighted_sum ≥ 0 → output 1 (majority)

## Applications

- Voting systems
- Fault-tolerant computing
- Consensus protocols
- Error correction (majority voting)

## Citation

```bibtex
@software{tiny_majority_prover_2025,
  title={tiny-Majority-verified: Formally Verified Majority Gate},
  author={Norton, Charles},
  url={https://huggingface.co/phanerozoic/tiny-Majority-verified},
  year={2025}
}
```