Skip to content

Commit eb21868

Browse files
committed
docs: add mathematical references document
1 parent 76313c8 commit eb21868

1 file changed

Lines changed: 239 additions & 0 deletions

File tree

REFERENCES.md

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# Mathematical References
2+
3+
This document contains the mathematical foundations and references for the algorithms used in TrueEntropy.
4+
5+
## Table of Contents
6+
7+
1. [Entropy and Information Theory](#entropy-and-information-theory)
8+
2. [Cryptographic Primitives](#cryptographic-primitives)
9+
3. [Random Number Generation](#random-number-generation)
10+
4. [Probability Distributions](#probability-distributions)
11+
5. [Statistical Tests](#statistical-tests)
12+
6. [External Sources](#external-sources)
13+
14+
---
15+
16+
## Entropy and Information Theory
17+
18+
### Shannon Entropy
19+
20+
The entropy of a discrete random variable X is defined as:
21+
22+
```
23+
H(X) = -Σ p(x) log₂ p(x)
24+
```
25+
26+
**References:**
27+
- Shannon, C. E. (1948). "A Mathematical Theory of Communication"
28+
- https://en.wikipedia.org/wiki/Entropy_(information_theory)
29+
30+
### Entropy Estimation
31+
32+
<!-- Add your entropy estimation formulas here -->
33+
34+
---
35+
36+
## Cryptographic Primitives
37+
38+
### SHA-256 Hash Function
39+
40+
Used for mixing entropy in the pool. Properties:
41+
- Output: 256 bits (32 bytes)
42+
- Collision resistance: 2^128 operations
43+
- Preimage resistance: 2^256 operations
44+
45+
**References:**
46+
- FIPS 180-4: Secure Hash Standard
47+
- https://csrc.nist.gov/publications/detail/fips/180/4/final
48+
49+
### Avalanche Effect
50+
51+
A small change in input produces a completely different output:
52+
53+
```
54+
P(bit_i changes | 1 bit input change) ≈ 0.5
55+
```
56+
57+
---
58+
59+
## Random Number Generation
60+
61+
### Uniform Float Generation
62+
63+
Converting n random bits to float in [0, 1):
64+
65+
```
66+
float_value = integer_value / 2^n
67+
```
68+
69+
We use 64 bits for maximum precision (~15-17 significant decimal digits).
70+
71+
### Rejection Sampling (Unbiased Integer Range)
72+
73+
To generate uniform integer in [a, b]:
74+
75+
```
76+
range = b - a + 1
77+
bits_needed = ceil(log₂(range))
78+
mask = 2^bits_needed - 1
79+
80+
repeat:
81+
raw = extract_bits(bits_needed)
82+
value = raw & mask
83+
until value < range
84+
85+
return a + value
86+
```
87+
88+
**Why rejection sampling?**
89+
Simple modulo causes bias when range doesn't divide 2^n evenly.
90+
91+
**References:**
92+
- https://en.wikipedia.org/wiki/Rejection_sampling
93+
94+
### Fisher-Yates Shuffle
95+
96+
For uniform random permutation:
97+
98+
```
99+
for i from n-1 down to 1:
100+
j = random_int(0, i)
101+
swap(arr[i], arr[j])
102+
```
103+
104+
**References:**
105+
- Fisher, R.A.; Yates, F. (1938). "Statistical Tables"
106+
- https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
107+
108+
---
109+
110+
## Probability Distributions
111+
112+
### Gaussian (Normal) Distribution
113+
114+
Using Box-Muller transform:
115+
116+
```
117+
Z₀ = √(-2 ln U₁) cos(2π U₂)
118+
Z₁ = √(-2 ln U₁) sin(2π U₂)
119+
```
120+
121+
Where U₁, U₂ ~ Uniform(0, 1)
122+
123+
**References:**
124+
- Box, G. E. P.; Muller, M. E. (1958)
125+
- https://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
126+
127+
### Exponential Distribution
128+
129+
Using inverse transform:
130+
131+
```
132+
X = -ln(U) / λ
133+
```
134+
135+
Where U ~ Uniform(0, 1), λ is rate parameter
136+
137+
**References:**
138+
- https://en.wikipedia.org/wiki/Exponential_distribution
139+
140+
### Triangular Distribution
141+
142+
```
143+
if U < (mode - low) / (high - low):
144+
X = low + √(U × (high - low) × (mode - low))
145+
else:
146+
X = high - √((1-U) × (high - low) × (high - mode))
147+
```
148+
149+
**References:**
150+
- https://en.wikipedia.org/wiki/Triangular_distribution
151+
152+
### Weighted Random Selection
153+
154+
Cumulative distribution method:
155+
156+
```
157+
total = sum(weights)
158+
threshold = random() * total
159+
cumulative = 0
160+
for i, weight in enumerate(weights):
161+
cumulative += weight
162+
if threshold < cumulative:
163+
return items[i]
164+
```
165+
166+
---
167+
168+
## Statistical Tests
169+
170+
### Chi-Square Test
171+
172+
For testing uniformity:
173+
174+
```
175+
χ² = Σ (O_i - E_i)² / E_i
176+
```
177+
178+
Where O_i = observed frequency, E_i = expected frequency
179+
180+
### NIST SP 800-22
181+
182+
Statistical test suite for random number generators:
183+
- Frequency (monobit) test
184+
- Block frequency test
185+
- Runs test
186+
- Longest run test
187+
- etc.
188+
189+
**References:**
190+
- https://csrc.nist.gov/publications/detail/sp/800-22/rev-1a/final
191+
192+
---
193+
194+
## External Sources
195+
196+
### Entropy Sources Quality
197+
198+
| Source | Entropy Quality | Notes |
199+
|--------|----------------|-------|
200+
| CPU Timing Jitter | Medium | OS scheduler, cache effects |
201+
| Network Latency | Medium | Congestion, routing variability |
202+
| System State | Low-Medium | Volatile but somewhat predictable |
203+
| Weather APIs | Medium | Chaotic atmospheric systems |
204+
| random.org | High | Atmospheric noise, quantum effects |
205+
| ANU QRNG | Very High | Quantum vacuum fluctuations |
206+
207+
### UUID v4 Generation (RFC 4122)
208+
209+
```
210+
xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
211+
212+
Where:
213+
- x = random hex digit
214+
- 4 = version (always 4 for random UUID)
215+
- y = variant (8, 9, a, or b)
216+
```
217+
218+
**References:**
219+
- RFC 4122: https://tools.ietf.org/html/rfc4122
220+
221+
---
222+
223+
## Contributing References
224+
225+
Add your mathematical references here following the format:
226+
227+
```markdown
228+
### Topic Name
229+
230+
Formula or algorithm description:
231+
232+
\`\`\`
233+
mathematical_notation_here
234+
\`\`\`
235+
236+
**References:**
237+
- Author (Year). "Title"
238+
- URL
239+
```

0 commit comments

Comments
 (0)