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

Commit

Permalink
doctest parameter log_function
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrenn committed Jan 8, 2017
1 parent 913adb4 commit 7c555da
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/sage/rings/asymptotic/asymptotic_ring.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,8 +1929,32 @@ def log(self, base=None, precision=None, log_function=None):
sage: log(x-1)
log(x) - x^(-1) - 1/2*x^(-2) - 1/3*x^(-3) - ... + O(x^(-21))
The coefficient ring aus automatically extended if needed::
sage: R.<x> = AsymptoticRing(growth_group='x^ZZ * log(x)^ZZ', coefficient_ring=ZZ, default_prec=3)
sage: (49*x^3-1).log()
3*log(x) + log(49) - 1/49*x^(-3) - 1/4802*x^(-6) ... + O(x^(-12))
sage: _.parent()
Asymptotic Ring <x^ZZ * log(x)^ZZ> over Symbolic Ring
If one wants to avoid this extending to the Symbolic Ring, then
the following helps::
sage: L.<log7> = ZZ[]
sage: def log_function(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)
3*log(x) + 2*log7 - 1/49*x^(-3) - 1/4802*x^(-6) ... + O(x^(-12))
TESTS::
sage: R.<x> = AsymptoticRing(growth_group='x^ZZ * log(x)^ZZ', coefficient_ring=QQ)
sage: log(R(1))
0
sage: log(R(0))
Expand Down
22 changes: 22 additions & 0 deletions src/sage/rings/asymptotic/growth_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2818,6 +2818,17 @@ def _log_factor_(self, base=None, log_function=None):
ArithmeticError: When calculating log(exp(x), base=2) a factor
1/log(2) != 1 appeared, which is not contained in
Growth Group exp(x)^ZZ * x^ZZ.
::
sage: from sage.rings.asymptotic.growth_group import MonomialGrowthGroup
sage: L.<log2> = ZZ[]
sage: G = MonomialGrowthGroup(L, 'x')
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(x)', 1),)
"""
if self.is_one():
return tuple()
Expand Down Expand Up @@ -3723,6 +3734,17 @@ def _log_factor_(self, base=None, log_function=None):
...
ArithmeticError: Cannot build log(4^x, base=2) since x is not in
Growth Group QQ^x.
::
sage: from sage.rings.asymptotic.growth_group import ExponentialGrowthGroup
sage: L.<log2> = ZZ[]
sage: G = ExponentialGrowthGroup(L, 'x')
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))
(('x', log2),)
"""
if self.is_one():
return tuple()
Expand Down
14 changes: 14 additions & 0 deletions src/sage/rings/asymptotic/term_monoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,20 @@ def _log_coefficient_(self, base=None, log_function=None):
:meth:`ExactTerm.log_term`,
:meth:`OTerm.log_term`.
TESTS::
sage: L.<log3> = QQ[]
sage: T = TermMonoid('exact', GrowthGroup('x^ZZ * log(x)^ZZ'), L)
sage: T(3*x^2)._log_coefficient_()
(log(3),)
sage: log_function=lambda z, base: log3 if z == 3 else log(z)
sage: T(3*x^2)._log_coefficient_(log_function=log_function)
(log3,)
sage: T(3*x^2).log_term() # indirect doctest
(log(3), 2*log(x))
sage: T(3*x^2).log_term(log_function=log_function) # indirect doctest
(log3, 2*log(x))
"""
if self.coefficient.is_one():
return tuple()
Expand Down

0 comments on commit 7c555da

Please sign in to comment.