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

Commit

Permalink
Trac #19540: variable_names for growth elements
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Feb 14, 2016
1 parent 0384e25 commit 3f0f855
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/sage/rings/asymptotic/growth_group.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/sage/rings/asymptotic/growth_group_cartesian.py
Expand Up @@ -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


Expand Down

0 comments on commit 3f0f855

Please sign in to comment.