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/groups-coercion' of trac.sagemath.org:sage…
Browse files Browse the repository at this point in the history
… into t/19094/asy/ring-exp-log

* 'u/dkrenn/asy/groups-coercion' of trac.sagemath.org:sage:
  Trac #18182, comment 20, 7: rename CartesianProductPolys --> CartesianProductPoly
  Trac #18182, comment 20, 2: rewrite OUTPUT-block
  add two doctests
  CartesianProductPolys: check whether other has a construction
  remove superfluous import in doctest, superfluous empty line in docstring, and fix spacing in a line (pep 8)
  fix ReSt-error
  improve language
  fix typos
  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 74cd899 + 311fc97 commit eb4e3c9
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 56 deletions.
10 changes: 5 additions & 5 deletions src/sage/categories/modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,11 @@ class CartesianProducts(CartesianProductsCategory):
"""
The category of modules constructed as cartesian products of modules
This construction gives the direct product of modules. See
discussion on:
This construction gives the direct product of modules. The
implementation is based on the following resources:
- http://groups.google.fr/group/sage-devel/browse_thread/thread/35a72b1d0a2fc77a/348f42ae77a66d16#348f42ae77a66d16
- http://en.wikipedia.org/wiki/Direct_product
- http://groups.google.fr/group/sage-devel/browse_thread/thread/35a72b1d0a2fc77a/348f42ae77a66d16#348f42ae77a66d16
- http://en.wikipedia.org/wiki/Direct_product
"""
def extra_super_categories(self):
"""
Expand All @@ -606,7 +606,7 @@ def extra_super_categories(self):
class ParentMethods:
def base_ring(self):
"""
Return the base ring this cartesian product.
Return the base ring of this cartesian product.
EXAMPLES::
Expand Down
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
67 changes: 41 additions & 26 deletions src/sage/categories/pushout.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,9 @@ def common_base(self, other_functor, self_bases, other_bases):
OUTPUT:
Raise a :class:`~sage.structure.coerce_exceptions.CoercionException`.
Nothing, since a
:class:`~sage.structure.coerce_exceptions.CoercionException`
is raised.
.. NOTE::
Expand Down Expand Up @@ -643,7 +645,6 @@ class MultivariateConstructionFunctor(ConstructionFunctor):
TESTS::
sage: from sage.categories.pushout import pushout
sage: from sage.sets.cartesian_product import CartesianProduct
sage: A = cartesian_product((QQ['z'], QQ))
sage: B = cartesian_product((ZZ['t']['z'], QQ))
sage: pushout(A, B)
Expand Down Expand Up @@ -680,7 +681,7 @@ def common_base(self, other_functor, self_bases, other_bases):
.. NOTE::
Overload this function in derived class, see
e.e. :class:`MultivariateConstructionFunctor`.
e.g. :class:`MultivariateConstructionFunctor`.
TESTS::
Expand All @@ -690,7 +691,7 @@ def common_base(self, other_functor, self_bases, other_bases):
...
CoercionException: No common base ("join") found for
The cartesian_product functorial construction(Integer Ring) and FractionField(Integer Ring):
(Multivariate) functors are inkompatibel.
(Multivariate) functors are incompatible.
sage: pushout(cartesian_product([ZZ]), cartesian_product([ZZ, QQ])) # indirect doctest
Traceback (most recent call last):
...
Expand All @@ -702,7 +703,7 @@ def common_base(self, other_functor, self_bases, other_bases):
if self != other_functor:
self._raise_common_base_exception_(
other_functor, self_bases, other_bases,
'(Multivariate) functors are inkompatibel')
'(Multivariate) functors are incompatible')
if len(self_bases) != len(other_bases):
self._raise_common_base_exception_(
other_functor, self_bases, other_bases,
Expand Down Expand Up @@ -3387,10 +3388,10 @@ def pushout(R, S):
Ambient free module of rank 2 over the principal ideal domain Univariate Polynomial Ring in x over Real Field with 53 bits of precision
Some more tests related to univariate/multivariate
constructions. We construct a parent for a generalization to
polynomials, where we not only specify a coefficient ring `C` but
also an additive monoid `E` for its exponents. Its elements are
then
constructions. We consider a generalization of polynomial rings,
where in addition to the coefficient ring `C` we also specify
an additive monoid `E` for the exponents of the indeterminate.
In particular, the elements of such a parent are given by
.. MATH::
Expand Down Expand Up @@ -3514,51 +3515,56 @@ def pushout(R, S):
(Univariate Polynomial Ring in x over Integer Ring,
Univariate Polynomial Ring in y over Rational Field,
Univariate Polynomial Ring in z over Univariate Polynomial Ring in t over Rational Field)
sage: pushout(ZZ, cartesian_product([ZZ, QQ]))
Traceback (most recent call last):
...
CoercionException: 'NoneType' object is not iterable
::
sage: from sage.categories.pushout import PolynomialFunctor
sage: from sage.sets.cartesian_product import CartesianProduct
sage: class CartesianProductPolys(CartesianProduct):
sage: class CartesianProductPoly(CartesianProduct):
....: def __init__(self, polynomial_rings):
....: sort = sorted(polynomial_rings, key=lambda P: P.variable_name())
....: super(CartesianProductPolys, self).__init__(sort, Sets().CartesianProducts())
....: super(CartesianProductPoly, self).__init__(sort, Sets().CartesianProducts())
....: def vars(self):
....: return tuple(P.variable_name() for P in self.cartesian_factors())
....: def _pushout_(self, other):
....: if isinstance(other, CartesianProductPolys):
....: if isinstance(other, CartesianProductPoly):
....: s_vars = self.vars()
....: o_vars = other.vars()
....: if s_vars == o_vars:
....: return
....: return pushout(CartesianProductPolys(
....: return pushout(CartesianProductPoly(
....: self.cartesian_factors() +
....: tuple(f for f in other.cartesian_factors()
....: if f.variable_name() not in s_vars)),
....: CartesianProductPolys(
....: CartesianProductPoly(
....: other.cartesian_factors() +
....: tuple(f for f in self.cartesian_factors()
....: if f.variable_name() not in o_vars)))
....: C = other.construction()[0]
....: if isinstance(C, PolynomialFunctor):
....: return pushout(self, CartesianProductPolys((other,)))
....: C = other.construction()
....: if C is None:
....: return
....: elif isinstance(C[0], PolynomialFunctor):
....: return pushout(self, CartesianProductPoly((other,)))
::
sage: pushout(CartesianProductPolys((ZZ['x'],)),
....: CartesianProductPolys((ZZ['y'],)))
sage: pushout(CartesianProductPoly((ZZ['x'],)),
....: CartesianProductPoly((ZZ['y'],)))
The cartesian product of
(Univariate Polynomial Ring in x over Integer Ring,
Univariate Polynomial Ring in y over Integer Ring)
sage: pushout(CartesianProductPolys((ZZ['x'], ZZ['y'])),
....: CartesianProductPolys((ZZ['x'], ZZ['z'])))
sage: pushout(CartesianProductPoly((ZZ['x'], ZZ['y'])),
....: CartesianProductPoly((ZZ['x'], ZZ['z'])))
The cartesian product of
(Univariate Polynomial Ring in x over Integer Ring,
Univariate Polynomial Ring in y over Integer Ring,
Univariate Polynomial Ring in z over Integer Ring)
sage: pushout(CartesianProductPolys((QQ['a,b']['x'], QQ['y'])),
....: CartesianProductPolys((ZZ['b,c']['x'], SR['z'])))
sage: pushout(CartesianProductPoly((QQ['a,b']['x'], QQ['y'])),
....: CartesianProductPoly((ZZ['b,c']['x'], SR['z'])))
The cartesian product of
(Univariate Polynomial Ring in x over
Multivariate Polynomial Ring in a, b, c over Rational Field,
Expand All @@ -3567,17 +3573,26 @@ def pushout(R, S):
::
sage: pushout(CartesianProductPolys((ZZ['x'],)), ZZ['y'])
sage: pushout(CartesianProductPoly((ZZ['x'],)), ZZ['y'])
The cartesian product of
(Univariate Polynomial Ring in x over Integer Ring,
Univariate Polynomial Ring in y over Integer Ring)
sage: pushout(QQ['b,c']['y'], CartesianProductPolys((ZZ['a,b']['x'],)))
sage: pushout(QQ['b,c']['y'], CartesianProductPoly((ZZ['a,b']['x'],)))
The cartesian product of
(Univariate Polynomial Ring in x over
Multivariate Polynomial Ring in a, b over Integer Ring,
Univariate Polynomial Ring in y over
Multivariate Polynomial Ring in b, c over Rational Field)
::
sage: pushout(CartesianProductPoly((ZZ['x'],)), ZZ)
Traceback (most recent call last):
...
CoercionException: No common base ("join") found for
The cartesian_product functorial construction(...) and None(Integer Ring):
(Multivariate) functors are incompatible.
AUTHORS:
- Robert Bradshaw
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 @@ -242,9 +242,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 growth_group import GenericGrowthGroup
class GenericProduct(CartesianProductPosets, GenericGrowthGroup):
class GenericProduct(CartesianProductPoset, GenericGrowthGroup):
r"""
A cartesian product of growth groups.
Expand Down Expand Up @@ -272,10 +272,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 @@ -289,7 +289,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 @@ -301,7 +301,7 @@ def __init__(self, sets, category, **kwds):
GenericGrowthGroup.__init__(self, sets[0], Vars, self.category(), **kwds)


__hash__ = CartesianProductPosets.__hash__
__hash__ = CartesianProductPoset.__hash__


def some_elements(self):
Expand Down Expand Up @@ -598,7 +598,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 @@ -832,7 +832,7 @@ def variable_names(self):
return tuple(v for v, _ in groupby(vars))


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

from growth_group import is_lt_one
is_lt_one = is_lt_one
Expand Down

0 comments on commit eb4e3c9

Please sign in to comment.