# HG changeset patch
# User Simon King <simon.king@unijena.de>
# Date 1306941016 7200
# Node ID e5236dab6a3b2cde3b45d0de2b5b12791dac341b
# Parent 94c5b31731e9441e3124a620458d0726cdc8c34c
#11316: Reviewer patch. Raise an error for nonpositive weights.
diff git a/sage/rings/polynomial/term_order.py b/sage/rings/polynomial/term_order.py
a

b


154  154  sage: x^2*y*z^2 > x*y^3*z 
155  155  True 
156  156  
157   Weighted degree reverse lexicographic (wdegrevlex) 
 157  Weighted degree reverse lexicographic (wdegrevlex), positive integral weights 
158  158  Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then 
159  159  `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 
160  160  there exists `1 \le i \le n` such that `a_n = b_n, \dots, a_{i+1} = b_{i+1}, a_i > b_i`. 
… 
… 

176  176  sage: y*z > x^3*y 
177  177  False 
178  178  
179   Weighted degree lexicographic (wdeglex) 
 179  Weighted degree lexicographic (wdeglex), positive integral weights 
180  180  Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then 
181  181  `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 
182  182  there exists `1 \le i \le n` such that `a_1 = b_1, \dots, a_{i1} = b_{i1}, a_i < b_i`. 
… 
… 

198  198  sage: y*z > x^3*y 
199  199  False 
200  200  
201   Negative weighted degree reverse lexicographic (negwdegrevlex) 
 201  Negative weighted degree reverse lexicographic (negwdegrevlex), positive integral weights 
202  202  Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then 
203  203  `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 
204  204  there exists `1 \le i \le n` such that `a_n = b_n, \dots, a_{i+1} = b_{i+1}, a_i > b_i`. 
… 
… 

220  220  sage: y*z > x^3*y 
221  221  False 
222  222  
223   Negative weighted degree lexicographic (negwdeglex) 
 223  Negative weighted degree lexicographic (negwdeglex), positive integral weights 
224  224  Let `\deg_w(x^a) = a_1w_1 + a_2w_2 + \dots + a_nw_n` with weights `w`, then 
225  225  `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 
226  226  there exists `1 \le i \le n` such that `a_1 = b_1, \dots, a_{i1} = b_{i1}, a_i < b_i`. 
… 
… 

242  242  sage: y*z > x^3*y 
243  243  False 
244  244  
245   Of these, only 'degrevlex', 'deglex', 'wdegrevlex', 'wdeglex', 'invlex' and 'lex' are global 
246   orders. 
 245  Of these, only 'degrevlex', 'deglex', 'wdegrevlex', 'wdeglex', 
 246  'invlex' and 'lex' are global orders. 
247  247  
248  248  Sage also supports matrix term order. Given a square matrix `A`, 
249  249  
… 
… 

535  535  
536  536   ``name``  name of the term order (default: lex) 
537  537  
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. 
540  541  
541  542   ``blocks``  this is deprecated. 
542  543  
… 
… 

582  583  nonblock orders like `deglex` are 
583  584  constructed. However, it is useful if block orders are 
584  585  to be constructed from this ``TermOrder`` object later. 
 586  
 587  TEST: 
 588  
 589  We demonstrate that nonpositive weights are refused and nonintegral 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  
585  600  """ 
586  601  if isinstance(name, TermOrder): 
587  602  self.__copy(name) 
… 
… 

687  702  elif isinstance(name, str) and (isinstance(n, tuple) or isinstance(n,list)): # weighted degree term orders 
688  703  if name not in print_name_mapping.keys() and name not in singular_name_mapping.values() and not force: 
689  704  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" 
691  708  
692  709  self._length = len(weights) 
693  710  self._name = name 
… 
… 

1527  1544  // block 3 : ordering lp 
1528  1545  // : names x8 x9 
1529  1546  // block 4 : ordering C 
 1547  
1530  1548  """ 
1531  1549  return self._singular_str 
1532  1550  
… 
… 

1574  1592  """ 
1575  1593  Return the term order blocks of self. 
1576  1594  
 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  
1577  1601  EXAMPLE:: 
1578  1602  
1579  1603  sage: t=TermOrder('deglex',2)+TermOrder('lex',2) 