Exemplo n.º 1
0
 def _next(self, expr):
     if self.deep is True and expr.is_Indexed:
         return expr.indices
     elif q_leaf(expr):
         return ()
     else:
         return expr.args
Exemplo n.º 2
0
 def _next(self, expr):
     if self.deep is True and expr.is_Indexed:
         return expr.indices
     elif q_leaf(expr):
         return ()
     else:
         return expr.args
Exemplo n.º 3
0
def pow_to_mul(expr):
    if q_leaf(expr) or isinstance(expr, Basic):
        return expr
    elif expr.is_Pow:
        base, exp = expr.as_base_exp()
        if exp > 10 or exp < -10 or int(exp) != exp or exp == 0:
            # Large and non-integer powers remain untouched
            return expr
        elif exp == -1:
            # Reciprocals also remain untouched, but we traverse the base
            # looking for other Pows
            return expr.func(pow_to_mul(base), exp, evaluate=False)
        elif exp > 0:
            return Mul(*[base] * int(exp), evaluate=False)
        else:
            # SymPy represents 1/x as Pow(x,-1). Also, it represents
            # 2/x as Mul(2, Pow(x, -1)). So we shouldn't end up here,
            # but just in case SymPy changes its internal conventions...
            posexpr = Mul(*[base] * (-int(exp)), evaluate=False)
            return Pow(posexpr, -1, evaluate=False)
    else:
        return expr.func(*[pow_to_mul(i) for i in expr.args], evaluate=False)
Exemplo n.º 4
0
 def _next(self, expr):
     return [] if q_leaf(expr) else expr.args