symplex 0.5.0

Exact symbolic mathematics for Rust: calculus, summation, solving, linear algebra, transforms, compile-time dimensional analysis, and Rust/C code generation
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
//! Tests for Wave η — inequality solving.
//!
//! Covers: solve_gt, solve_ge, solve_lt, solve_le, solveset,
//! constant expressions, linear, quadratic, and edge cases.

use super::common;

use symplex::prelude::*;

// ═══════════════════════════════════════════════════════════════════════════
// solve_gt — strict greater-than
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solve_x_gt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let result = x.solve_gt(&x);
    let s = format!("{result}");
    // x > 0 → (0, ∞)
    assert!(!s.contains("EmptySet"), "x > 0 should not be empty: {s}");
    assert!(
        s.contains("oo") || s.contains("") || s.contains("Interval"),
        "x > 0 should contain an interval to infinity: {s}"
    );
    // Interior: x=3 → 3 > 0 ✓
    common::assert_positive_at(&x, &x, 3, "x > 0 interior at x=3");
    // Exterior: x=-1 → -1 < 0 ✗
    common::assert_negative_at(&x, &x, -1, "x > 0 exterior at x=-1");
}

#[test]
fn solve_x2_minus_4_gt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let poly = &x.powi(2) - 4;
    let result = poly.solve_gt(&x);
    let s = format!("{result}");
    // x² - 4 > 0 → (-∞, -2) ∪ (2, ∞)
    assert!(
        !s.contains("EmptySet"),
        "x²-4 > 0 should have solutions: {s}"
    );
    // Should mention both 2 and -2 as boundary points
    assert!(s.contains("2"), "solution should reference 2: {s}");
    // Interior: x=3 → 9-4=5 > 0 ✓
    common::assert_positive_at(&poly, &x, 3, "x²-4 > 0 interior at x=3");
    // Interior: x=-3 → 9-4=5 > 0 ✓
    common::assert_positive_at(&poly, &x, -3, "x²-4 > 0 interior at x=-3");
    // Exterior: x=0 → 0-4=-4 < 0 ✗
    common::assert_negative_at(&poly, &x, 0, "x²-4 > 0 exterior at x=0");
}

#[test]
fn solve_positive_constant_gt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let five = ctx.int(5);
    let result = five.solve_gt(&x);
    let s = format!("{result}");
    // 5 > 0 is always true → (-∞, ∞)
    assert!(
        !s.contains("EmptySet"),
        "5 > 0 should be satisfied everywhere: {s}"
    );
    // Interior: constant 5 > 0 everywhere, check at x=0
    common::assert_positive_at(&five, &x, 0, "5 > 0 constant check");
}

#[test]
fn solve_negative_constant_gt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let neg = ctx.int(-3);
    let result = neg.solve_gt(&x);
    // -3 > 0 is always false → EmptySet
    assert_eq!(format!("{result}"), "EmptySet");
    // Spot check: -3 is negative everywhere
    common::assert_negative_at(&neg, &x, 0, "-3 > 0 constant check");
}

#[test]
fn solve_zero_gt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let zero = ctx.int(0);
    let result = zero.solve_gt(&x);
    // 0 > 0 is false → EmptySet
    assert_eq!(format!("{result}"), "EmptySet");
}

// ═══════════════════════════════════════════════════════════════════════════
// solve_ge — greater-than-or-equal
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solve_zero_ge() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let zero = ctx.int(0);
    let result = zero.solve_ge(&x);
    let s = format!("{result}");
    // 0 >= 0 is always true → (-∞, ∞)
    assert!(
        !s.contains("EmptySet"),
        "0 >= 0 should be satisfied everywhere: {s}"
    );
}

