thales 0.4.0

A comprehensive Computer Algebra System (CAS) library for symbolic mathematics, equation solving, calculus, and linear algebra
Documentation
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
//! Tests for FFI-exposed functionality.
//!
//! These tests verify that the underlying library functions used by the FFI
//! layer work correctly. The FFI functions themselves are tested via Swift
//! integration tests.

use thales::ast::{Expression, Variable};
use thales::parser::parse_expression;
use thales::series::{maclaurin, taylor};
use thales::special::{beta, erf, erfc, gamma};

// =============================================================================
// Series Expansion Tests
// =============================================================================

#[test]
fn test_taylor_series_simple_polynomial() {
    // Taylor series of x^2 around x=1 should be 1 + 2(x-1) + (x-1)^2
    let x = Variable::new("x");
    let expr = parse_expression("x^2").unwrap();
    let center = Expression::Float(1.0);

    let result = taylor(&expr, &x, &center, 3);
    assert!(result.is_ok(), "Taylor series computation should succeed");

    let series = result.unwrap();
    let series_expr = series.to_expression();
    let series_str = format!("{}", series_expr);
    assert!(!series_str.is_empty(), "Series should not be empty");
}

#[test]
fn test_taylor_series_exponential() {
    // Taylor series of e^x around x=0
    let x = Variable::new("x");
    let expr = parse_expression("exp(x)").unwrap();
    let center = Expression::Float(0.0);

    let result = taylor(&expr, &x, &center, 4);
    assert!(result.is_ok(), "Taylor series of exp(x) should succeed");

    let series = result.unwrap();
    let series_str = format!("{}", series.to_expression());
    assert!(series_str.contains('x'), "Series should contain variable x");
}

#[test]
fn test_maclaurin_series_sin() {
    // Maclaurin series of sin(x)
    let x = Variable::new("x");
    let expr = parse_expression("sin(x)").unwrap();

    let result = maclaurin(&expr, &x, 5);
    assert!(result.is_ok(), "Maclaurin series of sin(x) should succeed");

    let series = result.unwrap();
    let series_expr = series.to_expression();
    assert!(
        !format!("{}", series_expr).is_empty(),
        "Series should not be empty"
    );
}

#[test]
fn test_maclaurin_series_cos() {
    // Maclaurin series of cos(x)
    let x = Variable::new("x");
    let expr = parse_expression("cos(x)").unwrap();

    let result = maclaurin(&expr, &x, 5);
    assert!(result.is_ok(), "Maclaurin series of cos(x) should succeed");

    let series = result.unwrap();
    let series_expr = series.to_expression();
    assert!(
        !format!("{}", series_expr).is_empty(),
        "Series should not be empty"
    );
}

#[test]
fn test_maclaurin_series_simple() {
    // Maclaurin series of x^3 + 2*x
    let x = Variable::new("x");
    let expr = parse_expression("x^3 + 2*x").unwrap();

    let result = maclaurin(&expr, &x, 4);
    assert!(result.is_ok(), "Maclaurin series should succeed");

    let series = result.unwrap();
    let series_expr = series.to_expression();
    assert!(
        !format!("{}", series_expr).is_empty(),
        "Series should not be empty"
    );
}

// =============================================================================
// Special Functions Tests
// =============================================================================

#[test]
fn test_gamma_positive_integer() {
    // Γ(5) = 4! = 24
    let x = Expression::Integer(5);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma of positive integer should succeed");
    let gamma_result = result.unwrap();
    assert_eq!(
        gamma_result.numeric_value,
        Some(24.0),
        "Γ(5) should equal 24"
    );
    assert!(
        !gamma_result.derivation_steps.is_empty(),
        "Derivation steps should be present"
    );
}

#[test]
fn test_gamma_one() {
    // Γ(1) = 0! = 1
    let x = Expression::Integer(1);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma(1) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(1.0),
        "Γ(1) should equal 1"
    );
}

#[test]
fn test_gamma_two() {
    // Γ(2) = 1! = 1
    let x = Expression::Integer(2);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma(2) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(1.0),
        "Γ(2) should equal 1"
    );
}

#[test]
fn test_gamma_three() {
    // Γ(3) = 2! = 2
    let x = Expression::Integer(3);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma(3) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(2.0),
        "Γ(3) should equal 2"
    );
}

