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

Commit

Permalink
Trac #22154: rename log_function to log
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Oct 18, 2018
1 parent 33117ae commit ec74ad0
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 63 deletions.
46 changes: 23 additions & 23 deletions src/sage/rings/asymptotic/asymptotic_ring.py
Expand Up @@ -1956,7 +1956,7 @@ def O(self):
for element in self.summands.maximal_elements())


def log(self, base=None, precision=None, log_function=None):
def log(self, base=None, precision=None, log=None):
r"""
The logarithm of this asymptotic expansion.
Expand All @@ -1969,7 +1969,7 @@ def log(self, base=None, precision=None, log_function=None):
expansion. If ``None`` (default value) is used, the
default precision of the parent is used.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -2017,21 +2017,21 @@ def log(self, base=None, precision=None, log_function=None):
the following helps::
sage: L.<log7> = ZZ[]
sage: def log_function(z, base=None):
sage: def mylog(z, base=None):
....: try:
....: if ZZ(z).is_power_of(7):
....: return log(ZZ(z), 7) * log7
....: except TypeError, ValueError:
....: pass
....: return log(z, base)
sage: R.<x> = AsymptoticRing(growth_group='x^ZZ * log(x)^ZZ', coefficient_ring=L, default_prec=3)
sage: (49*x^3-1).log(log_function=log_function)
sage: (49*x^3-1).log(log=mylog)
3*log(x) + 2*log7 - 1/49*x^(-3) - 1/4802*x^(-6) ... + O(x^(-12))
A ``log_function`` can also be specified to always be used with the
A ``log``-function can also be specified to always be used with the
asymptotic ring::
sage: R.<x> = AsymptoticRing(growth_group='x^ZZ * log(x)^ZZ', coefficient_ring=L, default_prec=3, log_function=log_function)
sage: R.<x> = AsymptoticRing(growth_group='x^ZZ * log(x)^ZZ', coefficient_ring=L, default_prec=3, log=mylog)
sage: log(49*x^3-1)
3*log(x) + 2*log7 - 1/49*x^(-3) - 1/4802*x^(-6) - 1/352947*x^(-9) + O(x^(-12))
Expand All @@ -2054,8 +2054,8 @@ def log(self, base=None, precision=None, log_function=None):
"""
P = self.parent()

if log_function is None:
log_function = P.log_function
if log is None:
log = P.log

if not self.summands:
raise ArithmeticError('Cannot compute log(0) in %s.' % (self.parent(),))
Expand All @@ -2066,7 +2066,7 @@ def log(self, base=None, precision=None, log_function=None):
element = next(self.summands.elements())
return sum(P._create_element_in_extension_(l, element.parent())
for l in element.log_term(base=base,
log_function=log_function))
log=log))

(max_elem, x) = self._main_term_relative_error_()
geom = -x
Expand All @@ -2083,9 +2083,9 @@ def log(self, base=None, precision=None, log_function=None):
precision=precision)

if base:
result = result / log_function(base)
result = result / log(base)

result += x.parent()(max_elem).log(base=base, log_function=log_function)
result += x.parent()(max_elem).log(base=base, log=log)

return result

