How do diff(y,x) and diff(y)/diff(x) differ?
Hello,
Consider the following Sage code:
x = var('x')
y = 2*x
diff(y,x) #gives 2 as expected
diff(x,y) #expected 1/2, complains: "argument symb must be a symbol"
This can be resolved via (kind-off) Leibniz's notation approach:
x = var('x')
y = 2*x
diff(y)/diff(x) #gives 2 as expected
diff(x)/diff(y) #gives 1/2 as expected
Example above illustrates issue I keep having (Sage expressions of type diff(x,y) giving error where there exist a derivative)
Questions are:
Does example below shows "limitations" of what Sage can compute ?
Is there a difference between diff(y)/diff(x) and diff(y,x) ?
Is there a way to help Sage "recognize" that diff(x,y) = 1/2 ? If yes, how?
P.S. (If 3 is "Yes") This seems very basic problem, yet I was unable to find any related examples online. Is there a reference that explains described behavior o diff?
Update after Emmanuel Charpentier's answer
It appears that I am conflicting symbolic "function" and "expression" types you mentioned, i.e. I expect diff(x)
to return the total differential of f(x)=x. And it seems diff(...)
does dive differential when defining x using "function" syntax (although both x(x)=x
and var('x')
cases have the same "<'...Expression'>" type).
x = var('x')
diff(x) #same as diff(x,x), as explained by Emmanuel Charpentier
type(x) #<class 'sage.symbolic.expression.Expression'>
x(x) = x
type(x) #<class 'sage.symbolic.expression.Expression'>
diff(x) #gives differential "x |--> 1", what I assumed it does for single argument diff()
#"function" approach works for multivirable where "expression" gave error
myCos(x,y) = cos(x*y)
diff(myCos) #gives differential "(x, y) |--> (-y*sin(x*y), -x*sin(x*y))"
My last remaining question is:
Given object "x", how to tell whether it's a "function" or "expression" ?
P.S. There is good reading on the "expression vs. function" business in docs. https://doc.sagemath.org/html/en/tuto...
See the chapter 2 of the free book Computational Mathematics with SageMath, it's an excellent introduction to the sage symbolics.