当前位置: 首页>>代码示例>>Python>>正文


Python sympy.Pow方法代码示例

本文整理汇总了Python中sympy.Pow方法的典型用法代码示例。如果您正苦于以下问题:Python sympy.Pow方法的具体用法?Python sympy.Pow怎么用?Python sympy.Pow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy的用法示例。


在下文中一共展示了sympy.Pow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _replace_op_func

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _replace_op_func(e, variable):

    if isinstance(e, Operator):
        return OperatorFunction(e, variable)
    
    if e.is_Number:
        return e
    
    if isinstance(e, Pow):
        return Pow(_replace_op_func(e.base, variable), e.exp)
    
    new_args = [_replace_op_func(arg, variable) for arg in e.args]
    
    if isinstance(e, Add):
        return Add(*new_args)
    
    elif isinstance(e, Mul):
        return Mul(*new_args)
    
    else:
        return e 
开发者ID:sympsi,项目名称:sympsi,代码行数:23,代码来源:operator.py

示例2: _expand_powers

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _expand_powers(factors):
    """
    Helper function for normal_ordered_form and normal_order: Expand a
    power expression to a multiplication expression so that that the
    expression can be handled by the normal ordering functions.
    """

    new_factors = []
    for factor in factors.args:
        if (isinstance(factor, Pow)
                and isinstance(factor.args[1], Integer)
                and factor.args[1] > 0):
            for n in range(factor.args[1]):
                new_factors.append(factor.args[0])
        else:
            new_factors.append(factor)

    return new_factors 
开发者ID:sympsi,项目名称:sympsi,代码行数:20,代码来源:operatorordering.py

示例3: test_commutator

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def test_commutator():
    A = Operator('A')
    B = Operator('B')
    c = Commutator(A, B)
    c_tall = Commutator(A**2, B)
    assert str(c) == '[A,B]'
    assert pretty(c) == '[A,B]'
    assert upretty(c) == u('[A,B]')
    assert latex(c) == r'\left[A,B\right]'
    sT(c, "Commutator(Operator(Symbol('A')),Operator(Symbol('B')))")
    assert str(c_tall) == '[A**2,B]'
    ascii_str = \
"""\
[ 2  ]\n\
[A ,B]\
"""
    ucode_str = \
u("""\
⎡ 2  ⎤\n\
⎣A ,B⎦\
""")
    assert pretty(c_tall) == ascii_str
    assert upretty(c_tall) == ucode_str
    assert latex(c_tall) == r'\left[\left(A\right)^{2},B\right]'
    sT(c_tall, "Commutator(Pow(Operator(Symbol('A')), Integer(2)),Operator(Symbol('B')))") 
开发者ID:sympsi,项目名称:sympsi,代码行数:27,代码来源:test_printing.py

示例4: test_differentiable

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def test_differentiable():
    a = Function(name="a", grid=Grid((10, 10)))
    e = Function(name="e", grid=Grid((10, 10)))

    assert isinstance(1.2 * a.dx, Mul)
    assert isinstance(e + a, Add)
    assert isinstance(e * a, Mul)
    assert isinstance(a * a, Pow)
    assert isinstance(1 / (a * a), Pow)

    addition = a + 1.2 * a.dx
    assert isinstance(addition, Add)
    assert all(isinstance(a, Differentiable) for a in addition.args)

    addition2 = a + e * a.dx
    assert isinstance(addition2, Add)
    assert all(isinstance(a, Differentiable) for a in addition2.args) 
开发者ID:devitocodes,项目名称:devito,代码行数:19,代码来源:test_differentiable.py

示例5: test_diffify

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def test_diffify():
    a = Function(name="a", grid=Grid((10, 10)))
    e = Function(name="e", grid=Grid((10, 10)))

    assert isinstance(diffify(sympy.Mul(*[1.2, a.dx])), Mul)
    assert isinstance(diffify(sympy.Add(*[a, e])), Add)
    assert isinstance(diffify(sympy.Mul(*[e, a])), Mul)
    assert isinstance(diffify(sympy.Mul(*[a, a])), Pow)
    assert isinstance(diffify(sympy.Pow(*[a*a, -1])), Pow)

    addition = diffify(sympy.Add(*[a, sympy.Mul(*[1.2, a.dx])]))
    assert isinstance(addition, Add)
    assert all(isinstance(a, Differentiable) for a in addition.args)

    addition2 = diffify(sympy.Add(*[a, sympy.Mul(*[e, a.dx])]))
    assert isinstance(addition2, Add)
    assert all(isinstance(a, Differentiable) for a in addition2.args) 
开发者ID:devitocodes,项目名称:devito,代码行数:19,代码来源:test_differentiable.py

示例6: pow_to_mul

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def pow_to_mul(expr):
    if expr.is_Atom or expr.is_Indexed:
        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 sympy.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 = sympy.Mul(*[base]*(-int(exp)), evaluate=False)
            return sympy.Pow(posexpr, -1, evaluate=False)
    else:
        return expr.func(*[pow_to_mul(i) for i in expr.args], evaluate=False) 
开发者ID:devitocodes,项目名称:devito,代码行数:24,代码来源:manipulation.py

示例7: convert_mp

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def convert_mp(mp):
    if hasattr(mp, 'mp'):
        mp_left = mp.mp(0)
        mp_right = mp.mp(1)
    else:
        mp_left = mp.mp_nofunc(0)
        mp_right = mp.mp_nofunc(1)

    if mp.MUL() or mp.CMD_TIMES() or mp.CMD_CDOT():
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        return sympy.Mul(lh, rh, evaluate=False)
    elif mp.DIV() or mp.CMD_DIV() or mp.COLON():
        lh = convert_mp(mp_left)
        rh = convert_mp(mp_right)
        return sympy.Mul(lh, sympy.Pow(rh, -1, evaluate=False), evaluate=False)
    else:
        if hasattr(mp, 'unary'):
            return convert_unary(mp.unary())
        else:
            return convert_unary(mp.unary_nofunc()) 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:23,代码来源:process_latex.py

