From 4688e6411e5506ccbcdd70d690658c4d3f26a522 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Chapoton?= Date: Tue, 19 Apr 2016 22:30:54 +0200 Subject: [PATCH] taking care of the remaining classic divisions in combinat folder --- src/sage/combinat/alternating_sign_matrix.py | 2 +- src/sage/combinat/diagram_algebras.py | 4 ++-- src/sage/combinat/fully_packed_loop.py | 14 +++++++------- src/sage/combinat/perfect_matching.py | 3 ++- src/sage/combinat/q_analogues.py | 11 ++++++----- src/sage/combinat/ribbon_tableau.py | 8 ++++---- src/sage/combinat/subword_complex.py | 2 +- src/sage/combinat/tiling.py | 4 ++-- 8 files changed, 25 insertions(+), 23 deletions(-) diff --git a/src/sage/combinat/alternating_sign_matrix.py b/src/sage/combinat/alternating_sign_matrix.py index 040b97d6ce7..03f3bdb4d53 100644 --- a/src/sage/combinat/alternating_sign_matrix.py +++ b/src/sage/combinat/alternating_sign_matrix.py @@ -1273,7 +1273,7 @@ def from_height_function(self,height): [ 1 -1 1] [ 0 1 0] """ - return self.from_corner_sum(matrix( [[((i+j-height[i][j])/int(2)) + return self.from_corner_sum(matrix( [[((i+j-height[i][j])//int(2)) for i in range(len(list(height)))] for j in range(len(list(height)))] )) diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index 3c75aac400f..7cb2ff9708a 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -282,7 +282,7 @@ def check(self): """ if self._base_diagram: tst = sorted(flatten(self._base_diagram)) - if len(tst) % 2 != 0 or tst != range(-len(tst)/2,0) + range(1,len(tst)/2+1): + if len(tst) % 2 != 0 or tst != range(-len(tst) // 2,0) + range(1,len(tst) // 2+1): raise ValueError("this does not represent two rows of vertices") def __eq__(self, other): @@ -744,7 +744,7 @@ def __contains__(self, obj): return False if len(obj.base_diagram()) > 0: tst = sorted(flatten(obj.base_diagram())) - if len(tst)%2 != 0 or tst != range(-len(tst)/2,0) + range(1,len(tst)/2+1): + if len(tst)%2 != 0 or tst != range(-len(tst)//2,0) + range(1,len(tst)//2+1): return False return True return self.order == 0 diff --git a/src/sage/combinat/fully_packed_loop.py b/src/sage/combinat/fully_packed_loop.py index 686b805d1d3..af961e2a410 100644 --- a/src/sage/combinat/fully_packed_loop.py +++ b/src/sage/combinat/fully_packed_loop.py @@ -490,7 +490,7 @@ def __init__(self, parent, generator): self._six_vertex_model = generator self.configuration = matrix(list(self._six_vertex_model)) - self._n = len(self._end_point_dictionary)/2 + self._n = len(self._end_point_dictionary) // 2 Element.__init__(self, parent) def _repr_(self): @@ -1204,30 +1204,30 @@ def _end_point_dictionary(self): for k in range(n): if k % 2 == 0: # top row - end_points[1 + k/2] = (0, k) + end_points[1 + k // 2] = (0, k) # bottom row - end_points[n + 1 + k/2] = (n-1, n-1-k) + end_points[n + 1 + k // 2] = (n-1, n-1-k) # sides for even case if n % 2 == 0: for k in range(n): if k % 2 == 0: # left side - end_points[((3*n + 2 + k)/2)] = (n-1-k, 0) + end_points[((3*n + 2 + k) // 2)] = (n-1-k, 0) # right side - end_points[(n + 2 + k)/2] = (k, n-1) + end_points[(n + 2 + k) // 2] = (k, n-1) # side for odd case if n % 2 == 1: for k in range(n): if k % 2 == 1: # left side - end_points[(3*n + 2 + k)/2] = (n-1-k, 0) + end_points[(3*n + 2 + k) // 2] = (n-1-k, 0) # right side - end_points[(n + 2 + k)/2] = (k, n-1) + end_points[(n + 2 + k) // 2] = (k, n-1) return end_points diff --git a/src/sage/combinat/perfect_matching.py b/src/sage/combinat/perfect_matching.py index 00c8ff308b0..0af77f7fd17 100644 --- a/src/sage/combinat/perfect_matching.py +++ b/src/sage/combinat/perfect_matching.py @@ -834,7 +834,8 @@ def to_non_crossing_set_partition(self): raise ValueError("matching must be non-crossing") else: perm = self.to_permutation() - perm2 = Permutation([(perm[2*i])/2 for i in range(len(perm)/2)]) + perm2 = Permutation([perm[2 * i] // 2 + for i in range(len(perm) // 2)]) return SetPartition(perm2.cycle_tuples()) diff --git a/src/sage/combinat/q_analogues.py b/src/sage/combinat/q_analogues.py index 69d66ab3f2f..6197c379b3f 100644 --- a/src/sage/combinat/q_analogues.py +++ b/src/sage/combinat/q_analogues.py @@ -278,8 +278,8 @@ def q_binomial(n, k, q=None, algorithm='auto'): is_polynomial = isinstance(q, Polynomial) R = parent(q) - zero = R(0) - one = R(1) + zero = R.zero() + one = R.one() if not(0 <= k and k <= n): return zero @@ -290,7 +290,7 @@ def q_binomial(n, k, q=None, algorithm='auto'): if algorithm == 'auto': from sage.symbolic.ring import SR if is_polynomial: - if n <= 70 or k <= n/4: + if n <= 70 or k <= n // 4: algorithm = 'naive' else: algorithm = 'cyclo_polynomial' @@ -325,11 +325,12 @@ def q_binomial(n, k, q=None, algorithm='auto'): from sage.rings.polynomial.cyclotomic import cyclotomic_value return prod(cyclotomic_value(d,q) for d in range(2,n+1) - if (n/d).floor() != (k/d).floor() + ((n-k)/d).floor()) + if (n//d) != (k//d) + ((n-k)//d)) elif algorithm == 'cyclo_polynomial': return prod(R.cyclotomic_polynomial(d) for d in range(2,n+1) - if (n/d).floor() != (k/d).floor() + ((n-k)/d).floor()) + if (n//d) != (k//d) + ((n-k)//d)) + def gaussian_binomial(n, k, q=None, algorithm='auto'): r""" diff --git a/src/sage/combinat/ribbon_tableau.py b/src/sage/combinat/ribbon_tableau.py index 8610f09689e..c0b7e1dd494 100644 --- a/src/sage/combinat/ribbon_tableau.py +++ b/src/sage/combinat/ribbon_tableau.py @@ -106,20 +106,20 @@ def length(self): sage: RibbonTableau([[1,0],[2,0]]).length() 2 """ - if self.to_expr() == [[],[]]: + if self.to_expr() == [[], []]: return 0 tableau = self.to_expr()[1] l = 0 t = 0 for k in range(len(tableau)): - t += len( [ x for x in tableau[k] if x is not None and x > -1 ] ) - l += len( [ x for x in tableau[k] if x is not None and x > 0 ] ) + t += len([ x for x in tableau[k] if x is not None and x > -1]) + l += len([ x for x in tableau[k] if x is not None and x > 0]) if l == 0: return t else: - return t/l + return t // l def to_word(self): """ diff --git a/src/sage/combinat/subword_complex.py b/src/sage/combinat/subword_complex.py index d664c1f289d..84855b2fed1 100644 --- a/src/sage/combinat/subword_complex.py +++ b/src/sage/combinat/subword_complex.py @@ -341,7 +341,7 @@ def upper_root_configuration(self): conf = self._root_configuration_indices() W = self.parent().group() Phi = W.roots() - N = len(Phi) / 2 + N = len(Phi) // 2 return [Phi[i - N] for i in conf if i >= N] # weights diff --git a/src/sage/combinat/tiling.py b/src/sage/combinat/tiling.py index f4ceba36385..b4f7a0af329 100644 --- a/src/sage/combinat/tiling.py +++ b/src/sage/combinat/tiling.py @@ -1479,8 +1479,8 @@ def _rows_mod_box_isometries(self, i): We test that there are four times less rows for that polyomino:: - sage: len(T.rows()) / len(T._rows_mod_box_isometries(0)) - 4 + sage: len(T.rows()) == 4 * len(T._rows_mod_box_isometries(0)) + True Now, a real use case. A solution of the game Quantumino is a tiling of a 5x8x2 box. Since a 5x8x2 box has four orientation preserving