Skip to content

Commit

Permalink
Merge pull request #5676 from jwj61/belyirawlatex2
Browse files Browse the repository at this point in the history
Belyi rawlatex 2
  • Loading branch information
AndrewVSutherland authored Oct 11, 2023
2 parents 34535ec + 0266e02 commit 6416042
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 88 deletions.
42 changes: 9 additions & 33 deletions lmfdb/belyi/templates/belyi_galmap.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,38 +36,17 @@ <h2>Curve</h2>
<table>
<tr class='std_eqn nodisplay'>
<td>
$\displaystyle {{ data.curve }}$
{% if data.g == 0 %}
{{ data.curve|safe }}
{%- if data.g == 0 -%}
, with affine coordinate $x$
{% endif %}
{% if data["curve_label"] %}
, isomorphic to
{% if data.g == 1 %}
elliptic
{% endif %}
{% if data.g == 2 %}
genus 2
{% endif %}
curve with label <a href={{data["curve_url"]}}>{{data["curve_label"]}} </a>
{% endif %}
</td>
<td>
</td>
</tr>
<tr class='plane_eqn'>
<td>
\(\displaystyle {{ data.plane_model }} = 0\)
{% if data["curve_label"] %}
, isomorphic to
{% if data.g == 1 %}
elliptic
{% endif %}
{% if data.g == 2 %}
genus 2
{% endif %}
curve with label <a href={{data["curve_url"]}}>{{data["curve_label"]}} </a>
{% endif %}
</td>
{{ data.plane_model|safe }}
<td>
</td>
</tr>
Expand All @@ -88,9 +67,9 @@ <h2>Curve</h2>
<h2>{{ KNOWL('belyi.galmap', 'Map') }}</h2>
<div class='std_eqn nodisplay'>
{% if data.g == 0 %}
<p> \(\displaystyle \phi(x) = {{data.map}}\) </p>
<p> \(\displaystyle \phi(x) =\) {{data.map|safe}} </p>
{% else %}
<p> \(\displaystyle \phi(x,y) = {{data.map}}\) </p>
<p> \(\displaystyle \phi(x,y) =\) {{data.map|safe}} </p>
{% endif %}
</div>
<div class='plane_eqn'>
Expand All @@ -105,20 +84,17 @@ <h2>{{ KNOWL('belyi.galmap', 'Map') }}</h2>
{% else %}
<h2>Curve</h2>
<p>
\(\displaystyle {{data.curve}}\)
{% if data.g == 0 %}
{{data.curve|safe}}
{%- if data.g == 0 -%}
, with affine coordinate $x$
{% endif %}
{% if data["curve_label"] %}
, isomorphic to curve with label <a href={{data["curve_url"]}}>{{data["curve_label"]}} </a>
{% endif %}
</p>

<h2>{{ KNOWL('belyi.galmap', 'Map') }}</h2>
{% if data.g == 0 %}
<p> \(\displaystyle \phi(x) = {{data.map}}\) </p>
<p> \(\displaystyle \phi(x) =\) {{data.map|safe}} </p>
{% else %}
<p> \(\displaystyle \phi(x,y) = {{data.map}}\) </p>
<p> \(\displaystyle \phi(x,y) =\) {{data.map|safe}} </p>
{% endif %}
{% endif %}

Expand Down
5 changes: 3 additions & 2 deletions lmfdb/belyi/test_belyi.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def test_passport(self):
self.check_args("/Belyi/9T33-5.2.2_5.3.1_2.2.2.2.1-a", "3.1.14175.1")

def test_smooth_equation(self):
self.check_args("/Belyi/9T33-9_5.1.1.1.1_5.1.1.1.1-a", r"\phi(x) = 9075734485907514624 \frac{x^{9}}{4537867242953757312 x^{9} - 10520021716426424475 x^{8} + 12447550725170242500 x^{6} - 9941569340991356250 x^{4} + 4201111257707812500 x^{2} - 724916949326171875}\)")
self.check_args("/Belyi/7T5-7_7_3.3.1-a", r"\frac{50000 x^{5} + 60000 x^{4} + \left(7000 \nu + 5000\right) x^{3} + 50000 x^{2} y + \left(7000 \nu - 11400\right) x^{2} + 40000 x y + \left(455 \nu - 1725\right) x + \left(500 \nu + 2500\right) y - 532 \nu + 284}{50000 x^{5} + 60000 x^{4} + \left(7000 \nu + 5000\right) x^{3} + \left(7000 \nu - 11400\right) x^{2} + \left(455 \nu - 1725\right) x - 532 \nu + 284}")
self.check_args("/Belyi/7T5-7_7_3.3.1-a", r"y^{2} = x^{6} + \frac{4}{5} x^{5} + \left(\frac{13}{50} \nu - \frac{19}{50}\right) x^{4} + \left(\frac{21}{125} \nu - \frac{7}{25}\right) x^{3} + \left(-\frac{709}{10000} \nu + \frac{279}{10000}\right) x^{2} + \left(-\frac{153}{6250} \nu + \frac{67}{6250}\right) x + \frac{83}{15625} \nu + \frac{47}{15625}")

