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


Python sympy.expand_mul函数代码示例

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


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

示例1: test_issue841

def test_issue841():
    from sympy import expand_mul
    from sympy.abc import k

    assert expand_mul(integrate(exp(-x ** 2) * exp(I * k * x), (x, -oo, oo))) == sqrt(pi) * exp(-k ** 2 / 4)
    a, d = symbols("a d", positive=True)
    assert expand_mul(integrate(exp(-a * x ** 2 + 2 * d * x), (x, -oo, oo))) == sqrt(pi) * exp(d ** 2 / a) / sqrt(a)
开发者ID:arunenigma,项目名称:sympy,代码行数:7,代码来源:test_integrals.py

示例2: E

 def E(expr):
     res1 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                      (x, 0, oo), (y, -oo, oo), meijerg=True)
     res2 = integrate(expr*exponential(x, rate)*normal(y, mu1, sigma1),
                     (y, -oo, oo), (x, 0, oo), meijerg=True)
     assert expand_mul(res1) == expand_mul(res2)
     return res1
开发者ID:chaffra,项目名称:sympy,代码行数:7,代码来源:test_meijerint.py

示例3: eval

 def eval(cls, arg):
     from sympy.simplify.simplify import signsimp
     if hasattr(arg, '_eval_Abs'):
         obj = arg._eval_Abs()
         if obj is not None:
             return obj
     # handle what we can
     arg = signsimp(arg, evaluate=False)
     if arg.is_Mul:
         known = []
         unk = []
         for t in arg.args:
             tnew = cls(t)
             if tnew.func is cls:
                 unk.append(tnew.args[0])
             else:
                 known.append(tnew)
         known = Mul(*known)
         unk = cls(Mul(*unk), evaluate=False) if unk else S.One
         return known*unk
     if arg is S.NaN:
         return S.NaN
     if arg.is_Pow:
         base, exponent = arg.as_base_exp()
         if base.is_real:
             if exponent.is_integer:
                 if exponent.is_even:
                     return arg
                 if base is S.NegativeOne:
                     return S.One
                 if base.func is cls and exponent is S.NegativeOne:
                     return arg
                 return Abs(base)**exponent
             if base.is_positive == True:
                 return base**re(exponent)
             return (-base)**re(exponent)*C.exp(-S.Pi*im(exponent))
     if isinstance(arg, C.exp):
         return C.exp(re(arg.args[0]))
     if arg.is_zero:  # it may be an Expr that is zero
         return S.Zero
     if arg.is_nonnegative:
         return arg
     if arg.is_nonpositive:
         return -arg
     if arg.is_imaginary:
         arg2 = -S.ImaginaryUnit * arg
         if arg2.is_nonnegative:
             return arg2
     if arg.is_Add:
         if arg.has(S.Infinity, S.NegativeInfinity):
             if any(a.is_infinite for a in arg.as_real_imag()):
                 return S.Infinity
         if arg.is_real is None and arg.is_imaginary is None:
             if all(a.is_real or a.is_imaginary or (S.ImaginaryUnit*a).is_real for a in arg.args):
                 from sympy import expand_mul
                 return sqrt(expand_mul(arg*arg.conjugate()))
     if arg.is_real is False and arg.is_imaginary is False:
         from sympy import expand_mul
         return sqrt(expand_mul(arg*arg.conjugate()))
开发者ID:fetrocinol,项目名称:sympy,代码行数:59,代码来源:complexes.py

示例4: test_acsch

