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

Commit

Permalink
Enhanced meet() and join() to accept a list of elements as argument.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jori Mäntysalo committed Oct 27, 2014
1 parent 36c150e commit 8095cf3
Showing 1 changed file with 39 additions and 20 deletions.
59 changes: 39 additions & 20 deletions src/sage/combinat/posets/lattices.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _repr_(self):
return "Finite meet-semilattice containing %s elements"\
%self._hasse_diagram.order()

def meet(self,x,y):
def meet(self, x, y=None):
r"""
Return the meet of two elements in the lattice.
Expand All @@ -125,14 +125,14 @@ def meet(self,x,y):
sage: D.meet(1, 4)
1
If this method is used directly, it is not necessary to coerce
elements into the poset. (Trac #11292) ::
Using list of elements as an argument. Meet of empty list is
the bottom element::
sage: D = Posets.DiamondPoset(5)
sage: D.meet(1, 0)
sage: B4=Posets.BooleanLattice(4)
sage: B4.meet([3,5,6])
0
sage: D.meet(1, 4)
1
sage: B4.meet([])
15
Test that this method also works for facade lattices::
Expand All @@ -143,8 +143,14 @@ def meet(self,x,y):
0
"""
i, j = map(self._element_to_vertex,(x,y))
return self._vertex_to_element(self._hasse_diagram._meet[i,j])
if y is not None: # Handle basic case fast
i, j = map(self._element_to_vertex, (x,y))
return self._vertex_to_element(self._hasse_diagram._meet[i,j])
L = map(self._element_to_vertex, x)
m = self.cardinality()-1 # m = top element
for i in L:
m = self._hasse_diagram._meet[i, m]
return self._vertex_to_element(m)

####################################################################################

Expand Down Expand Up @@ -232,9 +238,15 @@ def _repr_(self):
return "Finite join-semilattice containing %s elements"\
%self._hasse_diagram.order()

def join(self,x,y):
def join(self, x, y=None):
r"""
Return the join of two elements in the lattice.
Return the join of given elements in the lattice.
INPUT:
- ``x, y`` - two elements of the (semi)lattice OR
- ``x`` - a list or tuple of elements
EXAMPLES::
Expand All @@ -248,14 +260,14 @@ def join(self,x,y):
sage: D.join(1, 0)
1
If this method is used directly, it is not necessary to coerce
elements into the poset. (Trac #11292) ::
Using list of elements as an argument. Join of empty list is
the bottom element::
sage: D = Posets.DiamondPoset(5)
sage: D.join(1, 0)
1
sage: D.join(1, 4)
4
sage: B4=Posets.BooleanLattice(4)
sage: B4.join([2,4,8])
14
sage: B4.join([])
0
Test that this method also works for facade lattices::
Expand All @@ -266,8 +278,15 @@ def join(self,x,y):
3
"""
i, j = map(self._element_to_vertex,(x,y))
return self._vertex_to_element(self._hasse_diagram._join[i,j])
if y is not None: # Handle basic case fast
i, j = map(self._element_to_vertex, (x,y))
return self._vertex_to_element(self._hasse_diagram._join[i,j])
L = map(self._element_to_vertex, x)
j = 0 # j = bottom element
for i in L:
j = self._hasse_diagram._join[i, j]
return self._vertex_to_element(j)


####################################################################################

Expand Down

0 comments on commit 8095cf3

Please sign in to comment.