def radical_singular(I):
    r""" Return the radical of this ideal.

    INPUT:

    - ``I`` -- an ideal of a polynomial ring over `\mathbb{Z}`

    OUTPUT: the radical of `I`

    """
    singular_lib('primdecint.lib')
    return singular_function('radicalZ')(I)
def minimal_ass_primes_singular(I):
    r""" Return the list of minimal associated primes of an ideal.

    INPUT:

    - ``I`` -- an ideal of a polynomial ring over `\mathbb{Z}`

    OUTPUT: the list of all minimal associated prime ideals of `I`

    """
    singular_lib('primdecint.lib')
    R = I.ring()
    return [R.ideal(G) for G in singular_function('minAssZ')(I)]
def horizontal_minimal_ass_primes(I):
    r""" Return the list of horizontal minimal associated primes of I.

    INPUT:

    - ``I`` -- an ideal of a polynomial ring over `\mathbb{Z}`

    OUTPUT: the list of all horizontal minimal associated prime ideals of `I`.
    Here a prime ideal `P` of a polynomial ring `R = \mathbb{Z}[x_1,\ldots,x_n]`
    is called *horizontal* if `P\cap\mathbb{Z}=(0)`.

    """
    singular_lib('primdecint.lib')
    R = I.ring()
    P_list = [R.ideal(G) for G in singular_function('minAssZ')(I)]
    return [P for P in P_list if P.elimination_ideal(R.gens()).is_zero()]
                M.set_row_to_multiple_of_row(u, u, a)
                M.add_multiple_of_row(u, i, -b)

    #print "\nafter: \n", M

    Mt = M[:, -MI.nrows():]
    Mres = M[:, :M0.ncols()]

    assert (Mt * (apply_swap(M0, swapped)) == Mres)

    return Mres, Mt, tuple(swapped)


from sage.libs.singular.function import singular_function
from sage.libs.singular.function import lib as singular_lib
singular_lib('primdecint.lib')
primdecZ = singular_function('primdecZ')
radicalZ = singular_function('radicalZ')


def primdec_ZZ(I):
    R = I.ring()
    P = primdecZ(I)
    V = [R.ideal(X[0]) for X in P]
    return V


def radical_ZZ(I):
    R = I.ring()
    r = radicalZ(I)
    return R.ideal(r)
        #print "g:", g, "a:", a, "b:", b
        M.set_row_to_multiple_of_row(u, u, a)
        M.add_multiple_of_row(u,i,-b)

  #print "\nafter: \n", M

  Mt = M[:,- MI.nrows():]
  Mres = M[:,:M0.ncols()]

  assert(Mt*(apply_swap(M0,swapped)) == Mres)

  return Mres,Mt,tuple(swapped)

from sage.libs.singular.function import singular_function
from sage.libs.singular.function import lib as singular_lib
singular_lib('primdecint.lib')
primdecZ = singular_function('primdecZ')
radicalZ = singular_function('radicalZ')

def primdec_ZZ(I):
  R = I.ring()
  P = primdecZ(I)
  V = [ R.ideal(X[0]) for X in P]
  return V

def radical_ZZ(I):
  R = I.ring()
  r = radicalZ(I)
  return R.ideal(r)

class FoundAttack(Exception):