Skip to content

Commit 9132000

Browse files
Merge pull request #41 from gbenroscience/methd-handles
text fixes
2 parents 0da76ef + d2e695d commit 9132000

2 files changed

Lines changed: 48 additions & 41 deletions

File tree

INTEGRATOR.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
## Executive Summary
88

9-
| Metric | Your Integrator | Gaussian | Chebyshev | Simpson | Romberg |
9+
| Metric | NumericalIntegrator | Gaussian | Chebyshev | Simpson | Romberg |
1010
|--------|---------|----------|-----------|---------|---------|
1111
| **Smooth Function Accuracy** | 15-16 digits | 15-16 digits | 12-14 digits | 6-8 digits | 10-12 digits |
1212
| **Log Singularity Handling** | **5-6 digits ✓** | 2-3 digits ✗ | 3-4 digits ✗ | Fails ✗ | Fails ✗ |
@@ -25,7 +25,7 @@
2525

2626
### 1. Singularity Handling
2727

28-
#### Your Integrator
28+
#### NumericalIntegrator
2929
- ✅ Auto-detects logarithmic singularities at boundaries
3030
- ✅ Auto-detects power-law singularities (√-type)
3131
- ✅ Detects internal poles via spike detection
@@ -69,7 +69,7 @@ double result = gaussianQuad(x -> 1/Math.sqrt(x), 0, 1);
6969

7070
### 2. Large Domain Compression
7171

72-
#### Your Integrator: [1, 200]
72+
#### NumericalIntegrator: [1, 200]
7373
```
7474
Interval size: 199 units
7575
Strategy: Logarithmic map compresses [1,200] → [-1,1]
@@ -101,13 +101,13 @@ Accuracy: Error > 0.03 (50% wrong)
101101

102102
| Method | Result | Error | Time | Status |
103103
|--------|--------|-------|------|--------|
104-
| **Your Integrator** | 0.0650624 | 1e-7 | 1100ms | ✓ Converged |
104+
| **NumericalIntegrator** | 0.0650624 | 1e-7 | 1100ms | ✓ Converged |
105105
| Gaussian Quadrature | 0.0312456 | 0.034 | >5000ms | ✗ Timeout |
106106
| Chebyshev | (hangs) || >5000ms | ✗ Never converges |
107107
| Simpson (1M points) | 0.0523891 | 0.0127 | >10000ms | ✗ Too slow |
108108
| Romberg | Oscillates | undefined || ✗ Diverges |
109109

110-
**Why Your Integrator Wins:**
110+
**Why NumericalIntegrator Wins:**
111111
1. Logarithmic map concentrates nodes where needed
112112
2. Aliasing detection catches undersampling
113113
3. Adaptive subdivision refines oscillatory regions
@@ -120,7 +120,7 @@ Accuracy: Error > 0.03 (50% wrong)
120120
### Test 1: Smooth Function - `∫₀^π sin(x) dx = 2`
121121

122122
```
123-
Your Integrator:
123+
NumericalIntegrator:
124124
Result: 2.0000000000000
125125
Error: 0.0
126126
Time: 250 ms
@@ -146,14 +146,14 @@ Romberg (1e-10):
146146
```
147147

148148
**Verdict:** Gaussian is fastest, but all deliver 16 digits.
149-
**Your integrator** trades speed for **robustness** on harder problems.
149+
**NumericalIntegrator** trades speed for **robustness** on harder problems.
150150

151151
---
152152

153153
### Test 2: Logarithmic Singularity - `∫₀.₀₀₁^1 ln(x) dx ≈ -0.992`
154154

155155
```
156-
Your Integrator:
156+
NumericalIntegrator:
157157
Result: -0.9920922447210182
158158
Error: 9.224472101820869e-5
159159
Time: 30 ms
@@ -194,7 +194,7 @@ Romberg (1e-10):
194194
### Test 3: Power-Law Singularity - `∫₀.₀₀₁^1 1/√x dx ≈ 1.937`
195195

