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
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)
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
def checkselfdual(self): """ Checks whether coefficients are real to determine whether L-function is selfdual """ if not hasattr(self, '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
def complex_to_lattice(z, d, a, N=None): """ Given an algebraic number z of degree d, set of up the lattice which tries to express a in terms of powers of z, where the last two colmns are weighted by N. """ if N is None: N = ZZ(2)**(z.prec() - 10) nums = [z**k for k in range(d)] + [a] last_columns = [[round(N * real_part(x)) for x in nums], [round(N * imag_part(x)) for x in nums]] A = matrix(identity_matrix(len(nums)).columns() + last_columns) return A.transpose()
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
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
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)) else: return("-" + seriesvar(index, seriestype)) else: if seriescoefftype == "series": # return(ans + " - " + truncatenumber(float(abs(rp)), precision) + seriesvar(index, seriestype)) return(ans + " - " + truncatenumber(-1*rp, precision) + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + "-" + truncatenumber(-1*rp, precision)) elif seriescoefftype == "serieshtml": # return(ans + " − " + truncatenumber(float(abs(rp)), precision) + seriesvar(index, seriestype)) return(ans + " − " + truncatenumber(-1*rp, precision) + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncatenumber(rp, precision)) # if we get this far, it is pure imaginary elif ip > truncation: if float(abs(ip - 1)) < truncation: if seriescoefftype == "literal": return("i") elif seriescoefftype == "signed": return("+i") elif seriescoefftype == "factor": return("i") elif seriescoefftype == "series": return(ans + " + i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " + <em>i</em>" + "·" + seriesvar(index, seriestype)) # yes, em is not the right tag, but it is styled with CSS else: if seriescoefftype == "series": return(ans + truncatenumber(ip, precision) + "i " + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " + " + truncatenumber(ip, precision) + "<em>i</em> " + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + "+" + truncatenumber(ip, precision) + "i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncatenumber(ip, precision) + "i") elif ip < -1 * truncation: if float(abs(ip + 1)) < truncation: if seriescoefftype == "serieshtml": return(" − <em>i</em>" + "·" + seriesvar(index, seriestype)) else: return("-i" + "·" + seriesvar(index, seriestype)) else: if seriescoefftype == "series": return(ans + truncatenumber(ip, precision) + "i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " − " + truncatenumber(float(abs(ip)), precision) + "<em>i</em>" + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + truncatenumber(ip, precision) + " i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncatenumber(ip, precision) + "i") # elif float(abs(ip+1))<truncation: # return("-" + "i"+ seriesvar(index, seriestype)) else: return(latex(coeff) + seriesvar(index, seriestype))
def mu_fe_prec(x): if L._Ltype == 'maass': return real_digits(imag_part(x)) else: return 3
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)) else: if seriescoefftype == "series": return(ans + " - " + truncate_number(-1*rp, precision) + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + "-" + truncate_number(-1*rp, precision)) elif seriescoefftype == "serieshtml": return(ans + " − " + truncate_number(-1*rp, precision) + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncate_number(rp, precision)) # if we get this far, it is pure imaginary elif ip > truncation: if float(abs(ip - 1)) < truncation: if seriescoefftype == "literal": return("i") elif seriescoefftype == "signed": return("+i") elif seriescoefftype == "factor": return("i") elif seriescoefftype == "series": return(ans + " + i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " + <em>i</em>" + "·" + seriesvar(index, seriestype)) # yes, em is not the right tag, but it is styled with CSS else: if seriescoefftype == "series": return(ans + truncate_number(ip, precision) + "i " + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " + " + truncate_number(ip, precision) + "<em>i</em> " + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + "+" + truncate_number(ip, precision) + "i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncate_number(ip, precision) + "i") elif ip < -1 * truncation: if float(abs(ip + 1)) < truncation: if seriescoefftype == "factor": #assumes that factor is used in math mode return("- i \cdot" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(" − <em>i</em> ·" + seriesvar(index, seriestype)) else: return("- i" + seriesvar(index, seriestype)) else: if seriescoefftype == "series": return(ans + truncate_number(ip, precision) + "i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return(ans + " − " + truncate_number(float(abs(ip)), precision) + "<em>i</em>" + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return(ans + truncate_number(ip, precision) + " i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return(ans + truncate_number(ip, precision) + "i") else: return(latex(coeff) + seriesvar(index, seriestype))
def _sage_(self): import sage.all as sage return sage.imag_part(self.args[0]._sage_())
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
def seriescoeff(coeff, index, seriescoefftype, seriestype, digits): # seriescoefftype can be: series, serieshtml, signed, literal, factor try: if isinstance(coeff, string_types): if coeff == "I": rp = 0 ip = 1 coeff = CDF(I) elif coeff == "-I": rp = 0 ip = -1 coeff = CDF(-I) 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
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)) else: if seriescoefftype == "series": return (ans + " - " + truncate_number(-1 * rp, precision) + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return (ans + "-" + truncate_number(-1 * rp, precision)) elif seriescoefftype == "serieshtml": return (ans + " − " + truncate_number(-1 * rp, precision) + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "literal" or seriescoefftype == "factor": return (ans + truncate_number(rp, precision)) # if we get this far, it is pure imaginary elif ip > truncation: if float(abs(ip - 1)) < truncation: if seriescoefftype == "literal": return ("i") elif seriescoefftype == "signed": return ("+i") elif seriescoefftype == "factor": return ("i") elif seriescoefftype == "series": return (ans + " + i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return (ans + " + <em>i</em>" + "·" + seriesvar(index, seriestype)) # yes, em is not the right tag, but it is styled with CSS else: if seriescoefftype == "series": return (ans + truncate_number(ip, precision) + "i " + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return (ans + " + " + truncate_number(ip, precision) + "<em>i</em> " + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return (ans + "+" + truncate_number(ip, precision) + "i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return (ans + truncate_number(ip, precision) + "i") elif ip < -1 * truncation: if float(abs(ip + 1)) < truncation: if seriescoefftype == "factor": #assumes that factor is used in math mode return ("- i \cdot" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return (" − <em>i</em> ·" + seriesvar(index, seriestype)) else: return ("- i" + seriesvar(index, seriestype)) else: if seriescoefftype == "series": return (ans + truncate_number(ip, precision) + "i" + seriesvar(index, seriestype)) elif seriescoefftype == "serieshtml": return (ans + " − " + truncate_number(float(abs(ip)), precision) + "<em>i</em>" + "·" + seriesvar(index, seriestype)) elif seriescoefftype == "signed": return (ans + truncate_number(ip, precision) + " i") elif seriescoefftype == "literal" or seriescoefftype == "factor": return (ans + truncate_number(ip, precision) + "i") else: return (latex(coeff) + seriesvar(index, seriestype))
def mu_fe_prec(x): if not L.algebraic: return real_digits(imag_part(x)) else: return 3
def parse_complex_number(z): z_parsed = "(" + str(real_part(z)) + "," + str(imag_part(z)) + ")" return z_parsed
def parse_complex_number(z): zs = p2sage(z) z_parsed = "(" + str(real_part(zs)) + "," + str(imag_part(zs)) + ")" return z_parsed