Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 4275b27

Browse files
author
Release Manager
committed
Trac #31530: New subs bug caused by #30378
As reported in https://trac.sagemath.org/ticket/30378#comment:49 Observed: {{{ sage: a, b, epsilon = SR.var('a, b, epsilon') sage: (a + b*epsilon).series(epsilon, 2).subs(a=a, b=b) b*epsilon }}} Expected: {{{ sage: a, b, epsilon = SR.var('a, b, epsilon') sage: (a + b*epsilon).series(epsilon, 2).subs(a=a, b=b) (a) + (b)*x + Order(x^2) }}} URL: https://trac.sagemath.org/31530 Reported by: mkoeppe Ticket author(s): Dave Morris Reviewer(s): Matthias Koeppe
2 parents 70711cf + 5c44e60 commit 4275b27

File tree

6 files changed

+27
-28
lines changed

6 files changed

+27
-28
lines changed

build/pkgs/configure/checksums.ini

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
tarball=configure-VERSION.tar.gz
2-
sha1=371681ab50f9b1156175f71d26999923b68bd410
3-
md5=961d28fdae428e2b911db45f169e7296
4-
cksum=4212743206
2+
sha1=2916d50d525d1b099bb5c54c2dbc60156bd79ef3
3+
md5=f121b77604fd797ddda9c8098adabd63
4+
cksum=3390986155
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
9322acfe193c57e20d4d655e42e5ee39bc3f9666
1+
761840fd551cb290092340bc73917336f22adfec
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.27.p1
1+
0.7.27.p3
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
diff --git a/ginac/power.cpp b/ginac/power.cpp
2+
index 5c07324..837fce3 100644
3+
--- a/ginac/power.cpp
4+
+++ b/ginac/power.cpp
5+
@@ -745,6 +745,10 @@ ex power::subs(const exmap & m, unsigned options) const
6+
if (!are_ex_trivially_equal(basis, subsed_basis)
7+
|| !are_ex_trivially_equal(exponent, subsed_exponent)) {
8+
ex p = power(subsed_basis, subsed_exponent);
9+
+ if (!is_exactly_a<power>(p)) {
10+
+ // trac 30378 and 31530: do not over-substitute
11+
+ return p;
12+
+ }
13+
ex t = ex_to<power>(p).subs_one_level(m, options);
14+
if ((t-*this).is_zero())
15+
return p;

src/sage/symbolic/expression.pyx

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,6 +5489,12 @@ cdef class Expression(CommutativeRingElement):
54895489
sage: f = function("f")
54905490
sage: integrate(f(x), x, 0, a).subs(a=cos(a))
54915491
integrate(f(x), x, 0, cos(a))
5492+
5493+
Check that :trac:`31530` is fixed::
5494+
5495+
sage: a, b = var("a b")
5496+
sage: (a + b*x).series(x, 2).subs(a=a, b=b)
5497+
(a) + (b)*x + Order(x^2)
54925498
"""
54935499
cdef dict sdict = {}
54945500
cdef GEx res
@@ -5509,28 +5515,6 @@ cdef class Expression(CommutativeRingElement):
55095515
# Check for duplicate
55105516
_dict_update_check_duplicate(sdict, varkwds)
55115517

5512-
# To work around the pynac bug in :trac:`30378`, we use two steps to do a
5513-
# substitution that only involves plugging expressions into variables, but
5514-
# where some of the expressions include variables that are in self.
5515-
if all(self.parent(k).is_symbol() for k in sdict.keys()):
5516-
dict_vars = tuple(v for k in sdict.keys()
5517-
for v in self.parent(sdict[k]).variables())
5518-
if not set(self.variables()).isdisjoint(dict_vars):
5519-
# Step 1: replace each variable with a new temporary variable
5520-
temp_vars = {v : self.parent().symbol() for v in self.variables()}
5521-
with hold:
5522-
first_step = self.substitute(temp_vars)
5523-
# Step 2: make the original substitutions into the new variables
5524-
result = first_step.substitute({
5525-
temp_vars[v] :
5526-
sdict[v] if v in sdict.keys() else v
5527-
for v in self.variables()})
5528-
if not set(result.variables()).issubset(self.variables() + dict_vars):
5529-
raise RuntimeError("substitution failed")
5530-
return result
5531-
5532-
# We are not in the basic case of only substituting expressions into
5533-
# variables, so we ask Ginac to do the work.
55345518
cdef GExMap smap
55355519
for k, v in sdict.iteritems():
55365520
smap.insert(make_pair((<Expression>self.coerce_in(k))._gobj,

src/sage/tests/books/computational-mathematics-with-sagemath/integration_doctest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
sage: mpmath.quad(sin(sin(x)), [0, 1])
150150
Traceback (most recent call last):
151151
...
152-
TypeError: unable to convert mpf('0.5') to a symbolic expression
152+
TypeError: no canonical coercion from <type 'sage.libs.mpmath.ext_main.mpf'> to Symbolic Ring
153153
154154
Sage example in ./integration.tex, line 866::
155155

0 commit comments

Comments
 (0)