Ask Your Question
1

Sage vs Python Integers

asked 2022-09-15 01:27:20 +0100

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

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2022-09-15 03:51:14 +0100

updated 2022-09-15 06:35:38 +0100

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.)

edit flag offensive delete link more

Comments

1

Or alternatively:

sage: tf(1r, [1r, 10r, 20r])
Sébastien gravatar imageSébastien ( 2022-09-16 21:12:26 +0100 )edit

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

John Palmieri gravatar imageJohn Palmieri ( 2022-09-16 23:34:27 +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: 2022-09-15 01:27:20 +0100

Seen: 588 times

Last updated: Sep 15 '22