本文整理汇总了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)
示例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)
示例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)
示例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)
示例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))
示例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))