You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Substituting for a derivative's variable is dropped: derivative(x^3, x) at x = 1 evaluates to 3 x^2 #2189
Substituting and evaluating do not commute: derivative(x^3, x).Evaled is 3 * x ^ 2, in which x is free.
FreeVariables already reports that x as free. #1045 left both nodes out of its binders because "d/dt denotes a function of t", and pinned that with a test. Substitute still treats the variable as bound. That reading dates from 2020 (x = 0 -> derive(temp_1 ^ 2 + a, temp_1) -> derive(temp_1 ^ 2 + a, temp_1)), and #1811 kept it.
What is open is how to write a derivative that cannot be computed, evaluated at a point: derivative(f(x), x) with x := 1. SymPy writes Subs(Derivative(f(x), x), x, 1). Two candidates here:
derivative(f, x) with x := v becomes apply(lambda(x, derivative(f, x)), v), the derivative evaluated at v, written in syntax the library already has. The same goes for the indefinite integral(f, x). Substitute stays structural and computes nothing. A definite integral, a sum, a product and a limit really do bind their variable, and stay as they are.
Applying a lambda whose body is a derivative or an indefinite integral in its parameter simplifies that body before substituting, so the derivative is taken as a function of x and only then evaluated. Every other body is still substituted first, as Applying a lambda to a vector treats the vector as a number #2132 needs. A derivative the library cannot compute keeps the application, unevaluated, rather than answering wrongly.
Capture: substituting a := x into derivative(a x^2, x) currently renames the bound variable and leaves it free, giving derivative(x * x_1 ^ 2, x_1), which is 2 * x_1 * x. The right answer is 2 x^2, which apply(lambda(x_1, derivative(x x_1^2, x_1)), x) gives.
Activity
Rafael-SOWNet commentedon Oct 29, 2026
Proposal, which I'm implementing now:
derivative(f, x)withx := vbecomesapply(lambda(x, derivative(f, x)), v), the derivative evaluated atv, written in syntax the library already has. The same goes for the indefiniteintegral(f, x).Substitutestays structural and computes nothing. A definite integral, asum, aproductand alimitreally do bind their variable, and stay as they are.xand only then evaluated. Every other body is still substituted first, as Applying a lambda to a vector treats the vector as a number #2132 needs. A derivative the library cannot compute keeps the application, unevaluated, rather than answering wrongly.a := xintoderivative(a x^2, x)currently renames the bound variable and leaves it free, givingderivative(x * x_1 ^ 2, x_1), which is2 * x_1 * x. The right answer is2 x^2, whichapply(lambda(x_1, derivative(x x_1^2, x_1)), x)gives.derivative(x^3, x),x := 1,Evaled3 * x ^ 23apply(lambda(x, derivative(x^3, x)), 1)3 * x ^ 23integral(x^2, x),x := 1,Evaledx ^ 3 / 3 + C1/3 + Cderivative(a x^2, x),a := x,Evaled2 * x_1 * x2 * x ^ 2A fresh variable put in for a derivative's variable renames it
The forward difference (#2201)
A value put in for a derivative's variable is where it is evaluated (A…