From d0c9fbd619c0d0c63a4e5c9a8934bf004168c79c Mon Sep 17 00:00:00 2001 From: zabrocki Date: Fri, 13 Apr 2018 10:28:22 -0500 Subject: [PATCH] move (restore) is_planar as a standalone function --- src/sage/combinat/diagram_algebras.py | 142 ++++++++++++++------------ 1 file changed, 79 insertions(+), 63 deletions(-) diff --git a/src/sage/combinat/diagram_algebras.py b/src/sage/combinat/diagram_algebras.py index 33e131948b3..15cde43f0b6 100644 --- a/src/sage/combinat/diagram_algebras.py +++ b/src/sage/combinat/diagram_algebras.py @@ -139,7 +139,7 @@ def temperley_lieb_diagrams(k): """ B = brauer_diagrams(k) for i in B: - if AbstractPartitionDiagram.is_planar(BrauerDiagram(i)): + if is_planar(i): yield i def planar_diagrams(k): @@ -164,7 +164,7 @@ def planar_diagrams(k): """ A = partition_diagrams(k) for i in A: - if AbstractPartitionDiagram.is_planar(PartitionDiagram(i)): + if is_planar(i): yield i def ideal_diagrams(k): @@ -434,67 +434,7 @@ def is_planar(self): sage: BrauerDiagram([[1,-1],[2,-2]]).is_planar() True """ - #Singletons don't affect planarity - to_consider = [x for x in (list(_) for _ in self) if len(x) > 1] - n = len(to_consider) - - for i in range(n): - #Get the positive and negative entries of this part - ap = [x for x in to_consider[i] if x>0] - an = [abs(x) for x in to_consider[i] if x<0] - - #Check if a includes numbers in both the top and bottom rows - if len(ap) > 0 and len(an) > 0: - for j in range(n): - if i == j: - continue - #Get the positive and negative entries of this part - bp = [x for x in to_consider[j] if x>0] - bn = [abs(x) for x in to_consider[j] if x<0] - - #Skip the ones that don't involve numbers in both - #the bottom and top rows - if not bn or not bp: - continue - - #Make sure that if min(bp) > max(ap) - #then min(bn) > max(an) - if max(bp) > max(ap): - if min(bn) < min(an): - return False - - #Go through the bottom and top rows - for row in [ap, an]: - if len(row) > 1: - row.sort() - for s in range(len(row)-1): - if row[s] + 1 == row[s+1]: - #No gap, continue on - continue - - rng = list(range(row[s] + 1, row[s+1])) - - #Go through and make sure any parts that - #contain numbers in this range are completely - #contained in this range - for j in range(n): - if i == j: - continue - - #Make sure we make the numbers negative again - #if we are in the bottom row - if row is ap: - sr = set(rng) - else: - sr = set((-1*x for x in rng)) - - sj = set(to_consider[j]) - intersection = sr.intersection(sj) - if intersection: - if sj != intersection: - return False - - return True + return is_planar(self) class IdealDiagram(AbstractPartitionDiagram): r""" @@ -3189,6 +3129,82 @@ def set_partition_composition(sp1, sp2): return (res, total_removed) +def is_planar(sp): + r""" + Return ``True`` if the diagram corresponding to the set partition ``sp`` + is planar; otherwise, return ``False``. + + EXAMPLES:: + + sage: import sage.combinat.diagram_algebras as da + sage: da.is_planar( da.to_set_partition([[1,-2],[2,-1]])) + False + sage: da.is_planar( da.to_set_partition([[1,-1],[2,-2]])) + True + """ + #Singletons don't affect planarity + to_consider = [x for x in (list(_) for _ in sp) if len(x) > 1] + n = len(to_consider) + + for i in range(n): + #Get the positive and negative entries of this part + ap = [x for x in to_consider[i] if x>0] + an = [abs(x) for x in to_consider[i] if x<0] + + #Check if a includes numbers in both the top and bottom rows + if len(ap) > 0 and len(an) > 0: + for j in range(n): + if i == j: + continue + #Get the positive and negative entries of this part + bp = [x for x in to_consider[j] if x>0] + bn = [abs(x) for x in to_consider[j] if x<0] + + #Skip the ones that don't involve numbers in both + #the bottom and top rows + if not bn or not bp: + continue + + #Make sure that if min(bp) > max(ap) + #then min(bn) > max(an) + if max(bp) > max(ap): + if min(bn) < min(an): + return False + + #Go through the bottom and top rows + for row in [ap, an]: + if len(row) > 1: + row.sort() + for s in range(len(row)-1): + if row[s] + 1 == row[s+1]: + #No gap, continue on + continue + + rng = list(range(row[s] + 1, row[s+1])) + + #Go through and make sure any parts that + #contain numbers in this range are completely + #contained in this range + for j in range(n): + if i == j: + continue + + #Make sure we make the numbers negative again + #if we are in the bottom row + if row is ap: + sr = set(rng) + else: + sr = set((-1*x for x in rng)) + + sj = set(to_consider[j]) + intersection = sr.intersection(sj) + if intersection: + if sj != intersection: + return False + + return True + + ########################################################################## # END BORROWED CODE ##########################################################################