Ask Your Question
0

2r^2 interpreted as 2^2 [closed]

asked 2023-12-24 04:20:51 +0100

hbghlyj gravatar image
var('r')
2r^2

outputs 4

Why is that?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by Max Alekseyev
close date 2023-12-24 20:07:45.471855

Comments

Please check the types in the following code:

print("Before var:",type(r))
var('r')
print("After var:",type(r))
print("2r^2:",2r^2)
print("type(2r):",type(2r))
print("type(2*r):",type(2*r))
print("2*r^2:",2*r^2)
print("(2*r)^2",(2*r)^2)
tolga gravatar imagetolga ( 2023-12-24 08:31:02 +0100 )edit
1

to multiply, you need *

FrédéricC gravatar imageFrédéricC ( 2023-12-24 09:18:51 +0100 )edit
Max Alekseyev gravatar imageMax Alekseyev ( 2023-12-24 20:07:38 +0100 )edit

I found the fact that 2r^2 was accepted extremely intriguing, and queried for it. John Palmieri's insightful answer pointed me to a feature of the preparser that I ignored after years of using Sage...

Emmanuel Charpentier gravatar imageEmmanuel Charpentier ( 2023-12-24 20:07:49 +0100 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2023-12-24 12:28:13 +0100

GPN gravatar image

Try the following code, notice the "*" I added:

var('r')
2*r^2

I hope its what you want GPN

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2023-12-24 04:20:51 +0100

Seen: 219 times

Last updated: Dec 24 '23