def test_acsch():
    x = Symbol('x')

    assert acsch(-x) == acsch(-x)
    assert acsch(x) == -acsch(-x)

    # values at fixed points
    assert acsch(1) == log(1 + sqrt(2))
    assert acsch(-1) == - log(1 + sqrt(2))
    assert acsch(0) == zoo
    assert acsch(2) == log((1+sqrt(5))/2)
    assert acsch(-2) == - log((1+sqrt(5))/2)

    assert acsch(I) == - I*pi/2
    assert acsch(-I) == I*pi/2
    assert acsch(-I*(sqrt(6) + sqrt(2))) == I*pi / 12
    assert acsch(I*(sqrt(2) + sqrt(6))) == -I*pi / 12
    assert acsch(-I*(1 + sqrt(5))) == I*pi / 10
    assert acsch(I*(1 + sqrt(5))) == -I*pi / 10
    assert acsch(-I*2 / sqrt(2 - sqrt(2))) == I*pi / 8
    assert acsch(I*2 / sqrt(2 - sqrt(2))) == -I*pi / 8
    assert acsch(-I*2) == I*pi / 6
    assert acsch(I*2) == -I*pi / 6
    assert acsch(-I*sqrt(2 + 2/sqrt(5))) == I*pi / 5
    assert acsch(I*sqrt(2 + 2/sqrt(5))) == -I*pi / 5
    assert acsch(-I*sqrt(2)) == I*pi / 4
    assert acsch(I*sqrt(2)) == -I*pi / 4
    assert acsch(-I*(sqrt(5)-1)) == 3*I*pi / 10
    assert acsch(I*(sqrt(5)-1)) == -3*I*pi / 10
    assert acsch(-I*2 / sqrt(3)) == I*pi / 3
    assert acsch(I*2 / sqrt(3)) == -I*pi / 3
    assert acsch(-I*2 / sqrt(2 + sqrt(2))) == 3*I*pi / 8
    assert acsch(I*2 / sqrt(2 + sqrt(2))) == -3*I*pi / 8
    assert acsch(-I*sqrt(2 - 2/sqrt(5))) == 2*I*pi / 5
    assert acsch(I*sqrt(2 - 2/sqrt(5))) == -2*I*pi / 5
    assert acsch(-I*(sqrt(6) - sqrt(2))) == 5*I*pi / 12
    assert acsch(I*(sqrt(6) - sqrt(2))) == -5*I*pi / 12

    # properties
    # acsch(x) == asinh(1/x)
    assert acsch(-I*sqrt(2)) == asinh(I/sqrt(2))
    assert acsch(-I*2 / sqrt(3)) == asinh(I*sqrt(3) / 2)

    # acsch(x) == -I*asin(I/x)
    assert acsch(-I*sqrt(2)) == -I*asin(-1/sqrt(2))
    assert acsch(-I*2 / sqrt(3)) == -I*asin(-sqrt(3)/2)

    # csch(acsch(x)) / x == 1
    assert expand_mul(csch(acsch(-I*(sqrt(6) + sqrt(2)))) / (-I*(sqrt(6) + sqrt(2)))) == 1
    assert expand_mul(csch(acsch(I*(1 + sqrt(5)))) / ((I*(1 + sqrt(5))))) == 1
    assert (csch(acsch(I*sqrt(2 - 2/sqrt(5)))) / (I*sqrt(2 - 2/sqrt(5)))).simplify() == 1
    assert (csch(acsch(-I*sqrt(2 - 2/sqrt(5)))) / (-I*sqrt(2 - 2/sqrt(5)))).simplify() == 1

    # numerical evaluation
    assert str(acsch(5*I+1).n(6)) == '0.0391819 - 0.193363*I'
    assert str(acsch(-5*I+1).n(6)) == '0.0391819 + 0.193363*I'
开发者ID:certik,项目名称:sympy,代码行数:56,代码来源:test_hyperbolic.py

示例5: test_asech

