From 1fc00c79ea943ceb18d023f7e13aac59cebcdd93 Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Tue, 26 Jan 2016 08:49:00 +0100 Subject: [PATCH 1/4] Trac #19946: fix _pushout_ for cartesian product of growth groups --- .../rings/asymptotic/growth_group_cartesian.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/sage/rings/asymptotic/growth_group_cartesian.py b/src/sage/rings/asymptotic/growth_group_cartesian.py index ed5ff1f83aa..64ab8347d13 100644 --- a/src/sage/rings/asymptotic/growth_group_cartesian.py +++ b/src/sage/rings/asymptotic/growth_group_cartesian.py @@ -692,11 +692,17 @@ def _pushout_(self, other): Growth Group QQ^x * x^QQ sage: cm.common_parent(GrowthGroup('QQ^x * x^ZZ'), GrowthGroup('ZZ^x * x^QQ')) Growth Group QQ^x * x^QQ + + :: + + sage: pushout(GrowthGroup('QQ^n * n^QQ'), GrowthGroup('SR^n')) + Growth Group SR^n * n^QQ """ from growth_group import GenericGrowthGroup, AbstractGrowthGroupFunctor from misc import merge_overlapping from misc import underlying_class + Sfactors = self.cartesian_factors() if isinstance(other, GenericProduct): Ofactors = other.cartesian_factors() elif isinstance(other, GenericGrowthGroup): @@ -759,7 +765,7 @@ def next(self): self.factors = tuple() from itertools import groupby - S = it(groupby(self.cartesian_factors(), key=lambda k: k.variable_names())) + S = it(groupby(Sfactors, key=lambda k: k.variable_names())) O = it(groupby(Ofactors, key=lambda k: k.variable_names())) newS = [] @@ -786,9 +792,9 @@ def next(self): assert(len(newS) == len(newO)) - if (len(self.cartesian_factors()) == len(newS) and - len(other.cartesian_factors()) == len(newO)): - # We had already all factors in each of the self and + if (len(Sfactors) == len(newS) and + len(Ofactors) == len(newO)): + # We had already all factors in each of self and # other, thus splitting it in subproblems (one for # each factor) is the strategy to use. If a pushout is # possible :func:`sage.categories.pushout.pushout` From 1b62954467b74292e349a1631f9837dbe8ff9c3b Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Tue, 26 Jan 2016 08:49:56 +0100 Subject: [PATCH 2/4] Trac #19946: add doctests to document behavior --- src/sage/rings/asymptotic/asymptotic_ring.py | 16 ++++++++++++++++ src/sage/rings/asymptotic/growth_group.py | 8 ++++++++ src/sage/rings/asymptotic/term_monoid.py | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/sage/rings/asymptotic/asymptotic_ring.py b/src/sage/rings/asymptotic/asymptotic_ring.py index 779504429a7..a31d07df1f3 100644 --- a/src/sage/rings/asymptotic/asymptotic_ring.py +++ b/src/sage/rings/asymptotic/asymptotic_ring.py @@ -1408,6 +1408,14 @@ def __pow__(self, exponent, precision=None): ValueError: Cannot take s + t to the exponent s. > *previous* ValueError: log(s + t) cannot be constructed since there are several maximal elements s, t. + + Check that :trac:`19946` is fixed:: + + sage: A. = AsymptoticRing('QQ^n * n^QQ', SR) + sage: 2^n + 2^n + sage: _.parent() + Asymptotic Ring over Symbolic Ring """ if not self.summands: if exponent == 0: @@ -1666,6 +1674,14 @@ def rpow(self, base, precision=None): ArithmeticError: Cannot construct y^x in Growth Group x^ZZ > *previous* TypeError: unsupported operand parent(s) for '*': 'Growth Group x^ZZ' and 'Growth Group SR^x' + + Check that :trac:`19946` is fixed:: + + sage: A. = AsymptoticRing('QQ^n * n^QQ', SR) + sage: n.rpow(2) + 2^n + sage: _.parent() + Asymptotic Ring over Symbolic Ring """ if isinstance(base, AsymptoticExpansion): return base.__pow__(self, precision=precision) diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index cdf54df97a2..2e685c27fd9 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -873,6 +873,14 @@ def _rpow_(self, base): sage: x = G('x') sage: (x * log(x)).rpow(2) # indirect doctest 2^(x*log(x)) + + :: + + sage: n = GrowthGroup('QQ^n * n^QQ')('n') + sage: n.rpow(2) + 2^n + sage: _.parent() + Growth Group QQ^n * n^QQ """ if base == 0: raise ValueError('%s is not an allowed base for calculating the ' diff --git a/src/sage/rings/asymptotic/term_monoid.py b/src/sage/rings/asymptotic/term_monoid.py index c8a2486d2d8..3d339948597 100644 --- a/src/sage/rings/asymptotic/term_monoid.py +++ b/src/sage/rings/asymptotic/term_monoid.py @@ -3308,6 +3308,26 @@ def rpow(self, base): Growth Group QQ^x * x^ZZ * log(x)^ZZ > *previous* TypeError: unsupported operand parent(s) for '*': 'Growth Group QQ^x * x^ZZ * log(x)^ZZ' and 'Growth Group ZZ^(x^2)' + + :: + + sage: T = TermMonoid('exact', GrowthGroup('QQ^n * n^QQ'), SR) + sage: n = T('n') + sage: n.rpow(2) + 2^n + sage: _.parent() + Exact Term Monoid QQ^n * n^SR with coefficients in Symbolic Ring + + Above, we get ``QQ^n * n^SR`` since + :: + + sage: (n^SR(1)).parent() + Exact Term Monoid QQ^n * n^SR with coefficients in Symbolic Ring + + and that is because of + + sage: (QQ(2)^SR(1)).parent(), (QQ(1)*SR(1)).parent() + (Rational Field, Symbolic Ring) """ P = self.parent() From 24c153cd49a1857b06ff2779e4442bace4a24c65 Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Tue, 26 Jan 2016 16:12:17 +0100 Subject: [PATCH 3/4] Trac #19946: reviewer commit: ReSt error --- src/sage/rings/asymptotic/term_monoid.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sage/rings/asymptotic/term_monoid.py b/src/sage/rings/asymptotic/term_monoid.py index 3d339948597..b9db5af4265 100644 --- a/src/sage/rings/asymptotic/term_monoid.py +++ b/src/sage/rings/asymptotic/term_monoid.py @@ -3324,7 +3324,7 @@ def rpow(self, base): sage: (n^SR(1)).parent() Exact Term Monoid QQ^n * n^SR with coefficients in Symbolic Ring - and that is because of + and that is because of :: sage: (QQ(2)^SR(1)).parent(), (QQ(1)*SR(1)).parent() (Rational Field, Symbolic Ring) From 7918417adce86770e782d2f7607f8be6f80c258d Mon Sep 17 00:00:00 2001 From: Clemens Heuberger Date: Tue, 26 Jan 2016 16:12:30 +0100 Subject: [PATCH 4/4] Trac #19946: additional doctest --- src/sage/rings/asymptotic/asymptotic_ring.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/sage/rings/asymptotic/asymptotic_ring.py b/src/sage/rings/asymptotic/asymptotic_ring.py index a31d07df1f3..c9cdbbdc7a3 100644 --- a/src/sage/rings/asymptotic/asymptotic_ring.py +++ b/src/sage/rings/asymptotic/asymptotic_ring.py @@ -1412,10 +1412,14 @@ def __pow__(self, exponent, precision=None): Check that :trac:`19946` is fixed:: sage: A. = AsymptoticRing('QQ^n * n^QQ', SR) - sage: 2^n + sage: e = 2^n; e 2^n - sage: _.parent() + sage: e.parent() Asymptotic Ring over Symbolic Ring + sage: e = A(e); e + 2^n + sage: e.parent() + Asymptotic Ring over Symbolic Ring """ if not self.summands: if exponent == 0: