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

Commit

Permalink
Merge branch 'u/dkrenn/asy/growthGroup-exponential' of trac.sagemath.…
Browse files Browse the repository at this point in the history
…org:sage into t/19073/asy/groups-coercion

* 'u/dkrenn/asy/growthGroup-exponential' of trac.sagemath.org:sage:
  fixup due to changes in #18587 (coming from #18223)
  fix code after changes by previous merge
  add a doctest dealing with coercion while comparing
  code-simplify CartesianProduct assignment
  rename CartesianProductPosets to CartesianProductPoset
  • Loading branch information
dkrenn committed Oct 8, 2015
2 parents 592a551 + 09221f0 commit 311fc97
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/sage/categories/posets.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,9 +683,8 @@ def is_antichain_of_poset(self, o):
"""
return all(not self.lt(x,y) for x in o for y in o)

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

class ElementMethods:
pass
Expand Down
40 changes: 30 additions & 10 deletions src/sage/combinat/posets/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sage.sets.cartesian_product import CartesianProduct


class CartesianProductPosets(CartesianProduct):
class CartesianProductPoset(CartesianProduct):
r"""
A class implementing cartesian products of posets (and elements
thereof). Compared to :class:`CartesianProduct` you are able to
Expand Down Expand Up @@ -83,7 +83,7 @@ class CartesianProductPosets(CartesianProduct):

def __init__(self, sets, category, order=None, **kwargs):
r"""
See :class:`CartesianProductPosets` for details.
See :class:`CartesianProductPoset` for details.
TESTS::
Expand Down Expand Up @@ -111,7 +111,7 @@ def __init__(self, sets, category, order=None, **kwargs):
if not isinstance(category, tuple):
category = (category,)
category = Category.join(category + (Posets(),))
super(CartesianProductPosets, self).__init__(
super(CartesianProductPoset, self).__init__(
sets, category, **kwargs)


Expand All @@ -132,7 +132,7 @@ def le(self, left, right):
.. NOTE::
This method uses the order defined on creation of this
cartesian product. See :class:`CartesianProductPosets`.
cartesian product. See :class:`CartesianProductPoset`.
EXAMPLES::
Expand Down Expand Up @@ -315,15 +315,15 @@ def _le_(self, other):
.. NOTE::
This method calls :meth:`CartesianProductPosets.le`. Override
This method calls :meth:`CartesianProductPoset.le`. Override
it in inherited class to change this.
It can be assumed that this element and ``other`` have
the same parent.
TESTS::
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPosets # needed until #19269 is fixed
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPoset # needed until #19269 is fixed
sage: def le_sum(left, right):
....: return (sum(left) < sum(right) or
....: sum(left) == sum(right) and left[0] <= right[0])
Expand Down Expand Up @@ -358,7 +358,8 @@ def __le__(self, other):
TESTS::
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPosets # needed until #19269 is fixed
sage: from sage.combinat.posets.cartesian_product import CartesianProductPoset
sage: QQ.CartesianProduct = CartesianProductPoset # needed until #19269 is fixed
sage: def le_sum(left, right):
....: return (sum(left) < sum(right) or
....: sum(left) == sum(right) and left[0] <= right[0])
Expand All @@ -367,6 +368,25 @@ def __le__(self, other):
True
sage: C((1/3, 2)) <= C((2, 2))
True
The following example tests that the coercion gets involved in
comparisons; it can be simplified once #18182 is in merged.
::
sage: class MyCP(CartesianProductPoset):
....: def _coerce_map_from_(self, S):
....: if isinstance(S, self.__class__):
....: S_factors = S.cartesian_factors()
....: R_factors = self.cartesian_factors()
....: if len(S_factors) == len(R_factors):
....: if all(r.has_coerce_map_from(s)
....: for r,s in zip(R_factors, S_factors)):
....: return True
sage: QQ.CartesianProduct = MyCP
sage: A = cartesian_product((QQ, ZZ), order=le_sum)
sage: B = cartesian_product((QQ, QQ), order=le_sum)
sage: A((1/2, 4)) <= B((1/2, 5))
True
"""
from sage.structure.element import have_same_parent
if have_same_parent(self, other):
Expand Down Expand Up @@ -402,7 +422,7 @@ def __ge__(self, other):
TESTS::
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPosets # needed until #19269 is fixed
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPoset # needed until #19269 is fixed
sage: def le_sum(left, right):
....: return (sum(left) < sum(right) or
....: sum(left) == sum(right) and left[0] <= right[0])
Expand Down Expand Up @@ -437,7 +457,7 @@ def __lt__(self, other):
TESTS::
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPosets # needed until #19269 is fixed
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPoset # needed until #19269 is fixed
sage: def le_sum(left, right):
....: return (sum(left) < sum(right) or
....: sum(left) == sum(right) and left[0] <= right[0])
Expand Down Expand Up @@ -472,7 +492,7 @@ def __gt__(self, other):
TESTS::
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPosets # needed until #19269 is fixed
sage: QQ.CartesianProduct = sage.combinat.posets.cartesian_product.CartesianProductPoset # needed until #19269 is fixed
sage: def le_sum(left, right):
....: return (sum(left) < sum(right) or
....: sum(left) == sum(right) and left[0] <= right[0])
Expand Down
16 changes: 8 additions & 8 deletions src/sage/rings/asymptotic/growth_group_cartesian.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,9 @@ def create_object(self, version, args, **kwds):
CartesianProductGrowthGroups = CartesianProductFactory('CartesianProductGrowthGroups')