def test_asech():
    x = Symbol('x')

    assert asech(-x) == asech(-x)

    # values at fixed points
    assert asech(1) == 0
    assert asech(-1) == pi*I
    assert asech(0) == oo
    assert asech(2) == I*pi/3
    assert asech(-2) == 2*I*pi / 3

    # at infinites
    assert asech(oo) == I*pi/2
    assert asech(-oo) == I*pi/2
    assert asech(zoo) == nan

    assert asech(I) == log(1 + sqrt(2)) - I*pi/2
    assert asech(-I) == log(1 + sqrt(2)) + I*pi/2
    assert asech(sqrt(2) - sqrt(6)) == 11*I*pi / 12
    assert asech(sqrt(2 - 2/sqrt(5))) == I*pi / 10
    assert asech(-sqrt(2 - 2/sqrt(5))) == 9*I*pi / 10
    assert asech(2 / sqrt(2 + sqrt(2))) == I*pi / 8
    assert asech(-2 / sqrt(2 + sqrt(2))) == 7*I*pi / 8
    assert asech(sqrt(5) - 1) == I*pi / 5
    assert asech(1 - sqrt(5)) == 4*I*pi / 5
    assert asech(-sqrt(2*(2 + sqrt(2)))) == 5*I*pi / 8

    # properties
    # asech(x) == acosh(1/x)
    assert asech(sqrt(2)) == acosh(1/sqrt(2))
    assert asech(2/sqrt(3)) == acosh(sqrt(3)/2)
    assert asech(2/sqrt(2 + sqrt(2))) == acosh(sqrt(2 + sqrt(2))/2)
    assert asech(S(2)) == acosh(1/S(2))

    # asech(x) == I*acos(1/x)
    # (Note: the exact formula is asech(x) == +/- I*acos(1/x))
    assert asech(-sqrt(2)) == I*acos(-1/sqrt(2))
    assert asech(-2/sqrt(3)) == I*acos(-sqrt(3)/2)
    assert asech(-S(2)) == I*acos(-S.Half)
    assert asech(-2/sqrt(2)) == I*acos(-sqrt(2)/2)

    # sech(asech(x)) / x == 1
    assert expand_mul(sech(asech(sqrt(6) - sqrt(2))) / (sqrt(6) - sqrt(2))) == 1
    assert expand_mul(sech(asech(sqrt(6) + sqrt(2))) / (sqrt(6) + sqrt(2))) == 1
    assert (sech(asech(sqrt(2 + 2/sqrt(5)))) / (sqrt(2 + 2/sqrt(5)))).simplify() == 1
    assert (sech(asech(-sqrt(2 + 2/sqrt(5)))) / (-sqrt(2 + 2/sqrt(5)))).simplify() == 1
    assert (sech(asech(sqrt(2*(2 + sqrt(2))))) / (sqrt(2*(2 + sqrt(2))))).simplify() == 1
    assert expand_mul(sech(asech((1 + sqrt(5)))) / ((1 + sqrt(5)))) == 1
    assert expand_mul(sech(asech((-1 - sqrt(5)))) / ((-1 - sqrt(5)))) == 1
    assert expand_mul(sech(asech((-sqrt(6) - sqrt(2)))) / ((-sqrt(6) - sqrt(2)))) == 1

    # numerical evaluation
    assert str(asech(5*I).n(6)) == '0.19869 - 1.5708*I'
    assert str(asech(-5*I).n(6)) == '0.19869 + 1.5708*I'
开发者ID:certik,项目名称:sympy,代码行数:55,代码来源:test_hyperbolic.py

示例6: test_issue_3940

def test_issue_3940():
    a, b, c, d = symbols('a:d', positive=True, finite=True)
    assert integrate(exp(-x**2 + I*c*x), x) == \
        -sqrt(pi)*exp(-c**2/4)*erf(I*c/2 - x)/2
    assert integrate(exp(a*x**2 + b*x + c), x) == \
        sqrt(pi)*exp(c)*exp(-b**2/(4*a))*erfi(sqrt(a)*x + b/(2*sqrt(a)))/(2*sqrt(a))

    from sympy import expand_mul
    from sympy.abc import k
    assert expand_mul(integrate(exp(-x**2)*exp(I*k*x), (x, -oo, oo))) == \
        sqrt(pi)*exp(-k**2/4)
    a, d = symbols('a d', positive=True)
    assert expand_mul(integrate(exp(-a*x**2 + 2*d*x), (x, -oo, oo))) == \
        sqrt(pi)*exp(d**2/a)/sqrt(a)
开发者ID:baoqchau,项目名称:sympy,代码行数:14,代码来源:test_integrals.py

示例7: eval

    def eval(cls, arg):
        from sympy.simplify.simplify import signsimp

        if hasattr(arg, "_eval_Abs"):
            obj = arg._eval_Abs()
            if obj is not None:
                return obj
        # handle what we can
        arg = signsimp(arg, evaluate=False)
        if arg.is_Mul:
            known = []
            unk = []
            for t in arg.args:
                tnew = cls(t)
                if tnew.func is cls:
                    unk.append(tnew.args[0])
                else:
                    known.append(tnew)
            known = Mul(*known)
            unk = cls(Mul(*unk), evaluate=False) if unk else S.One
            return known * unk
        if arg is S.NaN:
            return S.NaN
        if arg.is_zero:  # it may be an Expr that is zero
            return S.Zero
        if arg.is_nonnegative:
            return arg
        if arg.is_nonpositive:
            return -arg
        if arg.is_imaginary:
            arg2 = -S.ImaginaryUnit * arg
            if arg2.is_nonnegative:
                return arg2
        if arg.is_real is False and arg.is_imaginary is False:
            from sympy import expand_mul

            return sqrt(expand_mul(arg * arg.conjugate()))
        if arg.is_real is None and arg.is_imaginary is None and arg.is_Add:
            if all(a.is_real or a.is_imaginary or (S.ImaginaryUnit * a).is_real for a in arg.args):
                from sympy import expand_mul

                return sqrt(expand_mul(arg * arg.conjugate()))
        if arg.is_Pow:
            base, exponent = arg.as_base_exp()
            if exponent.is_even and base.is_real:
                return arg
            if exponent.is_integer and base is S.NegativeOne:
                return S.One
