First time here? Check out the FAQ!

Ask Your Question
0

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

asked 1 year ago

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

outputs 4

Why is that?

Preview: (hide)

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 ( 1 year ago )
1

to multiply, you need *

FrédéricC gravatar imageFrédéricC ( 1 year ago )

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 ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
1

answered 1 year ago

GPN gravatar image

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

var('r')
2*r^2

I hope its what you want GPN

Preview: (hide)
link

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 243 times

Last updated: Dec 24 '23