Repository navigation
Commit e828414
A long chain of sums is simplified from the bottom up, not by a recursion as deep as the chain (#2167)
A sum simplifies its left operand first, and that operand's left operand,
so a chain of n sums nested to the left was simplified by a recursion n
deep. A sum built one term at a time is that shape: CollectLikeTerms
builds one, and Simplify's search hands the collected chain on. The
integral of (q + p x)/(c + b x + a x^2)^3 with its symbols pinned reached
about 900, which overflowed C# Test's Debug build on a 1 MB stack on most
Windows runs since 2026-09-15 (#2165 moved that leg to Release), and
needed more than 384 KB in Release, where macOS gives 512 KB.
Sumf and Minusf now simplify every 32nd node of a left spine at least 64
deep first, deepest first. Every node's simplification is cached, so each
of those recursions stops at the checkpoint below it. The same nodes are
simplified, each once, in a different order, and an ordinary sum pays for a
walk of a few nodes and nothing else.
On a thread of a given stack size:
cubic row, Release 384 KB overflow (909 repeats) -> 256 KB passes
cubic row, Debug 1 MB overflow (654 repeats) -> 1 MB passes
(a_1+..+a_30)(b_1+..+b_30) expanded, Release, 256 KB:
400 terms overflow -> 900 and 1,600 pass
What overflows next on the cubic row, at 192 KB in Release, is
CostModel.ChildrenCost, 872 deep: a different recursion, with 2.7x
headroom on macOS.
Unit suite 17,128 passed, 0 failed. Against master on one machine:
allocation is identical (23,356 B per round of InnerSimplified on five
ordinary sums; 15.79 MB per round of Simplify on ten expressions), and
time is within noise (InnerSimplified 2,525 ms vs 2,557 ms, mean of three
200,000-round runs whose spread in one arm is 5%).
Fixes #2166
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>1 parent 90ac975 commit e828414
2 files changed
Lines changed: 105 additions & 4 deletions
File tree
- Sources
- AngouriMath/Functions/Evaluation/Evaluation.Continuous
- Tests/UnitTests/Common
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 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 | + | |
15 | 65 | | |
16 | 66 | | |
17 | 67 | | |
| |||
83 | 133 | | |
84 | 134 | | |
85 | 135 | | |
86 | | - | |
87 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
88 | 140 | | |
89 | 141 | | |
90 | 142 | | |
| |||
98 | 150 | | |
99 | 151 | | |
100 | 152 | | |
| 153 | + | |
101 | 154 | | |
102 | 155 | | |
103 | 156 | | |
104 | 157 | | |
105 | 158 | | |
106 | 159 | | |
107 | | - | |
108 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
109 | 164 | | |
110 | 165 | | |
111 | 166 | | |
| |||
127 | 182 | | |
128 | 183 | | |
129 | 184 | | |
| 185 | + | |
130 | 186 | | |
131 | 187 | | |
132 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 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 | + | |
0 commit comments