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

Commit

Permalink
add a native order option
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Sep 22, 2015
1 parent ca4a844 commit 693b0bd
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/sage/combinat/posets/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ class CartesianProductPosets(CartesianProduct):
- ``order`` -- a string or function specifying an order less or equal.
It can be one of the following:
- ``'native'`` -- elements are ordered by their native ordering,
i.e., the order the wrapped elements (tuples) provide.
- ``'lex'`` -- elements are ordered lexicographically.
- ``'product'`` -- an element is less or equal to another
Expand Down Expand Up @@ -252,6 +255,50 @@ def le_product(self, left, right):
zip(left.value, right.value, self.cartesian_factors()))


def le_native(self, left, right):
r"""
Test whether ``left`` is smaller or equal to ``right`` in the order
provided by the elements themselves.
INPUT:
- ``left`` -- an element.
- ``right`` -- an element.
OUTPUT:
A boolean.
EXAMPLES::
sage: P = Poset((srange(2), lambda left, right: left <= right))
sage: Q = cartesian_product((P, P), order='native')
sage: T = [Q((0, 0)), Q((1, 1)), Q((0, 1)), Q((1, 0))]
sage: for a in T:
....: for b in T:
....: assert(Q.le(a, b) == (a <= b))
....: print '%s <= %s = %s' % (a, b, a <= b)
(0, 0) <= (0, 0) = True
(0, 0) <= (1, 1) = True
(0, 0) <= (0, 1) = True
(0, 0) <= (1, 0) = True
(1, 1) <= (0, 0) = False
(1, 1) <= (1, 1) = True
(1, 1) <= (0, 1) = False
(1, 1) <= (1, 0) = False
(0, 1) <= (0, 0) = False
(0, 1) <= (1, 1) = True
(0, 1) <= (0, 1) = True
(0, 1) <= (1, 0) = True
(1, 0) <= (0, 0) = False
(1, 0) <= (1, 1) = True
(1, 0) <= (0, 1) = False
(1, 0) <= (1, 0) = True
"""
return left.value <= right.value


class Element(CartesianProduct.Element):

def _le_(self, other):
Expand Down

0 comments on commit 693b0bd

Please sign in to comment.