def test_plane_equation(self):
self.check_args("/Belyi/9T33-9_5.1.1.1.1_5.1.1.1.1-a", r"x^{9} t + \left(-126 x^{4} + 420 x^{3} - 540 x^{2} + 315 x - 70\right) = 0")
self.check_args("/Belyi/9T33-9_5.1.1.1.1_5.1.1.1.1-a", r"x^{9} t + \left(-126 x^{4} + 420 x^{3} - 540 x^{2} + 315 x - 70")

# web pages

Expand Down
125 changes: 74 additions & 51 deletions lmfdb/belyi/web_belyi.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-

from lmfdb.utils import web_latex
from lmfdb.number_fields.web_number_field import WebNumberField
from lmfdb.galois_groups.transitive_group import transitive_group_display_knowl
from sage.all import gcd, latex, CC, QQ, FractionField, PolynomialRing, NumberField, factor
from lmfdb.utils import names_and_urls, prop_int_pretty
from sage.all import gcd, latex, CC, QQ, FractionField, PolynomialRing
from lmfdb.utils import (names_and_urls, prop_int_pretty, raw_typeset,
web_latex, compress_expression)
from flask import url_for
import re

from lmfdb import db

Expand Down Expand Up @@ -111,37 +112,46 @@ def make_map_latex(map_str, nu=None):
phi_str = lc_str + "\\frac{%s}{%s}" % (num_str, den_str)
return phi_str

def make_plane_model_latex(crv_str, nu=None):
if "nu" not in crv_str:
R0 = QQ
else:
R0 = PolynomialRing(QQ, "nu")
R = PolynomialRing(R0, 2, "t,x")
f = R(crv_str)
#return teXify_pol(f)
return latex(f)+"=0"

def make_plane_model_latex_factored(crv_str, numfld_cs, nu=None):
R0 = PolynomialRing(QQ,"T")
K = NumberField(R0(numfld_cs), "nu") # sage factors out constants, ruining integrality
S0 = PolynomialRing(K,"x")
S = PolynomialRing(S0,"t")
t = S.gens()[0]
f = S(crv_str)
cs = f.coefficients()
cs.reverse()
mons = f.monomials()
L = len(cs)
f_str = ""
for i in range(0,L-1):
f_str += "%s%s" % (latex(factor(cs[i])), latex(t**(L-i-1)))
if i != L-2:
f_str += "+"
if mons[-1] == 1:
f_str += latex(factor(cs[-1]))
else:
f_str += latex(factor(cs[-1])) + latex(mons[-1])
return f_str
#def make_plane_model_latex(crv_str, nu=None):
# if "nu" not in crv_str:
# R0 = QQ
# else:
# R0 = PolynomialRing(QQ, "nu")
# R = PolynomialRing(R0, 2, "t,x")
# f = R(crv_str)
# #return teXify_pol(f)
# return latex(f)+"=0"
#
#def make_plane_model_latex_factored(crv_str, numfld_cs, nu=None):
# R0 = PolynomialRing(QQ,"T")
# K = NumberField(R0(numfld_cs), "nu") # sage factors out constants, ruining integrality
# S0 = PolynomialRing(K,"x")
# S = PolynomialRing(S0,"t")
# t = S.gens()[0]
# f = S(crv_str)
# cs = f.coefficients()
# cs.reverse()
# mons = f.monomials()
# L = len(cs)
# f_str = ""
# for i in range(0,L-1):
# f_str += "%s%s" % (latex(factor(cs[i])), latex(t**(L-i-1)))
# if i != L-2:
# f_str += "+"
# if mons[-1] == 1:
# f_str += latex(factor(cs[-1]))
# else:
# f_str += latex(factor(cs[-1])) + latex(mons[-1])
# return f_str

def belyi_latex(s):
str = s.replace('*',' ')
str = str.replace('(',r'\left(')
str = str.replace(')',r'\right)')
str = str.replace('nu',r'\nu')
# multidigit exponents
str = re.sub(r'\^\s*(\d+)', r'^{\1}',str)
return str

###############################################################################
# Belyi map class definitions
Expand Down Expand Up @@ -253,17 +263,43 @@ def __init__(self, galmap, triple=None):
my_dict['embedding'] = embed_strs[i]
data['embeddings_and_triples'].append(my_dict)

