Skip to content

Commit

Permalink
Trac #18223: cartesian products with orders
Browse files Browse the repository at this point in the history
Create cartesian products which have a particular order
(lexicographically or component-wise) on its elements.

This also incorporates the proposed changes of #18586 (won't be fixed;
see discussion there), namely passes keyword arguments on in
`cartesian_product` and adds `extra_category`.

URL: http://trac.sagemath.org/18223
Reported by: dkrenn
Ticket author(s): Daniel Krenn
Reviewer(s): Benjamin Hackl, Vincent Delecroix
  • Loading branch information
Release Manager authored and vbraun committed Oct 11, 2015
2 parents a677b85 + 8f9a619 commit 9481c0b
Show file tree
Hide file tree
Showing 7 changed files with 566 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/doc/en/reference/combinat/module_list.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ Comprehensive Module list
sage/combinat/permutation_nk
sage/combinat/posets/__init__
sage/combinat/posets/all
sage/combinat/posets/cartesian_product
sage/combinat/posets/elements
sage/combinat/posets/hasse_diagram
sage/combinat/posets/incidence_algebras
Expand Down
4 changes: 2 additions & 2 deletions src/sage/categories/covariant_functorial_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _repr_(self):
"""
return "The %s functorial construction"%self._functor_name

def __call__(self, args):
def __call__(self, args, **kwargs):
"""
Functorial construction application
Expand All @@ -220,7 +220,7 @@ def __call__(self, args):
args = tuple(args) # a bit brute force; let's see if this becomes a bottleneck later
assert(all( hasattr(arg, self._functor_name) for arg in args))
assert(len(args) > 0)
return getattr(args[0], self._functor_name)(*args[1:])
return getattr(args[0], self._functor_name)(*args[1:], **kwargs)

class FunctorialConstructionCategory(Category): # Should this be CategoryWithBase?
"""
Expand Down
3 changes: 3 additions & 0 deletions src/sage/categories/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,9 @@ def is_antichain_of_poset(self, o):
"""
return all(not self.lt(x,y) for x in o for y in o)

CartesianProduct = LazyImport(
'sage.combinat.posets.cartesian_product', 'CartesianProductPoset')

class ElementMethods:
pass
# TODO: implement x<y, x<=y, x>y, x>=y appropriately once #10130 is resolved
Expand Down
51 changes: 47 additions & 4 deletions src/sage/categories/sets_cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,10 +1400,32 @@ def _test_cardinality(self, **options):
# Functorial constructions

CartesianProduct = CartesianProduct
def cartesian_product(*parents):
def cartesian_product(*parents, **kwargs):
"""
Return the cartesian product of the parents.
INPUT:
- ``parents`` -- a list (or other iterable) of parents.
- ``category`` -- (default: ``None``) the category the
cartesian product belongs to. If ``None`` is passed,
then
:meth:`~sage.categories.covariant_functorial_construction.CovariantFactorialConstruction.category_from_parents`
is used to determine the category.
- ``extra_category`` -- (default: ``None``) a category
that is added to the cartesian product in addition
to the categories obtained from the parents.
- other keyword arguments will passed on to the class used
for this cartesian product (see also
:class:`~sage.sets.cartesian_product.CartesianProduct`).
OUTPUT:
The cartesian product.
EXAMPLES::
sage: C = AlgebrasWithBasis(QQ)
Expand All @@ -1423,10 +1445,31 @@ def cartesian_product(*parents):
sage: C.category()
Join of Category of rings and ...
and Category of Cartesian products of commutative additive groups
::
sage: cartesian_product([ZZ, ZZ], category=Sets()).category()
Category of sets
sage: cartesian_product([ZZ, ZZ]).category()
Join of
Category of Cartesian products of commutative rings and
Category of Cartesian products of enumerated sets
sage: cartesian_product([ZZ, ZZ], extra_category=Posets()).category()
Join of
Category of Cartesian products of commutative rings and
Category of posets and
Category of Cartesian products of enumerated sets
"""
return parents[0].CartesianProduct(
parents,
category = cartesian_product.category_from_parents(parents))
category = kwargs.pop('category', None)
extra_category = kwargs.pop('extra_category', None)

category = category or cartesian_product.category_from_parents(parents)
if extra_category:
if isinstance(category, (list, tuple)):
category = tuple(category) + (extra_category,)
else:
category = category & extra_category
return parents[0].CartesianProduct(parents, category=category, **kwargs)

def algebra(self, base_ring, category=None):
"""
Expand Down
2 changes: 2 additions & 0 deletions src/sage/combinat/posets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
- :ref:`sage.combinat.posets.incidence_algebras`
- :ref:`sage.combinat.posets.cartesian_product`
- :ref:`sage.combinat.tamari_lattices`
- :ref:`sage.combinat.interval_posets`
- :ref:`sage.combinat.shard_order`
Expand Down
Loading

0 comments on commit 9481c0b

Please sign in to comment.