Ask Your Question
1

What is sage equivalent to Pow in Sympy?

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

Nasser gravatar image

I am translating sympy function to use under sagemath

In sympy there is type Pow

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

In sagemath

sage: var('x')
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.

whattype(x^2)
                               ^
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

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

rburing gravatar image

Like this:

sage: expr = x^2
sage: expr.operator() == operator.pow
True
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

Stats

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

Seen: 1,987 times

Last updated: Dec 23 '19