196196
```
197-
Your Integrator:
197+
NumericalIntegrator:
198198
Result: 1.936754446796634
199199
Error: 0.00024555
200200
Time: 27 ms
@@ -235,7 +235,7 @@ Romberg (1e-10):
235235
### Test 4: Internal Pole - `∫₀.₁^0.49 1/(x-0.5) dx` (Pole at x=0.5)
236236

237237
```
238-
Your Integrator:
238+
NumericalIntegrator:
239239
Result: -3.688879454113936
240240
Error: —
241241
Time: 11 ms
@@ -290,7 +290,7 @@ YOUR INTEGRATOR ████████ ██████░░ ████
290290

291291
### 1. Adaptive Coordinate Transformations
292292

293-
Your integrator selects the optimal map based on function behavior:
293+
NumericalIntegrator selects the optimal map based on function behavior:
294294

295295
| Scenario | Map Used | Why | Benefit |
296296
|----------|----------|-----|---------|
@@ -322,7 +322,7 @@ If initial tail error is > 1e6 but no poles detected:
322322
### 3. Timeout Protection
323323

324324
```java
325-
// Your integrator: Guaranteed to finish
325+
// NumericalIntegrator: Guaranteed to finish
326326
integrate(f, 0, 1); // Max 1.5 seconds
327327
// Returns result or throws TimeoutException
328328

@@ -335,7 +335,7 @@ gaussianQuad(f, 0, 1); // May never return
335335

336336
### 4. Pole Detection and Handling
337337

338-
**Your Integrator:**
338+
**NumericalIntegrator:**
339339
1. Scans for internal poles (spike detection)
340340
2. Refines pole location (ternary search: 60 iterations, 1e-16 precision)
341341
3. Checks divergence (even vs. odd pole)
@@ -352,7 +352,7 @@ gaussianQuad(f, 0, 1); // May never return
352352
### 5. Relative Threshold Deduplication
353353

354354
```java
355-
// Your integrator
355+
// NumericalIntegrator
356356
double threshold = (b - a) * 1e-11; // Scales with interval
357357
// Prevents false duplicates on small intervals
358358
// Prevents merging distinct poles on large intervals
@@ -393,7 +393,7 @@ double threshold = (b - a) * 1e-11; // Scales with interval
393393

394394
**Example:** Archival/reference computations
395395

396-
### Use **Your Integrator** When:
396+
### Use **NumericalIntegrator** When:
397397
- ✅ Function behavior is unknown
398398
- ✅ Must handle singularities
399399
- ✅ Can't afford crashes (production systems)
@@ -420,17 +420,17 @@ Internal pole | 11 | Crash | Crash | Crash | Crash
420420
Oscillatory [1,200] | 1100 | Timeout | Timeout | Timeout | Diverge
421421
```
422422

423-
**Key insight:** Your integrator is slower on smooth functions (10-100x) but is the **only** one on pathological inputs.
423+
**Key insight:** NumericalIntegrator is slower on smooth functions (10-100x) but is the **only** one on pathological inputs.
424424

425425
---
426426

427427
## Code Examples
428428

429-
### Example 1: Smooth Function (Your Integrator is Slower)
429+
### Example 1: Smooth Function (NumericalIntegrator is Slower)
430430

431431
```java
432432
// Smooth function: sin(x)
433-
IntegrationCoordinator1 ic = new IntegrationCoordinator1();
433+
NumericalIntegrator ic = new NumericalIntegrator();
434434
double result = ic.integrate(x -> Math.sin(x), 0, Math.PI);
435435
// Time: 250 ms, Accuracy: 16 digits ✓
436436