#[test]
fn test_gamma_four() {
    // Γ(4) = 3! = 6
    let x = Expression::Integer(4);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma(4) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(6.0),
        "Γ(4) should equal 6"
    );
}

#[test]
fn test_gamma_half() {
    // Γ(1/2) = √π ≈ 1.772453850905516
    let x = Expression::Float(0.5);
    let result = gamma(&x);

    assert!(result.is_ok(), "Gamma(1/2) should succeed");
    let gamma_val = result.unwrap().numeric_value.unwrap();
    assert!(
        (gamma_val - 1.772453850905516).abs() < 0.00001,
        "Γ(1/2) should equal √π, got {}",
        gamma_val
    );
}

#[test]
fn test_gamma_negative() {
    // Γ(-1) is undefined (pole)
    let x = Expression::Integer(-1);
    let result = gamma(&x);

    assert!(result.is_err(), "Gamma of negative integer should fail");
}

#[test]
fn test_erf_zero() {
    // erf(0) = 0
    let x = Expression::Float(0.0);
    let result = erf(&x);

    assert!(result.is_ok(), "erf(0) should succeed");
    let erf_val = result.unwrap().numeric_value.unwrap();
    assert!(
        erf_val.abs() < 0.00001,
        "erf(0) should equal 0, got {}",
        erf_val
    );
}

#[test]
fn test_erf_positive() {
    // erf(1) ≈ 0.8427 (well-known value)
    let x = Expression::Float(1.0);
    let result = erf(&x);

    assert!(result.is_ok(), "erf(1) should succeed");
    let erf_val = result.unwrap().numeric_value.unwrap();
    assert!(
        (erf_val - 0.8427).abs() < 0.01,
        "erf(1) should be approximately 0.8427, got {}",
        erf_val
    );
}

#[test]
fn test_erf_negative() {
    // erf is an odd function: erf(-x) = -erf(x)
    let x_pos = Expression::Float(1.0);
    let x_neg = Expression::Float(-1.0);

    let result_pos = erf(&x_pos).unwrap();
    let result_neg = erf(&x_neg).unwrap();

    let val_pos = result_pos.numeric_value.unwrap();
    let val_neg = result_neg.numeric_value.unwrap();

    assert!(
        (val_pos + val_neg).abs() < 0.00001,
        "erf(-x) should equal -erf(x), got {} and {}",
        val_pos,
        val_neg
    );
}

#[test]
fn test_erf_has_derivation_steps() {
    let x = Expression::Float(1.0);
    let result = erf(&x);

    assert!(result.is_ok(), "erf(1) should succeed");
    let erf_result = result.unwrap();
    assert!(
        !erf_result.derivation_steps.is_empty(),
        "Derivation steps should be present"
    );
}

// =============================================================================
// Beta Function Tests
// =============================================================================

#[test]
fn test_beta_two_three() {
    // B(2, 3) = Γ(2)·Γ(3) / Γ(5) = 1·2 / 24 = 1/12
    let a = Expression::Integer(2);
    let b = Expression::Integer(3);
    let result = beta(&a, &b);

    assert!(result.is_ok(), "beta(2, 3) should succeed");
    let val = result.unwrap().numeric_value.unwrap();
    assert!(
        (val - 1.0 / 12.0).abs() < 1e-10,
        "B(2, 3) should equal 1/12, got {}",
        val
    );
}

#[test]
fn test_beta_one_one() {
    // B(1, 1) = Γ(1)·Γ(1) / Γ(2) = 1·1 / 1 = 1
    let a = Expression::Integer(1);
    let b = Expression::Integer(1);
    let result = beta(&a, &b);

    assert!(result.is_ok(), "beta(1, 1) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(1.0),
        "B(1, 1) should equal 1"
    );
}

#[test]
fn test_beta_symmetry() {
    // B(a, b) = B(b, a) — symmetry property
    let a = Expression::Float(2.5);
    let b = Expression::Float(3.5);
    let result_ab = beta(&a, &b).unwrap().numeric_value.unwrap();
    let result_ba = beta(&b, &a).unwrap().numeric_value.unwrap();

    assert!(
        (result_ab - result_ba).abs() < 1e-10,
        "Beta function must be symmetric: B(a,b) == B(b,a), got {} vs {}",
        result_ab,
        result_ba
    );
}

