Ticket #1396: trac1396-singular_options.2.patch

File trac1396-singular_options.2.patch, 48.4 KB (added by mpatel, 11 years ago)

Rebased for 4.5.2.alpha0 queue. See comment 9. Replaces all previous patches.

  • sage/interfaces/singular.py

    # HG changeset patch
    # User Simon King <simon.king@nuigalway.ie>
    # Date 1279223562 -3600
    # Node ID ee29319087da1911333c605b9bd5e7c7baa440c0
    # Parent  3f6506a65e77a5d12282f0e2c3611466b5b5d0f5
    #1396: Allow Singular's options (including prot and degBound) in libSingular; use a method decorator to ensure default options unless requested otherwise.
    
    diff --git a/sage/interfaces/singular.py b/sage/interfaces/singular.py
    a b class Singular(Expect): 
    381381        self.option("redTail")
    382382        self.option("redThrough")
    383383        self.option("intStrategy")
     384        self._saved_options = self.option('get')
    384385
    385386    def __reduce__(self):
    386387        """
  • sage/libs/singular/option.pyx

    diff --git a/sage/libs/singular/option.pyx b/sage/libs/singular/option.pyx
    a b We compute a Groebner basis for Cyclic-5 
    1717By default, tail reductions are performed::
    1818
    1919    sage: from sage.libs.singular.option import opt, opt_ctx
    20     sage: opt['redTail']
     20    sage: opt['red_tail']
    2121    True
    2222    sage: std(I)[-1]
    2323    d^2*e^6 + 28*b*c*d + ...
    By default, tail reductions are performe 
    2525If we don't want this, we can create an option context, which disables
    2626this::
    2727
    28     sage: with opt_ctx(redTail=False,redSB=False):
     28    sage: with opt_ctx(red_tail=False, red_sb=False):
    2929    ...      std(I)[-1]
    3030    d^2*e^6 + 8*c^3 + ...
    3131
    3232However, this does not affect the global state::
    3333
    34     sage: opt['redTail']
     34    sage: opt['red_tail']
    3535    True
    3636
    3737On the other hand, any assignment to an option object will immediately
    3838change the global state::
    3939
    40     sage: opt['redTail'] = False
    41     sage: opt['redTail']
     40    sage: opt['red_tail'] = False
     41    sage: opt['red_tail']
    4242    False
    43     sage: opt['redTail'] = True
    44     sage: opt['redTail']
     43    sage: opt['red_tail'] = True
     44    sage: opt['red_tail']
    4545    True
    4646
    4747Assigning values within an option context, only affects this context::
    4848
    4949    sage: with opt_ctx:
    50     ...      opt['redTail'] = False
     50    ...      opt['red_tail'] = False
    5151
    52     sage: opt['redTail']
     52    sage: opt['red_tail']
    5353    True
    5454
    5555Option contexts can also be safely stacked::
    5656
    5757    sage: with opt_ctx:
    58     ...       opt['redTail'] = False
     58    ...       opt['red_tail'] = False
    5959    ...       print opt
    6060    ...       with opt_ctx:
    61     ...           opt['redThrough'] = False
     61    ...           opt['red_through'] = False
    6262    ...           print opt
    6363    ...
    6464    general options for libSingular (current value 0x00000082)
    Option contexts can also be safely stack 
    6767    sage: print opt
    6868    general options for libSingular (current value 0x02000082)
    6969
     70Furthermore, the integer valued options ``deg_bound`` and
     71``mult_bound`` can be used::
     72
     73    sage: R.<x,y> = QQ[]
     74    sage: I = R*[x^3+y^2,x^2*y+1]
     75    sage: opt['deg_bound'] = 2
     76    sage: std(I)
     77    [x^2*y + 1, x^3 + y^2]
     78    sage: opt['deg_bound'] = 0
     79    sage: std(I)
     80    [y^3 - x, x^2*y + 1, x^3 + y^2]
    7081
    7182The same interface is available for verbosity options::
    7283
    7384    sage: from sage.libs.singular.option import opt_verb
    74     sage: opt_verb['notWarnSB']
     85    sage: opt_verb['not_warn_sb']
    7586    False
     87    sage: opt.reset_default()  # needed to avoid side effects
     88    sage: opt_verb.reset_default()  # needed to avoid side effects
    7689
    7790AUTHOR:
    7891
    7992- Martin Albrecht (2009-08): initial implementation
    8093- Martin Albrecht (2010-01): better interface, verbosity options
     94- Simon King (2010-07): Python-ic option names; deg_bound and mult_bound
    8195"""
    8296#*****************************************************************************
    8397#       Copyright (C) 2010 Martin Albrecht <M.R.Albrecht@rhul.ac.uk>
    AUTHOR: 
    86100#                  http://www.gnu.org/licenses/
    87101#*****************************************************************************
    88102
    89 from sage.libs.singular.decl cimport singular_options, singular_verbose_options
     103from sage.libs.singular.decl cimport singular_options, singular_verbose_options, Kstd1_deg, Kstd1_mu
    90104
    91 from sage.libs.singular.decl cimport OPT_PROT, OPT_REDSB, OPT_NOT_BUCKETS, OPT_NOT_SUGAR, OPT_SUGARCRIT, OPT_REDTHROUGH
     105from sage.libs.singular.decl cimport OPT_PROT, OPT_REDSB, OPT_NOT_BUCKETS, OPT_NOT_SUGAR, OPT_SUGARCRIT, OPT_REDTHROUGH, OPT_DEGBOUND, OPT_MULTBOUND
    92106from sage.libs.singular.decl cimport OPT_RETURN_SB, OPT_FASTHC, OPT_OLDSTD, OPT_REDTAIL, OPT_INTSTRATEGY, OPT_NOTREGULARITY
    93107from sage.libs.singular.decl cimport OPT_WEIGHTM, Sy_bit
    94108
    from sage.libs.singular.decl cimport V_S 
    96110from sage.libs.singular.decl cimport V_LOAD_PROC, V_DEF_RES, V_DEBUG_MEM, V_SHOW_USE, V_IMAP, V_PROMPT
    97111from sage.libs.singular.decl cimport V_NSB, V_CONTENTSB, V_CANCELUNIT, V_DEG_STOP
    98112
     113_options_py_to_singular={'return_sb':'returnSB',
     114                         'fast_hc':'fastHC',
     115                         'inf_red_tail':'infRedTail',
     116                         'int_strategy':'intStrategy',
     117                         'not_regularity':'notRegularity',
     118                         'not_sugar':'notSugar',
     119                         'not_buckets':'notBuckets',
     120                         'qring_nf':'qringNF',
     121                         'redsb':'redSB',
     122                         'red_sb':'redSB',
     123                         'red_tail':'redTail',
     124                         'red_through':'redThrough',
     125                         'sugar_crit':'sugarCrit',
     126                         'weight_m':'weightM',
     127                         'content_sb':'contentSB',
     128                         'mult_bound':'multBound',
     129                         'deg_bound':'degBound',
     130                         'imap':'Imap',
     131                         'debug_lib':'debugLib',
     132                         'def_res':'defRes',
     133                         'load_lib':'loadLib',
     134                         'load_proc':'loadProc',
     135                         'not_warn_sb':'notWarnSB'}
    99136
    100137cdef class LibSingularOptions_abstract:
    101138    """
    cdef class LibSingularOptions_abstract: 
    120157            sage: opt['redTail'] = True
    121158            sage: opt['redTail']
    122159            True
     160            sage: opt['deg_bound'] = 2
     161
     162        The options can be named in Python or Singular style::
     163
     164            sage: opt['degBound']
     165            2
    123166        """
    124167        for k,v in kwds.iteritems():
    125168            self[k] = v
    cdef class LibSingularOptions_abstract: 
    129172        EXAMPLE::
    130173
    131174            sage: from sage.libs.singular.option import opt
    132             sage: opt['redTail']
     175            sage: opt['red_tail']
    133176            True
     177            sage: opt['deg_bound'] = 2
     178
     179        The options can be named in Python or Singular style::
     180
     181            sage: opt['degBound']
     182            2
     183            sage: opt.reset_default()  # needed to avoid side effects
    134184        """
     185        name = _options_py_to_singular.get(name,name)
     186        if name == "degBound":
     187            if bool(self.global_options[0] & self.name_map[name]):
     188                return Kstd1_deg
     189            return int(0)
     190        if name == "multBound":
     191            if bool(self.global_options[0] & self.name_map[name]):
     192                return Kstd1_mu
     193            return int(0)
    135194        try:
    136195            return bool(self.global_options[0] & self.name_map[name])
    137196        except KeyError:
    cdef class LibSingularOptions_abstract: 
    148207            ...      opt['redTail'] = False
    149208            ...      opt['redTail']
    150209            False
     210            sage: opt['red_tail']
     211            True
     212            sage: opt.reset_default()  # needed to avoid side effects
    151213        """
     214        name = _options_py_to_singular.get(name,name)
    152215        try:
    153216            if value:
    154217                self.global_options[0] = self.global_options[0] | self.name_map[name]
    155218            else:
    156219                self.global_options[0] = self.global_options[0] & ~self.name_map[name]
     220            if name == 'degBound':
     221                global Kstd1_deg
     222                Kstd1_deg = value
     223            elif name == 'multBound':
     224                global Kstd1_mu
     225                Kstd1_mu = value
    157226        except KeyError:
    158227            raise NameError("Option '%s' unknown."%(name,))
    159228
    cdef class LibSingularOptions_abstract: 
    163232
    164233            sage: from sage.libs.singular.option import opt
    165234            sage: hex(int(opt))
    166             '0x2000082'
     235            '0x6000082'
    167236        """
    168237        return int(self.global_options[0])
    169238
     239    def save(self):
     240        """
     241        Return a triple of integers that allow reconstruction of the options.
     242
     243        EXAMPLE::
     244
     245            sage: from sage.libs.singular.option import opt
     246            sage: opt['deg_bound']
     247            0
     248            sage: opt['red_tail']
     249            True
     250            sage: s = opt.save()
     251            sage: opt['deg_bound'] = 2
     252            sage: opt['red_tail'] = False
     253            sage: opt['deg_bound']
     254            2
     255            sage: opt['red_tail']
     256            False
     257            sage: opt.load(s)
     258            sage: opt['deg_bound']
     259            0
     260            sage: opt['red_tail']
     261            True
     262            sage: opt.reset_default()  # needed to avoid side effects
     263        """
     264        return (int(self.global_options[0]), self['deg_bound'], self['mult_bound'])
     265
    170266    def load(self, value=None):
    171267        """
    172268        EXAMPLE::
    173269
    174270            sage: from sage.libs.singular.option import opt as sopt
    175             sage: bck = int(sopt); hex(bck)
    176             '0x2000082'
     271            sage: bck = sopt.save(); hex(bck[0]), bck[1], bck[2]
     272            ('0x6000082', 0, 0)
    177273            sage: sopt['redTail'] = False
    178274            sage: hex(int(sopt))
    179             '0x82'
     275            '0x4000082'
    180276            sage: sopt.load(bck)
    181277            sage: sopt['redTail']
    182278            True
    183279        """
    184         self.global_options[0] = int(value)
     280        if value == None:
     281            value = (None,0,0)
     282        self.global_options[0] = int(value[0])
     283        global Kstd1_deg
     284        global Kstd1_mu
     285        Kstd1_deg = value[1]
     286        Kstd1_mu  = value[2]
    185287
    186288    def __repr__(self):
    187289        """
    cdef class LibSingularOptions_abstract: 
    189291
    190292            sage: from sage.libs.singular.option import opt as sopt
    191293            sage: sopt
    192             general options for libSingular (current value 0x02000082)
     294            general options for libSingular (current value 0x06000082)
    193295        """
    194296        return "%s options for libSingular (current value 0x%08x)"%(self.name, self.global_options[0])
    195297
    cdef class LibSingularOptions(LibSingula 
    200302
    201303    Supported options are:
    202304
    203      - ``returnSB`` - the functions syz, intersect, quotient, modulo
    204        return a standard base instead of a generating set if returnSB
    205        is set. This option should not be used for lift.
     305     - ``return_sb`` or ``returnSB`` - the functions ``syz``,
     306       ``intersect``, ``quotient``, ``modulo`` return a standard
     307       base instead of a generating set if ``return_sb``
     308       is set. This option should not be used for ``lift``.
    206309
    207      - ``fastHC`` - tries to find the highest corner of the
    208        staircase (HC) as fast as possible during a standard basis
    209        computation (only used for local orderings).
     310     - ``fast_hc`` or ``fastHC`` - tries to find the highest corner
     311       of the staircase (HC) as fast as possible during a standard
     312       basis computation (only used for local orderings).
    210313
    211      - ``intStrategy`` - avoids division of coefficients during
    212        standard basis computations. This option is ring dependent. By
    213        default, it is set for rings with characteristic 0 and not set
    214        for all other rings.
     314     - ``int_strategy`` or ``intStrategy`` - avoids division of
     315       coefficients during standard basis computations. This option
     316       is ring dependent. By default, it is set for rings with
     317       characteristic 0 and not set for all other rings.
    215318
    216319     - ``lazy`` - uses a more lazy approach in std computations, which
    217320       was used in SINGULAR version before 2-0 (and which may lead to
    218        faster or slower computations, depending on the example)
     321       faster or slower computations, depending on the example).
    219322
    220      - ``length`` - select shorter reducers in std computations,
     323     - ``length`` - select shorter reducers in std computations.
    221324
    222      - ``notRegularity`` - disables the regularity bound for ``res`` and
    223        ``mres`` (see regularity).
     325     - ``not_regularity`` or ``notRegularity`` - disables the
     326       regularity bound for ``res`` and ``mres``.
    224327
    225      - ``notSugar`` - disables the sugar strategy during standard
    226        basis computation.
     328     - ``not_sugar`` or ``notSugar`` - disables the sugar strategy
     329       during standard basis computation.
    227330
    228      - ``notBuckets`` - disables the bucket representation of
    229        polynomials during standard basis computations. This option
    230        usually decreases the memory usage but increases the
    231        computation time. It should only be set for memory-critical
    232        standard basis computations.
     331     - ``not_buckets`` or ``notBuckets`` - disables the bucket
     332       representation of polynomials during standard basis
     333       computations. This option usually decreases the memory
     334       usage but increases the computation time. It should only
     335       be set for memory-critical standard basis computations.
    233336
    234      - ``oldStd`` - uses a more lazy approach in std computations,
    235        which was used in SINGULAR version before 2-0 (and which may
    236        lead to faster or slower computations, depending on the
    237        example)
     337     - ``old_std`` or ``oldStd`` - uses a more lazy approach in std
     338       computations, which was used in SINGULAR version before 2-0
     339       (and which may lead to faster or slower computations, depending
     340       on the example).
    238341
    239342     - ``prot`` - shows protocol information indicating the progress
    240343       during the following computations: ``facstd``, ``fglm``,
    241344       ``groebner``, ``lres``, ``mres``, ``minres``, ``mstd``,
    242        ``res``, ``slimgb``,``sres``, ``std``, ``stdfglm``,
     345       ``res``, ``slimgb``, ``sres``, ``std``, ``stdfglm``,
    243346       ``stdhilb``, ``syz``.
    244347
    245      - ``redSB`` - computes a reduced standard basis in any standard
    246        basis computation.
     348     - `red_sb`` or ``redSB`` - computes a reduced standard basis in
     349       any standard basis computation.
    247350
    248      - ``redTail`` - reduction of the tails of polynomials during
    249        standard basis computations. This option is ring dependent. By
    250        default, it is set for rings with global degree orderings and
    251        not set for all other rings.
     351     - ``red_tail`` or ``redTail`` - reduction of the tails of
     352       polynomials during standard basis computations. This option
     353       is ring dependent. By default, it is set for rings with global
     354       degree orderings and not set for all other rings.
    252355
    253      - ``redThrough`` - for inhomogenous input, polynomial reductions
    254        during standard basis computations are never postponed, but
    255        always finished through. This option is ring dependent. By
    256        default, it is set for rings with global degree orderings and
    257        not set for all other rings.
     356     - ``red_through`` or ``redThrough`` - for inhomogenous input,
     357       polynomial reductions during standard basis computations are
     358       never postponed, but always finished through. This option is
     359       ring dependent. By default, it is set for rings with global
     360       degree orderings and not set for all other rings.
    258361
    259      - ``sugarCrit`` - uses criteria similar to the homogeneous case
    260        to keep more useless pairs.
     362     - ``sugar_crit`` or ``sugarCrit`` - uses criteria similar to the
     363       homogeneous case to keep more useless pairs.
    261364
    262      - ``weightM`` - automatically computes suitable weights for the
    263        weighted ecart and the weighted sugar method.
    264                
     365     - ``weight_m`` or ``weightM`` - automatically computes suitable
     366       weights for the weighted ecart and the weighted sugar method.
     367   
     368    In addition, two integer valued parameters are supported, namely:
     369
     370    - ``deg_bound`` or ``degBound`` - The standard basis computation
     371      is stopped if the total (weighted) degree exceeds ``deg_bound``.
     372      ``deg_bound`` should not be used for a global ordering with
     373      inhomogeneous input. Reset this bound by setting ``deg_bound``
     374      to 0. The exact meaning of "degree" depends on the ring odering
     375      and the command: ``slimgb`` uses always the total degree with
     376      weights 1, ``std`` does so for block orderings, only.
     377
     378    - ``mult_bound`` or ``multBound`` - The standard basis computation
     379      is stopped if the ideal is zero-dimensional in a ring with local
     380      ordering and its multiplicity is lower than ``mult_bound``.
     381      Reset this bound by setting ``mult_bound`` to 0.
     382
    265383    EXAMPLE::
    266384
    267385        sage: from sage.libs.singular.option import LibSingularOptions
    268386        sage: libsingular_options = LibSingularOptions()
    269387        sage: libsingular_options
    270         general options for libSingular (current value 0x02000082)
     388        general options for libSingular (current value 0x06000082)
     389
     390    Here we demonstrate the intended way of using libSingular options::
     391
     392        sage: R.<x,y> = QQ[]
     393        sage: I = R*[x^3+y^2,x^2*y+1]
     394        sage: I.groebner_basis(deg_bound=2)
     395        [x^3 + y^2, x^2*y + 1]
     396        sage: I.groebner_basis()
     397        [x^3 + y^2, x^2*y + 1, y^3 - x]
     398
     399    The option ``mult_bound`` is only relevant in the local case::
     400
     401        sage: Rlocal.<x,y,z> = PolynomialRing(QQ, order='ds')
     402        sage: x^2<x
     403        True
     404        sage: J = [x^7+y^7+z^6,x^6+y^8+z^7,x^7+y^5+z^8, x^2*y^3+y^2*z^3+x^3*z^2,x^3*y^2+y^3*z^2+x^2*z^3]*Rlocal
     405        sage: J.groebner_basis(mult_bound=100)
     406        [x^3*y^2 + y^3*z^2 + x^2*z^3, x^2*y^3 + x^3*z^2 + y^2*z^3, y^5, x^6 + x*y^4*z^5, x^4*z^2 - y^4*z^2 - x^2*y*z^3 + x*y^2*z^3, z^6 - x*y^4*z^4 - x^3*y*z^5]
     407        sage: J.groebner_basis()
     408        [x^3*y^2 + y^3*z^2 + x^2*z^3, x^2*y^3 + x^3*z^2 + y^2*z^3, y^5, x^6, x^4*z^2 - y^4*z^2 - x^2*y*z^3 + x*y^2*z^3, z^6, y^4*z^3 - y^3*z^4 - x^2*z^5, x^3*y*z^4 - x^2*y^2*z^4 + x*y^3*z^4, x^3*z^5, x^2*y*z^5 + y^3*z^5, x*y^3*z^5]
     409
    271410    """
    272411    def __init__(self, **kwds):
    273412        """
    cdef class LibSingularOptions(LibSingula 
    278417            sage: from sage.libs.singular.option import LibSingularOptions
    279418            sage: libsingular_options = LibSingularOptions()
    280419            sage: libsingular_options
    281             general options for libSingular (current value 0x02000082)
     420            general options for libSingular (current value 0x06000082)
    282421        """
    283422        self.global_options = &singular_options
    284423        self.name = "general"
    cdef class LibSingularOptions(LibSingula 
    294433                         "redTail":       Sy_bit(OPT_REDTAIL),
    295434                         "intStrategy":   Sy_bit(OPT_INTSTRATEGY),
    296435                         "notRegularity": Sy_bit(OPT_NOTREGULARITY),
    297                          "weightM":       Sy_bit(OPT_WEIGHTM)}
     436                         "weightM":       Sy_bit(OPT_WEIGHTM),
     437                         "degBound":      Sy_bit(OPT_DEGBOUND),
     438                         "multBound":     Sy_bit(OPT_MULTBOUND)}
    298439        LibSingularOptions_abstract.__init__(self, **kwds)
    299440
     441    def reset_default(self):
     442        """
     443        Reset libSingular's default options.
     444
     445        EXAMPLE::
     446
     447            sage: from sage.libs.singular.option import opt
     448            sage: opt['red_tail']
     449            True
     450            sage: opt['red_tail'] = False
     451            sage: opt['red_tail']
     452            False
     453            sage: opt['deg_bound']
     454            0
     455            sage: opt['deg_bound'] = 2
     456            sage: opt['deg_bound']
     457            2
     458            sage: opt.reset_default()
     459            sage: opt['red_tail']
     460            True
     461            sage: opt['deg_bound']
     462            0
     463        """
     464        from sage.libs.singular.singular import _saved_options
     465        self.load(_saved_options)
     466
     467
    300468
    301469#############
    302470
    cdef class LibSingularVerboseOptions(Lib 
    306474
    307475    Supported options are:
    308476
    309      - ``mem`` -
    310      - ``yacc`` -
    311      - ``redefine`` -
    312      - ``reading`` -
    313      - ``loadLib`` -
    314      - ``debugLib`` -
    315      - ``loadProc`` -
    316      - ``defRes`` -
    317      - ``debugMem`` -
    318      - ``usage`` -
    319      - ``Imap`` -
    320      - ``prompt`` -
    321      - ``notWarnSB`` - do not warn if a basis is not a standard basis
    322      - ``contentSB`` -
    323      - ``cancelunit`` -
    324                
     477     - ``mem`` - shows memory usage in square brackets.
     478     - ``yacc`` - Only available in debug version.
     479     - ``redefine`` - warns about variable redefinitions.
     480     - ``reading`` - shows the number of characters read from a file.
     481     - ``loadLib`` or ``load_lib`` - shows loading of libraries.
     482     - ``debugLib`` or ``debug_lib`` - warns about syntax errors
     483       when loading a library.
     484     - ``loadProc`` or ``load_proc`` - shows loading of procedures
     485       from libraries.
     486     - ``defRes`` or ``def_res`` - shows the names of the syzygy
     487       modules while converting ``resolution`` to ``list``.
     488     - ``usage`` - shows correct usage in error messages.
     489     - ``Imap`` or ``imap`` - shows the mapping of variables with
     490       the ``fetch`` and ``imap`` commands.
     491     - ``notWarnSB`` or ``not_warn_sb`` - do not warn if
     492       a basis is not a standard basis
     493     - ``contentSB`` or ``content_sb`` - avoids to divide by the
     494       content of a polynomial in ``std`` and related algorithms.
     495       Should usually not be used.
     496     - ``cancelunit`` - avoids to divide polynomials by non-constant
     497       units in ``std`` in the local case. Should usually not be used.
     498         
    325499    EXAMPLE::
    326500
    327501        sage: from sage.libs.singular.option import LibSingularVerboseOptions
    cdef class LibSingularVerboseOptions(Lib 
    350524                         "debugLib": Sy_bit(V_DEBUG_LIB),
    351525                         "loadProc": Sy_bit(V_LOAD_PROC),
    352526                         "defRes":   Sy_bit(V_DEF_RES),   
    353                          "debugMem": Sy_bit(V_DEBUG_MEM),
     527                         #"debugMem": Sy_bit(V_DEBUG_MEM),
    354528                         "usage":    Sy_bit(V_SHOW_USE), 
    355529                         "Imap":     Sy_bit(V_IMAP),     
    356                          "prompt":   Sy_bit(V_PROMPT),   
    357                          "notWarnSB":Sy_bit(V_NSB),       
     530                         #"prompt":   Sy_bit(V_PROMPT),   
     531                         "notWarnSB":Sy_bit(V_NSB),
    358532                         "contentSB":Sy_bit(V_CONTENTSB),
    359                          "cancelunit":Sy_bit(V_CANCELUNIT),
     533                         "cancelunit":Sy_bit(V_CANCELUNIT)
    360534                         }
    361535        LibSingularOptions_abstract.__init__(self, **kwds)
    362536
     537    def reset_default(self):
     538        """
     539        Return to libSingular's default verbosity options
     540
     541        EXAMPLE::
     542
     543            sage: from sage.libs.singular.option import opt_verb
     544            sage: opt_verb['not_warn_sb']
     545            False
     546            sage: opt_verb['not_warn_sb'] = True
     547            sage: opt_verb['not_warn_sb']
     548            True
     549            sage: opt_verb.reset_default()
     550            sage: opt_verb['not_warn_sb']
     551            False
     552
     553        """
     554        from sage.libs.singular.singular import _saved_verbose_options
     555        self.global_options[0] = int(_saved_verbose_options)
     556
    363557cdef class LibSingularOptionsContext:
    364558    """
    365559    Option context
    cdef class LibSingularOptionsContext: 
    370564
    371565        sage: from sage.libs.singular.option import opt, opt_ctx
    372566        sage: opt
    373         general options for libSingular (current value 0x02000082)
     567        general options for libSingular (current value 0x06000082)
    374568
    375569    ::
    376570
    cdef class LibSingularOptionsContext: 
    379573        ...       with opt_ctx(redThrough=False):
    380574        ...           print opt
    381575        ...
    382         general options for libSingular (current value 0x00000082)
    383         general options for libSingular (current value 0x00000002)
     576        general options for libSingular (current value 0x04000082)
     577        general options for libSingular (current value 0x04000002)
    384578
    385579        sage: print opt
    386         general options for libSingular (current value 0x02000082)
     580        general options for libSingular (current value 0x06000082)
    387581    """
    388582    cdef list bck
     583    cdef list bck_degBound
     584    cdef list bck_multBound
    389585    cdef public LibSingularOptions_abstract opt
    390586    cdef object options
    391587
    cdef class LibSingularOptionsContext: 
    400596            general options context for libSingular
    401597        """
    402598        self.bck = []
     599        self.bck_degBound = []
     600        self.bck_multBound = []
    403601        self.options = kwds
    404602        self.opt = opt
    405603
    cdef class LibSingularOptionsContext: 
    415613            False
    416614        """
    417615        self.bck.append(self.opt.global_options[0])
     616        self.bck_degBound.append(Kstd1_deg)
     617        self.bck_multBound.append(Kstd1_mu)
    418618        opt = self.opt.__class__()
    419619        for k,v in self.options.iteritems():
    420620            opt[k] = v
    cdef class LibSingularOptionsContext: 
    447647            False
    448648        """
    449649        self.opt.global_options[0] = self.bck.pop()
     650        global Kstd1_deg
     651        global Kstd1_mu
     652        Kstd1_deg = self.bck_degBound.pop()
     653        Kstd1_mu  = self.bck_multBound.pop()
    450654
    451655    def __repr__(self):
    452656        """
    cdef class LibSingularOptionsContext: 
    460664
    461665
    462666opt = LibSingularOptions()
     667opt.reset_default()
    463668opt_verb = LibSingularVerboseOptions()
     669opt_verb.reset_default()
    464670opt_ctx = LibSingularOptionsContext(opt)
    465671opt_verb_ctx = LibSingularOptionsContext(opt_verb)
  • sage/libs/singular/singular-cdefs.pxi

    diff --git a/sage/libs/singular/singular-cdefs.pxi b/sage/libs/singular/singular-cdefs.pxi
    a b include "sage/ext/cdefs.pxi" 
    1414cdef extern from "stdlib.h":
    1515    void delete "delete" (void *ptr)
    1616
    17 
    1817cdef extern from "factory.h":
    1918
    2019    #
    cdef extern from "lists.h": 
    997996        leftv  *m
    998997        void (*Init)(int n)
    999998
     999cdef extern from "kstd1.h":
     1000    cdef extern int Kstd1_deg   # degBound, default 0
     1001    cdef extern int Kstd1_mu    # multBound, default 0
     1002
    10001003cdef extern from "intvec.h":
    10011004    # for the moment we need only new, as we use the cleanup of sleftv
    10021005    # to get rid of it again
  • sage/libs/singular/singular.pyx

    diff --git a/sage/libs/singular/singular.pyx b/sage/libs/singular/singular.pyx
    a b import os 
    2626from sage.misc.misc_c import is_64_bit
    2727
    2828from sage.libs.singular.decl cimport intvec
    29 from sage.libs.singular.decl cimport SR_HDL, SR_INT, SR_TO_INT, singular_options
     29from sage.libs.singular.decl cimport SR_HDL, SR_INT, SR_TO_INT, singular_options, singular_verbose_options
    3030from sage.libs.singular.decl cimport On, Off, SW_USE_NTL, SW_USE_NTL_GCD_0, SW_USE_EZGCD, SW_USE_NTL_SORT, SW_USE_NTL_GCD_P
    3131from sage.libs.singular.decl cimport napoly, lnumber, Sy_bit, OPT_REDSB, OPT_INTSTRATEGY, OPT_REDTAIL, OPT_REDTHROUGH
    3232from sage.libs.singular.decl cimport nlGetNom, nlGetDenom, nlDelete, nlInit2gmp
    from sage.libs.pari.all import pari 
    4848from sage.structure.parent_base cimport ParentWithBase
    4949from sage.rings.polynomial.multi_polynomial_libsingular cimport MPolynomial_libsingular
    5050
     51_saved_options = (int(0),0,0)
     52
    5153cdef Rational si2sa_QQ(number *n, ring *_ring):
    5254    """
    5355    TESTS::
    cdef init_libsingular(): 
    645647    far is to load the library again and to specify ``RTLD_GLOBAL``.
    646648    """
    647649    global singular_options
     650    global singular_verbose_options
    648651    global max_exponent_size
    649652
    650653    cdef void *handle = NULL
    cdef init_libsingular(): 
    667670
    668671    dlclose(handle)
    669672
    670     # we set some global Singular options
     673    # we set and save some global Singular options
    671674    singular_options = singular_options | Sy_bit(OPT_REDSB) | Sy_bit(OPT_INTSTRATEGY) | Sy_bit(OPT_REDTAIL) | Sy_bit(OPT_REDTHROUGH)
    672        
     675    global _saved_options
     676    global _saved_verbose_options
     677    _saved_options = (int(singular_options), 0, 0)
     678    _saved_verbose_options = int(singular_verbose_options)
     679
    673680    On(SW_USE_NTL)
    674681    On(SW_USE_NTL_GCD_0)
    675682    On(SW_USE_NTL_GCD_P)
  • sage/rings/polynomial/multi_polynomial_ideal.py

    diff --git a/sage/rings/polynomial/multi_polynomial_ideal.py b/sage/rings/polynomial/multi_polynomial_ideal.py
    a b import sage.rings.polynomial.toy_buchber 
    244244import sage.rings.polynomial.toy_variety as toy_variety
    245245import sage.rings.polynomial.toy_d_basis as toy_d_basis
    246246
    247 class RedSBContext:
     247class LibSingularDefaultContext:
     248    def __init__(self, singular=singular_default):
     249        from sage.libs.singular.option import opt_ctx
     250        self.libsingular_option_context = opt_ctx
     251    def __enter__(self):
     252        """
     253        EXAMPLE::
     254
     255            sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
     256            sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
     257            sage: I = sage.rings.ideal.Katsura(P,3)
     258            sage: singular.option('noredTail')
     259            sage: singular.option('noredThrough')
     260            sage: Is = I._singular_()
     261            sage: with SingularDefaultContext(): rgb = Is.groebner()
     262            sage: rgb
     263            84*c^4-40*c^3+c^2+c,
     264            7*b+210*c^3-79*c^2+3*c,
     265            7*a-420*c^3+158*c^2+8*c-7
     266        """
     267        self.libsingular_option_context.__enter__()
     268        self.libsingular_option_context.opt.reset_default()
     269        self.libsingular_option_context.opt['red_sb'] = True
     270        self.libsingular_option_context.opt['red_tail'] = True
     271        self.libsingular_option_context.opt['deg_bound'] = 0
     272        self.libsingular_option_context.opt['mult_bound'] = 0
     273
     274    def __exit__(self, typ, value, tb):
     275        """
     276        EXAMPLE::
     277
     278            sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
     279            sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
     280            sage: I = sage.rings.ideal.Katsura(P,3)
     281            sage: singular.option('noredTail')
     282            sage: singular.option('noredThrough')
     283            sage: Is = I._singular_()
     284            sage: with SingularDefaultContext(): rgb = Is.groebner()
     285            sage: rgb
     286            84*c^4-40*c^3+c^2+c,
     287            7*b+210*c^3-79*c^2+3*c,
     288            7*a-420*c^3+158*c^2+8*c-7
     289        """
     290        self.libsingular_option_context.__exit__(typ,value,tb)
     291
     292
     293class SingularDefaultContext:
    248294    """
    249295    Within this context all Singular Groebner basis calculations are
    250296    reduced automatically.
    class RedSBContext: 
    252298    AUTHORS:
    253299
    254300    - Martin Albrecht
     301    - Simon King
    255302    """
    256303    def __init__(self, singular=singular_default):
    257304        """
    class RedSBContext: 
    264311       
    265312        EXAMPLE::
    266313       
    267             sage: from sage.rings.polynomial.multi_polynomial_ideal import RedSBContext
     314            sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
    268315            sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
    269316            sage: I = sage.rings.ideal.Katsura(P,3)
    270317            sage: singular.option('noredTail')
    class RedSBContext: 
    279326        ::
    280327       
    281328            sage: from __future__ import with_statement
    282             sage: with RedSBContext(): rgb = Is.groebner()
     329            sage: with SingularDefaultContext(): rgb = Is.groebner()
    283330            sage: rgb
    284331            84*c^4-40*c^3+c^2+c,
    285332            7*b+210*c^3-79*c^2+3*c,
    class RedSBContext: 
    299346           Groebner basis is computed so the user does not need to use
    300347           it manually.
    301348        """
    302         from sage.libs.singular.option import opt_ctx
    303349        self.singular = singular
    304         self.libsingular_option_context = opt_ctx
    305350
    306351    def __enter__(self):
    307352        """
    308353        EXAMPLE::
    309354       
    310             sage: from sage.rings.polynomial.multi_polynomial_ideal import RedSBContext
     355            sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
    311356            sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
    312357            sage: I = sage.rings.ideal.Katsura(P,3)
    313358            sage: singular.option('noredTail')
    314359            sage: singular.option('noredThrough')
    315360            sage: Is = I._singular_()
    316             sage: with RedSBContext(): rgb = Is.groebner()
     361            sage: with SingularDefaultContext(): rgb = Is.groebner()
    317362            sage: rgb
    318363            84*c^4-40*c^3+c^2+c,
    319364            7*b+210*c^3-79*c^2+3*c,
    320365            7*a-420*c^3+158*c^2+8*c-7
    321366        """
     367        try:
     368            self.bck_degBound = int(self.singular.eval('degBound'))
     369        except RuntimeError:
     370            self.bck_degBound = int(0)
     371        try:
     372            self.bck_multBound = int(self.singular.eval('multBound'))
     373        except RuntimeError:
     374            self.bck_multBound = int(0)
    322375        self.o = self.singular.option("get")
     376        self.singular.option('set',self.singular._saved_options)
    323377        self.singular.option("redSB")
    324         self.libsingular_option_context.__enter__()
    325         self.libsingular_option_context.opt['redSB'] = True
    326         self.libsingular_option_context.opt['redTail'] = True
     378        self.singular.option("redTail")
     379        try:
     380            self.singular.eval('degBound=0')
     381        except RuntimeError:
     382            pass
     383        try:
     384            self.singular.eval('multBound=0')
     385        except RuntimeError:
     386            pass
    327387
    328388    def __exit__(self, typ, value, tb):
    329389        """
    330390        EXAMPLE::
    331391       
    332             sage: from sage.rings.polynomial.multi_polynomial_ideal import RedSBContext
     392            sage: from sage.rings.polynomial.multi_polynomial_ideal import SingularDefaultContext
    333393            sage: P.<a,b,c> = PolynomialRing(QQ,3, order='lex')
    334394            sage: I = sage.rings.ideal.Katsura(P,3)
    335395            sage: singular.option('noredTail')
    336396            sage: singular.option('noredThrough')
    337397            sage: Is = I._singular_()
    338             sage: with RedSBContext(): rgb = Is.groebner()
     398            sage: with SingularDefaultContext(): rgb = Is.groebner()
    339399            sage: rgb
    340400            84*c^4-40*c^3+c^2+c,
    341401            7*b+210*c^3-79*c^2+3*c,
    342402            7*a-420*c^3+158*c^2+8*c-7
    343403        """
    344404        self.singular.option("set",self.o)
    345         self.libsingular_option_context.__exit__(typ,value,tb)
     405        try:
     406            self.singular.eval('degBound=%d'%self.bck_degBound)
     407        except RuntimeError:
     408            pass
     409        try:
     410            self.singular.eval('multBound=%d'%self.bck_multBound)
     411        except RuntimeError:
     412            pass
    346413
    347 def redSB(func):
     414def singular_standard_options(func):
    348415    """
    349416    Decorator to force a reduced Singular groebner basis.
    350417   
    def redSB(func): 
    363430    """
    364431    def wrapper(*args, **kwds):
    365432        """
    366         Execute function in ``RedSBContext``.
     433        Execute function in ``SingularDefaultContext``.
    367434        """
    368         with RedSBContext():
     435        with SingularDefaultContext():
    369436            return func(*args, **kwds)
    370437
    371438    from sage.misc.sageinspect import sage_getsource
    def redSB(func): 
    374441    wrapper.__doc__ = func.__doc__
    375442    return wrapper
    376443
     444def libsingular_standard_options(func):
     445    """
     446    Decorator to force a reduced Singular groebner basis.
     447
     448    TESTS::
     449
     450        sage: P.<a,b,c,d,e> = PolynomialRing(GF(127))
     451        sage: J = sage.rings.ideal.Cyclic(P).homogenize()
     452        sage: from sage.misc.sageinspect import sage_getsource
     453        sage: "buchberger" in sage_getsource(J.interreduced_basis)
     454        True
     455
     456    .. note::
     457
     458       This decorator is used automatically internally so the user
     459       does not need to use it manually.
     460    """
     461    def wrapper(*args, **kwds):
     462        """
     463        Execute function in ``LibSingularDefaultContext``.
     464        """
     465        with LibSingularDefaultContext():
     466            return func(*args, **kwds)
     467
     468    from sage.misc.sageinspect import sage_getsource
     469    wrapper._sage_src_ = lambda: sage_getsource(func)
     470    wrapper.__name__ = func.__name__
     471    wrapper.__doc__ = func.__doc__
     472    return wrapper
     473
    377474class RequireField(MethodDecorator):
    378475    """
    379476    Decorator which throws an exception if a computation over a
    class MPolynomialIdeal_singular_repr: 
    608705        I.plot()
    609706
    610707    @require_field
    611     @redSB
     708    @libsingular_standard_options
    612709    def complete_primary_decomposition(self, algorithm="sy"):
    613710        r"""
    614711        Return a list of primary ideals and their associated primes such
    class MPolynomialIdeal_singular_repr: 
    772869        return [I for I, _ in self.complete_primary_decomposition(algorithm)]
    773870
    774871    @require_field
    775     @redSB
    776872    def associated_primes(self, algorithm='sy'):
    777873        r"""
    778874        Return a list of the associated primes of primary ideals of
    class MPolynomialIdeal_singular_repr: 
    837933        return [P for _,P in self.complete_primary_decomposition(algorithm)]
    838934           
    839935    @require_field
     936    @singular_standard_options
     937    @libsingular_standard_options
    840938    def triangular_decomposition(self, algorithm=None, singular=singular_default):
    841939        """
    842940        Decompose zero-dimensional ideal ``self`` into triangular
    class MPolynomialIdeal_singular_repr: 
    10831181        else:
    10841182            return vd
    10851183
    1086     @redSB
     1184    @singular_standard_options
    10871185    def _groebner_basis_singular(self, algorithm="groebner", *args, **kwds):
    10881186        """
    10891187        Return the reduced Groebner basis of this ideal. If the
    class MPolynomialIdeal_singular_repr: 
    11461244        S =  Sequence([R(S[i+1]) for i in range(len(S))], R, check=False, immutable=True)
    11471245        return S
    11481246
     1247    @cached_method
    11491248    def _groebner_basis_singular_raw(self, algorithm="groebner", singular=singular_default, *args, **kwds):
    11501249        r"""
    11511250        Return a Groebner basis in Singular format.
    class MPolynomialIdeal_singular_repr: 
    11591258            b*d^4 - b + d^5 - d, b*c - b*d + c^2*d^4 + c*d - 2*d^2,
    11601259            b^2 + 2*b*d + d^2, a + b + c + d]
    11611260        """
    1162         try:
    1163             return self.__gb_singular
    1164         except AttributeError:
    1165             pass
    1166         # singular options are preserved by @redSB so we don't
    1167         # need to do that here too
    1168         for o,v in kwds.iteritems():
    1169             if v:
    1170                 singular.option(o)
    1171             else:
    1172                 singular.option("no"+o)
     1261        #try:
     1262        #    return self.__gb_singular
     1263        #except AttributeError:
     1264        #    pass
     1265        # singular options are preserved by @singular_standard_options,
     1266        # so we don't eed to do that here too
     1267        from sage.libs.singular.option import _options_py_to_singular
     1268        S = self._singular_()   # for degBound, we need to ensure
     1269                                # that a ring is defined
     1270        for o,v in kwds.iteritems():
     1271            o = _options_py_to_singular.get(o,o)
     1272            if v:
     1273                if o in ['degBound','multBound']:
     1274                    singular.eval(o+'=%d'%v)
     1275                else:
     1276                    singular.option(o)
     1277            else:
     1278                if o in ['degBound','multBound']:
     1279                    singular.eval(o+'=0')
     1280                else:
     1281                    singular.option("no"+o)
    11731282
    11741283        if algorithm=="groebner":
    11751284            S = self._singular_().groebner()
    class MPolynomialIdeal_singular_repr: 
    11861295        self.__gb_singular = S
    11871296        return S
    11881297
    1189     @redSB
    1190     def _groebner_basis_libsingular(self, algorithm="groebner", redsb=True, red_tail=True):
     1298    @libsingular_standard_options
     1299    def _groebner_basis_libsingular(self, algorithm="groebner", *args, **kwds):
    11911300        """
    11921301        Return the reduced Groebner basis of this ideal. If the
    11931302        Groebner basis for this ideal has been calculated before the
    class MPolynomialIdeal_singular_repr: 
    12431352
    12441353        import sage.libs.singular
    12451354        groebner = sage.libs.singular.ff.groebner
     1355        from sage.all import get_verbose
    12461356
    1247         opt['redSB'] = redsb
    1248         opt['redTail'] = red_tail
     1357        if get_verbose()>=2:
     1358            opt['prot'] = True
     1359        for name,value in kwds.iteritems():
     1360            if value is not None:
     1361                opt[name] = value
    12491362
    12501363        T = self.ring().term_order()
    12511364       
    class MPolynomialIdeal_singular_repr: 
    12971410            self.__genus = Integer(genus(self))
    12981411            return self.__genus
    12991412
    1300     @redSB
     1413    @libsingular_standard_options
    13011414    def intersection(self, other):
    13021415        """
    13031416        Return the intersection of the two ideals.
    class MPolynomialIdeal_singular_repr: 
    13331446        return R.ideal(K)
    13341447
    13351448    @require_field
    1336     @redSB
     1449    @libsingular_standard_options
    13371450    def minimal_associated_primes(self):
    13381451        """
    13391452        OUTPUT:
    class MPolynomialIdeal_singular_repr: 
    13611474        return [R.ideal(J) for J in M]
    13621475
    13631476    @require_field
    1364     @redSB
     1477    @libsingular_standard_options
    13651478    def radical(self):
    13661479        r"""
    13671480        The radical of this ideal.
    class MPolynomialIdeal_singular_repr: 
    14141527        return S.ideal(r)
    14151528
    14161529    @require_field
    1417     @redSB
     1530    @libsingular_standard_options
    14181531    def integral_closure(self, p=0, r=True, singular=singular_default):
    14191532        """
    14201533        Let `I` = ``self``.
    class MPolynomialIdeal_singular_repr: 
    14411554            sage: I.integral_closure()
    14421555            [x^2, y^5, -x*y^3]
    14431556       
    1444         ALGORITHM: Use Singular
     1557        ALGORITHM: Use libSingular
    14451558        """
    14461559        R = self.ring()
    14471560        import sage.libs.singular
    class MPolynomialIdeal_singular_repr: 
    14791592        S = syz(self)
    14801593        return matrix(self.ring(), S)
    14811594
    1482     @redSB
    14831595    def reduced_basis(self):
    14841596        r"""
    14851597        .. warning::
    class MPolynomialIdeal_singular_repr: 
    15231635        deprecation("This function is deprecated. It will be removed in a future release of Sage. Please use the interreduced_basis() function instead.")
    15241636        return self.interreduced_basis()
    15251637
    1526     @redSB
     1638    @singular_standard_options
     1639    @libsingular_standard_options
    15271640    def interreduced_basis(self):
    15281641        r"""
    15291642        If this ideal is spanned by `(f_1, ..., f_n)` this method
    class MPolynomialIdeal_singular_repr: 
    15901703        return ret
    15911704
    15921705    @cached_method
     1706    @singular_standard_options
    15931707    def basis_is_groebner(self, singular=singular_default):
    15941708        r"""
    15951709        Returns ``True`` if the generators of this ideal
    class MPolynomialIdeal_singular_repr: 
    16951809        return True
    16961810
    16971811    @require_field
    1698     @redSB
     1812    @singular_standard_options
     1813    @libsingular_standard_options
    16991814    def transformed_basis(self, algorithm="gwalk", other_ring=None, singular=singular_default):
    17001815        """
    17011816        Returns a lex or ``other_ring`` Groebner Basis for this ideal.
    class MPolynomialIdeal_singular_repr: 
    17881903        else:
    17891904            raise TypeError, "Cannot convert basis with given algorithm"
    17901905
    1791     @redSB
     1906    @libsingular_standard_options
    17921907    def elimination_ideal(self, variables):
    17931908        r"""
    17941909        Returns the elimination ideal this ideal with respect to the
    class MPolynomialIdeal_singular_repr: 
    18231938        Is = MPolynomialIdeal(R,self.groebner_basis())
    18241939        return MPolynomialIdeal(R, eliminate(Is, prod(variables)) )
    18251940
    1826     @redSB
     1941    @libsingular_standard_options
    18271942    def quotient(self, J):
    18281943        r"""
    18291944        Given ideals `I` = ``self`` and `J` in the same polynomial
    class MPolynomialIdeal( MPolynomialIdeal 
    24052520                                        symmetry=symmetry, verbose=verbose)
    24062521
    24072522    @cached_method
    2408     def groebner_basis(self, algorithm='', *args, **kwds):
     2523    def groebner_basis(self, algorithm='', deg_bound=None, mult_bound=None, *args, **kwds):
    24092524        """
    2410         Return the reduced Groebner basis of this ideal. A Groebner
    2411         basis `g_1,...,g_n` for an ideal `I` is a basis such that
    2412         `<LM(g_i)> = LM(I)`, i.e., the leading monomial ideal of
    2413         `I` is spanned by the leading terms of
    2414         `g_1,...,g_n`. Groebner bases are the key concept in
    2415         computational ideal theory in multivariate polynomial rings
    2416         which allows a variety of problems to be solved.
     2525        Return the reduced Groebner basis of this ideal.
     2526
     2527        A Groebner basis `g_1,...,g_n` for an ideal `I` is a
     2528        generating set such that `<LM(g_i)> = LM(I)`, i.e.,
     2529        the leading monomial ideal of `I` is spanned by the
     2530        leading terms of `g_1,...,g_n`. Groebner bases are
     2531        the key concept in computational ideal theory in
     2532        multivariate polynomial rings which allows a variety
     2533        of problems to be solved.
     2534
    24172535        Additionally, a *reduced* Groebner basis `G` is a unique
    2418         representation for the ideal `<G>` with respect to the chosen
    2419         monomial ordering.
     2536        representation for the ideal `<G>` with respect to the
     2537        chosen monomial ordering.
    24202538       
    24212539        INPUT:
    24222540       
    class MPolynomialIdeal( MPolynomialIdeal 
    25662684            sage: I.groebner_basis('magma:GroebnerBasis') # optional - magma
    25672685            [a - 60*c^3 + 158/7*c^2 + 8/7*c - 1, b + 30*c^3 - 79/7*c^2 + 3/7*c, c^4 - 10/21*c^3 + 1/84*c^2 + 1/84*c]
    25682686       
     2687        Singular and libSingular can compute Groebner basis with degree
     2688        restrictions::
     2689
     2690            sage: R.<x,y> = QQ[]
     2691            sage: I = R*[x^3+y^2,x^2*y+1]
     2692            sage: I.groebner_basis(algorithm='singular')
     2693            [x^3 + y^2, x^2*y + 1, y^3 - x]
     2694            sage: I.groebner_basis(algorithm='singular',deg_bound=2)
     2695            [x^3 + y^2, x^2*y + 1]
     2696            sage: I.groebner_basis()
     2697            [x^3 + y^2, x^2*y + 1, y^3 - x]
     2698            sage: I.groebner_basis(deg_bound=2)
     2699            [x^3 + y^2, x^2*y + 1]
     2700
     2701        In the case of libSingular, a protocol is printed, if the
     2702        verbosity level is at least 2, or if the argument ``prot``
     2703        is provided. For some reason, the protocol does not appear
     2704        during doctests, so, we skip the examples with protocol
     2705        output.
     2706        ::
     2707
     2708            sage: set_verbose(2)
     2709            sage: I = R*[x^3+y^2,x^2*y+1]
     2710            sage: I.groebner_basis()  # not tested
     2711            std in (0),(x,y),(dp(2),C)
     2712            [4294967295:2]3ss4s6
     2713            (S:2)--
     2714            product criterion:1 chain criterion:0
     2715            [x^3 + y^2, x^2*y + 1, y^3 - x]
     2716            sage: I.groebner_basis(prot=False)
     2717            [x^3 + y^2, x^2*y + 1, y^3 - x]
     2718            sage: set_verbose(0)
     2719            sage: I.groebner_basis(prot=True)  # not tested
     2720            std in (0),(x,y),(dp(2),C)
     2721            [4294967295:2]3ss4s6
     2722            (S:2)--
     2723            product criterion:1 chain criterion:0
     2724            [x^3 + y^2, x^2*y + 1, y^3 - x]
     2725
     2726        The list of available options is provided at
     2727        :class:`~sage.libs.singular.option.LibSingularOptions`.
     2728
    25692729        Groebner bases over `\ZZ` can be computed. ::
    25702730       
    25712731            sage: P.<a,b,c> = PolynomialRing(ZZ,3)
    class MPolynomialIdeal( MPolynomialIdeal 
    26482808
    26492809        if algorithm is '':
    26502810            try:
    2651                 gb = self._groebner_basis_libsingular("groebner", *args, **kwds)
     2811                gb = self._groebner_basis_libsingular("groebner", deg_bound=deg_bound, mult_bound=mult_bound, *args, **kwds)
    26522812            except (TypeError,NameError), msg: # conversion to Singular not supported
    26532813                try:
    2654                     gb = self._groebner_basis_singular("groebner", *args, **kwds)
     2814                    gb = self._groebner_basis_singular("groebner", deg_bound=deg_bound, mult_bound=mult_bound, *args, **kwds)
    26552815                except (TypeError,NameError), msg: # conversion to Singular not supported
    26562816                    if self.ring().term_order().is_global() and is_IntegerModRing(self.ring().base_ring()) and not self.ring().base_ring().is_field():
    26572817                        verbose("Warning: falling back to very slow toy implementation.", level=0)
    class MPolynomialIdeal( MPolynomialIdeal 
    26722832                            raise TypeError, "Local/unknown orderings not supported by 'toy_buchberger' implementation."
    26732833
    26742834        elif algorithm.startswith('singular:'):
    2675             gb = self._groebner_basis_singular(algorithm[9:])
     2835            gb = self._groebner_basis_singular(algorithm[9:], deg_bound=deg_bound, mult_bound=mult_bound, *args, **kwds)
    26762836        elif algorithm.startswith('libsingular:'):
    2677             gb = self._groebner_basis_libsingular(algorithm[len('libsingular:'):], *args, **kwds)
     2837            gb = self._groebner_basis_libsingular(algorithm[len('libsingular:'):], deg_bound=deg_bound, mult_bound=mult_bound, *args, **kwds)
    26782838        elif algorithm == 'macaulay2:gb':
    26792839            gb = self._groebner_basis_macaulay2(*args, **kwds)
    26802840        elif algorithm == 'magma:GroebnerBasis':