Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPowerSeries: Don't go through symbolics to compute exp(0), log(1) #36260

Merged
merged 8 commits into from
Sep 16, 2023
4 changes: 2 additions & 2 deletions bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ SAGE_SPKG_CONFIGURE_$(echo ${pkgname} | tr '[a-z]' '[A-Z]')"
if test -f "$DIR/requirements.txt" -o -f "$DIR/install-requires.txt"; then
# A Python package
SPKG_TREE_VAR=SAGE_VENV
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions.m4
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(sage-get-system-packages install-requires-toml ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions_toml.m4
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(ENABLE_SYSTEM_SITE_PACKAGES=yes sage-get-system-packages install-requires ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions.m4
echo "define(>>>SPKG_INSTALL_REQUIRES_${pkgname}<<<, >>>$(echo $(ENABLE_SYSTEM_SITE_PACKAGES=yes sage-get-system-packages install-requires-toml ${pkgname}))<<<)dnl" >> m4/sage_spkg_versions_toml.m4
fi
fi
spkg_configures="$spkg_configures
Expand Down
22 changes: 14 additions & 8 deletions src/sage/rings/multi_power_series_ring_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ def exp(self, prec=infinity):
are not yet implemented and therefore such cases raise an error::

sage: g = 2 + f
sage: exp(g)
sage: exp(g) # needs sage.symbolic
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can avoid SR with g.exp() here and likewise in the other examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually this error does not come from going through SR but illustrates that exp(2) does not exist in the base ring.

2 of the other # needs sage.symbolic turned out to be unnecessary due to advances in modularization. Removed in 7dde129

Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for *: 'Symbolic Ring' and
Expand All @@ -1920,7 +1920,7 @@ def exp(self, prec=infinity):
Another workaround for this limitation is to change base ring
to one which is closed under exponentiation, such as `\RR` or `\CC`::

sage: exp(g.change_ring(RDF))
sage: exp(g.change_ring(RDF)) # needs sage.symbolic
7.38905609... + 7.38905609...*a + 7.38905609...*b + 3.69452804...*a^2 +
14.7781121...*a*b + 3.69452804...*b^2 + O(a, b)^3

Expand All @@ -1944,9 +1944,12 @@ def exp(self, prec=infinity):
R = self.parent()
Rbg = R._bg_power_series_ring

from sage.functions.log import exp
c = self.constant_coefficient()
exp_c = exp(c)
if not c:
exp_c = self.base_ring().one()
else:
from sage.functions.log import exp
exp_c = exp(c)
x = self._bg_value - c
if x.is_zero():
return exp_c
Expand Down Expand Up @@ -2000,7 +2003,7 @@ def log(self, prec=infinity):
are not yet implemented and therefore such cases raise an error::

sage: g = 2 + f
sage: log(g)
sage: log(g) # needs sage.symbolic
Traceback (most recent call last):
...
TypeError: unsupported operand parent(s) for -: 'Symbolic Ring' and 'Power
Expand All @@ -2009,7 +2012,7 @@ def log(self, prec=infinity):
Another workaround for this limitation is to change base ring
to one which is closed under exponentiation, such as `\RR` or `\CC`::

sage: log(g.change_ring(RDF))
sage: log(g.change_ring(RDF)) # needs sage.symbolic
1.09861228... + 0.333333333...*a + 0.333333333...*b - 0.0555555555...*a^2
+ 0.222222222...*a*b - 0.0555555555...*b^2 + 0.0123456790...*a^3
- 0.0740740740...*a^2*b - 0.0740740740...*a*b^2 + 0.0123456790...*b^3
Expand All @@ -2036,11 +2039,14 @@ def log(self, prec=infinity):
R = self.parent()
Rbg = R._bg_power_series_ring

from sage.functions.log import log
c = self.constant_coefficient()
if c.is_zero():
raise ValueError('Can only take formal power series for non-zero constant term.')
log_c = log(c)
if c.is_one():
log_c = self.base_ring().zero()
else:
from sage.functions.log import log
log_c = log(c)
x = 1 - self._bg_value/c
if x.is_zero():
return log_c
Expand Down
Loading