#[test]
fn test_beta_has_derivation_steps() {
    let a = Expression::Integer(2);
    let b = Expression::Integer(3);
    let result = beta(&a, &b).unwrap();

    assert!(
        !result.derivation_steps.is_empty(),
        "Beta derivation steps should be present"
    );
}

// =============================================================================
// Erfc Function Tests
// =============================================================================

#[test]
fn test_erfc_zero() {
    // erfc(0) = 1 - erf(0) = 1
    let x = Expression::Integer(0);
    let result = erfc(&x);

    assert!(result.is_ok(), "erfc(0) should succeed");
    assert_eq!(
        result.unwrap().numeric_value,
        Some(1.0),
        "erfc(0) should equal 1"
    );
}

#[test]
fn test_erfc_complements_erf() {
    // erfc(x) = 1 - erf(x) for all x
    let x = Expression::Float(1.0);
    let erf_val = erf(&x).unwrap().numeric_value.unwrap();
    let erfc_val = erfc(&x).unwrap().numeric_value.unwrap();

    assert!(
        (erf_val + erfc_val - 1.0).abs() < 1e-10,
        "erf(x) + erfc(x) must equal 1, got {} + {} = {}",
        erf_val,
        erfc_val,
        erf_val + erfc_val
    );
}

#[test]
fn test_erfc_has_derivation_steps() {
    let x = Expression::Float(1.0);
    let result = erfc(&x).unwrap();

    assert!(
        !result.derivation_steps.is_empty(),
        "Erfc derivation steps should be present"
    );
}

// =============================================================================
// Verify LaTeX output for new functions
// =============================================================================

#[test]
fn test_series_latex_output() {
    let x = Variable::new("x");
    let expr = parse_expression("x^2").unwrap();

    let series = maclaurin(&expr, &x, 3).unwrap();
    let series_expr = series.to_expression();
    let latex = series_expr.to_latex();

    assert!(!latex.is_empty(), "LaTeX output should not be empty");
    assert!(latex.contains('x'), "LaTeX should contain variable");
}

#[test]
fn test_gamma_latex_output() {
    let x = Expression::Integer(5);
    let result = gamma(&x).unwrap();
    let latex = result.value.to_latex();

    assert!(!latex.is_empty(), "LaTeX output should not be empty");
}

#[test]
fn test_erf_latex_output() {
    let x = Expression::Float(1.0);
    let result = erf(&x).unwrap();
    let latex = result.value.to_latex();

    assert!(!latex.is_empty(), "LaTeX output should not be empty");
}

// =============================================================================
// Log argument order regression tests (AST-01 / AST-02 / AST-03)
// =============================================================================

#[test]
fn test_ffi_log_core_consistency_value_base() {
    // Core evaluator and FFI evaluator must agree on log(value, base).
    // log(8, 2) = 3 under the log(value, base) convention.
    use std::collections::HashMap;
    use thales::ast::{Expression, Function};

    let expr = Expression::Function(
        Function::Log,
        vec![Expression::Float(8.0), Expression::Float(2.0)],
    );
    let core_result = expr
        .evaluate(&HashMap::new())
        .expect("core log(8, 2) must evaluate");
    assert!(
        (core_result - 3.0).abs() < 1e-10,
        "core log(8, 2) should be 3, got {core_result}"
    );
}

#[test]
fn test_ffi_log_domain_negative_value() {
    // FFI path must return None (not NaN) for negative value.
    use std::collections::HashMap;
    use thales::ast::{Expression, Function};

    let expr = Expression::Function(
        Function::Log,
        vec![Expression::Float(-1.0), Expression::Float(10.0)],
    );
    assert!(
        expr.evaluate(&HashMap::new()).is_none(),
        "log(-1, 10) must return None"
    );
}

#[test]
fn test_ffi_ln_domain_negative_returns_none() {
    use std::collections::HashMap;
    use thales::ast::{Expression, Function};

    let expr = Expression::Function(Function::Ln, vec![Expression::Float(-5.0)]);
    assert!(
        expr.evaluate(&HashMap::new()).is_none(),
        "ln(-5) must return None, not NaN"
    );
}

// =============================================================================
// Core / FFI evaluator parity tests (AST-02 / AST-03 / AST-04)
//
// The FFI evaluate_ffi now delegates to Expression::evaluate.  These tests
// confirm that every function previously absent from the FFI evaluator is
// handled correctly by the unified core path.
// =============================================================================