开发者ID:Bercio,项目名称:sympy,代码行数:48,代码来源:complexes.py

示例8: eval

 def eval(cls, arg):
     if arg.is_Mul:
         known = []
         unk = []
         for t in arg.args:
             tnew = cls(t)
             if tnew.func is cls:
                 unk.append(tnew.args[0])
             else:
                 known.append(tnew)
         known = Mul(*known)
         unk = cls(Mul(*unk), evaluate=False) if unk else S.One
         return known*unk
     if arg is S.NaN:
         return S.NaN
     if arg.is_zero:
         return arg
     if arg.is_positive:
         return arg
     if arg.is_negative:
         return -arg
     if arg.is_real is False:
         from sympy import expand_mul
         return sqrt( expand_mul(arg * arg.conjugate()) )
     if arg.is_Pow:
         base, exponent = arg.as_base_exp()
         if exponent.is_even and base.is_real:
             return arg
开发者ID:MichaelMayorov,项目名称:sympy,代码行数:28,代码来源:complexes.py

示例9: _eval_as_leading_term

    def _eval_as_leading_term(self, x):
        from sympy import expand_mul, factor_terms

        old = self

        self = expand_mul(self)
        if not self.is_Add:
            return self.as_leading_term(x)

        unbounded = [t for t in self.args if t.is_unbounded]

        self = self.func(*[t.as_leading_term(x) for t in self.args]).removeO()
        if not self:
            # simple leading term analysis gave us 0 but we have to send
            # back a term, so compute the leading term (via series)
            return old.compute_leading_term(x)
        elif self is S.NaN:
            return old.func._from_args(unbounded)
        elif not self.is_Add:
            return self
        else:
            plain = self.func(*[s for s, _ in self.extract_leading_order(x)])
            rv = factor_terms(plain, fraction=False)
            rv_simplify = rv.simplify()
            # if it simplifies to an x-free expression, return that;
            # tests don't fail if we don't but it seems nicer to do this
            if x not in rv_simplify.free_symbols:
                if rv_simplify.is_zero and plain.is_zero is not True:
                    return (self - plain)._eval_as_leading_term(x)
                return rv_simplify
            return rv
开发者ID:Jeyatharsini,项目名称:sympy,代码行数:31,代码来源:add.py

示例10: _eval_as_leading_term

    def _eval_as_leading_term(self, x):
        from sympy import expand_mul, factor_terms

        old = self

        self = expand_mul(self)
        if not self.is_Add:
            return self.as_leading_term(x)

        unbounded = [t for t in self.args if t.is_unbounded]
        if unbounded:
            return Add._from_args(unbounded)

        self = Add(*[t.as_leading_term(x) for t in self.args]).removeO()
        if not self:
            # simple leading term analysis gave us 0 but we have to send
            # back a term, so compute the leading term (via series)
            return old.compute_leading_term(x)
        elif not self.is_Add:
            return self
        else:
            plain = Add(*[s for s, _ in self.extract_leading_order(x)])
            rv = factor_terms(plain, fraction=False)
            rv_fraction = factor_terms(rv, fraction=True)
            # if it simplifies to an x-free expression, return that;
            # tests don't fail if we don't but it seems nicer to do this
            if x not in rv_fraction.free_symbols:
                return rv_fraction
            return rv
开发者ID:StefenYin,项目名称:sympy,代码行数:29,代码来源:add.py

示例11: _eval_expand_trig

    def _eval_expand_trig(self, **hints):
        from sympy import expand_mul
        arg = self.args[0]
        x = None
        if arg.is_Add:  # TODO, implement more if deep stuff here
            # TODO: Do this more efficiently for more than two terms
            x, y = arg.as_two_terms()
            sx = sin(x, evaluate=False)._eval_expand_trig()
            sy = sin(y, evaluate=False)._eval_expand_trig()
            cx = cos(x, evaluate=False)._eval_expand_trig()
            cy = cos(y, evaluate=False)._eval_expand_trig()
            return sx*cy + sy*cx
        else:
            n, x = arg.as_coeff_Mul(rational=True)
            if n.is_Integer:  # n will be positive because of .eval
                # canonicalization

                # See http://mathworld.wolfram.com/Multiple-AngleFormulas.html
                if n.is_odd:
                    return (-1)**((n - 1)/2)*C.chebyshevt(n, sin(x))
                else:
                    return expand_mul((-1)**(n/2 - 1)*cos(x)*C.chebyshevu(n -
                        1, sin(x)), deep=False)
            pi_coeff = _pi_coeff(arg)
            if pi_coeff is not None:
                if pi_coeff.is_Rational:
                    return self.rewrite(sqrt)
        return sin(arg)
