本文整理汇总了Python中sage.all.imag_part函数的典型用法代码示例。如果您正苦于以下问题:Python imag_part函数的具体用法?Python imag_part怎么用?Python imag_part使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imag_part函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkselfdual
def checkselfdual(self):
""" Checks whether coefficients are real to determine
whether L-function is selfdual
"""
self.selfdual = True
for n in range(1, min(8, len(self.dirichlet_coefficients))):
if abs(imag_part(self.dirichlet_coefficients[n] / self.dirichlet_coefficients[0])) > 0.00001:
self.selfdual = False
示例2: createLcalcfile_ver1
def createLcalcfile_ver1(L):
""" Creates the lcalcfile of L, version 1
"""
thefile = ""
if L.selfdual:
thefile += "2\n" # 2 means real coefficients
else:
thefile += "3\n" # 3 means complex coefficients
thefile += "0\n" # 0 means unknown type
thefile += str(len(L.dirichlet_coefficients)) + "\n"
thefile += "0\n" # assume the coefficients are not periodic
thefile += str(L.quasidegree) + "\n" # number of actual Gamma functions
for n in range(0, L.quasidegree):
thefile = thefile + str(L.kappa_fe[n]) + "\n"
thefile = thefile + str(real_part(L.lambda_fe[n])) + " " + str(imag_part(L.lambda_fe[n])) + "\n"
thefile += str(real_part(L.Q_fe)) + "\n"
thefile += str(real_part(L.sign)) + " " + str(imag_part(L.sign)) + "\n"
thefile += str(len(L.poles)) + "\n" # counts number of poles
for n in range(0, len(L.poles)):
thefile += str(real_part(L.poles[n])) + " " + str(imag_part(L.poles[n])) + "\n" # pole location
thefile += str(
real_part(L.residues[n])) + " " + str(imag_part(L.residues[n])) + "\n" # residue at pole
for n in range(0, len(L.dirichlet_coefficients)):
thefile += str(real_part(L.dirichlet_coefficients[n])) # add real part of Dirichlet coefficient
if not L.selfdual: # if not selfdual
thefile += " " + str(imag_part(L.dirichlet_coefficients[n]))
# add imaginary part of Dirichlet coefficient
thefile += "\n"
return(thefile)
示例3: checkselfdual
def checkselfdual(self):
""" Checks whether coefficients are real to determine
whether L-function is selfdual
"""
if not hasattr(self, 'selfdual'):
# if 'selfdual' not in self:
# if self.selfdual not in [True, False]:
self.selfdual = True
for n in range(1, min(8, len(self.dirichlet_coefficients))):
if abs(imag_part(self.dirichlet_coefficients[n] / self.dirichlet_coefficients[0])) > 0.00001:
self.selfdual = False
示例4: pretty_coeff
def pretty_coeff(c, prec=9):
'''
Format the complex coefficient `c` for display on the website.
'''
if isinstance(c, complex):
x = c.real
y = c.imag
else:
x = real_part(c)
y = imag_part(c)
# the number of digits to display 'prec' digits after the .
digits = lambda z: len(str(abs(z)).split('.')[0].lstrip('0')) + prec
res = display_complex(x, y, digits = max(map(digits, [x, y])))
if res == '0':
return ' 0'
else:
return res
示例5: seriescoeff
def seriescoeff(coeff, index, seriescoefftype, seriestype, truncationexp, precision):
# seriescoefftype can be: series, serieshtml, signed, literal, factor
# truncationexp is used to determine if a number is 'really' 0 or 1 or -1 or I or -I or 0.5 or -0.5
# precision is used to truncate decimal numbers
truncation = float(10 ** truncationexp)
try:
if isinstance(coeff,str) or isinstance(coeff,unicode):
coeff = string2number(coeff)
if type(coeff) == complex:
rp = coeff.real
ip = coeff.imag
else:
rp = real_part(coeff)
ip = imag_part(coeff)
except TypeError: # mostly a hack for Dirichlet L-functions
if seriescoefftype == "serieshtml":
if coeff == "I":
return " + " + "$i$" + "·" + seriesvar(index, seriestype)
elif coeff == "-I":
return "−" + " $i$" + "·" + seriesvar(index, seriestype)
else:
return " +" + coeff + "·" + seriesvar(index, seriestype)
else:
return coeff
# below we use float(abs()) instead of abs() to avoid a sage bug
if (float(abs(rp)) > truncation) & (float(abs(ip)) > truncation): # has a real and an imaginary part
ans = ""
if seriescoefftype == "series" or seriescoefftype == "signed":
ans += "+"
ans += "("
ans += truncate_number(rp, precision)
elif seriescoefftype == "serieshtml":
ans += " + "
ans += "("
if rp > 0:
ans += truncate_number(rp, precision)
else:
ans += "−"+truncate_number(float(abs(rp)), precision)
elif seriescoefftype == "factor":
ans += "("
ans += truncate_number(rp, precision)
else:
ans += truncate_number(rp, precision)
if ip > 0:
ans += " + "
if seriescoefftype == "series" or seriescoefftype == "signed":
ans += truncate_number(ip, precision) + " i"
elif seriescoefftype == "serieshtml":
if ip > 0:
ans += truncate_number(ip, precision)
else:
ans += " − "+truncate_number(float(abs(ip)), precision)
ans += "<em>i</em>"
elif seriescoefftype == "factor":
ans += truncate_number(ip, precision) + "i" + ")"
else:
ans += truncate_number(ip, precision) + "i"
if seriescoefftype == "series" or seriescoefftype == "serieshtml" or seriescoefftype == "signed":
return(ans + ")" + " " + seriesvar(index, seriestype))
else:
return(ans)
elif (float(abs(rp)) < truncation) & (float(abs(ip)) < truncation):
if seriescoefftype != "literal":
return("")
else:
return("0")
# if we get this far, either pure real or pure imaginary
ans = ""
if rp > truncation:
if float(abs(rp - 1)) < truncation:
if seriescoefftype == "literal":
return("1")
elif seriescoefftype == "signed":
return("+1")
elif seriescoefftype == "factor":
return("")
elif seriescoefftype == "series" or seriescoefftype == "serieshtml":
return(ans + " + " + seriesvar(index, seriestype))
else:
if seriescoefftype == "series" or seriescoefftype == "serieshtml":
return(" + " + ans + truncate_number(rp, precision) + "·" + seriesvar(index, seriestype))
elif seriescoefftype == "signed":
return(ans + "+" + truncate_number(rp, precision))
elif seriescoefftype == "literal" or seriescoefftype == "factor":
return(ans + truncate_number(rp, precision))
elif rp < -1 * truncation:
if float(abs(rp + 1)) < truncation:
if seriescoefftype == "literal":
return("-1" + seriesvar(index, seriestype))
elif seriescoefftype == "signed":
return("-1" + seriesvar(index, seriestype))
elif seriescoefftype == "factor":
return("-" + seriesvar(index, seriestype))
elif seriescoefftype == "series": # adding space between minus sign and value
return(" - " + seriesvar(index, seriestype))
elif seriescoefftype == "serieshtml": # adding space between minus sign and value
return(" − " + seriesvar(index, seriestype))
else:
return("-" + seriesvar(index, seriestype))
#.........这里部分代码省略.........
示例6: mu_fe_prec
def mu_fe_prec(x):
if L._Ltype == 'maass':
return real_digits(imag_part(x))
else:
return 3
示例7: seriescoeff
def seriescoeff(coeff, index, seriescoefftype, seriestype, digits):
# seriescoefftype can be: series, serieshtml, signed, literal, factor
try:
if isinstance(coeff,str) or isinstance(coeff,unicode):
if coeff == "I":
rp = 0
ip = 1
elif coeff == "-I":
rp = 0
ip = -1
else:
coeff = string2number(coeff)
if type(coeff) == complex:
rp = coeff.real
ip = coeff.imag
else:
rp = real_part(coeff)
ip = imag_part(coeff)
except TypeError: # mostly a hack for Dirichlet L-functions
if seriescoefftype == "serieshtml":
return " +" + coeff + "·" + seriesvar(index, seriestype)
else:
return coeff
ans = ""
if seriescoefftype in ["series", "serieshtml", "signed", "factor"]:
parenthesis = True
else:
parenthesis = False
coeff_display = display_complex(rp, ip, digits, method="truncate", parenthesis=parenthesis)
# deal with the zero case
if coeff_display == "0":
if seriescoefftype=="literal":
return "0"
else:
return ""
if seriescoefftype=="literal":
return coeff_display
if seriescoefftype == "factor":
if coeff_display == "1":
return ""
elif coeff_display == "-1":
return "-"
#add signs and fix spacing
if seriescoefftype in ["series", "serieshtml"]:
if coeff_display == "1":
coeff_display = " + "
elif coeff_display == "-1":
coeff_display = " - "
# purely real or complex number that starts with -
elif coeff_display[0] == '-':
# add spacings around the minus
coeff_display = coeff_display.replace('-',' - ')
else:
ans += " + "
elif seriescoefftype == 'signed' and coeff_display[0] != '-':
# add the plus without the spaces
ans += "+"
ans += coeff_display
if seriescoefftype == "serieshtml":
ans = ans.replace('i',"<em>i</em>").replace('-',"−")
if coeff_display[-1] not in [')', ' ']:
ans += "·"
if seriescoefftype in ["series", "serieshtml", "signed"]:
ans += seriesvar(index, seriestype)
return ans
示例8: _sage_
def _sage_(self):
import sage.all as sage
return sage.imag_part(self.args[0]._sage_())
示例9: parse_complex_number
def parse_complex_number(z):
z_parsed = "(" + str(real_part(z)) + "," + str(imag_part(z)) + ")"
return z_parsed
示例10: seriescoeff
def seriescoeff(coeff, index, seriescoefftype, seriestype, truncationexp, precision):
# seriescoefftype can be: series, serieshtml, signed, literal, factor
truncation = float(10 ** truncationexp)
try:
if isinstance(coeff,str) or isinstance(coeff,unicode):
coeff = string2number(coeff)
if type(coeff) == complex:
rp = coeff.real
ip = coeff.imag
else:
rp = real_part(coeff)
ip = imag_part(coeff)
except TypeError: # mostly a hack for Dirichlet L-functions
if seriescoefftype == "serieshtml":
if coeff == "I":
return " + " + "$i$" + "·" + seriesvar(index, seriestype)
elif coeff == "-I":
return "−" + " $i$" + "·" + seriesvar(index, seriestype)
else:
return " +" + coeff + "·" + seriesvar(index, seriestype)
else:
return coeff
# below we use float(abs()) instead of abs() to avoid a sage bug
if (float(abs(rp)) > truncation) & (float(abs(ip)) > truncation): # has a real and an imaginary part
ans = ""
if seriescoefftype == "series" or seriescoefftype == "signed":
ans += "+"
ans += "("
ans += truncatenumber(rp, precision)
elif seriescoefftype == "serieshtml":
ans += " + "
ans += "("
if rp > 0:
ans += truncatenumber(rp, precision)
else:
ans += "−"+truncatenumber(float(abs(rp)), precision)
elif seriescoefftype == "factor":
ans += "("
ans += truncatenumber(rp, precision)
else:
ans += truncatenumber(rp, precision)
if ip > 0:
ans += " + "
if seriescoefftype == "series" or seriescoefftype == "signed":
ans += truncatenumber(ip, precision) + " i"
elif seriescoefftype == "serieshtml":
if ip > 0:
ans += truncatenumber(ip, precision)
else:
ans += " − "+truncatenumber(float(abs(ip)), precision)
ans += "<em>i</em>"
elif seriescoefftype == "factor":
ans += truncatenumber(ip, precision) + "i" + ")"
else:
ans += truncatenumber(ip, precision) + "i"
if seriescoefftype == "series" or seriescoefftype == "serieshtml" or seriescoefftype == "signed":
return(ans + ")" + " " + seriesvar(index, seriestype))
else:
return(ans)
elif (float(abs(rp)) < truncation) & (float(abs(ip)) < truncation):
if seriescoefftype != "literal":
return("")
else:
return("0")
# if we get this far, either pure real or pure imaginary
ans = ""
# if seriescoefftype=="series":
# ans=ans+" + "
# commenting out the above "if" code so as to fix + - problem
# logger.info("rp={0}".format(rp))
if rp > truncation:
if float(abs(rp - 1)) < truncation:
if seriescoefftype == "literal":
return("1")
elif seriescoefftype == "signed":
return("+1")
elif seriescoefftype == "factor":
return("")
elif seriescoefftype == "series" or seriescoefftype == "serieshtml":
return(ans + " + " + seriesvar(index, seriestype))
else:
if seriescoefftype == "series" or seriescoefftype == "serieshtml":
return(" + " + ans + truncatenumber(rp, precision) + "·" + seriesvar(index, seriestype))
elif seriescoefftype == "signed":
return(ans + "+" + truncatenumber(rp, precision))
elif seriescoefftype == "literal" or seriescoefftype == "factor":
return(ans + truncatenumber(rp, precision))
elif rp < -1 * truncation:
if float(abs(rp + 1)) < truncation:
if seriescoefftype == "literal":
return("-1" + seriesvar(index, seriestype))
elif seriescoefftype == "signed":
return("-1" + seriesvar(index, seriestype))
elif seriescoefftype == "factor":
return("-" + seriesvar(index, seriestype))
elif seriescoefftype == "series": # adding space between minus sign and value
return(" - " + seriesvar(index, seriestype))
elif seriescoefftype == "serieshtml": # adding space between minus sign and value
return(" − " + seriesvar(index, seriestype))
#.........这里部分代码省略.........