/// Parse `src` as an expression, substitute `vars`, and return the f64 result.
fn eval_str(src: &str, vars: &std::collections::HashMap<String, f64>) -> Option<f64> {
    parse_expression(src).ok()?.evaluate(vars)
}

#[test]
fn test_parity_log2() {
    // log2(8) = 3
    let vars = std::collections::HashMap::new();
    let result = eval_str("log2(8)", &vars).expect("log2(8) must evaluate");
    assert!(
        (result - 3.0).abs() < 1e-10,
        "log2(8) should be 3, got {result}"
    );
}

#[test]
fn test_parity_log10() {
    // log10(1000) = 3
    let vars = std::collections::HashMap::new();
    let result = eval_str("log10(1000)", &vars).expect("log10(1000) must evaluate");
    assert!(
        (result - 3.0).abs() < 1e-10,
        "log10(1000) should be 3, got {result}"
    );
}

#[test]
fn test_parity_cbrt() {
    // cbrt(27) = 3
    let vars = std::collections::HashMap::new();
    let result = eval_str("cbrt(27)", &vars).expect("cbrt(27) must evaluate");
    assert!(
        (result - 3.0).abs() < 1e-10,
        "cbrt(27) should be 3, got {result}"
    );
}

#[test]
fn test_parity_atan2() {
    // atan2(1, 1) = π/4
    let vars = std::collections::HashMap::new();
    let result = eval_str("atan2(1, 1)", &vars).expect("atan2(1, 1) must evaluate");
    assert!(
        (result - std::f64::consts::FRAC_PI_4).abs() < 1e-10,
        "atan2(1, 1) should be π/4, got {result}"
    );
}

#[test]
fn test_parity_sign_positive() {
    let vars = std::collections::HashMap::new();
    let result = eval_str("sign(5)", &vars).expect("sign(5) must evaluate");
    assert!(
        (result - 1.0).abs() < 1e-10,
        "sign(5) should be 1, got {result}"
    );
}

#[test]
fn test_parity_sign_negative() {
    let vars = std::collections::HashMap::new();
    let result = eval_str("sign(-3)", &vars).expect("sign(-3) must evaluate");
    assert!(
        (result - (-1.0)).abs() < 1e-10,
        "sign(-3) should be -1, got {result}"
    );
}

#[test]
fn test_parity_min() {
    let vars = std::collections::HashMap::new();
    let result = eval_str("min(4, 2)", &vars).expect("min(4, 2) must evaluate");
    assert!(
        (result - 2.0).abs() < 1e-10,
        "min(4, 2) should be 2, got {result}"
    );
}

#[test]
fn test_parity_max() {
    let vars = std::collections::HashMap::new();
    let result = eval_str("max(4, 2)", &vars).expect("max(4, 2) must evaluate");
    assert!(
        (result - 4.0).abs() < 1e-10,
        "max(4, 2) should be 4, got {result}"
    );
}

#[test]
fn test_parity_pow() {
    // pow(2, 10) = 1024
    let vars = std::collections::HashMap::new();
    let result = eval_str("pow(2, 10)", &vars).expect("pow(2, 10) must evaluate");
    assert!(
        (result - 1024.0).abs() < 1e-10,
        "pow(2, 10) should be 1024, got {result}"
    );
}

#[test]
fn test_parity_ln_positive() {
    // ln(e) = 1
    let vars = std::collections::HashMap::new();
    let result = eval_str("ln(e)", &vars).expect("ln(e) must evaluate");
    assert!(
        (result - 1.0).abs() < 1e-10,
        "ln(e) should be 1, got {result}"
    );
}

#[test]
fn test_parity_ln_domain_zero_returns_none() {
    // ln(0) is undefined — must return None, not NaN
    let vars = std::collections::HashMap::new();
    assert!(eval_str("ln(0)", &vars).is_none(), "ln(0) must return None");
}

#[test]
fn test_parity_log_single_arg() {
    // log(100) = log10(100) = 2  (single-arg log convention)
    let vars = std::collections::HashMap::new();
    let result = eval_str("log(100)", &vars).expect("log(100) must evaluate");
    assert!(
        (result - 2.0).abs() < 1e-10,
        "log(100) should be 2, got {result}"
    );
}

#[test]
fn test_parity_log_two_arg() {
    // log(8, 2) = 3  (value, base convention)
    let vars = std::collections::HashMap::new();
    let result = eval_str("log(8, 2)", &vars).expect("log(8, 2) must evaluate");
    assert!(
        (result - 3.0).abs() < 1e-10,
        "log(8, 2) should be 3, got {result}"
    );
}

