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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
//! Built-in domain presets for common mathematical domains
//!
//! These presets configure symbol sets, weights, and user constants
//! appropriate for different areas of mathematics.
use crate::profile::{Profile, UserConstant};
use crate::symbol::{NumType, Symbol};
/// Available built-in presets
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum Preset {
/// Analytic number theory: ζ values, Γ, log, π powers
AnalyticNT,
/// Elliptic/modular: K(k), E(k), Γ(1/4), q-series
Elliptic,
/// Combinatorics: Catalan, Apéry, polylog patterns
Combinatorics,
/// Physics: π, log, γ, ζ, Clausen-type constants
Physics,
/// Number theory: rational/algebraic focus
NumberTheory,
/// Calculus: standard functions, no exotic constants
Calculus,
}
impl Preset {
/// Get preset name for CLI
pub fn name(&self) -> &'static str {
match self {
Preset::AnalyticNT => "analytic-nt",
Preset::Elliptic => "elliptic",
Preset::Combinatorics => "combinatorics",
Preset::Physics => "physics",
Preset::NumberTheory => "number-theory",
Preset::Calculus => "calculus",
}
}
/// Get preset description
pub fn description(&self) -> &'static str {
match self {
Preset::AnalyticNT => "Analytic number theory: ζ values, Γ, log, π powers",
Preset::Elliptic => "Elliptic/modular: K(k), E(k), Γ(1/4), q-series constants",
Preset::Combinatorics => "Combinatorics: Catalan, Apéry, polylog patterns",
Preset::Physics => "Physics: π, log, γ, ζ, Clausen-type constants",
Preset::NumberTheory => "Number theory: rational/algebraic focus",
Preset::Calculus => "Calculus: standard functions, no exotic constants",
}
}
/// Parse from string (for CLI)
#[allow(clippy::should_implement_trait)]
pub fn from_str(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"analytic-nt" | "ant" | "analytic" => Some(Preset::AnalyticNT),
"elliptic" | "modular" => Some(Preset::Elliptic),
"combinatorics" | "combo" | "catalan" => Some(Preset::Combinatorics),
"physics" | "phys" => Some(Preset::Physics),
"number-theory" | "nt" | "algebraic" => Some(Preset::NumberTheory),
"calculus" | "calc" => Some(Preset::Calculus),
_ => None,
}
}
/// Generate the profile for this preset
#[allow(clippy::wrong_self_convention)]
pub fn to_profile(&self) -> Profile {
let mut profile = Profile::new();
match self {
Preset::AnalyticNT => {
// Analytic number theory uses zeta values, gamma, log, powers of pi
// Lower weights for: pi, e, log, exp
// Higher weights for: trig (less common)
// Add zeta(2) = π²/6, zeta(3), zeta(4) as constants
profile.symbol_weights = vec![
(Symbol::Pi, 6), // Lower weight - very common
(Symbol::Ln, 6), // Lower weight - very common
(Symbol::Exp, 6), // Lower weight - very common
(Symbol::SinPi, 12), // Higher weight - less common
(Symbol::CosPi, 12), // Higher weight - less common
(Symbol::TanPi, 14), // Higher weight - less common
(Symbol::LambertW, 16), // Rarely used
]
.into_iter()
.collect();
// Add zeta(2) = π²/6 ≈ 1.644934
profile.constants.push(UserConstant {
weight: 10,
name: "z2".to_string(),
description: "ζ(2) = π²/6 (Basel problem)".to_string(),
value: std::f64::consts::PI * std::f64::consts::PI / 6.0,
num_type: NumType::Transcendental,
});
// zeta(3) ≈ 1.202057 (Apéry's constant) - already built-in as 'z'
// But let's ensure it has a good weight
profile.symbol_weights.insert(Symbol::Apery, 8);
// Euler-Mascheroni gamma - already built-in as 'g'
profile.symbol_weights.insert(Symbol::Gamma, 8);
}
Preset::Elliptic => {
// Elliptic integrals, modular forms
// Focus on: sqrt, powers, log
// Avoid: trig (elliptic integrals replace them)
profile.symbol_weights = vec![
(Symbol::Sqrt, 4), // Lower - very common
(Symbol::Square, 4), // Lower - very common
(Symbol::Ln, 6), // Common
(Symbol::Pi, 6), // Common
(Symbol::SinPi, 16), // Avoid - elliptic replaces
(Symbol::CosPi, 16), // Avoid - elliptic replaces
(Symbol::TanPi, 18), // Avoid - elliptic replaces
]
.into_iter()
.collect();
// Γ(1/4) ≈ 3.6256 - important for elliptic integrals
profile.constants.push(UserConstant {
weight: 12,
name: "g14".to_string(),
description: "Γ(1/4) - elliptic integral constant".to_string(),
value: 3.625609908221908,
num_type: NumType::Transcendental,
});
// K(1/√2) = Γ²(1/4)/(4√π) ≈ 1.85407
profile.constants.push(UserConstant {
weight: 14,
name: "K1".to_string(),
description: "K(1/√2) - complete elliptic integral".to_string(),
value: 1.854074677301372,
num_type: NumType::Transcendental,
});
// Golden ratio - already built-in, ensure good weight
profile.symbol_weights.insert(Symbol::Phi, 8);
}
Preset::Combinatorics => {
// Combinatorics: Catalan, Apéry, polylog patterns
// Focus on: integers, rationals, simple algebraic
profile.symbol_weights = vec![
(Symbol::One, 2), // Very common
(Symbol::Two, 2), // Very common
(Symbol::Three, 2), // Very common
(Symbol::Four, 3), // Common
(Symbol::Five, 3), // Common
(Symbol::Pi, 12), // Less common
(Symbol::E, 12), // Less common
(Symbol::Ln, 14), // Rare
(Symbol::Exp, 14), // Rare
]
.into_iter()
.collect();
// Catalan's constant G ≈ 0.915966 - already built-in
profile.symbol_weights.insert(Symbol::Catalan, 8);
// Apéry's constant ζ(3) ≈ 1.202057 - already built-in
profile.symbol_weights.insert(Symbol::Apery, 8);
}
Preset::Physics => {
// Physics constants: π, log, γ, ζ, combinations
// Similar to analytic-nt but more focused on practical values
profile.symbol_weights = vec![
(Symbol::Pi, 5), // Very common
(Symbol::E, 6), // Very common
(Symbol::Ln, 6), // Common
(Symbol::Exp, 6), // Common
(Symbol::Sqrt, 5), // Common
(Symbol::SinPi, 10), // Moderate
(Symbol::CosPi, 10), // Moderate
]
.into_iter()
.collect();
// Euler-Mascheroni gamma
profile.symbol_weights.insert(Symbol::Gamma, 8);
// Fine structure constant α ≈ 1/137.036 (inverse)
// Not adding as it's very specific, but γ is important
}
Preset::NumberTheory => {
// Number theory: focus on rationals, algebraic numbers
// Avoid transcendentals, focus on integers
profile.symbol_weights = vec![
(Symbol::One, 2),
(Symbol::Two, 2),
(Symbol::Three, 2),
(Symbol::Four, 3),
(Symbol::Five, 3),
(Symbol::Six, 3),
(Symbol::Seven, 3),
(Symbol::Eight, 4),
(Symbol::Nine, 4),
(Symbol::Sqrt, 6), // Algebraic
(Symbol::Square, 6), // Algebraic
(Symbol::Pi, 16), // Avoid transcendental
(Symbol::E, 16), // Avoid transcendental
(Symbol::Ln, 18), // Avoid
(Symbol::Exp, 18), // Avoid
]
.into_iter()
.collect();
// Golden ratio - algebraic
profile.symbol_weights.insert(Symbol::Phi, 8);
// Plastic constant - algebraic
profile.symbol_weights.insert(Symbol::Plastic, 10);
}
Preset::Calculus => {
// Standard calculus: all functions available, no exotic constants
// Balanced weights for general use
profile.symbol_weights = vec![
(Symbol::Pi, 7),
(Symbol::E, 7),
(Symbol::Ln, 7),
(Symbol::Exp, 7),
(Symbol::Sqrt, 5),
(Symbol::Square, 5),
(Symbol::SinPi, 8),
(Symbol::CosPi, 8),
(Symbol::TanPi, 9),
]
.into_iter()
.collect();
}
}
profile
}
/// List all available presets
pub fn all() -> &'static [Preset] {
&[
Preset::AnalyticNT,
Preset::Elliptic,
Preset::Combinatorics,
Preset::Physics,
Preset::NumberTheory,
Preset::Calculus,
]
}
}
/// Print available presets (for --list-presets)
#[allow(clippy::print_literal)]
pub fn print_presets() {
println!("Available domain presets:");
println!();
println!(" {:<15} {}", "PRESET", "DESCRIPTION");
println!(" {}", "-".repeat(70));
for preset in Preset::all() {
println!(" {:<15} {}", preset.name(), preset.description());
}
println!();
println!("Usage: ries-rs --preset <name> <target>");
println!("Example: ries-rs --preset physics 6.67430e-11");
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_preset_parse() {
assert_eq!(Preset::from_str("analytic-nt"), Some(Preset::AnalyticNT));
assert_eq!(Preset::from_str("ANT"), Some(Preset::AnalyticNT));
assert_eq!(Preset::from_str("physics"), Some(Preset::Physics));
assert_eq!(Preset::from_str("PHYS"), Some(Preset::Physics));
assert_eq!(Preset::from_str("invalid"), None);
}
#[test]
fn test_preset_profile_non_empty() {
for preset in Preset::all() {
let profile = preset.to_profile();
// Each preset should modify at least something
assert!(
!profile.symbol_weights.is_empty() || !profile.constants.is_empty(),
"Preset {:?} should have some configuration",
preset
);
}
}
#[test]
fn test_analytic_nt_has_gamma() {
let profile = Preset::AnalyticNT.to_profile();
assert!(profile.symbol_weights.contains_key(&Symbol::Gamma));
}
#[test]
fn test_number_theory_avoids_transcendentals() {
let profile = Preset::NumberTheory.to_profile();
// Pi and E should have high weights (discouraged)
assert!(profile.symbol_weights.get(&Symbol::Pi) > Some(&10));
assert!(profile.symbol_weights.get(&Symbol::E) > Some(&10));
}
}