correct derivative command returns syntax error

63 views
Skip to first unread message

Germano Massullo

unread,
Sep 21, 2015, 6:21:53 AM9/21/15
to sage-support
Since I did not remember the command to do a derivative, I was trying with a very simple formula. Since I did not find the right command on my own, I looked at [SageMath guide](http://www.sagemath.org/calctut/derivative.html) and then I tried to run the following command

    derivative(5x, x)

but it returns error

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "_sage_input_22.py", line 10, in <module>
        exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("ZGVyaXZhdGl2ZSg1eCwgeCk="),globals())+"\\n"); execfile(os.path.abspath("___code___.py"))
      File "", line 1, in <module>
       
      File "/tmp/tmpZWBMYQ/___code___.py", line 2
        derivative(5x, x)
                    ^
    SyntaxError: invalid syntax

Instead the command from the guide

    derivative(x^2, x)

works flawlessly. They seem both equal, but mine does not work. Why?

Germano Massullo

unread,
Sep 21, 2015, 6:25:04 AM9/21/15
to sage-support
SageMath Version 6.5

Germano Massullo

unread,
Sep 21, 2015, 6:48:14 AM9/21/15
to sage-support
derivative(5*x, x)
Putting a * solves the problem. Does SageMath really need * symbol to understand that 5x is 5*x ???? If yes there is something really wrong in SM syntax...

Simon King

unread,
Sep 21, 2015, 8:53:23 AM9/21/15
to sage-s...@googlegroups.com
Hi Germano,
What computer algebra systems (or pocket calculators) would understand
that 5x means 5*x?

Anyway, implicit multiplication is optional in SageMath. Have a look at
the function implicit_multiplication (as usual, you can see the
documentation of the command by typing implicit_multiplication? followed
by return on the command line or shift-return in the notebook).

After implicit_multiplication(True), the incorrect syntax 5x is
automatically translated into the correct syntax 5*x---in an interactive
session. If you are writing a module then you have to stick to Python
syntax (Python is the underlying language of Sage).

Best regards,
Simon


Jori Mäntysalo

unread,
Sep 21, 2015, 9:06:39 AM9/21/15
to sage-s...@googlegroups.com
On Mon, 21 Sep 2015, Simon King wrote:

> What computer algebra systems (or pocket calculators) would understand
> that 5x means 5*x?

Mathematica understand at least "5 x". Or at least understood in version
4.

--
Jori Mäntysalo

slelievre

unread,
Sep 23, 2015, 12:15:48 PM9/23/15
to sage-support


2015-09-21 12:48:14 UTC+2, Germano Massullo a écrit :
derivative(5*x, x)
Putting a * solves the problem. Does SageMath really need * symbol to understand that 5x is 5*x ???? If yes there is something really wrong in SM syntax...

Sage has implicit multiplication turned off by default,
but lets you turn it on, and even lets you set the level
of implicit multiplication you want, see this answer
on Math.SE and the links there.

  http://math.stackexchange.com/questions/1186165/why-can-you-not-omit-the-sign-for-multiplication-in-sage-matlab-and-other/1186678#1186678

Other programming languages or software systems
have different conventions. For example, Julia lets you
write 5x or 2x^2.

Reply all
Reply to author
Forward
0 new messages