示例8: convert_exp

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def convert_exp(exp):
    if hasattr(exp, 'exp'):
        exp_nested = exp.exp()
    else:
        exp_nested = exp.exp_nofunc()

    if exp_nested:
        base = convert_exp(exp_nested)
        if isinstance(base, list):
            raise Exception("Cannot raise derivative to power")
        if exp.atom():
            exponent = convert_atom(exp.atom())
        elif exp.expr():
            exponent = convert_expr(exp.expr())
        return sympy.Pow(base, exponent, evaluate=False)
    else:
        if hasattr(exp, 'comp'):
            return convert_comp(exp.comp())
        else:
            return convert_comp(exp.comp_nofunc()) 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:22,代码来源:process_latex.py

示例9: _surd_coefficients

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _surd_coefficients(sympy_exp):
  """Extracts coefficients a, b, where sympy_exp = a + b * sqrt(base)."""
  sympy_exp = sympy.simplify(sympy.expand(sympy_exp))

  def extract_b(b_sqrt_base):
    """Returns b from expression of form b * sqrt(base)."""
    if isinstance(b_sqrt_base, sympy.Pow):
      # Just form sqrt(base)
      return 1
    else:
      assert isinstance(b_sqrt_base, sympy.Mul)
      assert len(b_sqrt_base.args) == 2
      assert b_sqrt_base.args[0].is_rational
      assert isinstance(b_sqrt_base.args[1], sympy.Pow)  # should be sqrt.
      return b_sqrt_base.args[0]

  if sympy_exp.is_rational:
    # Form: a.
    return sympy_exp, 0
  elif isinstance(sympy_exp, sympy.Add):
    # Form: a + b * sqrt(base)
    assert len(sympy_exp.args) == 2
    assert sympy_exp.args[0].is_rational
    a = sympy_exp.args[0]
    b = extract_b(sympy_exp.args[1])
    return a, b
  else:
    # Form: b * sqrt(base).
    return 0, extract_b(sympy_exp) 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:31,代码来源:arithmetic.py

示例10: sympy

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def sympy(self):
    return sympy.Mul(
        self.children['numer'], sympy.Pow(self.children['denom'], -1)) 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:5,代码来源:ops.py

示例11: __init__

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def __init__(self, a, b):
    super(Pow, self).__init__({'a': a, 'b': b}) 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:4,代码来源:ops.py

示例12: _print_Pow

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _print_Pow(self, power):
        from sympy.simplify.simplify import fraction
        b, e = power.as_base_exp()
        if power.is_commutative:
            if e is S.NegativeOne:
                return prettyForm("1")/self._print(b)
            n, d = fraction(e)
            if n is S.One and d.is_Atom and not e.is_Integer:
                return self._print_nth_root(b, e)
            if e.is_Rational and e < 0:
                return prettyForm("1")/self._print(C.Pow(b, -e, evaluate=False))

        return self._print(b)**self._print(e) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:15,代码来源:pretty.py

示例13: _print_ProductSet

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _print_ProductSet(self, p):
        if len(p.sets) > 1 and not has_variety(p.sets):
            from sympy import Pow
            return self._print(Pow(p.sets[0], len(p.sets), evaluate=False))
        else:
            prod_char = u('\xd7')
            return self._print_seq(p.sets, None, None, ' %s ' % prod_char,
                parenthesize=lambda set: set.is_Union or set.is_Intersection) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:pretty.py

示例14: _sympystr

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _sympystr(self, printer, *args):
        from sympy.printing.str import sstr
        length = len(self.args)
        s = ''
        for i in range(length):
            if isinstance(self.args[i], (Add, Pow, Mul)):
                s = s + '('
            s = s + sstr(self.args[i])
            if isinstance(self.args[i], (Add, Pow, Mul)):
                s = s + ')'
            if i != length - 1:
                s = s + 'x'
        return s 
开发者ID:sympsi,项目名称:sympsi,代码行数:15,代码来源:tensorproduct.py

示例15: _getExpression

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Pow [as 别名]
def _getExpression(expr, input_dict):
    """
    all the operations is dependent on the conditions 
    whether all the elements are leafs or only some of them.
    Only return expressions and not the individual elements
    """
    t = expr.args if len(expr.atoms()) > 1 else [expr]
    # print t

    # find out the length of the components within this node
    t_lengths = np.array(list(map(_expressionLength, t)))
    # print(tLengths)
    if np.all(t_lengths == 0):
        # if all components are leafs, then the node is an expression
        input_dict.setdefault(expr, 0)
        input_dict[expr] += 1
    else:
        for i, ti in enumerate(t):
            # if the leaf is a singleton, then it is an expression
            # else, go further along the tree
            if t_lengths[i] == 0:
                input_dict.setdefault(ti, 0)
                input_dict[ti] += 1
            else:
                if isinstance(ti, sympy.Mul):
                    _getExpression(ti, input_dict)
                elif isinstance(ti, sympy.Pow):
                    input_dict.setdefault(ti, 0)
                    input_dict[ti] += 1 
开发者ID:publichealthengland,项目名称:pygom,代码行数:31,代码来源:_ode_composition.py


注:本文中的sympy.Pow方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。