Skip to content

Commit c95bd14

Browse files
author
Release Manager
committed
gh-36260: `MPowerSeries`: Don't go through symbolics to compute exp(0), log(1) <!-- ^^^^^ Please provide a concise, informative and self-explanatory title. Don't put issue numbers in there, do this in the PR body below. For example, instead of "Fixes #1234" use "Introduce new method to calculate 1+1" --> <!-- Describe your changes here in detail --> <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> - Part of: #29705 - Cherry-picked from: #35095 <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> <!-- If your change requires a documentation PR, please link it appropriately --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> <!-- Feel free to remove irrelevant items. --> - [x] The title is concise, informative, and self-explanatory. - [ ] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> - Depends on #36240 (merged here) - Depends on #36263 (merged here) <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #36260 Reported by: Matthias Köppe Reviewer(s): Matthias Köppe, Michael Orlitzky
2 parents cac16e2 + e2a76d2 commit c95bd14

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/sage/rings/multi_power_series_ring_element.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ def exp(self, prec=infinity):
19101910
are not yet implemented and therefore such cases raise an error::
19111911
19121912
sage: g = 2 + f
1913-
sage: exp(g)
1913+
sage: exp(g) # needs sage.symbolic
19141914
Traceback (most recent call last):
19151915
...
19161916
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and
@@ -1944,9 +1944,12 @@ def exp(self, prec=infinity):
19441944
R = self.parent()
19451945
Rbg = R._bg_power_series_ring
19461946

1947-
from sage.functions.log import exp
19481947
c = self.constant_coefficient()
1949-
exp_c = exp(c)
1948+
if not c:
1949+
exp_c = self.base_ring().one()
1950+
else:
1951+
from sage.functions.log import exp
1952+
exp_c = exp(c)
19501953
x = self._bg_value - c
19511954
if x.is_zero():
19521955
return exp_c
@@ -2000,7 +2003,7 @@ def log(self, prec=infinity):
20002003
are not yet implemented and therefore such cases raise an error::
20012004
20022005
sage: g = 2 + f
2003-
sage: log(g)
2006+
sage: log(g) # needs sage.symbolic
20042007
Traceback (most recent call last):
20052008
...
20062009
TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power
@@ -2036,11 +2039,14 @@ def log(self, prec=infinity):
20362039
R = self.parent()
20372040
Rbg = R._bg_power_series_ring
20382041

2039-
from sage.functions.log import log
20402042
c = self.constant_coefficient()
20412043
if c.is_zero():
20422044
raise ValueError('Can only take formal power series for non-zero constant term.')
2043-
log_c = log(c)
2045+
if c.is_one():
2046+
log_c = self.base_ring().zero()
2047+
else:
2048+
from sage.functions.log import log
2049+
log_c = log(c)
20442050
x = 1 - self._bg_value/c
20452051
if x.is_zero():
20462052
return log_c

0 commit comments

Comments
 (0)