@@ -439,11 +439,11 @@ double result_g = gaussianQuad(x -> Math.sin(x), 0, Math.PI);
439439
// Time: 15 ms, Accuracy: 16 digits ✓
440440
```
441441

442-
### Example 2: Singular Function (Your Integrator Dominates)
442+
### Example 2: Singular Function (NumericalIntegrator Dominates)
443443

444444
```java
445445
// Singular function: ln(x)
446-
IntegrationCoordinator1 ic = new IntegrationCoordinator1();
446+
NumericalIntegrator ic = new NumericalIntegrator();
447447
double result = ic.integrate(x -> Math.log(x), 0.001, 1.0);
448448
// Time: 30 ms, Accuracy: 5 digits ✓✓✓
449449

@@ -453,11 +453,11 @@ double result_g = gaussianQuad(x -> Math.log(x), 0.001, 1.0);
453453
// Error: 0.015 (1.5% off)
454454
```
455455

456-
### Example 3: Internal Pole (Your Integrator Only Works)
456+
### Example 3: Internal Pole (NumericalIntegrator Only Works)
457457

458458
```java
459459
// Function with internal pole at x=0.5
460-
IntegrationCoordinator1 ic = new IntegrationCoordinator1();
460+
NumericalIntegrator ic = new NumericalIntegrator();
461461
double result = ic.integrate(x -> 1/(x - 0.5), 0.1, 0.49);
462462
// Time: 11 ms
463463
// Result: -3.6889... ✓ (correctly integrated around pole)
@@ -477,7 +477,7 @@ double result_g = gaussianQuad(x -> 1/(x - 0.5), 0.1, 0.49);
477477
- **5-6 digits**: 5-6 significant figures (1e-5 to 1e-6 relative error)
478478
- **3-4 digits**: 3-4 significant figures (1e-3 to 1e-4 relative error)
479479

480-
### Your Integrator's Accuracy Guarantees
480+
### NumericalIntegrator's Accuracy Guarantees
481481

