Esempio n. 1
0
def d_basis(F, strat=True):
    r"""
    Return the `d`-basis for the Ideal ``F`` as defined in [BW93]_.

    INPUT:

    - ``F`` - an ideal
    - ``strat`` - use update strategy (default: ``True``)

    EXAMPLE::

        sage: from sage.rings.polynomial.toy_d_basis import d_basis
        sage: A.<x,y> = PolynomialRing(ZZ, 2)
        sage: f = -y^2 - y + x^3 + 7*x + 1
        sage: fx = f.derivative(x)
        sage: fy = f.derivative(y)
        sage: I = A.ideal([f,fx,fy])
        sage: gb = d_basis(I); gb
        [x - 2020, y - 11313, 22627]
    """
    R = F.ring()
    K = R.base_ring()

    G = set(inter_reduction(F.gens()))
    B = set(filter(lambda (x, y): x != y, [(f1, f2) for f1 in G for f2 in G]))
    D = set()
    C = set(B)

    LCM = R.monomial_lcm
    divides = R.monomial_divides
    divides_ZZ = lambda x, y: ZZ(x).divides(ZZ(y))

    while B != set():
        while C != set():
            f1, f2 = select(C)
            C.remove((f1, f2))
            lcm_lmf1_lmf2 = LCM(LM(f1), LM(f2))
            if not any( divides(LM(g), lcm_lmf1_lmf2) and \
                        divides_ZZ( LC(g), LC(f1) ) and \
                        divides_ZZ( LC(g), LC(f2) ) \
                        for g in G):
                h = gpol(f1, f2)
                h0 = h.reduce(G)
                if h0.lc() < 0:
                    h0 *= -1
                if not strat:
                    D = D.union([(g, h0) for g in G])
                    G.add(h0)
                else:
                    G, D = update(G, D, h0)
                G = inter_reduction(G)

        f1, f2 = select(B)
        B.remove((f1, f2))
        h = spol(f1, f2)
        h0 = h.reduce(G)
        if h0 != 0:
            if h0.lc() < 0:
                h0 *= -1
            if not strat:
                D = D.union([(g, h0) for g in G])
                G.add(h0)
            else:
                G, D = update(G, D, h0)

        B = B.union(D)
        C = D
        D = set()

    return Sequence(sorted(inter_reduction(G), reverse=True))
Esempio n. 2
0
def d_basis(F, strat=True):
    r"""
    Return the `d`-basis for the Ideal ``F`` as defined in [BW93]_.

    INPUT:

    - ``F`` - an ideal
    - ``strat`` - use update strategy (default: ``True``)

    EXAMPLE::

        sage: from sage.rings.polynomial.toy_d_basis import d_basis
        sage: A.<x,y> = PolynomialRing(ZZ, 2)
        sage: f = -y^2 - y + x^3 + 7*x + 1
        sage: fx = f.derivative(x)
        sage: fy = f.derivative(y)
        sage: I = A.ideal([f,fx,fy])
        sage: gb = d_basis(I); gb
        [x - 2020, y - 11313, 22627]
    """
    R = F.ring()
    K = R.base_ring()

    G = set(inter_reduction(F.gens()))
    B = set((f1, f2) for f1 in G for f2 in G if f1 != f2)
    D = set()
    C = set(B)

    LCM = R.monomial_lcm
    divides = R.monomial_divides
    divides_ZZ = lambda x, y: ZZ(x).divides(ZZ(y))

    while B!=set():
        while C!=set():
            f1,f2 = select(C)
            C.remove( (f1,f2) )
            lcm_lmf1_lmf2 = LCM(LM(f1),LM(f2) )
            if not any( divides(LM(g), lcm_lmf1_lmf2) and \
                        divides_ZZ( LC(g), LC(f1) ) and \
                        divides_ZZ( LC(g), LC(f2) ) \
                        for g in G):
                h = gpol(f1,f2)
                h0 = h.reduce(G)
                if h0.lc() < 0:
                    h0 *= -1
                if not strat:
                    D = D.union( [(g,h0) for g in G] )
                    G.add(h0)
                else:
                    G, D = update(G,D,h0)
                G = inter_reduction(G)

        f1,f2 = select(B)
        B.remove((f1,f2))
        h = spol(f1,f2)
        h0 = h.reduce( G )
        if h0 != 0:
            if h0.lc() < 0:
               h0 *= -1
            if not strat:
                D = D.union( [(g,h0) for g in G] )
                G.add( h0 )
            else:
                G, D = update(G,D,h0)

        B = B.union(D)
        C = D
        D = set()

    return Sequence(sorted(inter_reduction(G),reverse=True))