Is this Application of Leibniz Rule in Symbolic Math Toolbox Incorrect?

95 views (last 30 days)
Referring to Leibniz Integral Rule:
Verify R2025b
matlabRelease
ans =
matlabRelease with properties: Release: "R2025b" Stage: "release" Update: 2 Date: 16-Oct-2025
Define some functions
syms t x
syms f_1(x) f_2(x) g(t)
Case 1 looks correct:
syms G(x)
eqn1 = G(x) == int(g(t),t,f_1(x),f_2(x));
eqn2 = diff(eqn1,x);
case1 = [eqn1;eqn2]
case1 = 
Case 2 looks correct. Same as case 1 with dg(t)/dt replacing g(t).
Dg(t) = diff(g(t),t);
eqn3 = G(x) == int(Dg(t),t,f_1(x),f_2(x));
eqn4 = diff(eqn3,x);
case2 = [eqn3;eqn4]
case2 = 
Case 3 looks correct. Same as case 1 with g(t) = h(t)p(t)
syms h(t) p(t)
eqn5 = G(x) == int(h(t)*p(t),t,f_1(x),f_2(x));
eqn6 = diff(eqn5,x);
case3 = [eqn5;eqn6]
case3 = 
Case 4 looks incorrect
Dp(t) = diff(p(t),t);
eqn7 = G(x) == int(h(t)*Dp(t),t,f_1(x),f_2(x));
eqn8 = diff(eqn7,x);
case4 = [eqn7;eqn8]
case4 = 
I don't understand the meaning of the third multiplicands in both terms of the derivative expression. What does it mean to differentiate with respect to a function?
Seems like case 4 should be:
eqn9 = diff(G(x),x) == h(f_2(x))*Dp(f_2(x))*diff(f_2(x),x) - h(f_1(x))*Dp(f_1(x))*diff(f_1(x),x)
eqn9 = 
Is case 4 (eqn8) incorrect or am I misunderstanding the mathematical meaning of
diff(p(f_2(x)),f_2(x))
ans = 
  7 Comments
