Ticket #11316: trac11316_reviewer.patch

File trac11316_reviewer.patch, 5.1 KB (added by SimonKing, 11 years ago)

Raise an error on invalid degree weights. State in the docs which weights are accepted

  • sage/rings/polynomial/term_order.py

    # HG changeset patch
    # User Simon King <simon.king@uni-jena.de>
    # Date 1306941016 -7200
    # Node ID e5236dab6a3b2cde3b45d0de2b5b12791dac341b
    # Parent  94c5b31731e9441e3124a620458d0726cdc8c34c
    #11316: Reviewer patch. Raise an error for non-positive weights.
    
    diff --git a/sage/rings/polynomial/term_order.py b/sage/rings/polynomial/term_order.py
    a b  
    154154        sage: x^2*y*z^2 > x*y^3*z
    155155        True
    156156
    157 Weighted degree reverse lexicographic (wdegrevlex)
     157Weighted degree reverse lexicographic (wdegrevlex), positive integral weights
    158158    Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then
    159159    `x^a < x^b` if and only if `\deg_w(x^a) < \deg_w(x^b)` or `\deg_w(x^a) = \deg_w(x^b)` and 
    160160    there exists `1 \le i \le n` such that `a_n = b_n, \dots, a_{i+1} = b_{i+1}, a_i > b_i`.   
     
    176176        sage: y*z > x^3*y
    177177        False
    178178
    179 Weighted degree lexicographic (wdeglex)
     179Weighted degree lexicographic (wdeglex), positive integral weights
    180180    Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then
    181181    `x^a < x^b` if and only if `\deg_w(x^a) < \deg_w(x^b)` or `\deg_w(x^a) = \deg_w(x^b)` and
    182182    there exists `1 \le i \le n` such that `a_1 = b_1, \dots, a_{i-1} = b_{i-1}, a_i < b_i`. 
     
    198198        sage: y*z > x^3*y
    199199        False
    200200
    201 Negative weighted degree reverse lexicographic (negwdegrevlex)
     201Negative weighted degree reverse lexicographic (negwdegrevlex), positive integral weights
    202202    Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then
    203203    `x^a < x^b` if and only if `\deg_w(x^a) > \deg_w(x^b)` or `\deg_w(x^a) = \deg_w(x^b)` and 
    204204    there exists `1 \le i \le n` such that `a_n = b_n, \dots, a_{i+1} = b_{i+1}, a_i > b_i`. 
     
    220220        sage: y*z > x^3*y
    221221        False
    222222
    223 Negative weighted degree lexicographic (negwdeglex)
     223Negative weighted degree lexicographic (negwdeglex), positive integral weights
    224224    Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then
    225225    `x^a < x^b` if and only if `\deg_w(x^a) > \deg_w(x^b)` or `\deg_w(x^a) = \deg_w(x^b)` and
    226226    there exists `1 \le i \le n` such that `a_1 = b_1, \dots, a_{i-1} = b_{i-1}, a_i < b_i`.   
     
    242242        sage: y*z > x^3*y
    243243        False
    244244
    245 Of these, only 'degrevlex', 'deglex', 'wdegrevlex', 'wdeglex', 'invlex' and 'lex' are global
    246 orders.   
     245Of these, only 'degrevlex', 'deglex', 'wdegrevlex', 'wdeglex',
     246'invlex' and 'lex' are global orders.
    247247
    248248Sage also supports matrix term order. Given a square matrix `A`,
    249249
     
    535535       
    536536        - ``name`` - name of the term order (default: lex)
    537537       
    538         - ``n`` - number of variables (default is `0`) or weights for
    539           weighted degree orders
     538        - ``n`` - number of variables (default is `0`) weights for
     539          weighted degree orders. The weights are converted to
     540          integers and must be positive.
    540541
    541542        - ``blocks`` - this is deprecated.
    542543       
     
    582583           non-block orders like `deglex` are
    583584           constructed. However, it is useful if block orders are
    584585           to be constructed from this ``TermOrder`` object later.
     586
     587        TEST:
     588
     589        We demonstrate that non-positive weights are refused and non-integral weights
     590        are converted to integers (and potentially rounded)::
     591
     592            sage: N.<a,b,c> = PolynomialRing(QQ, 3, order=TermOrder('wdeglex',[-1,2,-3]))
     593            Traceback (most recent call last):
     594            ...
     595            ValueError: the degree weights must be positive integers
     596            sage: N.<a,b,c> = PolynomialRing(QQ, 3, order=TermOrder('wdeglex',[1.1,2,3]))
     597            sage: a.degree()
     598            1
     599
    585600        """ 
    586601        if isinstance(name, TermOrder):
    587602            self.__copy(name)
     
    687702        elif isinstance(name, str) and (isinstance(n, tuple) or isinstance(n,list)): # weighted degree term orders
    688703            if name not in print_name_mapping.keys() and name not in singular_name_mapping.values() and not force:
    689704                raise TypeError, "Unknown term order '%s'"%(name,) 
    690             weights = tuple(n) # n is a tuple of weights
     705            weights = tuple(int(w) for w in n) # n is a tuple of weights
     706            if any([w<=0 for w in weights]):
     707                raise ValueError, "the degree weights must be positive integers"
    691708           
    692709            self._length = len(weights)
    693710            self._name = name
     
    15271544            //        block   3 : ordering lp
    15281545            //                  : names    x8 x9
    15291546            //        block   4 : ordering C
     1547
    15301548        """
    15311549        return self._singular_str
    15321550
     
    15741592        """
    15751593        Return the term order blocks of self.
    15761594
     1595        NOTE:
     1596
     1597        This method has been added in trac ticket #11316. There used
     1598        to be an *attribute* of the same name and the same content.
     1599        So, it is a backward incompatible syntax change.
     1600
    15771601        EXAMPLE::
    15781602
    15791603            sage: t=TermOrder('deglex',2)+TermOrder('lex',2)