On Aug 14, 7:54 am, Nathan Dunfield <nat...@dunfield.info> wrote:
> You can find code I wrote to compute the Alexander polynomial using a
> mix of Sage and Magma here:
>
> http://dunfield.info/fibered-faces/
>
> If you don't have Magma, it shouldn't be too hard to port what's in
> "alexander.magma" into Sage, and indeed this would be a worthwhile
> project.  

I just realized that the code I referred to above used the old Python<-
>SnapPea inverface, not SnapPy.  Below is a code snippet for using
"alexander.magma" with Sage and SnapPy.  An usage example:

sage: attach alexander.py
sage: M = snappy.Manifold("8^2_4")
sage: alexander_polynomial(M)
a^5 + 2*a^4 - 2*a^3*b + a^2*b^2 + a^3 - 2*a^2*b + 2*a*b^2 + b^2

Best,

Nathan

----Contents of "alexander.py"-----------------------------

import os, sys, re, string, snappy

#------------------------------------------------
#
#  Computing Alexander polynomials via Magma
#
#------------------------------------------------

magma.load("alexander.magma")

magma.eval("""
DeconstructPolynomial := function(p)
   return [Exponents(m) : m in Monomials(p)], Coefficients(p);
end function;
""")

def sage_poly_from_magma(poly):
    exponents, coeffs = poly.DeconstructPolynomial(nvals=2)
    exponents, coeffs = exponents.sage(), coeffs.sage()
    n = len(exponents[0])
    R = PolynomialRing(Rationals(), list(string.lowercase[:n]))
    gens = R.gens()
    def make_term(exp, c):
        ans = c
        for i in range(len(exp)):
            ans = ans * gens[i]**exp[i]
        return ans

    return sum(
        [ make_term(exponents[i], coeffs[i]) for i in range(len
(exponents))])

def alexander_polynomial(manifold):
    G = manifold.fundamental_group()
    if len(G.generators()) == 1 and len(G.relators()) == 0:
        return PolynomialRing(ZZ, "a")(1)

    G = magma(manifold.fundamental_group())
    return sage_poly_from_magma(G.AlexanderPolynomial())

--~--~---------~--~----~------------~-------~--~----~
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
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to