本文整理汇总了Python中sage.all.latex函数的典型用法代码示例。如果您正苦于以下问题:Python latex函数的具体用法?Python latex怎么用?Python latex使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了latex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_group_webpage
def render_group_webpage(args):
data = None
info = {}
if 'label' in args:
label = clean_input(args['label'])
label = label.replace('t', 'T')
C = base.getDBConnection()
data = C.transitivegroups.groups.find_one({'label': label})
if data is None:
bread = get_bread([("Search error", url_for('.search'))])
info['err'] = "Group " + label + " was not found in the database."
info['label'] = label
return search_input_error(info, bread)
title = 'Galois Group:' + label
n = data['n']
t = data['t']
data['yesno'] = yesno
order = data['order']
data['orderfac'] = latex(ZZ(order).factor())
orderfac = latex(ZZ(order).factor())
data['ordermsg'] = "$%s=%s$" % (order, latex(orderfac))
if ZZ(order) == 1:
data['ordermsg'] = "$1$"
if ZZ(order).is_prime():
data['ordermsg'] = "$%s$ (is prime)" % order
pgroup = len(ZZ(order).prime_factors()) < 2
if n == 1:
G = gap.SmallGroup(n, t)
else:
G = gap.TransitiveGroup(n, t)
if ZZ(order) < ZZ('10000000000'):
ctable = chartable(n, t)
else:
ctable = 'Group too large'
data['gens'] = generators(n, t)
if n == 1 and t == 1:
data['gens'] = 'None needed'
data['chartable'] = ctable
data['parity'] = "$%s$" % data['parity']
data['cclasses'] = conjclasses(G, n)
data['subinfo'] = subfield_display(C, n, data['subs'])
data['resolve'] = resolve_display(C, data['resolve'])
# if len(data['resolve']) == 0: data['resolve'] = 'None'
data['otherreps'] = otherrep_display(n, t, C, data['repns'])
prop2 = [
('Order:', '\(%s\)' % order),
('n:', '\(%s\)' % data['n']),
('Cyclic:', yesno(data['cyc'])),
('Abelian:', yesno(data['ab'])),
('Solvable:', yesno(data['solv'])),
('Primitive:', yesno(data['prim'])),
('$p$-group:', yesno(pgroup)),
('Name:', group_display_short(n, t, C)),
]
info.update(data)
bread = get_bread([(label, ' ')])
return render_template("gg-show-group.html", credit=GG_credit, title=title, bread=bread, info=info, properties2=prop2)
示例2: splitint
def splitint(a,p):
if a==1:
return ' '
j = valuation(a,p)
if j==0:
return str(a)
a = a/p**j
if a==1:
return latex(ZZ(p**j).factor())
return str(a)+r'\cdot'+latex(ZZ(p**j).factor())
示例3: safe_reduce
def safe_reduce(f):
if not m:
return latex(f)
try:
if f in sam.field():
return latex(redc(f))
else:
return latex(redp(f))
except ZeroDivisionError:
return '\\textrm{Unable to reduce} \\bmod\\mathfrak{m}'
示例4: make_map_latex
def make_map_latex(map_str):
# FIXME: Get rid of nu when map is defined over QQ
if "nu" not in map_str:
R0 = QQ
else:
R0 = PolynomialRing(QQ,'nu')
R = PolynomialRing(R0,2,'x,y')
F = FractionField(R)
phi = F(map_str)
num = phi.numerator()
den = phi.denominator()
c_num = num.denominator()
c_den = den.denominator()
lc = c_den/c_num
# rescale coeffs to make them integral. then try to factor out gcds
# numerator
num_new = c_num*num
num_cs = num_new.coefficients()
if R0 == QQ:
num_cs_ZZ = num_cs
else:
num_cs_ZZ = []
for el in num_cs:
num_cs_ZZ = num_cs_ZZ + el.coefficients()
num_gcd = gcd(num_cs_ZZ)
# denominator
den_new = c_den*den
den_cs = den_new.coefficients()
if R0 == QQ:
den_cs_ZZ = den_cs
else:
den_cs_ZZ = []
for el in den_cs:
den_cs_ZZ = den_cs_ZZ + el.coefficients()
den_gcd = gcd(den_cs_ZZ)
lc = lc*(num_gcd/den_gcd)
num_new = num_new/num_gcd
den_new = den_new/den_gcd
# make strings for lc, num, and den
num_str = latex(num_new)
den_str = latex(den_new)
if lc==1:
lc_str=""
else:
lc_str = latex(lc)
if den_new==1:
if lc ==1:
phi_str = num_str
else:
phi_str = lc_str+"("+num_str+")"
else:
phi_str = lc_str+"\\frac{"+num_str+"}"+"{"+den_str+"}"
return phi_str
示例5: make_curve_latex
def make_curve_latex(crv_str):
# FIXME: Get rid of nu when map is defined over QQ
if "nu" not in crv_str:
R0 = QQ
else:
R0 = PolynomialRing(QQ,'nu')
R = PolynomialRing(R0,2,'x,y')
F = FractionField(R)
sides = crv_str.split("=")
lhs = latex(F(sides[0]))
rhs = latex(F(sides[1]))
eqn_str = lhs + '=' + rhs
return eqn_str
示例6: _latex_using_dpd_depth1
def _latex_using_dpd_depth1(self, dpd_dct):
names = [dpd_dct[c] for c in self._consts]
_gcd = QQ(gcd(self._coeffs))
coeffs = [c / _gcd for c in self._coeffs]
coeffs_names = [(c, n) for c, n in zip(coeffs, names) if c != 0]
tail_terms = ["%s %s %s" % ("+" if c > 0 else "", c, n) for c, n in coeffs_names[1:]]
c0, n0 = coeffs_names[0]
head_term = str(c0) + " " + str(n0)
return r"\frac{{{pol_num}}}{{{pol_dnm}}} \left({terms}\right)".format(
pol_dnm=latex(_gcd.denominator() * self._scalar_const._polynomial_expr()),
pol_num=latex(_gcd.numerator()),
terms=" ".join([head_term] + tail_terms),
)
示例7: disc_factored_latex
def disc_factored_latex(self):
D = self.disc()
s = ''
if D < 0:
D = -D
s = r'-\,'
return s + latex(D.factor())
示例8: latex
def latex(self, prec=None, name=None, keepzeta=False):
"""
Change the name of the variable in a polynomial. If keepzeta, then don't change
the name of zetaN in the defining polynomial of a cyclotomic field.
(keepzeta not implemented yet)
"""
if prec is None:
qe = self.value()
else:
qe = self.value()
if not qe is None:
qe = qe.truncate_powerseries(prec)
wl = web_latex_split_on_re(qe)
if name is not None and self.value().base_ring().absolute_degree()>1:
oldname = latex(self.value().base_ring().gen())
subfrom = oldname.strip()
subfrom = subfrom.replace("\\","\\\\")
subfrom = subfrom.replace("{","\\{") # because x_{0} means something in a regular expression
if subfrom[0].isalpha():
subfrom = "\\b" + subfrom
subto = name.replace("\\","\\\\") + " "
if keepzeta and "zeta" in subfrom:
pass # keep the variable as-is
else:
wl = re.sub(subfrom, subto, wl)
return wl
else:
return wl
示例9: web_latex_split_on_re
def web_latex_split_on_re(x, r = '(q[^+-]*[+-])'):
def insert_latex(s):
return s.group(1) + '\) \('
if isinstance(x, (str, unicode)):
return x
else:
A = "\( %s \)" % latex(x)
c = re.compile(r)
A = A.replace('+', '\) \( {}+ ')
A = A.replace('-', '\) \( {}- ')
# A = A.replace('\left(','\left( {}\\right.') # parantheses needs to be balanced
# A = A.replace('\\right)','\left.\\right)')
A = A.replace('\left(','\\bigl(')
A = A.replace('\\right)','\\bigr)')
A = c.sub(insert_latex, A)
# the above will be re-done using a more sophisticated method involving
# regular expressions. Below fixes bad spacing when the current approach
# encounters terms like (-3+x)
A = A.replace('( {}','(')
A = A.replace('(\) \(','(')
A = A.replace('\(+','\(\mathstrut+')
A = A.replace('\(-','\(\mathstrut-')
A = A.replace('( ','(')
A = A.replace('( ','(')
A = A.replace('+\) \(O','+O')
return A
示例10: eigs_as_seqseq_to_qexp
def eigs_as_seqseq_to_qexp(self, prec_max):
# Takes a sequence of sequence of integers (or pairs of integers in the hecke_ring_cyclotomic_generator != 0 case) and returns a string for the corresponding q expansion
# For example, eigs_as_seqseq_to_qexp([[0,0],[1,3]]) returns "\((1+3\beta_{1})q\)\(+O(q^2)\)"
prec = min(self.qexp_prec, prec_max)
if prec == 0:
return 'O(1)'
eigseq = self.qexp[:prec]
use_knowl = too_big(eigseq, 10**24)
s = ''
for j in range(len(eigseq)):
term = self._elt(eigseq[j])
if term != 0:
latexterm = latex(term)
if use_knowl:
latexterm = make_bigint(latexterm)
if term.number_of_terms() > 1:
latexterm = r"(" + latexterm + r")"
if j > 0:
if term == 1:
latexterm = ''
elif term == -1:
latexterm = '-'
if j == 1:
latexterm += ' q'
else:
latexterm += ' q^{%d}' % j
if s != '' and latexterm[0] != '-':
latexterm = '+' + latexterm
s += '\(' + latexterm + '\) '
# Work around bug in Sage's latex
s = s.replace('betaq', 'beta q')
return s + '\(+O(q^{%d})\)' % prec
示例11: web_latex_split_on_pm
def web_latex_split_on_pm(x):
on = ['+', '-']
# A = "\( %s \)" % latex(x)
try:
A = "\(" + x + "\)" # assume we are given LaTeX to split on
except:
A = "\( %s \)" % latex(x)
# need a more clever split_on_pm that inserts left and right properly
A = A.replace("\\left","")
A = A.replace("\\right","")
for s in on:
# A = A.replace(s, '\) ' + s + ' \( ')
# A = A.replace(s, '\) ' + ' \( \mathstrut ' + s )
A = A.replace(s, '\)' + ' \(\mathstrut ' + s + '\mathstrut ')
# the above will be re-done using a more sophisticated method involving
# regular expressions. Below fixes bad spacing when the current approach
# encounters terms like (-3+x)
for s in on:
A = A.replace('(\) \(\mathstrut '+s,'(' + s)
A = A.replace('( {}','(')
A = A.replace('(\) \(','(')
A = A.replace('\(+','\(\mathstrut+')
A = A.replace('\(-','\(\mathstrut-')
A = A.replace('( ','(')
A = A.replace('( ','(')
return A
示例12: eigs_as_seqseq_to_qexp
def eigs_as_seqseq_to_qexp(self, prec_max):
# Takes a sequence of sequence of integers and returns a string for the corresponding q expansion
# For example, eigs_as_seqseq_to_qexp([[0,0],[1,3]]) returns "\((1+3\beta_{1})q\)\(+O(q^2)\)"
prec = min(self.qexp_prec, prec_max)
if prec == 0:
return 'O(1)'
eigseq = self.qexp[:prec]
d = self.dim
Rgens = self._get_Rgens()
s = ''
for j in range(len(eigseq)):
term = sum([Rgens[i]*eigseq[j][i] for i in range(d)])
if term != 0:
latexterm = latex(term)
if term.number_of_terms() > 1:
latexterm = r"\left(" + latexterm + r"\right)"
if j > 0:
if term == 1:
latexterm = ''
elif term == -1:
latexterm = '-'
if j == 1:
latexterm += ' q'
else:
latexterm += ' q^{%d}' % j
#print latexterm
if s != '' and latexterm[0] != '-':
latexterm = '+' + latexterm
s += '\(' + latexterm + '\) '
# Work around bug in Sage's latex
s = s.replace('betaq', 'beta q')
return s + '\(+O(q^{%d})\)' % prec
示例13: nf_knowl_guts
def nf_knowl_guts(label):
out = ''
wnf = WebNumberField(label)
if wnf.is_null():
return 'Cannot find global number field %s' % label
out += "Global number field %s" % label
out += '<div>'
out += 'Defining polynomial: '
out += "\(%s\)" % latex(wnf.poly())
D = wnf.disc()
Dfact = wnf.disc_factored_latex()
if D.abs().is_prime() or D == 1:
Dfact = "\(%s\)" % str(D)
else:
Dfact = '%s = \(%s\)' % (str(D),Dfact)
out += '<br>Discriminant: '
out += Dfact
out += '<br>Signature: '
out += str(wnf.signature())
out += '<br>Galois group: '+group_pretty_and_nTj(wnf.degree(),wnf.galois_t(), True)
out += '<br>Class number: %s ' % str(wnf.class_number_latex())
if wnf.can_class_number():
out += wnf.short_grh_string()
out += '</div>'
out += '<div align="right">'
out += '<a href="%s">%s home page</a>' % (str(url_for("number_fields.number_field_render_webpage", natural=label)),label)
out += '</div>'
return out
示例14: get_local_algebra
def get_local_algebra(self, p):
local_algebra_dict = self._data.get('loc_algebras', None)
if local_algebra_dict is None:
return None
if str(p) in local_algebra_dict:
R = PolynomialRing(QQ, 'x')
palg = local_algebra_dict[str(p)]
palgs = [R(str(s)) for s in palg.split(',')]
try:
palgstr = [
list2string([int(c) for c in pol.coefficients(sparse=False)])
for pol in palgs]
palgrec = [db.lf_fields.lucky({'p': p, 'coeffs': map(int, c.split(','))}) for c in palgstr]
return [
[
LF['label'],
latex(f),
int(LF['e']),
int(LF['f']),
int(LF['c']),
group_display_knowl(LF['n'], LF['galT']),
LF['t'],
LF['u'],
LF['slopes']
]
for LF, f in zip(palgrec, palgs) ]
except: # we were unable to find the local fields in the database
return None
示例15: web_latex_split_on
def web_latex_split_on(x, on=['+', '-']):
if isinstance(x, (str, unicode)):
return x
else:
A = "\( %s \)" % latex(x)
for s in on:
A = A.replace(s, '\) ' + s + ' \( ')
return A