Expand Down Expand Up @@ -3418,7 +3418,7 @@ class AsymptoticRing(Algebra, UniqueRepresentation):
def __classcall__(cls, growth_group=None, coefficient_ring=None,
names=None, category=None, default_prec=None,
term_monoid_factory=None,
log_function=None):
log=None):
r"""
Normalizes the input in order to ensure a unique
representation of the parent.
Expand Down Expand Up @@ -3553,11 +3553,11 @@ def format_names(N):
category=category,
default_prec=default_prec,
term_monoid_factory=term_monoid_factory,
log_function=log_function)
log=log)

def __init__(self, growth_group, coefficient_ring,
category, default_prec,
term_monoid_factory, log_function):
term_monoid_factory, log):
r"""
See :class:`AsymptoticRing` for more information.
Expand All @@ -3581,7 +3581,7 @@ def __init__(self, growth_group, coefficient_ring,
self._growth_group_ = growth_group
self._default_prec_ = default_prec
self._term_monoid_factory_ = term_monoid_factory
self._log_function_ = log_function
self._log_ = log
super(AsymptoticRing, self).__init__(base_ring=coefficient_ring,
category=category)

Expand Down Expand Up @@ -3688,7 +3688,7 @@ def term_monoid(self, type):


@property
def log_function(self):
def log(self):
r"""
The customized log function of this asymptotic ring.
Expand All @@ -3698,17 +3698,17 @@ def log_function(self):
sage: AR.log_function is None
True
sage: AR = AsymptoticRing(growth_group='x^ZZ', coefficient_ring=ZZ, log_function=log)
sage: AR.log_function
sage: AR.log
<function log at 0x...>
.. SEEALSO::
:doc:`term_monoid`
"""
if self._log_function_ is None:
if self._log_ is None:
from sage.functions.log import log
return log
return self._log_function_
return self._log_


def change_parameter(self, **kwds):
Expand Down Expand Up @@ -3743,7 +3743,7 @@ def change_parameter(self, **kwds):
True
"""
parameters = ('growth_group', 'coefficient_ring', 'default_prec',
'term_monoid_factory', 'log_function')
'term_monoid_factory', 'log')
values = dict()
for parameter in parameters:
default = getattr(self, parameter)
Expand Down Expand Up @@ -4609,7 +4609,7 @@ class AsymptoticRingFunctor(ConstructionFunctor):

def __init__(self, growth_group,
default_prec=None, category=None,
term_monoid_factory=None, log_function=None,
term_monoid_factory=None, log=None,
cls=None):
r"""
See :class:`AsymptoticRingFunctor` for details.
Expand All @@ -4629,7 +4629,7 @@ def __init__(self, growth_group,
self._default_prec_ = default_prec
self._category_ = category
self._term_monoid_factory_ = term_monoid_factory
self._log_function_ = log_function
self._log_ = log

from sage.categories.rings import Rings
super(ConstructionFunctor, self).__init__(
Expand Down Expand Up @@ -4707,7 +4707,7 @@ def _apply_functor(self, coefficient_ring):
kwds = {'growth_group': self.growth_group,
'coefficient_ring': coefficient_ring}
parameters = ('category', 'default_prec',
'term_monoid_factory', 'log_function')
'term_monoid_factory', 'log')
for parameter in parameters:
value = getattr(self, '_{}_'.format(parameter))
if value is not None:
Expand Down
32 changes: 15 additions & 17 deletions src/sage/rings/asymptotic/growth_group.py
Expand Up @@ -777,7 +777,7 @@ def _log_(self, base=None):

# The following function is used in the classes GenericGrowthElement and
# GenericProduct.Element as a method.
def _log_factor_(self, base=None, log_function=None):
def _log_factor_(self, base=None, log=None):
r"""
Return the logarithm of the factorization of this
element.
Expand All @@ -787,7 +787,7 @@ def _log_factor_(self, base=None, log_function=None):
- ``base`` -- the base of the logarithm. If ``None``
(default value) is used, the natural logarithm is taken.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -838,7 +838,7 @@ def _log_factor_(self, base=None, log_function=None):
sage: (exp(x) * x).log_factor() # indirect doctest
((x, 1), (log(x), 1))
"""
log_factor = self._log_factor_(base=base, log_function=log_function)
log_factor = self._log_factor_(base=base, log=log)

for g, c in log_factor:
if hasattr(g, 'parent') and \
Expand Down Expand Up @@ -1216,7 +1216,7 @@ def _lt_(self, other):
log = _log_
log_factor = _log_factor_

def _log_factor_(self, base=None, log_function=None):
def _log_factor_(self, base=None, log=None):
r"""
Helper method for calculating the logarithm of the factorization
of this element.
Expand All @@ -1226,7 +1226,7 @@ def _log_factor_(self, base=None, log_function=None):
- ``base`` -- the base of the logarithm. If ``None``
(default value) is used, the natural logarithm is taken.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -2630,7 +2630,7 @@ def __pow__(self, exponent):
"""
return self.parent()._create_element_in_extension_(self.exponent * exponent)

def _log_factor_(self, base=None, log_function=None):
def _log_factor_(self, base=None, log=None):
r"""
Helper method for calculating the logarithm of the factorization
of this element.
Expand All @@ -2640,7 +2640,7 @@ def _log_factor_(self, base=None, log_function=None):
- ``base`` -- the base of the logarithm. If ``None``
(default value) is used, the natural logarithm is taken.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -2678,7 +2678,7 @@ def _log_factor_(self, base=None, log_function=None):
sage: G(raw_element=log2)._log_factor_(base=2)
(('log(x)', log2/log(2)),)
sage: G(raw_element=log2)._log_factor_(base=2,
....: log_function=lambda z: log2 if z == 2 else log(z))
....: log=lambda z: log2 if z == 2 else log(z))
(('log(x)', 1),)
"""
if self.is_one():
Expand All @@ -2702,10 +2702,9 @@ def _log_factor_(self, base=None, log_function=None):
v = 'log(%s)' % (var,)

if base is not None:
if log_function is None:
if log is None:
from sage.functions.log import log
log_function = log
coefficient = coefficient / log_function(base)
coefficient = coefficient / log(base)
return ((v, coefficient),)

def _rpow_element_(self, base):
Expand Down Expand Up @@ -3540,7 +3539,7 @@ def __pow__(self, exponent):
"""
return self.parent()._create_element_in_extension_(self.base ** exponent)

def _log_factor_(self, base=None, log_function=None):
def _log_factor_(self, base=None, log=None):
r"""
Helper method for calculating the logarithm of the factorization
of this element.
Expand All @@ -3550,7 +3549,7 @@ def _log_factor_(self, base=None, log_function=None):
- ``base`` -- the base of the logarithm. If ``None``
(default value) is used, the natural logarithm is taken.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -3578,7 +3577,7 @@ def _log_factor_(self, base=None, log_function=None):
sage: G(raw_element=2)._log_factor_()
(('x', log(2)),)
sage: G(raw_element=2)._log_factor_(
....: log_function=lambda z, base: log2 if z == 2 else log(z))
....: log=lambda z, base: log2 if z == 2 else log(z))
(('x', log2),)
"""
if self.is_one():
Expand All @@ -3590,10 +3589,9 @@ def _log_factor_(self, base=None, log_function=None):
elif base is None and str(b) == 'e':
coefficient = self.parent().base().one()
else:
if log_function is None:
if log is None:
from sage.functions.log import log
log_function = log
coefficient = log_function(b, base=base)
coefficient = log(b, base=base)

return ((str(self.parent()._var_), coefficient),)

Expand Down
6 changes: 3 additions & 3 deletions src/sage/rings/asymptotic/growth_group_cartesian.py
Expand Up @@ -995,7 +995,7 @@ def factors(self):
log_factor = _log_factor_


def _log_factor_(self, base=None, log_function=None):
def _log_factor_(self, base=None, log=None):
r"""
Helper method for calculating the logarithm of the factorization
of this element.
Expand All @@ -1005,7 +1005,7 @@ def _log_factor_(self, base=None, log_function=None):
- ``base`` -- the base of the logarithm. If ``None``
(default value) is used, the natural logarithm is taken.
- ``log_function`` -- a function. If ``None`` (default value)
- ``log`` -- a function. If ``None`` (default value)
is used, then the usual
:class:`log <sage.functions.log.Function_log>` is taken.
Expand Down Expand Up @@ -1036,7 +1036,7 @@ def try_create_growth(g):
return sum(iter(tuple((try_create_growth(g), c)
for g, c in
factor._log_factor_(base=base,
log_function=log_function))
log=log))
for factor in self.cartesian_factors()
if factor != factor.parent().one()),
tuple())
Expand Down

0 comments on commit ec74ad0

Please sign in to comment.