And is this (see attatched version) is correct now? Example 1: > magma_free('P<x> := PolynomialRing(IntegerRing());\nFactorization(x^8 - 1);')
Result is: [ <x - 1, 1>, <x + 1, 1>, <x^2 + 1, 1>, <x^4 + 1, 1> ] Example 2: > magma_free("Factorization(9290348092384)") Result is: [ <2, 5>, <290323377887, 1> 12.12.2010 18:40, Ugur пишет: > Hey thanks for the new code. But unfortunately, if I understood > correctly, the new code just takes the last line of the output : > ( E.g., compare results of magma_free('[[a,b,c]:a,b,c in [1..20] | > a^2+b^2 eq c^2 and a le b];') both in Sage and in Magma-Calc. There > might be another problem, but for the time being, I can report this > problem. > > On Dec 12, 3:10 am, "Alexey U. Gudchenko" <p...@goodok.ru> wrote: >> 12.12.2010 02:31, Ugur пишет: >> >>> As the layout of Magma's website have changed, the code for >>> magma_free() should be updated. Just want to bring to your attention. >> >> I have edit file according new redesign of Magma's website >> >> Sage-4.6.3/local/lib/python2.6/site-packages/sage/interfaces/magma_free.py >> >> In atachment there is result. >> >> It work for example as in documentation: >> >>> print magma_free("Factorization(9290348092384)") >> >> [ <2, 5>, <290323377887, 1> ] >> >> I don't understand Magma and can't know more difucult examples, so it >> must be verified !!! >> >> magma_free.py >> 3KViewDownload > -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
#***************************************************************************** # Copyright (C) 2007 William Stein <wst...@gmail.com> # # Distributed under the terms of the GNU General Public License (GPL) # # This code is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # The full text of the GPL is available at: # # http://www.gnu.org/licenses/ #***************************************************************************** class MagmaExpr(str): def __repr__(self): return str(self) def magma_free_eval(code, strip=True, columns=0): """ Use the free online MAGMA calculator to evaluate the given input code and return the answer as a string. LIMITATIONS: The code must evaluate in at most 20 seconds and there is a limitation on the amount of RAM. EXAMPLES: sage: magma_free("Factorization(9290348092384)") # optional - internet [ <2, 5>, <290323377887, 1> ] """ import urllib, httplib server = "magma.maths.usyd.edu.au" processPath = "/calc/process.xml" refererPath = "/calc/" refererUrl = "http://%s%s" % ( server, refererPath) code = "SetColumns(%s);\n"%columns + code params = urllib.urlencode({'input':code}) headers = {"Content-type": "application/x-www-form-urlencoded", "Accept":"Accept: text/html, application/xml, application/xhtml+xml", "Referer": refererUrl} conn = httplib.HTTPConnection(server) conn.request("POST", processPath, params, headers) response = conn.getresponse() results = response.read() conn.close() # Result is in form: # <?xml version="1.0"?> # <calculator> # <headers> # <max_time>60</max_time> # <seed>341657781</seed> # <version>2.17-1</version> # <time>0.320</time> # <memory>9.53MB</memory> # </headers> # <results> # <line>[ <2, 5>, <290323377887, 1> ]</line> # </results> # </calculator> # "Factorization(9290348092384)" # results = """<?xml version="1.0"?><calculator><headers><max_time>60</max_time><seed>341657781</seed><version>2.17-1</version><time>0.320</time><memory>9.53MB</memory></headers><results><line>[ <2, 5>, <290323377887, 1> ]</line></results></calculator>""" # "P<x> := PolynomialRing(IntegerRing());\nFactorization(x^8 - 1);" # results = """<?xml version="1.0"?><calculator><headers><max_time>60</max_time><seed>3769196379</seed><version>2.17-1</version><time>0.270</time><memory>9.53MB</memory></headers><results><line>[</line><line><x - 1, 1>,</line><line><x + 1, 1>,</line><line><x^2 + 1, 1>,</line><line><x^4 + 1, 1></line><line>]</line></results></calculator>""" from xml.dom.minidom import parseString xmlDoc = parseString(results) res = u"" # oHeaders = xmlDoc.getElementsByTagName('headers') # for version and timing reslutsNodeList = xmlDoc.getElementsByTagName('results') if len(reslutsNodeList) > 0: reslutsNode = reslutsNodeList[0] lines = reslutsNode.getElementsByTagName('line') if len(reslutsNodeList) > 0: for line in lines: textNode = line.childNodes[0] res += textNode.data + "\n" class MagmaExpr(str): def __repr__(self): return str(self) return MagmaExpr(res) class MagmaFree: """ Evaluate MAGMA code without requiring that MAGMA be installed on your computer by using the free online MAGMA calculator. EXAMPLES: sage: magma_free("Factorization(9290348092384)") # optional - internet [ <2, 5>, <290323377887, 1> ] """ def eval(self, x, **kwds): return magma_free_eval(x) def __call__(self, code, strip=True, columns=0): return magma_free_eval(code, strip=strip, columns=columns) magma_free = MagmaFree()