Hi,

Often people want to try something out in the latest version of MAGMA,
but perhaps they don't have easy access to MAGMA.
If you past the following into SAGE (see below) or a notebook cell,
you'll get a new
command magma_free_eval that will evaluate code in the latest version
of MAGMA and return the result.  Moreover, if you type "%magma_free"
at the top of a notebook cell, the rest of the cell is evaluated using MAGMA.
This works by interacting with the free website:

     http://magma.maths.usyd.edu.au/calc/

which I actually created a long long time ago for MAGMA, and which is
hosted by MAGMA.

# --------------------------------------------

class MagmaExpr(str):
    def __repr__(self):
        return str(self)

def magma_free_eval(code, strip=True):
    """
    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
    url = "http://magma.maths.usyd.edu.au/calc/";
    urldata = urllib.urlencode({'input':code})
    results = urllib.urlopen(url, urldata).read()
    if strip:
        i = results.find('-----\n\n') + 7
        j = results.rfind('\n\nTotal time')
    else:
        i = results.find('Magma V')
        j = results.rfind('</textarea>')
    class MagmaExpr(str):
       def __repr__(self):
          return str(self)
    return MagmaExpr(results[i:j])

class MagmaFree:
    def eval(self, x):
        return magma_free_eval(x)

magma_free = MagmaFree()


# --------------------------------------------


Actual usage:


{{{
magma_free_eval("Basis(ModularForms(23,2))")
///
[
    1 + 12*q^3 + 12*q^4 + 12*q^6 + O(q^8),
    q - q^3 - q^4 - 2*q^6 + 2*q^7 + O(q^8),
    q^2 - 2*q^3 - q^4 + 2*q^5 + q^6 + 2*q^7 + O(q^8)
]
}}}

{{{
%magma_free

print "Factorization =", Factorization(329080832);
A := MatrixAlgebra(RationalField(),4)![Random(1,10) : i in [1..16]];
print "A matrix inverse:", A^(-1);
print "Some modular forms:", Basis(ModularForms(23,2))
///
Factorization = [ <2, 13>, <17, 2>, <139, 1> ]
A matrix inverse:
[    -12   109/6   -16/3     -17]
[   32/3  -146/9    43/9    46/3]
[  -11/3  103/18   -16/9   -16/3]
[   25/3 -227/18    35/9    35/3]
Some modular forms: [
    1 + 12*q^3 + 12*q^4 + 12*q^6 + O(q^8),
    q - q^3 - q^4 - 2*q^6 + 2*q^7 + O(q^8),
    q^2 - 2*q^3 - q^4 + 2*q^5 + q^6 + 2*q^7 + O(q^8)
]
}}}

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to