Repository navigation
The total derivative in an unknown function, a partial-derivative node, and substitution into a derivative over an expression - #2477
Open
Rafael-SOWNet wants to merge 2 commits into
Open
Rafael-SOWNet wants to merge 2 commits into
Rafael-SOWNet wants to merge 2 commits into
Conversation
… node
derivative(expr, u) over an expression u in one variable x is the total
derivative, (d expr/dx) / (du/dx), and it declined where u was an unknown
function applied, apply(f, x), or a derivative of one: f was counted as a
variable u varies in, and the derivative of an unknown function, f', was read
as a derivative not taken. The name of an unknown function is now not a
variable it varies in, and f' is taken as the value it is. So
derivative(x f, f) is f/f' + x, and derivative(f^2 + f'^2, f) is
2(f + f'') provided not f' = 0. What answered before is unchanged, and over
two variables, derivative(x + y, x * y), it is still left as written.
partialderivative(L, q) and partialderivative(L, q, n) are the partial
derivative dL/dq as its own node, PartialDerivativef, built by
MathS.PartialDerivative: q is a slot -- a variable, an unknown function
applied, or a derivative of one in a variable -- and every other slot is held
fixed, as in the Euler-Lagrange equation. Every slot is renamed to a fresh
variable, the derivatives first so that f' is not read as a function of f,
and an unknown function of the slot, g(f), is not renamed. So
partialderivative(f^2 + f'^2, f) is 2f and partialderivative(x f, f) is x.
Over a variable it is the derivative; over anything else it is left as
written, since x^2 is a slot of x^2 and not of x * x. It does not bind; a
value put in for x goes into the slot too. Wired through printing, LaTeX
(\frac{\partial}{\partial q}), SymPy's diff, Substitute, differentiation, the
limit and solver hooks, serialization, the compilers' refusal, the F#
wrapper, the MCP syntax document and classifier, and Syntax.md beside the
total derivative. Tests check every answer by value with f made concrete.
Grammar: one alternative, 'partialderivative(', after lambda( so that no
literal token is renumbered; the unmodified grammar regenerated to an empty
diff first. partialderivative(x) with one argument was the product
partialderivative * x and is now an arity error; both changes are in
BREAKING-CHANGES.md, measured on the 2.7.0 package.
Part of #230
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A derivative or an indefinite integral over an expression u of x is taken by letting x move, and Substitute put a value for x into the expression alone: derivative(x^3, x^2) at x = 2 became derivative(8, x^2), which is 0 where the answer is 3, and integral(x, x^2) kept an x. With the mixed case now answered, derivative(x f(x)^2, f(x)) at 2 would have been 0 as well, where it is f(2)^2/f'(2) + 4 f(2). Such a node is now taken first and the value put into its answer, or, where it cannot be taken, the value is held outside it as apply(lambda(x, ...), 2), which lambda application now takes in the same order. Over a variable nothing changes. The partial derivative holds a value outside the same way where its slot stops being one. Recorded in BREAKING-CHANGES.md, measured on the 2.7.0 package. The shader printer declines a partial derivative with Compile's message, and a test says so. Part of #230 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2477 +/- ##
==========================================
- Coverage 86.97% 86.90% -0.08%
==========================================
Files 324 324
Lines 71840 71446 -394
Branches 20952 20948 -4
==========================================
- Hits 62483 62090 -393
- Misses 5024 5025 +1
+ Partials 4333 4331 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
The design decided on #230 (comment of 2026-11-15, edited 2026-11-16), and a wrong answer in 2.7.0 that it would otherwise have made more reachable. Two commits, meant to be merged as they are (rebase, not squash).
1. The total derivative in an unknown function, and a partial-derivative node
derivativestays the total, change-of-variables derivative, and now answers the mixed case it declined: d(expr)/d(u) = (d expr/dx)/(du/dx). It declined becauseapply(f, x)reportedfas a variable, so two variables were seen, andf'read as a derivative it had failed to take. The scope is one underlying variable, as decided: other variables are held fixed, and a target in two free variables stays unevaluated.f=apply(f, x)derivative(x*f, f)f/f' + xderivative(f^2+f'^2, f)2(f + f'') provided not f' = 0derivative(f^2*f', f)f^2 f''/f' + 2 f f'derivative(y sin x, cos x)-y csc(x) cos(x)derivative(x+y, x*y)partialderivative(L, q[, n]), a new node (PartialDerivativef,MathS.PartialDerivative), named after the "Partial derivative" of Wikipedia and MathWorld: its slotq(a variable, an unknown function applied, or a derivative of one) is varied with everything else held fixed,f'andxincluded, as in Euler–Lagrange.partialderivative(f^2+f'^2, f)is2f,partialderivative(x*f, f)isx. Over a variable it is the same asderivative, as SymPy'sdiffis, sopartialderivative(apply(f, x, y), x)is ∂f/∂x. It does not bind. LaTeX\frac{\partial}{\partial q}, in the operator formderivativeuses; SymPysympy.diff; refused by both compilers throughBinders.Refusal, soMathS.Shadersdeclines it with the same message.Syntax.mdsets the two derivatives out side by side.partialderivative(x)was the productpartialderivative * x; it is now an arity error.2. A value for a variable a derivative is taken over goes into its answer
A derivative or indefinite integral taken over an expression of
x, rather than overx, put a substituted value into the body alone, which changed the question and simplified to wrong values. Now the derivative is taken first and the value goes into the answer; where it cannot be taken, the value is held outside asapply(lambda(x, …), v), and lambda application takes such a node before putting its argument in. Over a plain variable nothing changes:derivative(x*y, y)atx = 2is stillderivative(2 * y, y), that is 2.x = 2, withSimplifyderivative(x^3, x^2)03derivative(y sin x, cos x)0-y csc(2) cos(2)derivative(sin(x!), x^2)0cos(2)(3/2 - eulergamma)/2integral(x, x^2)C + 2x^216/3 + CBoth are in
BREAKING-CHANGES.md, measured on the 2.7.0 package. A limit and a definite integral bind their variable and are left as they were.Checks
DerivativeInAFunctionTest: every answer checked by value withf= sin, eᵗ and t³ + t at three points, total derivatives against (d expr/dx)/(du/dx), partial ones against the derivative in a plain variable standing for the slot, and the substitution at x = 0.3, 0.7, 1.3 againstf^2/f' + 2xf. The grammar gains one alternative afterlambda(; master's grammar was regenerated unchanged first and matched byte for byte.Full check on the second commit before the rebase onto 1a80be1 (clean): 20,695 unit tests, 0 failed; MCP 450, Terminal 69, F# 135, Interactive 19; AOT OK; BoundCheck 0 disagreements, RootCheck 596/596, CasBench 120/121 with 0 wrong, SimpSweep 10463/10463, RuleCheck clean, CanonCheck and Confluence at their baselines.
Closes #230.
🤖 Generated with Claude Code