當前位置: 首頁>>代碼示例>>Python>>正文


Python C.re方法代碼示例

本文整理匯總了Python中basic.C.re方法的典型用法代碼示例。如果您正苦於以下問題:Python C.re方法的具體用法?Python C.re怎麽用?Python C.re使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在basic.C的用法示例。


在下文中一共展示了C.re方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _eval_expand_complex

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
    def _eval_expand_complex(self, deep=True, **hints):
        if self.exp.is_Integer:
            exp = self.exp
            re, im = self.base.as_real_imag()
            if exp >= 0:
                base = re + S.ImaginaryUnit*im
            else:
                mag = re**2 + im**2
                base = re/mag - S.ImaginaryUnit*(im/mag)
                exp = -exp
            return (base**exp).expand()
        elif self.exp.is_Rational:
            # NOTE: This is not totally correct since for x**(p/q) with
            #       x being imaginary there are actually q roots, but
            #       only a single one is returned from here.
            re, im = self.base.as_real_imag()

            r = (re**2 + im**2)**S.Half
            t = C.atan2(im, re)

            rp, tp = r**self.exp, t*self.exp

            return rp*C.cos(tp) + rp*C.sin(tp)*S.ImaginaryUnit
        else:
            if deep:
                hints['complex'] = False
                return C.re(self.expand(deep, **hints)) + \
                S.ImaginaryUnit*C.im(self. expand(deep, **hints))
            else:
                return C.re(self) + S.ImaginaryUnit*C.im(self)
            return C.re(self) + S.ImaginaryUnit*C.im(self)
開發者ID:Sumith1896,項目名稱:sympy-polys,代碼行數:33,代碼來源:power.py

示例2: as_real_imag

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
    def as_real_imag(self, deep=True, **hints):
        from sympy.core.symbol import symbols
        from sympy.polys.polytools import poly
        from sympy.core.function import expand_multinomial
        if self.exp.is_Integer:
            exp = self.exp
            re, im = self.base.as_real_imag(deep=deep)
            a, b = symbols('a, b', dummy=True)
            if exp >= 0:
                if re.is_Number and im.is_Number:
                    # We can be more efficient in this case
                    expr = expand_multinomial(self.base**exp)
                    return expr.as_real_imag()

                expr = poly((a + b)**exp) # a = re, b = im; expr = (a + b*I)**exp
            else:
                mag = re**2 + im**2
                re, im = re/mag, -im/mag
                if re.is_Number and im.is_Number:
                    # We can be more efficient in this case
                    expr = expand_multinomial((re + im*S.ImaginaryUnit)**-exp)
                    return expr.as_real_imag()

                expr = poly((a + b)**-exp)

            # Terms with even b powers will be real
            r = [i for i in expr.terms() if not i[0][1] % 2]
            re_part = Add(*[cc*a**aa*b**bb for (aa, bb), cc in r])
            # Terms odd b powers will be imaginary
            r = [i for i in expr.terms() if i[0][1] % 4 == 1]
            im_part1 = Add(*[cc*a**aa*b**bb for (aa, bb), cc in r])
            r = [i for i in expr.terms() if i[0][1] % 4 == 3]
            im_part3 = Add(*[cc*a**a*b**bb for (aa, bb), cc in r])

            return (re_part.subs({a: re, b: S.ImaginaryUnit*im}),
            im_part1.subs({a: re, b: im}) + im_part3.subs({a: re, b: -im}))

        elif self.exp.is_Rational:
            # NOTE: This is not totally correct since for x**(p/q) with
            #       x being imaginary there are actually q roots, but
            #       only a single one is returned from here.
            re, im = self.base.as_real_imag(deep=deep)

            r = (re**2 + im**2)**S.Half
            t = C.atan2(im, re)

            rp, tp = r**self.exp, t*self.exp

            return (rp*C.cos(tp), rp*C.sin(tp))
        else:

            if deep:
                hints['complex'] = False
                return (C.re(self.expand(deep, complex=False)),
                C.im(self. expand(deep, **hints)))
            else:
                return (C.re(self), C.im(self))
開發者ID:bibile,項目名稱:sympy,代碼行數:59,代碼來源:power.py