#[test]
fn solve_x2_minus_4_ge_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let poly = &x.powi(2) - 4;
    let result = poly.solve_ge(&x);
    let s = format!("{result}");
    // x² - 4 >= 0 → (-∞, -2] ∪ [2, ∞)
    // The solution must not be empty and should include the roots.
    assert!(
        !s.contains("EmptySet"),
        "x²-4 >= 0 should have solutions: {s}"
    );
    // Interior: x=5 → 25-4=21 > 0 ✓
    common::assert_positive_at(&poly, &x, 5, "x²-4 >= 0 interior at x=5");
    // Exterior: x=1 → 1-4=-3 < 0 ✗
    common::assert_negative_at(&poly, &x, 1, "x²-4 >= 0 exterior at x=1");
}

#[test]
fn solve_positive_constant_ge() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let seven = ctx.int(7);
    let result = seven.solve_ge(&x);
    let s = format!("{result}");
    // 7 >= 0 always true
    assert!(
        !s.contains("EmptySet"),
        "7 >= 0 should be true everywhere: {s}"
    );
    common::assert_positive_at(&seven, &x, 0, "7 >= 0 constant check");
}

// ═══════════════════════════════════════════════════════════════════════════
// solve_lt — strict less-than
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solve_x_lt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let result = x.solve_lt(&x);
    let s = format!("{result}");
    // x < 0 → (-∞, 0)
    assert!(!s.contains("EmptySet"), "x < 0 should not be empty: {s}");
    // Interior: x=-2 → -2 < 0 ✓
    common::assert_negative_at(&x, &x, -2, "x < 0 interior at x=-2");
    // Exterior: x=1 → 1 > 0 ✗
    common::assert_positive_at(&x, &x, 1, "x < 0 exterior at x=1");
}

#[test]
fn solve_x2_minus_4_lt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let poly = &x.powi(2) - 4;
    let result = poly.solve_lt(&x);
    let s = format!("{result}");
    // x² - 4 < 0 → (-2, 2)
    assert!(
        !s.contains("EmptySet"),
        "x²-4 < 0 should have solutions: {s}"
    );
    assert!(s.contains("2"), "solution should reference 2: {s}");
    // Interior: x=0 → 0-4=-4 < 0 ✓
    common::assert_negative_at(&poly, &x, 0, "x²-4 < 0 interior at x=0");
    // Interior: x=1 → 1-4=-3 < 0 ✓
    common::assert_negative_at(&poly, &x, 1, "x²-4 < 0 interior at x=1");
    // Exterior: x=3 → 9-4=5 > 0 ✗
    common::assert_positive_at(&poly, &x, 3, "x²-4 < 0 exterior at x=3");
}

#[test]
fn solve_negative_constant_lt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let neg = ctx.int(-5);
    let result = neg.solve_lt(&x);
    let s = format!("{result}");
    // -5 < 0 is always true → (-∞, ∞)
    assert!(
        !s.contains("EmptySet"),
        "-5 < 0 should be true everywhere: {s}"
    );
    common::assert_negative_at(&neg, &x, 0, "-5 < 0 constant check");
}

#[test]
fn solve_positive_constant_lt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let pos = ctx.int(3);
    let result = pos.solve_lt(&x);
    // 3 < 0 is always false → EmptySet
    assert_eq!(format!("{result}"), "EmptySet");
    common::assert_positive_at(&pos, &x, 0, "3 < 0 constant is positive");
}

// ═══════════════════════════════════════════════════════════════════════════
// solve_le — less-than-or-equal
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solve_x2_minus_4_le_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let poly = &x.powi(2) - 4;
    let result = poly.solve_le(&x);
    let s = format!("{result}");
    // x² - 4 ≤ 0 → [-2, 2]
    assert!(
        !s.contains("EmptySet"),
        "x²-4 ≤ 0 should have solutions: {s}"
    );
    // Interior: x=0 → -4 < 0 ✓
    common::assert_negative_at(&poly, &x, 0, "x²-4 ≤ 0 interior at x=0");
    // Exterior: x=5 → 21 > 0 ✗
    common::assert_positive_at(&poly, &x, 5, "x²-4 ≤ 0 exterior at x=5");
}

