Search code examples
sympypow

How to prevent Sympy from calculating degree in pow


There is an expression:

3^(48*x)

Sympy on further calculations will convert it to:

79766443076872509863361^x

Perhaps there is some kind of flag that prohibits such horrors.


Solution

  • If simplify is used it will cause that expansion. One way you can keep this from happening is to replace 48 with Symbol("48") so it is a variable. An UnevaluatedExpr will not be protected from the actions of simplify so that might be your only option.

    >>> simplify(UnevaluatedExpr(2**(4*x))+1)
    16**x + 1
    >>> simplify(2**(Symbol('4')*x)+1)
    2**(4*x) + 1