Repository navigation
Commit 8d4af56
authored
* Apply l'Hopital's rule at infinity too (#596)
The rule was only ever reached when the destination was finite, so the ordinary
competing-growth limits had nothing to catch them:
lim x->+oo ln(x) / x was unevaluated, and NaN once simplified
lim x->+oo x / e^x "
lim x->+oo ln(x) / sqrt(x) "
lim x->+oo e^x / (e^x + 1) "
Three things had to be settled before the rule could be let loose there.
It has to stop. Differentiating both parts does not always make the quotient
simpler: x / sqrt(x^2 + 1) turns into sqrt(x^2 + 1) / x, which turns back, so
neither form ever settles. The recursion is bounded, at a depth that still leaves
room for the degree of a polynomial, since x^10 / e^x takes ten steps.
It has to leave a wrong answer no worse. NaN asserts that a limit does not exist,
which is a stronger claim than the rule can make when it has not settled, so the
rule's answer is only taken when it is not NaN; otherwise whatever was there
before stands, unevaluated included.
It has to recognise the quotient. Two shapes were being turned away:
- Differentiation does not produce quotients. d/dx ln(x)^2 is 2 * ln(x) * (1 / x),
a product with a quotient inside rather than 2 * ln(x) / x, and only the second
has a limit here, so the derivative quotient is simplified before it is used. The
domain condition that simplification leaves behind is dropped with it: a
Providedf is not a continuous node and would be turned away unread, and limits
already treat the expression as continuous.
- A product with a reciprocal factor is a quotient. That is the shape in #596,
where lim x->+oo x^4 * e^(-x) came out as NaN while x^4 / e^x gave 0.
Corpus 88/117 -> 91/117 with no wrong answers: lim:oo/oo goes to 4 out of 4 and
x / ln(x)^2 joins it. 3909 unit tests and 127 F# tests pass, and the property
checker's 1320 checks are clean.
Still out of reach and still left unevaluated rather than guessed: e^x - x,
sqrt(x^2 + x) - x and e^(x + e^(-x)) - e^x, none of which is a quotient.
* Bound the work l'Hopital's rule does, not just its depth
The rule as added in this branch could run for more than twenty seconds on
lim x -> +oo sqrt(x^2 - x) / x and on x^(3/2) * sqrt(1 + 1/x^2) / x^2, both of
which master answers, unevaluated, in under two hundred milliseconds.
The bound on the depth was not a bound on the work. Every step asks what the two
parts of its quotient tend to before differentiating them, and each of those is a
limit the rule may be applied to in turn, so the steps fan out rather than follow
one another and sixteen deep is far more than sixteen steps. Two conditions stop
the fan-out at its source: the rule declines a quotient it is already partway
through, since differentiating sqrt(x^2 - x) / x gives its reciprocal and
differentiating that gives the first back; and it declines one that has grown by
more than the derivative of a power or a logarithm accounts for, since a bigger
quotient makes the two questions each step asks harder than the one being
answered. The measured room is wide: a step on the way to an answer adds two
nodes and the most any was seen to add is six, against eighteen for the quotient
above. A cap on the total number of applications is left behind them as a
backstop.
Depth is now held for the whole of the rule rather than only for its recursive
call, so the two limits each step asks for are counted as well.
Both forms now terminate, the second of them in 86 ms, and the two are pinned.
Every limit the branch already answered is unchanged and no faster or slower:
x^10 / e^x still takes ten steps and 40 ms. 3911 tests, corpus 91/117 with
nothing wrong, in error or timing out.
1 parent 7cbdc3e commit 8d4af56
3 files changed
Lines changed: 232 additions & 4 deletions
File tree
- Sources
- AngouriMath/Functions/Continuous/Limits
- Solvers
- Tests/UnitTests/Calculus
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
68 | 80 | | |
69 | 81 | | |
70 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
72 | 73 | | |
73 | 74 | | |
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 | + | |
75 | 160 | | |
76 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
77 | 178 | | |
78 | 179 | | |
79 | 180 | | |
80 | 181 | | |
81 | 182 | | |
82 | 183 | | |
83 | 184 | | |
84 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
85 | 200 | | |
86 | | - | |
87 | | - | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
88 | 208 | | |
89 | 209 | | |
90 | 210 | | |
| |||
| 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 | + | |
| 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 | + | |
0 commit comments