0
# Pattern Recognition and Mathematical Identification
1
2
Tools for identifying mathematical constants, finding integer relations, polynomial fitting, and discovering mathematical patterns in numerical data.
3
4
## Capabilities
5
6
### Integer Relation Detection
7
8
Find integer linear combinations that sum to zero or small values.
9
10
```python { .api }
11
def pslq(x, tol=None, maxcoeff=1000, maxsteps=100, verbose=False):
12
"""
13
PSLQ algorithm for finding integer relations.
14
15
Args:
16
x: List of real numbers to find relations among
17
tol: Tolerance for relation detection (default: machine precision)
18
maxcoeff: Maximum coefficient size to search (default: 1000)
19
maxsteps: Maximum algorithm steps (default: 100)
20
verbose: Print algorithm progress (default: False)
21
22
Returns:
23
List of integers [a₁, a₂, ..., aₙ] such that a₁x₁ + a₂x₂ + ... + aₙxₙ ≈ 0
24
Returns None if no relation found within constraints
25
"""
26
```
27
28
### Mathematical Constant Identification
29
30
Identify unknown constants by matching against known mathematical constants.
31
32
```python { .api }
33
def identify(x, constants=None, tol=None, maxcoeff=1000, verbose=False, full=False):
34
"""
35
Identify mathematical constant by finding simple expressions.
36
37
Args:
38
x: Number to identify
39
constants: List of known constants to use in identification
40
(default: π, e, γ, φ, ln(2), etc.)
41
tol: Tolerance for matching (default: machine precision)
42
maxcoeff: Maximum coefficient in expressions (default: 1000)
43
verbose: Print search details (default: False)
44
full: Return all found relations (default: False, returns best match)
45
46
Returns:
47
String description of identified constant or None if not found
48
If full=True, returns list of all plausible expressions
49
"""
50
```
51
52
### Polynomial Root Finding and Fitting
53
54
Find polynomials with given roots or fit polynomials to data.
55
56
```python { .api }
57
def findpoly(roots, tol=None, maxdegree=None, **kwargs):
58
"""
59
Find polynomial with given roots.
60
61
Args:
62
roots: List of polynomial roots (real or complex)
63
tol: Tolerance for coefficient simplification
64
maxdegree: Maximum polynomial degree (default: len(roots))
65
**kwargs: Additional options
66
67
Returns:
68
List of polynomial coefficients [aₙ, aₙ₋₁, ..., a₁, a₀]
69
representing aₙxⁿ + aₙ₋₁xⁿ⁻¹ + ... + a₁x + a₀
70
"""
71
```
72
73
### Usage Examples
74
75
```python
76
import mpmath
77
from mpmath import mp
78
79
# Set precision for better identification
80
mp.dps = 50
81
82
# Example 1: Integer relation detection with PSLQ
83
print("=== Integer Relations with PSLQ ===")
84
85
# Find relation for π, e, and some combination
86
x = [mp.pi, mp.e, mp.pi - mp.e]
87
relation = mp.pslq(x, maxcoeff=100)
88
if relation:
89
print(f"Found relation: {relation}")
90
# Verify the relation
91
result = sum(relation[i] * x[i] for i in range(len(x)))
92
print(f"Verification: {result}")
93
else:
94
print("No integer relation found")
95
96
# Example 2: Famous mathematical relations
97
# Euler's identity: e^(iπ) + 1 = 0, so [1, 1] should be a relation for [e^(iπ), 1]
98
vals = [mp.exp(mp.j * mp.pi), 1]
99
relation = mp.pslq([mp.re(vals[0]), mp.im(vals[0]), vals[1]])
100
print(f"Euler identity relation: {relation}")
101
102
# Example 3: Identify mathematical constants
103
print("\n=== Constant Identification ===")
104
105
# Identify well-known constants
106
constants_to_test = [
107
mp.pi,
108
mp.e,
109
mp.sqrt(2),
110
mp.pi**2 / 6, # ζ(2)
111
mp.euler, # Euler-Mascheroni constant
112
mp.phi, # Golden ratio
113
(1 + mp.sqrt(5)) / 2, # Another form of golden ratio
114
]
115
116
for const in constants_to_test:
117
identification = mp.identify(const)
118
print(f"{const} → {identification}")
119
120
# Example 4: Identify unknown expressions
121
print("\n=== Identifying Unknown Expressions ===")
122
123
# Create some "unknown" values and try to identify them
124
unknown1 = mp.pi**2 / 8
125
identification1 = mp.identify(unknown1)
126
print(f"{unknown1} → {identification1}")
127
128
unknown2 = mp.sqrt(mp.pi) * mp.gamma(0.5)
129
identification2 = mp.identify(unknown2)
130
print(f"{unknown2} → {identification2}")
131
132
unknown3 = mp.ln(2) + mp.ln(3) - mp.ln(6) # Should be 0
133
identification3 = mp.identify(unknown3)
134
print(f"{unknown3} → {identification3}")
135
136
# Example 5: Polynomial with known roots
137
print("\n=== Polynomial Fitting ===")
138
139
# Find polynomial with roots 1, 2, 3
140
roots = [1, 2, 3]
141
poly_coeffs = mp.findpoly(roots)
142
print(f"Polynomial with roots {roots}:")
143
print(f"Coefficients: {poly_coeffs}")
144
145
# Verify by evaluating polynomial at roots
146
def eval_poly(coeffs, x):
147
return sum(coeffs[i] * x**(len(coeffs)-1-i) for i in range(len(coeffs)))
148
149
for root in roots:
150
value = eval_poly(poly_coeffs, root)
151
print(f"P({root}) = {value}")
152
153
# Example 6: Complex roots
154
print("\n=== Complex Polynomial Roots ===")
155
complex_roots = [1+1j, 1-1j, 2] # Complex conjugate pair + real root
156
complex_poly = mp.findpoly(complex_roots)
157
print(f"Polynomial with complex roots {complex_roots}:")
158
print(f"Coefficients: {complex_poly}")
159
160
# Example 7: Advanced PSLQ applications
161
print("\n=== Advanced PSLQ Applications ===")
162
163
# Test for algebraic relations involving special functions
164
# Example: Is there a relation between π, ln(2), and ζ(3)?
165
test_values = [mp.pi, mp.ln(2), mp.zeta(3)]
166
relation = mp.pslq(test_values, maxcoeff=20)
167
if relation:
168
print(f"Found relation among π, ln(2), ζ(3): {relation}")
169
verification = sum(relation[i] * test_values[i] for i in range(len(test_values)))
170
print(f"Verification: {verification}")
171
else:
172
print("No simple relation found among π, ln(2), ζ(3)")
173
174
# Example 8: Identify ratios of constants
175
print("\n=== Identifying Ratios ===")
176
177
ratio1 = mp.pi / 4
178
identification = mp.identify(ratio1)
179
print(f"π/4 = {ratio1} → {identification}")
180
181
ratio2 = mp.e / mp.pi
182
identification = mp.identify(ratio2)
183
print(f"e/π = {ratio2} → {identification}")
184
185
# Example 9: Series and limit identification
186
print("\n=== Series Identification ===")
187
188
# Compute a series value and try to identify it
189
def harmonic_series_partial(n):
190
return sum(mp.mpf(1)/k for k in range(1, n+1))
191
192
h_100 = harmonic_series_partial(100)
193
h_100_minus_ln = h_100 - mp.ln(100)
194
identification = mp.identify(h_100_minus_ln)
195
print(f"H₁₀₀ - ln(100) = {h_100_minus_ln}")
196
print(f"Identification: {identification}")
197
198
# Example 10: Numerical integration results
199
print("\n=== Integration Result Identification ===")
200
201
# Integrate e^(-x²) from 0 to ∞ and identify result
202
def gaussian_integral():
203
return mp.quad(lambda x: mp.exp(-x**2), [0, mp.inf])
204
205
integral_result = gaussian_integral()
206
identification = mp.identify(integral_result)
207
print(f"∫₀^∞ e^(-x²) dx = {integral_result}")
208
print(f"Identification: {identification}")
209
print(f"√π/2 = {mp.sqrt(mp.pi)/2}") # Known exact value
210
211
# Example 11: Working with algebraic numbers
212
print("\n=== Algebraic Number Relations ===")
213
214
# Find minimal polynomial for √2 + √3
215
sqrt2_plus_sqrt3 = mp.sqrt(2) + mp.sqrt(3)
216
# To find minimal polynomial, we can use powers
217
powers = [sqrt2_plus_sqrt3**i for i in range(5)] # Include x⁰, x¹, x², x³, x⁴
218
relation = mp.pslq(powers, maxcoeff=100)
219
if relation:
220
print(f"Minimal polynomial relation for √2 + √3: {relation}")
221
# This should give us the minimal polynomial coefficients
222
223
print("\n=== Pattern Recognition Complete ===")
224
```
225
226
### Advanced Features
227
228
#### PSLQ Algorithm Details
229
- Based on the Bailey-Borwein-Plouffe algorithm
230
- Finds integer relations with high confidence
231
- Adjustable precision and coefficient bounds
232
- Handles both real and complex numbers
233
234
#### Constant Database
235
The identification system includes knowledge of:
236
- **Elementary constants**: π, e, √2, ln(2), etc.
237
- **Special function values**: ζ(2), ζ(3), Γ(1/3), etc.
238
- **Algebraic numbers**: Golden ratio, cube roots of unity
239
- **Combinatorial constants**: Catalan's constant, Euler-Mascheroni constant
240
241
#### Polynomial Analysis
242
- Finds exact rational coefficients when possible
243
- Handles complex roots and conjugate pairs
244
- Supports various coefficient formats
245
- Can work with approximate roots
246
247
### Applications
248
249
#### Mathematical Research
250
- **Conjecture verification**: Test suspected mathematical relations
251
- **Constant evaluation**: Identify values from numerical computation
252
- **Pattern discovery**: Find unexpected connections between constants
253
254
#### Computational Mathematics
255
- **Result verification**: Confirm analytical predictions
256
- **Error analysis**: Detect computational mistakes
257
- **Symbolic computation**: Bridge numerical and symbolic methods
258
259
#### Educational Applications
260
- **Concept illustration**: Demonstrate mathematical relationships
261
- **Problem solving**: Identify unknown quantities in exercises
262
- **Mathematical exploration**: Discover patterns in student investigations
263
264
These tools provide powerful capabilities for mathematical discovery and verification, enabling researchers to find hidden patterns and confirm theoretical predictions through high-precision numerical computation.