#[test]
fn solve_zero_le() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let zero = ctx.int(0);
    let result = zero.solve_le(&x);
    let s = format!("{result}");
    // 0 <= 0 always true
    assert!(
        !s.contains("EmptySet"),
        "0 <= 0 should be satisfied everywhere: {s}"
    );
}

#[test]
fn solve_negative_constant_le() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let neg = ctx.int(-2);
    let result = neg.solve_le(&x);
    let s = format!("{result}");
    // -2 <= 0 always true
    assert!(
        !s.contains("EmptySet"),
        "-2 <= 0 should be true everywhere: {s}"
    );
    common::assert_negative_at(&neg, &x, 0, "-2 <= 0 constant check");
}

// ═══════════════════════════════════════════════════════════════════════════
// solveset — equation solving as a set
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solveset_quadratic() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let poly = &x.powi(2) - &x * 5 + 6;
    let result = poly.solve_as_set(&x);
    let s = format!("{result}");
    // x² - 5x + 6 = 0 → {2, 3}
    assert!(
        !s.contains("EmptySet"),
        "solveset of x²-5x+6 should find roots: {s}"
    );
    assert!(s.contains("2"), "should contain root 2: {s}");
    assert!(s.contains("3"), "should contain root 3: {s}");
    // Verify roots: poly at x=2 → 4-10+6=0
    let val_at_2 = poly
        .subs(&x, &ctx.int(2))
        .eval_f64()
        .expect("eval at root 2 should succeed");
    assert!(
        val_at_2.abs() < 1e-10,
        "poly(2) should be 0, got {val_at_2}"
    );
    // Verify roots: poly at x=3 → 9-15+6=0
    let val_at_3 = poly
        .subs(&x, &ctx.int(3))
        .eval_f64()
        .expect("eval at root 3 should succeed");
    assert!(
        val_at_3.abs() < 1e-10,
        "poly(3) should be 0, got {val_at_3}"
    );
}

#[test]
fn solveset_linear() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let expr = &x - 7;
    let result = expr.solve_as_set(&x);
    let s = format!("{result}");
    // x - 7 = 0 → {7}
    assert!(s.contains("7"), "should contain root 7: {s}");
    // Verify root
    let val_at_7 = expr
        .subs(&x, &ctx.int(7))
        .eval_f64()
        .expect("eval at root 7 should succeed");
    assert!(
        val_at_7.abs() < 1e-10,
        "expr(7) should be 0, got {val_at_7}"
    );
}

#[test]
fn solveset_no_real_roots() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x² + 1 = 0 has no real roots (only complex)
    let expr = &x.powi(2) + 1;
    let result = expr.solve_as_set(&x);
    let s = format!("{result}");
    // The solver may or may not find complex roots; if it doesn't,
    // we should at least get something (possibly EmptySet or a set
    // with imaginary values). Just assert it doesn't panic.
    assert!(!s.is_empty(), "solveset should produce output: {s}");
    // Verify the polynomial is always positive for real x
    common::assert_positive_at(&expr, &x, 0, "x²+1 at x=0");
    common::assert_positive_at(&expr, &x, 5, "x²+1 at x=5");
    common::assert_positive_at(&expr, &x, -3, "x²+1 at x=-3");
}

#[test]
fn solveset_constant_nonzero() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let five = ctx.int(5);
    let result = five.solve_as_set(&x);
    // 5 = 0 has no solutions → EmptySet
    assert_eq!(format!("{result}"), "EmptySet");
}

// ═══════════════════════════════════════════════════════════════════════════
// Quadratic sign-chart: full coverage
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn quadratic_positive_leading_coeff_gt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x² - 1 > 0 → (-∞, -1) ∪ (1, ∞)
    let poly = &x.powi(2) - 1;
    let result = poly.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "x²-1 > 0 should have solutions: {s}"
    );
    // Interior: x=2 → 4-1=3 > 0 ✓
    common::assert_positive_at(&poly, &x, 2, "x²-1 > 0 interior at x=2");
    // Interior: x=-2 → 4-1=3 > 0 ✓
    common::assert_positive_at(&poly, &x, -2, "x²-1 > 0 interior at x=-2");
    // Exterior: x=0 → 0-1=-1 < 0 ✗
    common::assert_negative_at(&poly, &x, 0, "x²-1 > 0 exterior at x=0");
}

