asc-community / asc-community/AngouriMath

A correct rule costs time on integrands it never fires on, because a sub-answer lets a doomed search continue

Open
#1,265 3 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
C#
Stars
831
Forks
79
Avg merge
3h 23m
Merged PRs (30d)
309

Description

Four correct integration rules have now been written, verified, and **not merged**, each for the same reason. It is worth naming, because it is the thing standing between the integrator and a much larger rule set — and because the obvious fixes have been tried and measured, and do not work.

### The shape

A rule answers a sub-integral that used to come back `null`. The rule is right; its answer differentiates back. But the search that asked for it **used to stop there**, and now carries on — into work that was always doomed, on an integrand the new rule never fires on.

So the cost lands somewhere other than where the rule is, and it is paid on inputs the rule does not touch.

### Four instances

| | the rule | what it gained | what it cost |
|---|---|---|---|
| #1244 | Euler's substitution for `sqrt(quadratic)` | 2 answers | 7 problems from fast decline to full budget |
| #1245 | tan/cot/sec/csc reach the half-angle substitution | 26 answers | corpus wall clock roughly doubled |
| #1255 | a constant factor out of a denominator | (merged) | `1/(b^2cos^2 + a^2sin^2)`: 107 s → >400 s to decline |
| `secant-powers` | Rubi 4.5.1.1's secant/cosecant power reduction | 2 answers, 28/28 on probe | `sec(x)^6*tan(x)^3`: 637 ms → >400 s to decline |

The last is the clearest, because it is instrumented: on `sec(x)^6*tan(x)^3` the new rule fires exactly **twice**, at `n = 6` and `n = 4`, and terminates both times. The rule does almost no work. What changed is that two sub-integrals stopped failing.

### What has been tried, and measured not to work

- **A cap on the rule's own recursion.** Does nothing where the recursion is already finite — the secant power never grows.
- **A size bound on the rewritten integrand.** Tried on Euler (400 nodes) and on the half-angle rewrite. Neither moved the number: `sec(x)^6` is 25 nodes and 8.4 s, `1/(1 + cos(x))` is 10 nodes and 1 ms. Size does not predict cost.
- **A structural guard on what the rule accepts.** Tried twice on the constant-factor rule — rational-only, then symbolic-constant-only. Both measured no better than none, because the expensive firings are *inside* the rule's intended domain, not outside it.

### What would

Two candidates, neither of which belongs inside any one rule:

**A work budget.** `WorkBudget` from #896 is the instrument that already exists. A rule handing a speculative sub-problem to the whole chain should be able to say how much of the remaining budget it will spend on it, and stop.

**Or scope: answer what was asked, do not volunteer.** A reduction like the secant one is the right answer when the caller asked for `∫sec^n` and a distraction when it is offered into the middle of another rule's search. Firing only at the top of the descent would keep every gain in the table above and cost none of the time. That needs the descent depth, which is private to `Integration`, and it is a deliberate decision about what a rule is *for* rather than a guard.

The second is cheaper and probably more honest about the problem. The first is more general.

### Why it matters more than four rules

Every one of these was a correct, tested, measured rule that had to be thrown away. Any serious attempt to widen coverage — porting more of Rubi's rules, which is MIT-licensed and organised to match the test suite already vendored here — will hit this on roughly every second rule. The rules are not the hard part; this is.

Branches, so the next attempt starts from code rather than a description: `euler-substitution`, `secant-powers`, `trigrules-both`.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Contributor guide

Open the contributing guide

Research direction

Start with the Integration descent and the existing WorkBudget from #896, then review the euler-substitution, secant-powers, and trigrules-both branches. Reproduce the reported secant-power and other decline timings, and compare the budget and scope approaches. Done means preserving the verified rule answers without imposing the reported search-time regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.