ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Tue, 14 Dec 2021 02:49:30 +0100How do diff(y,x) and diff(y)/diff(x) differ?https://ask.sagemath.org/question/60248/how-do-diffyx-and-diffydiffx-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:
1. Does example below shows "limitations" of what Sage can compute ?
2. Is there a difference between diff(y)/diff(x) and diff(y,x) ?
3. 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/tutorial/tour_functions.htmlAlexKnyazevTue, 14 Dec 2021 02:49:30 +0100https://ask.sagemath.org/question/60248/