(
p: Problem,
seed: number,
rubi?: { ce: ComputeEngine; driver: RubiDriver }
)
| 194 | const fMag = Math.max( |
| 195 | Math.hypot(Fp.re, Fp.im), |
| 196 | Math.hypot(Fm.re, Fm.im) |
| 197 | ); |
| 198 | if (Math.hypot(Fp.re - Fm.re, Fp.im - Fm.im) < 1e-9 * fMag) return null; |
| 199 | const d1 = { re: (Fp.re - Fm.re) / (2 * h), im: (Fp.im - Fm.im) / (2 * h) }; |
| 200 | const Fp2 = at(h / 2); |
| 201 | const Fm2 = at(-h / 2); |
| 202 | if (!Fp2 || !Fm2) return d1; |
| 203 | const d2 = { re: (Fp2.re - Fm2.re) / h, im: (Fp2.im - Fm2.im) / h }; |
| 204 | return { re: (4 * d2.re - d1.re) / 3, im: (4 * d2.im - d1.im) / 3 }; |
| 205 | } |
| 206 | |
| 207 | function runProblem( |
| 208 | p: Problem, |
| 209 | seed: number, |
| 210 | rubi?: { ce: ComputeEngine; driver: RubiDriver } |
| 211 | ): ProblemResult { |
| 212 | const start = Date.now(); |
| 213 | let steps: number | undefined; |
| 214 | let intMs: number | undefined; |
| 215 | const done = ( |
| 216 | outcome: Outcome, |
| 217 | extra: Partial<ProblemResult> = {} |
| 218 | ): ProblemResult => ({ |
| 219 | file: p.file, |
| 220 | index: p.index, |
| 221 | source: p.source, |
| 222 | outcome, |
| 223 | ms: Date.now() - start, |
| 224 | ...(steps !== undefined ? { steps, intMs } : {}), |
| 225 | ...extra, |
| 226 | }); |
| 227 | |
| 228 | // Fresh engine per problem (avoids cross-problem state) — except in |
| 229 | // --rubi mode, where compiled patterns are tied to a shared engine. |
| 230 | const ce = rubi?.ce ?? new ComputeEngine(); |
| 231 | |
| 232 | try { |
| 233 | const f = ce.expr(p.integrand as any); |
| 234 | let result: BoxedExpression; |
| 235 | if (rubi) { |
| 236 | const tInt = Date.now(); |
| 237 | rubi.driver.stats.steps = undefined; |
| 238 | result = |
| 239 | rubi.driver.int(f, p.variable) ?? |
| 240 | ce.function('Integrate', [f, ce.symbol(p.variable)]); |
| 241 | intMs = Date.now() - tInt; |
| 242 | steps = rubi.driver.stats.steps; |
| 243 | } else |
| 244 | result = ce.expr(['Integrate', p.integrand as any, p.variable]).evaluate(); |
| 245 | |
| 246 | if (containsOperator(result, 'Integrate')) |
| 247 | return done('unsolved', { result: result.toString() }); |
| 248 | |
| 249 | // verification on huge results can grind for minutes — call it |
| 250 | // inconclusive rather than stalling the harness (numeric |
| 251 | // central-difference is per-point subs+N, so the budget is generous) |
| 252 | if (leafCount(result) > 10_000) |
| 253 | return done('inconclusive', { |
no test coverage detected