Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
move (restore) is_planar as a standalone function
Browse files Browse the repository at this point in the history
  • Loading branch information
zabrocki committed Apr 13, 2018
1 parent 783bca5 commit d0c9fbd
Showing 1 changed file with 79 additions and 63 deletions.
142 changes: 79 additions & 63 deletions src/sage/combinat/diagram_algebras.py
Expand Up @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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"""
Expand Down Expand Up @@ -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
##########################################################################

0 comments on commit d0c9fbd

Please sign in to comment.