# Friends
self.friends = [("Passport", url_for_belyi_passport_label(galmap["plabel"]))]
if galmap['label'] != galmap['primitivization']:
self.friends.append(("Primitivization", url_for_belyi_galmap_label(galmap["primitivization"])))
self.friends.extend(names_and_urls(galmap['friends']))

curve_ref = ''
# add curve link, if in LMFDB
if 'curve_label' in galmap.keys():
data['curve_label'] = galmap['curve_label']
for name, url in self.friends:
if "curve" in name.lower() and data['curve_label'] in name:
data["curve_url"] = url

# curve reference
curve_ref = ', isomorphic to '
if galmap['g'] == 1:
curve_ref += 'elliptic'
if galmap['g'] == 2:
curve_ref += 'genus 2'
curve_ref += rf' curve with label <a href="{url}">{data["curve_label"]}</a>'



# curve equations
crv_str = galmap["curve"]
if crv_str == "PP1":
data["curve"] = r"\mathbb{P}^1"
data["curve"] = r"$\mathbb{P}^1$"
else:
data["curve"] = make_curve_latex(crv_str, nu=self.embedding)
data["curve"] = raw_typeset(crv_str, r'$\displaystyle '+compress_expression(make_curve_latex(crv_str, nu=self.embedding))+'$', extra=curve_ref)

data["map"] = make_map_latex(galmap["map"], nu=self.embedding)
data["map"] = raw_typeset(galmap["map"], r'$\displaystyle '+compress_expression(make_map_latex(galmap["map"], nu=self.embedding))+'$')
data["lambdas"] = [str(c)[1:-1] for c in galmap["lambdas"]]
# plane model
if galmap.get("plane_model"):
data["plane_model"] = galmap["plane_model_latex"]
data["plane_model"] = raw_typeset(compress_expression(galmap["plane_model"])+'=0', r'$\displaystyle '+belyi_latex(galmap["plane_model"])+'=0$', extra=curve_ref)

if galmap.get('plane_map_constant_factored'):
data['plane_map_constant_factored'] = galmap['plane_map_constant_factored']

Expand All @@ -284,19 +320,6 @@ def __init__(self, galmap, triple=None):
]
self.properties = properties

# Friends
self.friends = [("Passport", url_for_belyi_passport_label(galmap["plabel"]))]
if galmap['label'] != galmap['primitivization']:
self.friends.append(("Primitivization", url_for_belyi_galmap_label(galmap["primitivization"])))
self.friends.extend(names_and_urls(galmap['friends']))

# add curve link, if in LMFDB
if 'curve_label' in galmap.keys():
data['curve_label'] = galmap['curve_label']
for name, url in self.friends:
if "curve" in name.lower() and data['curve_label'] in name:
data["curve_url"] = url

# Downloads
data_label = data["label"]
if galmap["g"] <= 2:
Expand Down
1 change: 1 addition & 0 deletions lmfdb/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
],
maxExpand: Infinity,
macros: {
"\\C": '{\\mathbb{C}}',
"\\R": '{\\mathbb{R}}',
Expand Down
2 changes: 2 additions & 0 deletions lmfdb/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
'raw_typeset', 'raw_typeset_poly', 'raw_typeset_poly_factor',
'raw_typeset_qexp', 'raw_typeset_int', 'compress_poly_Q',
'input_string_to_poly', 'dispZmat', 'dispcyclomat',
'compress_expression',
'pos_int_and_factor', 'compress_polynomial']

from flask import (request, make_response, flash, url_for,
Expand Down Expand Up @@ -115,6 +116,7 @@
raw_typeset_poly,
compress_poly_Q,
compress_polynomial,
compress_expression,
pos_int_and_factor,
raw_typeset_poly_factor,
raw_typeset_qexp,
Expand Down
11 changes: 9 additions & 2 deletions lmfdb/utils/web_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ def web_latex(x, enclose=True):

def compress_int(n, cutoff=15, sides=2):
res = str(n)
if abs(n) >= 10**cutoff:
short = res[:sides + (1 if n < 0 else 0)] + r'\!\cdots\!' + res[-sides:]
minus_width = 1 if '-' in res else 0
if len(res) > cutoff+minus_width:
short = res[:sides + minus_width] + r'\!\cdots\!' + res[-sides:]
return short, True
else:
return res, False

def compress_expression(expression, cutoff=15, sides=2):
r"""
Takes a string and any numbers (consecutive digits) longer than
cutoff gets replaced
"""
return re.sub(r'\d+', lambda a: compress_int(str(a.group()),cutoff, sides)[0], expression)

def bigint_knowl(n, cutoff=20, max_width=70, sides=2):
short, shortened = compress_int(n, cutoff=cutoff, sides=sides)
Expand Down

0 comments on commit 6416042

Please sign in to comment.