Ask Your Question

What is sage equivalent to Pow in Sympy?

asked 2019-12-23 06:55:48 +0200

Nasser gravatar image

I am translating sympy function to use under sagemath

In sympy there is type Pow

>>> from import x
>>> type(x**2)
<class 'sympy.core.power.Pow'>
>>> isinstance(x**2,Pow)

In sagemath

sage: var('x')
sage: type(x^2)
<type 'sage.symbolic.expression.Expression'>
sage: isinstance(x^2,Pow)
NameError                                 Traceback (most recent call last)
<ipython-input-15-0e5e926fd38c> in <module>()
----> 1 isinstance(x**Integer(2),Pow)

NameError: name 'Pow' is not defined

How to check in sagemath if expression is type Power? i.e. something raised to power? fyi, in Maple this is given by type ^ also.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2019-12-23 09:08:56 +0200

rburing gravatar image

Like this:

sage: expr = x^2
sage: expr.operator() == operator.pow
sage: expr.operands()
[x, 2]
edit flag offensive delete link more

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


Asked: 2019-12-23 06:55:48 +0200

Seen: 1,789 times

Last updated: Dec 23 '19