开发者ID:bhlegm,项目名称:sympy,代码行数:28,代码来源:trigonometric.py

示例12: _bell_poly

 def _bell_poly(n, prev):
     s = 1
     a = 1
     for k in xrange(2, n+1):
         a = a * (n-k+1) // (k-1)
         s += a * prev[k-1]
     return expand_mul(_sym * s)
开发者ID:BDGLunde,项目名称:sympy,代码行数:7,代码来源:numbers.py

示例13: _bell_incomplete_poly

    def _bell_incomplete_poly(n, k, symbols):
        r"""
        The second kind of Bell polynomials (incomplete Bell polynomials).

        Calculated by recurrence formula:

        .. math:: B_{n,k}(x_1, x_2, \dotsc, x_{n-k+1}) =
                \sum_{m=1}^{n-k+1}
                \x_m \binom{n-1}{m-1} B_{n-m,k-1}(x_1, x_2, \dotsc, x_{n-m-k})

        where
            B_{0,0} = 1;
            B_{n,0} = 0; for n>=1
            B_{0,k} = 0; for k>=1

        """
        if (n==0) and (k==0):
            return S.One
        elif (n==0) or (k==0):
            return S.Zero
        s = S.Zero
        a = S.One
        for m in xrange(1, n-k+2):
            s += a*bell._bell_incomplete_poly(n-m, k-1, symbols)*symbols[m-1]
            a = a*(n-m)/m
        return expand_mul(s)
开发者ID:BDGLunde,项目名称:sympy,代码行数:26,代码来源:numbers.py

示例14: test_sqrtdenest

def test_sqrtdenest():
    d = {sqrt(5 + 2 * sqrt(6)): sqrt(2) + sqrt(3),
        sqrt(sqrt(2)): sqrt(sqrt(2)),
        sqrt(5+sqrt(7)): sqrt(5+sqrt(7)),
        sqrt(3+sqrt(5+2*sqrt(7))):
            sqrt(6+3*sqrt(7))/(sqrt(2)*(5+2*sqrt(7))**Rational(1,4)) +
            3*(5+2*sqrt(7))**Rational(1,4)/(sqrt(2)*sqrt(6+3*sqrt(7))),
        sqrt(3+2*sqrt(3)): 3**Rational(1,4)/sqrt(2)+3/(sqrt(2)*3**Rational(1,4))}
    for i in d:
        assert sqrtdenest(i) == d[i] or denester([i])[0] == d[i]

    # this test caused a pattern recognition failure in sqrtdenest
    # nest = sqrt(2) + sqrt(5) - sqrt(7)
    nest = symbols('nest')
    x0, x1, x2, x3, x4, x5, x6 = symbols('x:7')
    l = sqrt(2) + sqrt(5)
    r = sqrt(7) + nest
    s = (l**2 - r**2).expand() + nest**2 # == nest**2
    ok = solve(nest**4 - s**2, nest)[1] # this will change if results order changes
    assert abs((l - r).subs(nest, ok).n()) < 1e-12
    x0 = sqrt(3)
    x2 = root(45*I*x0 - 28, 3)
    x3 = 19/x2
    x4 = x2 + x3
    x5 = -x4 - 14
    x6 = sqrt(-x5)
    ans = -x0*x6/3 + x0*sqrt(-x4 + 28 - 6*sqrt(210)*x6/x5)/3
    assert expand_mul(radsimp(ok) - ans) == 0
    # issue 2554
    eq = sqrt(sqrt(sqrt(2) + 2) + 2)
    assert sqrtdenest(eq) == eq
开发者ID:AlexandruFlorescu,项目名称:sympy,代码行数:31,代码来源:test_sqrtdenest.py

示例15: _combine_inverse

 def _combine_inverse(lhs, rhs):
     """
     Returns lhs - rhs, but treats arguments like symbols, so things like
     oo - oo return 0, instead of a nan.
     """
     from sympy import oo, I, expand_mul
     if lhs == oo and rhs == oo or lhs == oo*I and rhs == oo*I:
         return S.Zero
     return expand_mul(lhs - rhs)
开发者ID:ENuge,项目名称:sympy,代码行数:9,代码来源:add.py


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