From 3f0f855c98d9e9223b3ae52e8eb142dd2e4a832c Mon Sep 17 00:00:00 2001 From: Daniel Krenn Date: Sun, 14 Feb 2016 20:06:54 +0100 Subject: [PATCH] Trac #19540: variable_names for growth elements --- src/sage/rings/asymptotic/growth_group.py | 64 +++++++++++++++++++ .../asymptotic/growth_group_cartesian.py | 30 +++++++++ 2 files changed, 94 insertions(+) diff --git a/src/sage/rings/asymptotic/growth_group.py b/src/sage/rings/asymptotic/growth_group.py index f06e0f8e2fd..f5d84d29b9d 100644 --- a/src/sage/rings/asymptotic/growth_group.py +++ b/src/sage/rings/asymptotic/growth_group.py @@ -1397,6 +1397,24 @@ def _substitute_(self, rules): 'base class %s.' % (self.parent(),))) + def variable_names(self): + r""" + Return the names of the variables of this generic growth element. + + OUTPUT: + + A tuple of strings. + + EXAMPLES:: + + sage: from sage.rings.asymptotic.growth_group import GenericGrowthGroup + sage: G = GenericGrowthGroup(QQ) + sage: G(raw_element=2).variable_names() + () + """ + return self.parent()._var_.variable_names() + + class GenericGrowthGroup( sage.structure.unique_representation.UniqueRepresentation, sage.structure.parent.Parent): @@ -2814,6 +2832,29 @@ def _substitute_(self, rules): substitute_raise_exception(self, e) + def variable_names(self): + r""" + Return the names of the variables of this monomial growth element. + + OUTPUT: + + A tuple of strings. + + EXAMPLES:: + + sage: from sage.rings.asymptotic.growth_group import GrowthGroup + sage: G = GrowthGroup('m^QQ') + sage: G('m^2').variable_names() + ('m',) + sage: G('m^0').variable_names() + () + """ + if self.is_one(): + return tuple() + else: + return self.parent()._var_.variable_names() + + class MonomialGrowthGroup(GenericGrowthGroup): r""" A growth group dealing with powers of a fixed object/symbol. @@ -3480,6 +3521,29 @@ def _substitute_(self, rules): substitute_raise_exception(self, e) + def variable_names(self): + r""" + Return the names of the variables of this exponential growth element. + + OUTPUT: + + A tuple of strings. + + EXAMPLES:: + + sage: from sage.rings.asymptotic.growth_group import GrowthGroup + sage: G = GrowthGroup('QQ^m') + sage: G('2^m').variable_names() + ('m',) + sage: G('1^m').variable_names() + () + """ + if self.is_one(): + return tuple() + else: + return self.parent()._var_.variable_names() + + class ExponentialGrowthGroup(GenericGrowthGroup): r""" A growth group dealing with expressions involving a fixed diff --git a/src/sage/rings/asymptotic/growth_group_cartesian.py b/src/sage/rings/asymptotic/growth_group_cartesian.py index 8670481ea64..2c96e8fe490 100644 --- a/src/sage/rings/asymptotic/growth_group_cartesian.py +++ b/src/sage/rings/asymptotic/growth_group_cartesian.py @@ -1191,6 +1191,36 @@ def _substitute_(self, rules): substitute_raise_exception(self, e) + def variable_names(self): + r""" + Return the names of the variables of this growth element. + + OUTPUT: + + A tuple of strings. + + EXAMPLES:: + + sage: from sage.rings.asymptotic.growth_group import GrowthGroup + sage: G = GrowthGroup('QQ^m * m^QQ * log(n)^ZZ') + sage: G('2^m * m^4 * log(n)').variable_names() + ('m', 'n') + sage: G('2^m * m^4').variable_names() + ('m',) + sage: G('log(n)').variable_names() + ('n',) + sage: G('m^3').variable_names() + ('m',) + sage: G('m^0').variable_names() + () + """ + vars = sum(iter(factor.variable_names() + for factor in self.factors()), + tuple()) + from itertools import groupby + return tuple(v for v, _ in groupby(vars)) + + CartesianProduct = CartesianProductGrowthGroups