482482
```
483483
Function Class | Guaranteed Accuracy | Method
@@ -493,7 +493,7 @@ Oscillatory (limited) | 2-4 digits | Adaptive subdivision
493493

494494
## Computational Complexity
495495

496-
### Your Integrator
496+
### NumericalIntegrator
497497

498498
- **Best case** (smooth): O(N log N) where N=256 nodes
499499
- **Worst case** (singular): O(2^d · N) where d ≤ 18 (max depth)
@@ -527,7 +527,7 @@ Oscillatory (limited) | 2-4 digits | Adaptive subdivision
527527
- **Gaussian Quadrature:** Golub & Welsch (1969), "Calculation of Gauss Quadrature Rules"
528528
- **Clenshaw-Curtis:** Clenshaw & Curtis (1960), "A method for numerical integration..."
529529
- **Adaptive Methods:** De Doncker et al., "Quadpack: A Subroutine Package for Automatic Integration"
530-
- **Your Integrator Inspiration:** GSL (GNU Scientific Library) quad integration
530+
- **NumericalIntegrator Inspiration:** GSL (GNU Scientific Library) quad integration
531531

532532
---
533533

@@ -551,7 +551,7 @@ Speed Smooth functions Pathological functions Robu
551551

552552
### The Killer Quote
553553

554-
> *"While Gaussian Quadrature is 10x faster on smooth integrands, IntegrationCoordinator1 is the **only** integrator that handles singular, oscillatory, and pathological functions without crashing, timing out, or returning garbage. Choose speed when you know your function is well-behaved. Choose robustness when you don't."*
554+
> *"While Gaussian Quadrature is 10x faster on smooth integrands, NumericalIntegrator is the **only** integrator that handles singular, oscillatory, and pathological functions without crashing, timing out, or returning garbage. Choose speed when you know your function is well-behaved. Choose robustness when you don't."*
555555
556556
---
557557

@@ -572,4 +572,4 @@ Speed Smooth functions Pathological functions Robu
572572

573573
---
574574

575-
**Conclusion:** Use Your Integrator for production systems where reliability matters more than raw speed. Use Gaussian if you know your function is smooth and speed is critical.
575+
**Conclusion:** Use NumericalIntegrator for production systems where reliability matters more than raw speed. Use Gaussian if you know your function is smooth and speed is critical.

src/test/java/com/github/gbenroscience/parser/turbo/ScalarTurboEvaluatorTest.java

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ public void testSum() throws Throwable {
147147
double[] vars = new double[0];
148148
double v1 = compiled.applyScalar(vars);
149149
Assertions.assertEquals(v, v1);
150-
151150
}
152151

153152
@Test
@@ -205,7 +204,7 @@ public void testComplexExpression(boolean withFolding) throws Throwable {
205204

206205
@Test
207206
public void testWithVariablesSimple() throws Throwable {
208-
System.out.println("\n=== WITH VARIABLES: SIMPLE; FOLDING OFF ===\n");
207+
209208

210209
String expr = "x*sin(x)+2";
211210

@@ -227,8 +226,7 @@ public void testWithVariablesSimple() throws Throwable {
227226

228227
@Test
229228
public void testWithVariablesAdvanced() throws Throwable {
230-
System.out.println("\n=== WITH VARIABLES: ADVANCED; FOLDING OFF ===\n");
231-
229+
232230
String expr = "x=0;y=0;z=0;x*sin(x) + y*sin(y) + z / cos(x - y) + sqrt(x^2 + y^2)";
233231
MathExpression interpreted = new MathExpression(expr, false);
234232

@@ -252,8 +250,7 @@ public void testWithVariablesAdvanced() throws Throwable {
252250

253251
@Test
254252
public void testConstantFolding() throws Throwable {
255-
System.out.println("\n=== CONSTANT FOLDING; FOLDING OFF ===\n");
256-
253+
257254
String expr = "2^10 + 3^5 - 4! + sqrt(256)";
258255
MathExpression interpreted = new MathExpression(expr, false);
259256

@@ -270,8 +267,7 @@ public void testConstantFolding() throws Throwable {
270267

271268
@Test
272269
public void testQuadratic() throws Throwable {
273-
System.out.println("\n=== QUADRATIC ROOTS: SIMPLE; ===\n");
274-
270+
275271
String expr = "quadratic(@(x)3*x^2-4*x-18)";
276272

277273
MathExpression interpreted = new MathExpression(expr, false);
@@ -287,8 +283,7 @@ public void testQuadratic() throws Throwable {
287283

288284
@Test
289285
public void testTartaglia() throws Throwable {
290-
System.out.println("\n=== Tartaglia's roots: SIMPLE; ===\n".toUpperCase());
291-
286+
292287
String expr = "t_root(@(x)3*x^3-4*x-18)";
293288

294289
MathExpression interpreted = new MathExpression(expr, false);
@@ -299,10 +294,22 @@ public void testTartaglia() throws Throwable {
299294
TurboExpressionEvaluator tee = TurboEvaluatorFactory.getCompiler(interpreted);
300295
FastCompositeExpression fce = tee.compile();
301296
double[] v1 = fce.applyVector(vars);
302-
System.out.println("v = "+Arrays.toString(v));
303-
System.out.println("v1 = "+Arrays.toString(v1));
304-
305-
297+
306298
Assertions.assertTrue(Arrays.toString(v).equals(Arrays.toString(v1)));
307299
}
300+
301+
@Test
302+
public void testGeneralRoot() throws Throwable {//-1.8719243686213027618871370090528, -3.2052577019546360952204703423861
303+
304+
String expr = "root(@(x)3*x^3-4*x-18,2)";
305+
MathExpression interpreted = new MathExpression(expr, false);
306+
307+
double[] vars = new double[0];
308+
309+
double v = interpreted.solveGeneric().scalar;
310+
TurboExpressionEvaluator tee = TurboEvaluatorFactory.getCompiler(interpreted);
311+
FastCompositeExpression fce = tee.compile();
312+
double v1 = fce.applyScalar(vars);
313+
314+
}
308315
}

0 commit comments

Comments
 (0)