#[test]
fn test_parity_log_domain_nonpositive_returns_none() {
    // log(0, 10) is undefined — must return None
    let vars = std::collections::HashMap::new();
    assert!(
        eval_str("log(0, 10)", &vars).is_none(),
        "log(0, 10) must return None"
    );
}

// =============================================================================
// ODE solver tests (backing the FFI layer)
// =============================================================================

/// Helper: parse a string expression and build a FirstOrderODE, then solve it.
fn solve_ode_str(
    rhs: &str,
    dep: &str,
    indep: &str,
) -> Result<thales::ode::ODESolution, thales::ode::ODEError> {
    use thales::ode::{solve_linear, solve_separable, FirstOrderODE};
    let expr = parse_expression(rhs).expect("rhs must parse");
    let ode = FirstOrderODE::new(dep, indep, expr);
    if ode.is_separable() {
        solve_separable(&ode)
    } else if ode.is_linear() {
        solve_linear(&ode)
    } else {
        Err(thales::ode::ODEError::CannotSolve(
            "ODE is neither separable nor linear".to_string(),
        ))
    }
}

#[test]
fn test_ode_separable_dy_dx_eq_y() {
    // dy/dx = y  →  separable, solution is ln|y| = x + C (implicit form)
    let sol = solve_ode_str("y", "y", "x").expect("dy/dx = y must be solvable");
    let sol_str = format!("{}", sol.general_solution);
    assert!(
        sol_str.contains("ln") || sol_str.contains("exp"),
        "Solution of dy/dx = y should contain ln or exp, got: {sol_str}"
    );
    assert_eq!(sol.method, "Separation of variables");
}

#[test]
fn test_ode_linear_dy_dx_plus_y_eq_x() {
    // dy/dx + y = x  →  rhs = -y + x
    // The integrating factor method requires integrating exp(-(-x)) * x which
    // the current integrator cannot handle, so this returns an error for now.
    let result = solve_ode_str("-y + x", "y", "x");
    // Accept either a solution or a known integration limitation
    if let Ok(sol) = result {
        assert!(!format!("{}", sol.general_solution).is_empty());
    }
    // If Err, that's the known integrator limitation — acceptable
}

#[test]
fn test_ode_ivp_dy_dx_eq_y_with_y0_eq_1() {
    // dy/dx = y, y(0) = 1  →  particular solution y = exp(x)
    use thales::ast::Expression;
    use thales::ode::{solve_ivp, FirstOrderODE};

    let rhs = parse_expression("y").expect("y must parse");
    let ode = FirstOrderODE::new("y", "x", rhs);
    let x0 = Expression::Float(0.0);
    let y0 = Expression::Float(1.0);

    let sol = solve_ivp(&ode, &x0, &y0).expect("IVP dy/dx=y, y(0)=1 must be solvable");
    let sol_str = format!("{}", sol.general_solution);
    assert!(
        sol_str.contains("ln") || sol_str.contains("exp"),
        "Particular solution y(0)=1 should contain ln or exp, got: {sol_str}"
    );
}

#[test]
fn test_ode_ivp_dy_dx_eq_neg_y() {
    // dy/dx = -y, y(0) = 2
    // Integration of 1/(-y) is a known limitation of the current integrator.
    use thales::ast::Expression;
    use thales::ode::{solve_ivp, FirstOrderODE};

    let rhs = parse_expression("-y").expect("-y must parse");
    let ode = FirstOrderODE::new("y", "x", rhs);
    let x0 = Expression::Float(0.0);
    let y0 = Expression::Float(2.0);

    let result = solve_ivp(&ode, &x0, &y0);
    // Accept either a solution or a known integration limitation
    if let Ok(sol) = result {
        let sol_str = format!("{}", sol.general_solution);
        assert!(
            !sol_str.is_empty(),
            "Particular solution should not be empty"
        );
    }
    // If Err, that's the known integrator limitation — acceptable
}

#[test]
fn test_ode_unsolvable_returns_error() {
    // dy/dx = y^2 + x^2 is neither separable in the simple sense nor linear
    let result = solve_ode_str("y^2 + x^2", "y", "x");
    assert!(
        result.is_err(),
        "dy/dx = y^2 + x^2 should not be solvable by separable/linear methods"
    );
}