I had some library problems in creating a Sage sandbox but resolved
them with the help of ask.sagemath.org.  So now i'm back into
submitting to Sage a function that checks whether a list of
polynomials is algebraically independent.  Since my function uses an
elimination ideal, i took Simon's advice and added it as a method of
the class
sage.rings.polynomial.multi_polynomial_libsingular.MPolynomialRing_libsingular.
Then i ran into trouble, because that class is written in Cython, i
only know Python, and my code is written in Sage.  Man, this is
getting difficult, and yet my function is so simple!

So do i need to convert my code to Cython?  For concreteness, here's
the code, which is short.  The examples are kind of bogus, because,
while the answers are correct ---i got them by running a non-object-
oriented version of the method--- the syntax of the calls currently
doesn't work.

Alex

====================================
def algebraic_dependence(self,fs):
    r"""
    Returns an irreducible annihilating polynomial for the polynomials
in the
    list `fs`, if those polynomials are algebraically dependent.
    Otherwise returns the zero polynomial.

    INPUT:

    - ``fs`` - A list of polynomials `f_1,\ldots,f_r' from self.

    OUTPUT:

    If the polynomials in the list `fs` are algebraically dependent,
then the
    output is an irreducible polynomial `g` in `K[T_1,\ldots,T_r]`
such that
    `g(f_1,\ldots,f_r) = 0`.
    Here `K` is the coefficient ring of self and `T_1,\ldots,T_r` are
    indeterminates different from those of self.
    If the polynomials in `fs` are algebraically independent, then the
output
    is the zero polynomial.

    EXAMPLES::

        sage: R.<x>= PolynomialRing(QQ)
        sage: fs= [x-3, x^2+1]
        sage: g= R.algebraic_dependence(fs); g
        10 + 6*T0 - T1 + T0^2
        sage: g(fs)
        0

    ::

        sage: R.<w,z>= PolynomialRing(QQ)
        sage: fs= [w,  (w^2 + z^2 - 1)^2, w*z - 2]
        sage: g= R.algebraic_dependence(fs); g
        16 + 32*T2 - 8*T0^2 + 24*T2^2 - 8*T0^2*T2 + 8*T2^3 + 9*T0^4 -
2*T0^2*T2^2 + T2^4 - T0^4*T1 + 8*T0^4*T2 - 2*T0^6 + 2*T0^4*T2^2 + T0^8
        sage: g(fs)
        0
        sage: g.parent()
        Multivariate Polynomial Ring in T0, T1, T2 over Rational Field

    ::

        sage: R.<x,y,z>= PolynomialRing(GF(7))
        sage: fs= [x*y,y*z]
        sage: g= R.algebraic_dependence(fs); g
        0

    AUTHORS:

    -Alexander Raichev (2011-01-06)
    """
    r= len(fs)
    R= self
    B= R.base_ring()
    Xs= list(R.gens())
    d= len(Xs)

    # Expand R by r new variables.
    T= 'T'
    while T in [str(x) for x in Xs]:
        T= T+'T'
    Ts= [T + str(j) for j in range(r)]
    RR= PolynomialRing(B,d+r,tuple(Xs+Ts))
    Vs= list(RR.gens())
    Xs= Vs[0:d]
    Ts= Vs[d:]

    # Find an irreducible annihilating polynomial g for the fs if
there is one.
    J= ideal([ Ts[j] -RR(fs[j]) for j in range(r)])
    JJ= J.elimination_ideal(Xs)
    g= JJ.gens()[0]

    # Shrink the ambient ring of g to include only Ts.
    # Using the negdeglex because i find it convenient in my work.
    RRR= PolynomialRing(B,r,tuple(Ts),order='negdeglex')
    return RRR(g)

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to