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


Python sympy.Mul方法代码示例

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


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

示例1: subs_bilinear

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def subs_bilinear(expr):
    """
    Substitutes bilinear forms from an expression with dedicated variables
    :param expr:
    :return:
    """

    bilinear_ix = [isinstance(x,sympy.Mul) for e,x in enumerate(expr.args)]

    new_expr = expr.copy()

    replacement_dict = dict()

    for bix in bilinear_ix:
        term = expr.args[bix]
        name = '__MUL__'.join(term.args)
        z = sympy.Symbol(name = name)

        new_expr = new_expr.subs(term,z)
        replacement_dict[term] = z

    return new_expr, replacement_dict 
开发者ID:EPFL-LCSB,项目名称:pytfa,代码行数:24,代码来源:reformulation.py

示例2: sympy_to_grim

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def sympy_to_grim(expr, **kwargs):
    import sympy
    assert isinstance(expr, sympy.Expr)
    if expr.is_Integer:
        return Expr(int(expr))
    if expr.is_Symbol:
        return Expr(symbol_name=expr.name)
    if expr is sympy.pi:
        return Pi
    if expr is sympy.E:
        return ConstE
    if expr is sympy.I:
        return ConstI
    if expr.is_Add:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Add(*args)
    if expr.is_Mul:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        return Mul(*args)
    if expr.is_Pow:
        args = [sympy_to_grim(x, **kwargs) for x in expr.args]
        b, e = args
        return Pow(b, e)
    raise NotImplementedError("converting %s to Grim", type(expr)) 
开发者ID:fredrik-johansson,项目名称:fungrim,代码行数:26,代码来源:sympy_interface.py

示例3: _replace_op_func

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例4: _normal_ordered_form_terms

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def _normal_ordered_form_terms(expr, independent=False, recursive_limit=10,
                               _recursive_depth=0):
    """
    Helper function for normal_ordered_form: loop through each term in an
    addition expression and call _normal_ordered_form_factor to perform the
    factor to an normally ordered expression.
    """

    new_terms = []
    for term in expr.args:
        if isinstance(term, Mul):
            new_term = _normal_ordered_form_factor(
                term, recursive_limit=recursive_limit,
                _recursive_depth=_recursive_depth, independent=independent)
            new_terms.append(new_term)
        elif isinstance(term, Expectation):
            term = Expectation(normal_ordered_form(term.args[0]), term.is_normal_order)
            new_terms.append(term)
        else:
            new_terms.append(term)

    return Add(*new_terms) 
开发者ID:sympsi,项目名称:sympsi,代码行数:24,代码来源:operatorordering.py

示例5: _normal_order_terms

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def _normal_order_terms(expr, recursive_limit=10, _recursive_depth=0):
    """
    Helper function for normal_order: look through each term in an addition
    expression and call _normal_order_factor to perform the normal ordering
    on the factors.
    """

    new_terms = []
    for term in expr.args:
        if isinstance(term, Mul):
            new_term = _normal_order_factor(term,
                                            recursive_limit=recursive_limit,
                                            _recursive_depth=_recursive_depth)
            new_terms.append(new_term)
        else:
            new_terms.append(term)

    return Add(*new_terms) 
开发者ID:sympsi,项目名称:sympsi,代码行数:20,代码来源:operatorordering.py

示例6: _generate_outer_prod

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def _generate_outer_prod(self, arg1, arg2):
        c_part1, nc_part1 = arg1.args_cnc()
        c_part2, nc_part2 = arg2.args_cnc()

        if ( len(nc_part1) == 0 or
             len(nc_part2) == 0 ):
            raise ValueError('Atleast one-pair of'
                             ' Non-commutative instance required'
                             ' for outer product.')

        # Muls of Tensor Products should be expanded
        # before this function is called
        if (isinstance(nc_part1[0], TensorProduct) and
                len(nc_part1) == 1 and len(nc_part2) == 1):
            op = tensor_product_simp(nc_part1[0] * Dagger(nc_part2[0]))
        else:
            op = Mul(*nc_part1) * Dagger(Mul(*nc_part2))

        return Mul(*c_part1)*Mul(*c_part2)*op 
开发者ID:sympsi,项目名称:sympsi,代码行数:21,代码来源:density.py

示例7: test_repr_preserves_type_information

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def test_repr_preserves_type_information():
    t = sympy.Symbol('t')

    assert repr(cirq.Duration(micros=1500)) == 'cirq.Duration(micros=1500)'
    assert repr(cirq.Duration(micros=1500.0)) == 'cirq.Duration(micros=1500.0)'
    assert repr(cirq.Duration(millis=1.5)) == 'cirq.Duration(micros=1500.0)'

    assert repr(cirq.Duration(
        micros=1500 *
        t)) == ("cirq.Duration(micros=sympy.Mul(sympy.Integer(1500), "
                "sympy.Symbol('t')))")
    assert repr(cirq.Duration(micros=1500.0 * t)) == (
        "cirq.Duration(micros=sympy.Mul(sympy.Float('1500.0', precision=53), "
        "sympy.Symbol('t')))")
    assert repr(cirq.Duration(millis=1.5 * t)) == (
        "cirq.Duration(micros=sympy.Mul(sympy.Float('1500.0', precision=53), "
        "sympy.Symbol('t')))") 
开发者ID:quantumlib,项目名称:Cirq,代码行数:19,代码来源:duration_test.py

示例8: test_differentiable

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例9: test_diffify

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例10: pow_to_mul

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例11: convert_mp

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例12: convert_unary

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def convert_unary(unary):
    if hasattr(unary, 'unary'):
        nested_unary = unary.unary()
    else:
        nested_unary = unary.unary_nofunc()
    if hasattr(unary, 'postfix_nofunc'):
        first = unary.postfix()
        tail = unary.postfix_nofunc()
        postfix = [first] + tail
    else:
        postfix = unary.postfix()

    if unary.ADD():
        return convert_unary(nested_unary)
    elif unary.SUB():
        return sympy.Mul(-1, convert_unary(nested_unary), evaluate=False)
    elif postfix:
        return convert_postfix_list(postfix) 
开发者ID:augustt198,项目名称:latex2sympy,代码行数:20,代码来源:process_latex.py

示例13: _surd_coefficients

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [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

示例14: expanded_signs_and_terms

# 需要导入模块: import sympy [as 别名]
# 或者: from sympy import Mul [as 别名]
def expanded_signs_and_terms(self):
    """Returns a list of arguments, plus any sub-arguments from sub-adds.

    E.g., if this op is `Add(Add(2, Neg(3)), Mul(4, 5), 1)`, then will return
    `[(True, 2), (False, 3), (True, Mul(4, 5)), (True, 1)]` (the arguments of
    the inner add have been extracted).
    """ 
开发者ID:deepmind,项目名称:mathematics_dataset,代码行数:9,代码来源:ops.py

示例15: sympy

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


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