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


Python C.im方法代码示例

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


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

示例1: eval

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
    def eval(cls, arg):
        if arg.is_integer:
            return arg
        if arg.is_imaginary or (S.ImaginaryUnit*arg).is_real:
            i = C.im(arg)
            if not i.has(S.ImaginaryUnit):
                return cls(i)*S.ImaginaryUnit
            return cls(arg, evaluate=False)

        v = cls._eval_number(arg)
        if v is not None:
            return v

        # Integral, numerical, symbolic part
        ipart = npart = spart = S.Zero

        # Extract integral (or complex integral) terms
        terms = Add.make_args(arg)

        for t in terms:
            if t.is_integer or (t.is_imaginary and C.im(t).is_integer):
                ipart += t
            elif t.has(C.Symbol):
                spart += t
            else:
                npart += t

        if not (npart or spart):
            return ipart

        # Evaluate npart numerically if independent of spart
        if npart and (
            not spart or
            npart.is_real and (spart.is_imaginary or (S.ImaginaryUnit*spart).is_real) or
                npart.is_imaginary and spart.is_real):
            try:
                re, im = get_integer_part(
                    npart, cls._dir, {}, return_ints=True)
                ipart += C.Integer(re) + C.Integer(im)*S.ImaginaryUnit
                npart = S.Zero
            except (PrecisionExhausted, NotImplementedError):
                pass

        spart += npart
        if not spart:
            return ipart
        elif spart.is_imaginary or (S.ImaginaryUnit*spart).is_real:
            return ipart + cls(C.im(spart), evaluate=False)*S.ImaginaryUnit
        else:
            return ipart + cls(spart, evaluate=False)
开发者ID:Bercio,项目名称:sympy,代码行数:52,代码来源:integers.py

示例2: canonize

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
    def canonize(cls, arg):
        if arg.is_integer:
            return arg
        if arg.is_imaginary:
            return cls(C.im(arg))*S.ImaginaryUnit

        v = cls._eval_number(arg)
        if v is not None:
            return v

        # Integral, numerical, symbolic part
        ipart = npart = spart = S.Zero

        # Extract integral (or complex integral) terms
        if arg.is_Add:
            terms = arg.args
        else:
            terms = [arg]

        for t in terms:
            if t.is_integer or (t.is_imaginary and C.im(t).is_integer):
                ipart += t
            elif t.atoms(C.Symbol):
                spart += t
            else:
                npart += t

        if not (npart or spart):
            return ipart

        # Evaluate npart numerically if independent of spart
        orthogonal = (npart.is_real and spart.is_imaginary) or \
            (npart.is_imaginary and spart.is_real)
        if npart and ((not spart) or orthogonal):
            try:
                re, im = get_integer_part(npart, cls._dir, {}, return_ints=True)
                ipart += C.Integer(re) + C.Integer(im)*S.ImaginaryUnit
                npart = S.Zero
            except (PrecisionExhausted, NotImplementedError):
                pass

        spart = npart + spart
        if not spart:
            return ipart
        elif spart.is_imaginary:
            return ipart + cls(C.im(spart),evaluate=False)*S.ImaginaryUnit
        else:
            return ipart + cls(spart, evaluate=False)
开发者ID:jcockayne,项目名称:sympy-rkern,代码行数:50,代码来源:integers.py

示例3: _eval_expand_trig

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
    def _eval_expand_trig(self, **hints):
        arg = self.args[0]
        x = None
        if arg.is_Add:
            from sympy import symmetric_poly
            n = len(arg.args)
            TX = []
            for x in arg.args:
                tx = tan(x, evaluate=False)._eval_expand_trig()
                TX.append(tx)

            Yg = numbered_symbols('Y')
            Y = [ Yg.next() for i in xrange(n) ]

            p = [0,0]
            for i in xrange(n+1):
                p[1-i%2] += symmetric_poly(i,Y)*(-1)**((i%4)//2)
            return (p[0]/p[1]).subs(zip(Y,TX))

        else:
            coeff, terms = arg.as_coeff_Mul(rational=True)
            if coeff.is_Integer and coeff > 1:
                I = S.ImaginaryUnit
                z = C.Symbol('dummy',real=True)
                P = ((1+I*z)**coeff).expand()
                return (C.im(P)/C.re(P)).subs([(z,tan(terms))])
        return tan(arg)
开发者ID:bhlegm,项目名称:sympy,代码行数:29,代码来源:trigonometric.py

示例4: _eval_expand_trig

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
    def _eval_expand_trig(self, **hints):
        arg = self.args[0]
        x = None
        if arg.is_Add:
            from sympy import symmetric_poly

            n = len(arg.args)
            CX = []
            for x in arg.args:
                cx = cot(x, evaluate=False)._eval_expand_trig()
                CX.append(cx)

            Yg = numbered_symbols("Y")
            Y = [Yg.next() for i in xrange(n)]

            p = [0, 0]
            for i in xrange(n, -1, -1):
                p[(n - i) % 2] += symmetric_poly(i, Y) * (-1) ** (((n - i) % 4) // 2)
            return (p[0] / p[1]).subs(zip(Y, CX))
        else:
            coeff, terms = arg.as_coeff_Mul(rational=True)
            if coeff.is_Integer and coeff > 1:
                I = S.ImaginaryUnit
                z = C.Symbol("dummy", real=True)
                P = ((z + I) ** coeff).expand()
                return (C.re(P) / C.im(P)).subs([(z, cot(terms))])
        return cot(arg)
开发者ID:amitjamadagni,项目名称:sympy,代码行数:29,代码来源:trigonometric.py

示例5: as_real_imag

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
 def as_real_imag(self, deep=True, **hints):
     other = []
     coeff = S(1)
     for a in self.args:
         if a.is_real:
             coeff *= a
         else:
             other.append(a)
     m = Mul(*other)
     if hints.get('ignore') == m:
         return None
     else:
         return (coeff*C.re(m), coeff*C.im(m))
开发者ID:FireJade,项目名称:sympy,代码行数:15,代码来源:mul.py

示例6: as_real_imag

# 需要导入模块: from sympy.core.basic import C [as 别名]
# 或者: from sympy.core.basic.C import im [as 别名]
 def as_real_imag(self, deep=True, **hints):
     other = []
     coeff = S(1)
     for a in self.args:
         if a.is_real:
             coeff *= a
         elif a.is_commutative:
             # search for complex conjugate pairs:
             for i, x in enumerate(other):
                 if x == a.conjugate():
                     coeff *= C.Abs(x)**2
                     del other[i]
                     break
             else:
                 other.append(a)
         else:
             other.append(a)
     m = Mul(*other)
     if hints.get('ignore') == m:
         return None
     else:
         return (coeff*C.re(m), coeff*C.im(m))
开发者ID:Abhityagi16,项目名称:sympy,代码行数:24,代码来源:mul.py


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