示例3: get_integer_part

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
def get_integer_part(expr, no, options, return_ints=False):
    """
    With no = 1, computes ceiling(expr)
    With no = -1, computes floor(expr)

    Note: this function either gives the exact result or signals failure.
    """

    # The expression is likely less than 2^30 or so
    assumed_size = 30
    ire, iim, ire_acc, iim_acc = evalf(expr, assumed_size, options)

    # We now know the size, so we can calculate how much extra precision
    # (if any) is needed to get within the nearest integer
    if ire and iim:
        gap = max(fastlog(ire)-ire_acc, fastlog(iim)-iim_acc)
    elif ire:
        gap = fastlog(ire)-ire_acc
    elif iim:
        gap = fastlog(iim)-iim_acc
    else:
        # ... or maybe the expression was exactly zero
        return None, None, None, None

    margin = 10

    if gap >= -margin:
        ire, iim, ire_acc, iim_acc = evalf(expr, margin+assumed_size+gap, options)

    # We can now easily find the nearest integer, but to find floor/ceil, we
    # must also calculate whether the difference to the nearest integer is
    # positive or negative (which may fail if very close)
    def calc_part(expr, nexpr):
        nint = int(to_int(nexpr, round_nearest))
        expr = C.Add(expr, -nint, evaluate=False)
        x, _, x_acc, _ = evalf(expr, 10, options)
        check_target(expr, (x, None, x_acc, None), 3)
        nint += int(no*(mpf_cmp(x or fzero, fzero) == no))
        nint = from_int(nint)
        return nint, fastlog(nint) + 10

    re, im, re_acc, im_acc = None, None, None, None

    if ire:
        re, re_acc = calc_part(C.re(expr, evaluate=False), ire)
    if iim:
        im, im_acc = calc_part(C.im(expr, evaluate=False), iim)

    if return_ints:
        return int(to_int(re or fzero)), int(to_int(im or fzero))
    return re, im, re_acc, im_acc
開發者ID:cran,項目名稱:rSymPy,代碼行數:53,代碼來源:evalf.py

示例4: as_real_imag

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
    def as_real_imag(self, deep=True):
        """Performs complex expansion on 'self' and returns a tuple
           containing collected both real and imaginary parts. This
           method can't be confused with re() and im() functions,
           which does not perform complex expansion at evaluation.

           However it is possible to expand both re() and im()
           functions and get exactly the same results as with
           a single call to this function.

           >>> from sympy import symbols, I

           >>> x, y = symbols('xy', real=True)

           >>> (x + y*I).as_real_imag()
           (x, y)

           >>> from sympy.abc import z, w

           >>> (z + w*I).as_real_imag()
           (-im(w) + re(z), im(z) + re(w))

        """
        return (C.re(self), C.im(self))
開發者ID:bibile,項目名稱:sympy,代碼行數:26,代碼來源:expr.py

示例5: _eval_expand_complex

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
 def _eval_expand_complex(self, deep=True, **hints):
     if deep:
         func = self.func(*[ a.expand(deep, **hints) for a in self.args ])
     else:
         func = self.func(*self.args)
     return C.re(func) + S.ImaginaryUnit * C.im(func)
開發者ID:hazelnusse,項目名稱:sympy-old,代碼行數:8,代碼來源:function.py

示例6: _eval_expand_complex

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
 def _eval_expand_complex(self, *args):
     return C.re(self) + C.im(self)*S.ImaginaryUnit
開發者ID:gnulinooks,項目名稱:sympy,代碼行數:4,代碼來源:symbol.py

示例7: as_real_imag

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
 def as_real_imag(self, deep=True):
     return (C.re(self), C.im(self))
開發者ID:bibile,項目名稱:sympy,代碼行數:4,代碼來源:symbol.py

示例8: _eval_expand_complex

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
 def _eval_expand_complex(self, *args):
     func = self.func(*[ a._eval_expand_complex(*args) for a in self.args ])
     return C.re(func) + S.ImaginaryUnit * C.im(func)
開發者ID:gnulinooks,項目名稱:sympy,代碼行數:5,代碼來源:function.py

示例9: _eval_expand_complex

# 需要導入模塊: from basic import C [as 別名]
# 或者: from basic.C import re [as 別名]
 def _eval_expand_complex(self, deep=True, **hints):
         return C.re(self) + C.im(self)*S.ImaginaryUnit
開發者ID:Sumith1896,項目名稱:sympy-polys,代碼行數:4,代碼來源:symbol.py


注:本文中的basic.C.re方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。