Ask Your Question
1

Variables r and R are gobbled

asked 2020-06-23 04:41:20 +0100

Juanjo gravatar image

updated 2020-06-23 04:44:09 +0100

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
1

answered 2020-06-23 08:12:09 +0100

FrédéricC gravatar image

r means raw python integer

edit flag offensive delete link more

Comments

1

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 11:49:40 +0100 )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

Stats

Asked: 2020-06-23 04:41:20 +0100

Seen: 264 times

Last updated: Jun 23 '20