Paul
Paul on 26 Dec 2025 at 15:29
Edited: Paul on 27 Dec 2025 at 15:35
Hi David,
When I see "functional derivative" I think of Functional Derivative (or in Matlab functionalDerivative), but I don't think that's what you meant.
I understand where you're coming from, but let me make sure.
My claim is that Case 4 result should include the follwing term:
syms p(t) f_1(x)
Dp(t) = diff(p(t),t);
term1 = Dp(f_1)
term1 = 
By the Chain Rule we know that
eqn1 = term1 == diff(p(f_1(x)),x)/diff(f_1(x),x)
eqn1 = 
Interestingly enough, Matlab knows (in accordance with the display) that the RHS is the derivative of p wrt to its argument evaluated at f_1(x) (which is exactly the LHS of eqn1). Note we also saw that notation in Case 2 in my original example. But we don't see that same term displayed in the ouput of Case 4, which might be an indication that something is amiss.
If I'm following correctly, my eqn1 is basically a restatement of your equation:
% dg/df = (dg/dx) / (df/dx)
However, the term that actually shows up in Matlab's result for Case 4 (at least according to its display is)
term2 = diff(p(f_1),f_1(x))
term2 = 
which is not by appearance the same as the LHS or RHS of eqn1 (though maybe it has the same meaning, more on this below).
char(lhs(eqn1))
ans = 'subs(diff(p(t), t), t, f_1(x))'
char(rhs(eqn1))
ans = 'D(p)(f_1(x))'
char(term2)
ans = 'diff(p(f_1(x)), f_1(x))'
Let's put in some actual functions for p(t) and f_1(x)
p(t) = t^2; f_1(x) = x^3;
f_1(x) = 
subs(eqn1) % 2*t evaluated at t = x^3
ans = 
subs(term2)
ans = 
The software itself is apparently unsure of what term2 is, again indicating something might be amiss (but see below).
FWIW, if we go back to the original expression for term2, but try to define it with actual definitions for p(t) and f1(x), we actually get an error
So even if term2 is supposed to be the same as term1, it doesn't seem particularly useful if it can't evaluate when actual expressions for p(t) and f_1(x) are defined (but, more on this below).
In the interest of full disclosure, somehow term2 comes up with the correct result for this f_1(x)
f_1(x) = cos(x);
subs([eqn1;term2])
ans = 
OTOH, we also have this result, which is a bit ... odd
f_1(x) = exp(x);
subs([eqn1;term2])
ans = 
Digging in a little deeper ...
term2 can be defined this way, as long as f_1(x) is not defined
syms p(t) f_1(x)
term2 = diff(p(f_1),f_1(x))
term2 = 
Now define p(t)
p(t) = t^2;
p(f_1)
ans = 
And we get the expected result from diff
diff(p(f_1),f_1(x))
ans = 
or subs
term2 = subs(term2)
term2 = 
Now we can define f_1(x) and get the correct result
f_1(x) = exp(x);
term2 = subs(term2)
term2 = 
So we can get it to work with a two step process.
At the end of the day, I suppose one can argue that my preferred expression and Matlab's actual expression for Case 4 are equivalent
syms p(t) f_1(x)
eqn = subs(Dp(t),t,f_1(x)) == diff(p(f_1),f_1(x))
eqn = 
as long as one understands precisely how to interpret the RHS of eqn and how to work with it after p(t) and f_1(x) are subsequently defined.
Though Matlab doesn't necessarily agree (I show this with a bit of tongue in cheek, because isAlways can be finicky and has to consider corner cases).
isAlways(eqn)
Warning: Unable to prove 'subs(diff(p(t), t), t, f_1(x)) == diff(p(f_1(x)), f_1(x))'.
ans = logical
0
BTW, this whole exploration started with an expression like this
syms G(x) X h(tau)
eqn = G(x) == int(h(x-tau)*Dp(tau),tau,x-X,x)
eqn = 
diff(eqn,x)
ans = 
When I saw that middle term, I could only guess what it meant from context. IMO, it's not standard mathematical notation.
It's all a bit confusing that Matlab uses three different representations that all (apparently) mean the same thing: lhs(eqn1), rhs(eqn1), and term2.
David Goodmanson
David Goodmanson on 29 Dec 2025 at 11:16
Hi Paul,
As you suggested, by 'functional derivative' I didn't mean what is usually meant by that term, i .e. the derivative of a functional (for example an integral with the function as part of the integrand) w/r/t a function. I should have done better with terminology.
Yes, I think the both sides of your eqn 1 and term 2 all represent the same thing, and here is some scribbling on the topic. The answer to the original expression has a lower limit term from f1 and upper limit term from f2. Both are the same problem, so I'll just take the upper limit, call it f(x) and put the lower limit as 0 to get it out of the picture.
Case 4 is basically
G = Int{0, f(x)} h(t) (dp(t)/dt) dt
= Int{0, f(x)} h(t) p'(t) dt
% Then
dG/df = h(f) dp(f)/df
= h(f) p'(f)
Since dx is not involved, x is merely implicit. f can be considered to be an independent variable, and the fact that it might be a function of x is neither here nor there [except that x might be needed for bookkeeping purposes to specify the value of f = f(x) at the point of interest.]. So it's also true that in that sense,
dG/df(x) = h(f(x)) dp(f(x)) / df(x)
= h(f(x)) p'(f(x))
For the evaluation of the lhs of eqn. 1, for any derivative,
dh(u)/du = dh(y)/dy | y=u
where y is just a dummy variable (t in eqn.1). So all these various expressions are equivalent.
Only with d/dx does x really come into the picture to supply the extra factor from the chain rule.
dG/dx = (dG/df) (df/dx) = h(f) p'(f) df/dx
I should get more serious about syms. In this case it brought up possibilities. Sometimes is works pretty well. In some other cases though, it seems harder to get it to agree with what you know to be true than it is to forego it entirely and work out the result some other way. And it's well known for sometimes cranking out a result that is hundreds of characters long if not thousands, and which might actually be correct.

Sign in to comment.

Answers (0)

Products


Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!