Skip to content

l'Hopital's rule is not applied across the jumps of a step function - #2284

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
lhopitals-rule-is-not-applied-across-the-jumps-of-a-step-function
Oct 31, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
lhopitals-rule-is-not-applied-across-the-jumps-of-a-step-function

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

limit(floor(x) / x, x, +oo) was 0, where it is 1. l'Hopital's rule needs both parts differentiable on a punctured neighbourhood of the destination. The derivative of floor(x) is 0 provided not x in ZZ, and every neighbourhood of +oo contains integers, yet the rule stripped the condition and read 0 / 1. SolveAsLogarithmDivision's own use of the rule did the same.

HasAStepThatJumpsNear asks whether a step function jumps arbitrarily close to the destination: a floor, ceil or round whose argument does not tend to a finite value, or a sgn whose argument has no limit. Both uses of the rule decline in that case. Where the argument settles, the step is constant on either side of the destination, and the rule applies as before.

Input 2.6.0 and master Now Is
limit(floor(x) / x, x, +oo) 0 unevaluated 1
limit(floor(2x) / x, x, +oo) 0 unevaluated 2
limit(ln(floor(x)) / ln(x), x, +oo) 0 unevaluated 1
limit(ln(x) / ln(floor(x)), x, +oo) NaN unevaluated 1
limit((x - floor(x)) / x, x, +oo) 1 unevaluated 0
limitright(x * floor(1/x), x, 0) 0 unevaluated 1

LHopitalAcrossAJumpTest: its eight cases that were answered wrongly fail on master. Five more, where the step settles, pass on both. The suite (18,278), the trio, F#, AOT and the eight harnesses pass locally.

limit(round(x) / x, x, +oo) still throws, because round(+oo) does; that is #2282. With both, it is left unevaluated.

Fixes #2281.

🤖 Generated with Claude Code

limit(floor(x) / x, x, +oo) was 0, where it is 1, and so was
limit(ln(floor(x)) / ln(x), x, +oo). l'Hopital's rule needs both parts
differentiable on a punctured neighbourhood of the destination. The
derivative of floor(x) is 0 provided not x in ZZ, and every
neighbourhood of +oo holds integers, but the rule stripped the
condition and read 0 / 1. SolveAsLogarithmDivision's own use of the
rule did the same.

HasAStepThatJumpsNear asks whether a floor, ceil or round has an
argument that does not tend to a finite value, or a sign one that has
no limit, and both uses of the rule decline there. Where the argument
settles, the step is constant on either side of the destination and
the rule is applied as before.

LHopitalAcrossAJumpTest takes eight limits the rule answered wrongly,
which must now be right or unevaluated, and five where a step settles,
which are answered as before; the eight fail on master. The suite, the
trio, F#, AOT and the eight harnesses pass.

limit(round(x) / x, x, +oo) still throws, because round(+oo) does
(#2282).

Fixes #2281.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@Rafael-SOWNet Rafael-SOWNet added this to the 2.7.0 milestone Oct 30, 2026
@Rafael-SOWNet Rafael-SOWNet moved this from Todo to In review in AngouriMath Oct 30, 2026
@codecov

codecov Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.57143% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.71%. Comparing base (b90ae8f) to head (e3cc372).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ath/Functions/Continuous/Limits/Transformations.cs 72.72% 1 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2284      +/-   ##
==========================================
+ Coverage   86.70%   86.71%   +0.01%     
==========================================
  Files         310      310              
  Lines       67846    67862      +16     
  Branches    19689    19693       +4     
==========================================
+ Hits        58824    58848      +24     
+ Misses       4902     4892      -10     
- Partials     4120     4122       +2     
Flag Coverage Δ
cpp 37.77% <ø> (ø)
csharp 87.26% <78.57%> (+0.01%) ⬆️
fsharp 32.97% <ø> (ø)
interactive 40.72% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...nctions/Continuous/Limits/Solvers/Limit.Solvers.cs 86.04% <100.00%> (+0.33%) ⬆️
...ath/Functions/Continuous/Limits/Transformations.cs 87.26% <72.72%> (-0.33%) ⬇️

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Rafael-SOWNet
Rafael-SOWNet merged commit 34a4fe5 into master Oct 31, 2026
35 checks passed
@github-project-automation github-project-automation Bot moved this from In review to Done in AngouriMath Oct 31, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the lhopitals-rule-is-not-applied-across-the-jumps-of-a-step-function branch October 31, 2026 03:27
Rafael-SOWNet added a commit that referenced this pull request Oct 31, 2026
Compiled into a function returning double or float, every value
computed on the way is real, so sin(arcsin(x)) at 2, which is 2, is
NaN, as 1/x is at 0 where there is no value. That is the behaviour, and
it is now written on every Compile overload, in the .tt
templates those overloads are generated from.

MathS.Settings.RefuseNonRealCompilation, off by default, refuses such
an expression instead: with it on, an expression that cannot be shown
real wherever it is defined throws UncompilableNodeException, so a NaN
from the compiled function means only that there is no value. The
showing is TreeAnalyzer.IsRealValued, with each argument written as
one fresh variable, and it is conservative: sqrt(x) and ln(x) are
refused too. The Complex compilers and statements are unaffected.

IsRealValued now reads floor, ceil, round, min and max of real
arguments as real, which the setting needs and which also answers the
derivative of a modulus or a sign of one: d/dx abs(floor(x)) was left
unevaluated. limit(sin(floor(x)) / x, x, +oo) is 0 again, as in 2.6.0:
#2284 took away the l'Hopital route that had answered it.

RefuseNonRealCompilationTest takes the default NaN, the refusals over
double and float, what is real still compiled, a division by zero still
NaN, and the Complex compiler and a statement unaffected. PublicApi.txt
gains the setting. The suite, the trio, F#, AOT and the eight harnesses
pass.

Fixes #2286.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

l'Hopital's rule is applied through floor, ceil and round, whose derivative is 0 only between jumps

1 participant