mpmath matrix commands integers sage vs python

asked 2024-09-29 20:14:44 +0200

Karl007 gravatar image

I import mpmath into sage by

import mpmath as mp

then I try to create an identity matrix by

mp.eye(3)

but this does not work, it raises the error

TypeError: could not interpret given arguments

rather I have to tell mpmath that indeed 3 is an integer, so

mp.eye(int(3))

does work. Also raising mpmath matrix M to a power has the same problem

M^3

does not work. Again I have to do

M^(int(3))

why is this the case? can that be circumvented somehow? ("eye(3)" does work in python)

edit retag flag offensive close merge delete

Comments

2

Sage has a preparser that wrap integers with Integer(...). Try "preparse(4)" to see what it does.

sage: preparser()
sage: type(4)
<class 'sage.rings.integer.Integer'>
sage: preparser(False)
sage: type(4)
<class 'int'>
FrédéricC gravatar imageFrédéricC ( 2024-09-29 20:27:04 +0200 )edit

One could view this as a bug in mpmath, since at least some basic Python functions (for example range) can handle Sage integers as inputs just fine. So using Integer(3) should not be an obstacle, but I guess mpmath has not implemented this.

John Palmieri gravatar imageJohn Palmieri ( 2024-09-29 22:07:48 +0200 )edit