from sage.combinat.posets.cartesian_product import CartesianProductPosets
from sage.combinat.posets.cartesian_product import CartesianProductPoset
from sage.rings.asymptotic.growth_group import GenericGrowthGroup
class GenericProduct(CartesianProductPosets, GenericGrowthGroup):
class GenericProduct(CartesianProductPoset, GenericGrowthGroup):
r"""
A cartesian product of growth groups.
Expand Down Expand Up @@ -394,10 +394,10 @@ class GenericProduct(CartesianProductPosets, GenericGrowthGroup):
.. SEEALSO::
:class:`~sage.sets.cartesian_product.CartesianProduct`,
:class:`~sage.combinat.posets.cartesian_product.CartesianProductPosets`.
:class:`~sage.combinat.posets.cartesian_product.CartesianProductPoset`.
"""

__classcall__ = CartesianProductPosets.__classcall__
__classcall__ = CartesianProductPoset.__classcall__


def __init__(self, sets, category, **kwds):
Expand All @@ -411,7 +411,7 @@ def __init__(self, sets, category, **kwds):
Growth Group x^ZZ * y^ZZ
"""
order = kwds.pop('order')
CartesianProductPosets.__init__(self, sets, category, order, **kwds)
CartesianProductPoset.__init__(self, sets, category, order, **kwds)

vars = sum(iter(factor.variable_names()
for factor in self.cartesian_factors()),
Expand All @@ -423,7 +423,7 @@ def __init__(self, sets, category, **kwds):
GenericGrowthGroup.__init__(self, sets[0], Vars, self.category(), **kwds)


__hash__ = CartesianProductPosets.__hash__
__hash__ = CartesianProductPoset.__hash__


def _element_constructor_(self, data):
Expand Down Expand Up @@ -647,7 +647,7 @@ def _coerce_map_from_(self, S):
sage: B.has_coerce_map_from(A) # indirect doctest
False
"""
if CartesianProductPosets.has_coerce_map_from(self, S):
if CartesianProductPoset.has_coerce_map_from(self, S):
return True

elif isinstance(S, GenericProduct):
Expand Down Expand Up @@ -880,7 +880,7 @@ def variable_names(self):
return tuple(v for v, _ in groupby(vars))


class Element(CartesianProductPosets.Element):
class Element(CartesianProductPoset.Element):

def _repr_(self):
r"""
Expand Down
2 changes: 0 additions & 2 deletions src/sage/sets/cartesian_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
AUTHORS:
- Nicolas Thiery (2010-03): initial version
- Daniel Krenn (2015-06): cartesian products for posets with different orders
"""
#*****************************************************************************
# Copyright (C) 2008 Nicolas Thiery <nthiery at users.sf.net>,
Expand Down

0 comments on commit 311fc97

Please sign in to comment.