Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sage's hell is somehow paved of it's authors good intentions...

diff(x) should denote the derivative of an expression (its forst argument) with respect to a variable which should be given as it's second argument.

Here, this second argument is missing, so, instead of failing, Sage attempts to guess" it by establishing the list of its variables, which turns out to be a singleton ; it uses this unique variable as the derivation variable. As in :

sage: diff(cos(x))
-sin(x)

But this shortcut fails if the expression has more than one variable :

sage: diff(cos(x*y))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

[ Snip...]

ValueError: No differentiation variable specified.

Morality : always specify yourb differentiation variable, notwithstanding Sage's attempt to save your bacon...

BTW : your statement

y=2*x gives the Python variable y the value 2*x, which is a symbolic expression ; as a consequence, y does not specify a symbolic variable nor a function. The former would need var("y"), the latter y(x)=2*x.

HTH,

Sage's hell is somehow paved of it's authors with its authors' good intentions...

diff(x)diff(...) should denote the derivative of an expression (its forst argument) first argument) with respect to a variable which should be given as it's its second argument.

Here, this second argument is missing, so, instead of failing, Sage attempts to guess" attempts to guess it by establishing the list of its variables, which turns out to be a singleton ; be a singleton; it uses this unique variable as the derivation variable. As in :in:

sage: diff(cos(x))
-sin(x)

But this shortcut fails if the expression has more than one variable :

sage: diff(cos(x*y))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

[ Snip...]

ValueError: No differentiation variable specified.

Morality : Morality: always specify yourb your differentiation variable, variable, notwithstanding Sage's attempt to save your bacon...

BTW : BTW: regarding your statement

y=2*x gives expectations:

After running y = 2*x, the Python variable y has the value 2*x, , which is a symbolic expression expression; as a consequence, y is neither a symbolic variable nor a function. To define y as a symbolic variable, use var("y"); as a consequence, y does not specify a symbolic variable nor a function. The former would need var("y"), the latter y(x)=2*xto define y as a function, use y(x) = 2*x.

HTH,

Sage's hell is somehow paved with its authors' good intentions...

diff(...) should denote the derivative of an expression (its first argument) with respect to a variable which should be given as its second argument.

Here, this second argument is missing, so, instead of failing, Sage attempts to guess it by establishing the list of its variables, which turns out to be a singleton; it uses this unique variable as the derivation variable. As in:

sage: diff(cos(x))
-sin(x)

But this shortcut fails if the expression has more than one variable :

sage: diff(cos(x*y))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

[ Snip...]

ValueError: No differentiation variable specified.

Morality: always specify your differentiation variable, notwithstanding Sage's attempt to save your bacon...

BTW: regarding your expectations:

After running y = 2*x, the Python variable y has the value 2*x, which is a symbolic expression; as a consequence, y is neither a symbolic variable nor a function. To define y as a symbolic variable, use var("y"); to define y as a function, use y(x) = 2*x.

EDIT :

Given object "x", how to tell whether it's a "function" or "expression" ?

This one deserved its own question, not an addendum...

Compare :

sage: ex=sin(x)
sage: f(x)=sin(x)
sage: ex.is_callable()
False
sage: f.is_callable()
True