Repository navigation
Give sgn a derivative, and stop a constant exponent taking the logarithmic rule - #672
Merged
Happypig375 merged 2 commits intoAug 3, 2026
Merged
Conversation
Two ways a derivative came back unusable, both found by differentiating antiderivatives back and checking them at points. sgn had no derivative. It returned an unevaluated node, with a note that the delta function would be needed first. But leaving it unevaluated does not represent the delta either -- it only means the derivative of anything containing sgn cannot be evaluated at all, and that reaches callers: the antiderivative of abs(x) is sgn(x) * x^2 / 2, and differentiating it back stopped at derivative(sgn(x), x). sgn is flat either side of zero and has no derivative at zero, so the derivative is 0 wherever it exists, and the condition says where that is. This is the stance abs already takes right below it, whose derivative is sgn(x) provided not x = 0. Whichever way the distributional reading is eventually handled, it is the same question for both. TestSgnDer pinned the unevaluated form and now pins this one, with the reasoning next to it. Separately, Powf decided whether the exponent was constant with a type test. An exponent written as a sum is not a Number even when it is constant, and the integral table leaves them that way -- (x - 1)^(4 + 1). Read as non-constant it fell to the logarithmic rule, which needs a positive base, so differentiating the antiderivative of (x - 1)^4 came back undefined for x < 1. It now asks Evaled instead. Genuinely symbolic exponents are unaffected and still carry their condition. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #672 +/- ##
==========================================
- Coverage 80.99% 79.71% -1.29%
==========================================
Files 155 155
Lines 13687 12431 -1256
Branches 1957 2013 +56
==========================================
- Hits 11086 9909 -1177
+ Misses 1990 1934 -56
+ Partials 611 588 -23 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two ways a derivative came back unusable. Both were found by differentiating
antiderivatives back and checking them at points, rather than by reading code.
sgnhad no derivativeThis is the one to look at first, because it changes a deliberate decision.
Leaving the node unevaluated does not represent the delta either. What it does is make
the derivative of anything containing
sgnunevaluable, and that reaches callers: theantiderivative of
abs(x)issgn(x) * x^2 / 2, and differentiating it back stops atderivative(sgn(x), x). So∫abs(x) dxcannot be checked or used numerically.sgnis flat either side of zero and has no derivative at zero, so its derivative is0wherever it exists, and a condition says where that is:
That is the stance
absalready takes directly below it —sgn(x) provided not x = 0,likewise undefined at zero. Whichever way the distributional reading is eventually
handled, it is the same question for both, and answering one but not the other is what
was inconsistent.
TestSgnDerasserted the unevaluated form and now asserts this one, with the reasoningbeside it. If you would rather keep the node unevaluated, say so and I will drop this
half — the second half stands on its own.
A constant exponent was read as symbolic
Powfdecided whether the exponent was constant with a type test:An exponent written as a sum is not a
Numbereven when it is constant — and theintegral table leaves them exactly that way,
(x - 1)^(4 + 1). Read as non-constant itfell through to the logarithmic rule, which needs a positive base, so:
The antiderivative of
(x - 1)^4differentiated back to something undefined forx < 1. It now asks
Exponent.Evaledinstead. Genuinely symbolic exponents areuntouched and still carry their condition:
d/dx x^nx^n * n / x provided x > 0d/dx 2^xln(2) * 2^xd/dx x^x(1 + ln(x)) * x^x provided not x = 0Testing
UnitTests3667 passed / 0 failed,FSharpWrapperUnitTests127 passed / 0 failed, bothnetstandard2.0andnet7.0build.Nine new tests: the
sgnderivative, four antiderivatives of absolute valuesdifferentiating back at points, the power case at a point below the base's root — which
is where the spurious condition bit — and the symbolic exponents that must not change.
Independent of #663 through #671.
🤖 Generated with Claude Code