#[test]
fn quadratic_positive_leading_coeff_lt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x² - 1 < 0 → (-1, 1)
    let poly = &x.powi(2) - 1;
    let result = poly.solve_lt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "x²-1 < 0 should have solutions: {s}"
    );
    // Should be a bounded interval between -1 and 1
    assert!(s.contains("1"), "solution should reference 1: {s}");
    // Interior: x=0 → -1 < 0 ✓
    common::assert_negative_at(&poly, &x, 0, "x²-1 < 0 interior at x=0");
    // Exterior: x=3 → 8 > 0 ✗
    common::assert_positive_at(&poly, &x, 3, "x²-1 < 0 exterior at x=3");
}

// ═══════════════════════════════════════════════════════════════════════════
// Linear inequalities
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn linear_2x_minus_6_gt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // 2x - 6 > 0 → x > 3 → (3, ∞)
    let expr = &x * 2 - 6;
    let result = expr.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "2x-6 > 0 should have solutions: {s}"
    );
    assert!(s.contains("3"), "solution should reference 3: {s}");
    // Interior: x=5 → 10-6=4 > 0 ✓
    common::assert_positive_at(&expr, &x, 5, "2x-6 > 0 interior at x=5");
    // Exterior: x=1 → 2-6=-4 < 0 ✗
    common::assert_negative_at(&expr, &x, 1, "2x-6 > 0 exterior at x=1");
}

#[test]
fn linear_neg_x_plus_5_le_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // -x + 5 ≤ 0 → x ≥ 5 → [5, ∞)
    let expr = -&x + 5;
    let result = expr.solve_le(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "-x+5 ≤ 0 should have solutions: {s}"
    );
    assert!(s.contains("5"), "solution should reference 5: {s}");
    // Interior: x=10 → -10+5=-5 < 0 ✓
    common::assert_negative_at(&expr, &x, 10, "-x+5 ≤ 0 interior at x=10");
    // Exterior: x=2 → -2+5=3 > 0 ✗
    common::assert_positive_at(&expr, &x, 2, "-x+5 ≤ 0 exterior at x=2");
}

// ═══════════════════════════════════════════════════════════════════════════
// Cubic polynomial
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn cubic_x3_minus_x_gt_0() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x³ - x = x(x-1)(x+1) > 0  → (-1, 0) ∪ (1, ∞)
    let poly = &x.powi(3) - &x;
    let result = poly.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "x³-x > 0 should have solutions: {s}"
    );
    // Interior: x=2 → 8-2=6 > 0 ✓
    common::assert_positive_at(&poly, &x, 2, "x³-x > 0 interior at x=2");
    // Exterior: x=-2 → -8+2=-6 < 0 ✗
    common::assert_negative_at(&poly, &x, -2, "x³-x > 0 exterior at x=-2");
}

// ═══════════════════════════════════════════════════════════════════════════
// Edge: large positive / large negative constants
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn large_positive_constant_gt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let big = ctx.int(999999);
    let result = big.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "999999 > 0 should be true everywhere: {s}"
    );
    common::assert_positive_at(&big, &x, 0, "999999 > 0 constant check");
}

#[test]
fn large_negative_constant_lt() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    let big_neg = ctx.int(-999999);
    let result = big_neg.solve_lt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "-999999 < 0 should be true everywhere: {s}"
    );
    common::assert_negative_at(&big_neg, &x, 0, "-999999 < 0 constant check");
}

