Ask Your Question

Variables r and R are gobbled

asked 2020-06-22 21:41:20 -0500

Juanjo gravatar image

updated 2020-06-22 21:44:09 -0500

If implicit multiplication is not active, something like 4y^2 should raise an error. This is what actually happens:

sage: var("y"); 4y^2
  File "<ipython-input-22-25bcbc82148c>", line 1
    var("y"); 4y**Integer(2)
SyntaxError: invalid syntax

If we replace y by a different variable or consider a similar expression, we also get an error... except if the variable is r or R. For example,

sage: var("r, R"); 4r^2, 3R + 5r + 2R^3
(16, 16)

Surprisingly, there is no error. Variables r and R seem to be gobbled, so that SageMath parses 4r^2 as 4**Integer(2) and 3R + 5r + 2R^3 as 3 + 5 + 2**Integer(3). Why? Is this a bug?

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2020-06-23 01:12:09 -0500

FrédéricC gravatar image

r means raw python integer

edit flag offensive delete link more



Many thanks. I now understand. This is a source of potential problems, as happened to some of my students. They inadvertently did a wrong computation, like integral(sqrt(1+4r^2), r, 0, 1), and so failed an exercise.

Juanjo gravatar imageJuanjo ( 2020-06-23 04:49:40 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2020-06-22 21:41:20 -0500

Seen: 51 times

Last updated: Jun 22