def DiscriminantSurfaceP3_init(): global __magma_DiscriminantSurfaceP3_init__ if not __magma_DiscriminantSurfaceP3_init__: magma.eval(""" R4<sage0, sage1, sage2, sage3> := PolynomialRing(IntegerRing(), 4); DiscriminantSurfaceP3 := function(f) P<x, y, z, w> := PolynomialRing(IntegerRing(), 4); D := 1; for j := 1 to 4 do B := ideal<P | [ Derivative(P!f, i) : i in [1..4] ] cat [P.j - 1]>; G := GroebnerBasis(B); D := LCM(G[#G],D); end for; return D; end function; """) __magma_DiscriminantSurfaceP3_init__ = True
def assert_if_magma(self, expected, magma_code, mode='equal'): """Helper method for running test_download_magma test. Checks equality only if magma is installed; if it isn't, then the test passes.""" from sage.all import magma try: if mode == 'equal': assert expected == magma.eval(magma_code) elif mode == 'in': assert expected in magma.eval(magma_code) else: raise ValueError("mode must be either 'equal' or 'in") except RuntimeError as the_error: if str(the_error).startswith("unable to start magma"): pass else: raise
def test_download_magma(self): L = self.tc.get( '/ModularForm/GL2/TotallyReal/4.4.725.1/holomorphic/4.4.725.1-31.1-a/download/magma' ) assert 'NN := ideal<ZF | {31, 31, w^3 - 4*w + 1}>;' in L.data assert '[89, 89, 3*w^3 - 2*w^2 - 7*w],' in L.data assert 'heckeEigenvaluesArray := [4, -4,' in L.data page = self.tc.get( 'ModularForm/GL2/TotallyReal/3.3.837.1/holomorphic/3.3.837.1-48.3-z/download/magma' ) assert 'No such form' in page.data # These tests take too long to use magma_free, so we run magma when it is installed from sage.all import magma import sys for field, label, expected in [ [ '2.2.28.1', '2.2.28.1-531.1-m', 'heckeEigenvaluesArray := [e, -1, -1, e^7 - 1/2*e^6 - 10*e^5 + 11/2*e^4 + 27*e^3 - 15*e^2 - 15*e + 4' ], [ '3.3.837.1', '3.3.837.1-2.1-b', 'heckeEigenvaluesArray := [1, e, e^2 - e - 7, -e^2 + 6, -e + 2, 2*e + 2, -e^2 + 2*e + 8, 2*e^2 - 4*e - 16' ], [ '4.4.725.1', '4.4.725.1-31.1-a', 'heckeEigenvaluesArray := [4, -4, -7, -4, 4, 2, -2, -1, -8, 2, 10' ] ]: sys.stdout.write("{}...".format(label)) sys.stdout.flush() page = self.tc.get( '/ModularForm/GL2/TotallyReal/{}/holomorphic/{}/download/magma' .format(field, label)) assert expected in page.data assert 'make_newform' in page.data try: magma_code = page.data + '\n' magma_code += 'f, iso := Explode(make_newform());\n' magma_code += 'assert(&and([iso(heckeEigenvalues[P]) eq HeckeEigenvalue(f,P): P in primes[1..10]]));\n' magma_code += 'f;\n' assert 'success' in magma.eval(magma_code) except RuntimeError: pass
def DiscriminantSurfaceP3(F): """ INPUT: - ``F`` -- a polynomial in 4 variables OUTPUT: an integer D such that F mod p is smooth <=> p \ndivides D EXAMPLES: sage: R4.<x,y,z,w> = ZZ[]; sage: F = x^4 - 3*x^2*y^2 - 3*x^2*z^2 - 3*x^2*w^2 - 2*x*y*z*w + y^4 - 3*y^2*z^2 - 3*y^2*w^2 + z^4 - 3*z^2*w^2 + w^4; sage: DiscriminantSurfaceP3(F) 188160 """ assert len(F.variables()) == 4 assert F.base_ring() == ZZ DiscriminantSurfaceP3_init() x, y, z, w = var('sage0 sage1 sage2 sage3') D = ZZ(magma.eval("DiscriminantSurfaceP3(%s);" % F(x, y, z, w))) return D
def test_download_magma(self): # A dimension 1 example L = self.tc.get( '/ModularForm/GL2/ImaginaryQuadratic/2.0.7.1/88.5/a/download/magma' ).get_data(as_text=True) assert 'NN := ideal<ZF | {44, 2*a + 30}>;' in L assert '[263,a+123],' in L page = self.tc.get( 'ModularForm/GL2/ImaginaryQuadratic/159.0.7.1/30.5/a/download/magma' ).get_data(as_text=True) assert 'Bianchi newform not found' in page # These tests take too long to use magma_free, so we run magma when it is installed from sage.all import magma import sys for label, expected in [[ '2.0.4.1/100.2/a', 'ALEigenvalues[ideal<ZF | {i + 1}>] := -1;' ], ['2.0.11.1/933.1/a', 'ideal<ZF | {a + 30, 933}>;']]: sys.stdout.write("{}...".format(label)) sys.stdout.flush() page = self.tc.get( '/ModularForm/GL2/ImaginaryQuadratic/{}/download/magma'.format( label)).get_data(as_text=True) assert expected in page assert 'make_newform' in page magma_code = page + '\n' magma_code += 'f, iso := Explode(make_newform());\n' magma_code += 'for P in primes[1..15] do;\n if Valuation(NN,P) eq 0 then;\n assert iso(heckeEigenvalues[P]) eq HeckeEigenvalue(f,P);\n end if;\nend for;\n' magma_code += 'f;\n' try: assert 'success' in magma.eval(magma_code) except RuntimeError as the_error: if str(the_error).startswith("unable to start magma"): pass else: raise
def has_magma(): try: magma.eval('2') return True except (TypeError, RuntimeError): return False
def url_for_isogeny_class_label(label): slabel = label.split(".") return url_for(".by_url_isogeny_class_label", cond=slabel[0], alpha=slabel[1]) def class_from_curve_label(label): return ".".join(label.split(".")[:2]) ################################################################################ # Searching ################################################################################ try: magma.eval('2') has_magma = True except (TypeError, RuntimeError): has_magma = False def genus2_lookup_equation(f): if not has_magma: return None f.replace(" ", "") # TODO allow other variables, if so, fix the error message accordingly R = PolynomialRing(QQ, "x") if ("x" in f and "," in f) or "],[" in f: if "],[" in f: e = f.split("],[") f = [