// ═══════════════════════════════════════════════════════════════════════════
// solveset / solve_gt with Context API
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solveset_with_context() {
    let ctx = Context::new();
    let x = ctx.symbol("x");
    let poly = &x.powi(2) - &x * 5 + 6;
    let result = poly.solve_as_set(&x);
    let s = format!("{result}");
    assert!(s.contains("2"), "should contain 2: {s}");
    assert!(s.contains("3"), "should contain 3: {s}");
}

#[test]
fn solve_gt_with_context() {
    let ctx = Context::new();
    let x = ctx.symbol("x");
    let five = ctx.int(5);
    let result = five.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "5 > 0 via context should be true: {s}"
    );
}

// ═══════════════════════════════════════════════════════════════════════════
// Rational coefficients
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solveset_with_rational_roots() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // 2x - 1 = 0 → x = 1/2
    let expr = &x * 2 - 1;
    let result = expr.solve_as_set(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "2x - 1 = 0 should have a solution: {s}"
    );
}

// ═══════════════════════════════════════════════════════════════════════════
// New tests: always positive, always negative, boundary inclusion
// ═══════════════════════════════════════════════════════════════════════════

#[test]
fn solve_always_positive() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x² + 1 > 0 should be true for all real x → UniversalSet or (-∞, ∞)
    let poly = &x.powi(2) + 1;
    let result = poly.solve_gt(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "x²+1 > 0 should be always true, got: {s}"
    );
    // Should be the entire real line — UniversalSet or an interval from -oo to oo
    assert!(
        s.contains("UniversalSet") || (s.contains("-oo") && s.contains("oo")),
        "x²+1 > 0 should be the entire real line, got: {s}"
    );
    // Verify polynomial is positive at several points
    common::assert_positive_at(&poly, &x, 0, "x²+1 at x=0");
    common::assert_positive_at(&poly, &x, 100, "x²+1 at x=100");
    common::assert_positive_at(&poly, &x, -100, "x²+1 at x=-100");
}

#[test]
fn solve_always_negative() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // -(x² + 1) > 0 should be false for all real x → EmptySet
    let poly = -&(&x.powi(2) + 1);
    let result = poly.solve_gt(&x);
    let s = format!("{result}");
    assert_eq!(s, "EmptySet", "-(x²+1) > 0 should be EmptySet, got: {s}");
    // Verify polynomial is negative at several points
    common::assert_negative_at(&poly, &x, 0, "-(x²+1) at x=0");
    common::assert_negative_at(&poly, &x, 5, "-(x²+1) at x=5");
    common::assert_negative_at(&poly, &x, -5, "-(x²+1) at x=-5");
}

#[test]
fn solve_ge_includes_boundary() {
    let ctx = Context::new();
    symplex::syms!(ctx; x);
    // x² - 4 >= 0 should include x=2 and x=-2 as boundary
    let poly = &x.powi(2) - 4;
    let result = poly.solve_ge(&x);
    let s = format!("{result}");
    assert!(
        !s.contains("EmptySet"),
        "x²-4 >= 0 should have solutions: {s}"
    );
    // At the boundary x=2, x²-4 = 0 which satisfies >= 0
    let val_at_2 = poly
        .subs(&x, &ctx.int(2))
        .eval_f64()
        .expect("eval at boundary x=2 should succeed");
    assert!(
        val_at_2.abs() < 1e-10,
        "x²-4 at x=2 should be 0, got {val_at_2}"
    );
    // At the boundary x=-2, x²-4 = 0
    let val_at_neg2 = poly
        .subs(&x, &ctx.int(-2))
        .eval_f64()
        .expect("eval at boundary x=-2 should succeed");
    assert!(
        val_at_neg2.abs() < 1e-10,
        "x²-4 at x=-2 should be 0, got {val_at_neg2}"
    );
    // The ge solution should include the boundary — 0 >= 0 is true
    // Also verify interior and exterior
    common::assert_positive_at(&poly, &x, 3, "x²-4 >= 0 interior at x=3");
    common::assert_negative_at(&poly, &x, 0, "x²-4 >= 0 exterior at x=0");
}