First time here? Check out the FAQ!

Ask Your Question
1

Sage vs Python Integers

asked 2 years ago

Pickle gravatar image

Hello,

I am trying to use a recently installed module "control" in Sage. However, I run into issues with what seems like the variable type.

Below is an image of me running the same code side-by-side. Left is in Sage. Right is in the Sage repository's python kernel. I think the issue is regarding the variable types but I am not sure. Does someone have any insight to offer?

image description

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 2 years ago

updated 2 years ago

It looks like the control module is restrictive, I would say too restrictive, on the classes it allows. The error arises in a function _clean_part, which starts

valid_types = (int, float, complex, np.number)

so it will not accept Sage integers, which have type sage.rings.integer.Integer. You can fix this by just using Python ints, and this has to be done either explicitly:

tf(int(1), [int(1), int(10), int(20)])

or by turning off Sage's preparser:

preparser(False)
tf(1, [1, 10, 20])

(The preparser automatically converts an integer like "7" to a Sage integer, it converts ^ to the exponentiation operator, and does a few other things which are natural for a mathematical audience.)

Preview: (hide)
link

Comments

1

Or alternatively:

sage: tf(1r, [1r, 10r, 20r])
Sébastien gravatar imageSébastien ( 2 years ago )

@Sébastien: yes, good point, and should also work for floats.

John Palmieri gravatar imageJohn Palmieri ( 2 years ago )

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: 2 years ago

Seen: 752 times

Last updated: Sep 15 '22