Skip to content

Commit

Permalink
Trac #31479: Do not use pynac's poly_mul_expand function until it has…
Browse files Browse the repository at this point in the history
… been debugged

Pynac's `poly_mul_expand` function silently produces wrong results when
expanding certain sums. This ticket eliminates its use by pynac's
`ex::expand` method, and therefore provides a (temporary) fix for the
problems reported in #31077 and #31411.

This is part of metaticket #31478.

Use of the `poly_mul_expand` function can be re-enabled after the bugs
have been fixed.

URL: https://trac.sagemath.org/31479
Reported by: gh-DaveWitteMorris
Ticket author(s): Dave Morris
Reviewer(s): Volker Braun, Matthias Koeppe
  • Loading branch information
Release Manager committed Apr 11, 2021
2 parents 7495558 + eeb6cc2 commit c0dc957
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
6 changes: 3 additions & 3 deletions build/pkgs/configure/checksums.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
tarball=configure-VERSION.tar.gz
sha1=8809623aaeee9f8b0c9de1de8309e873d4f6d9cc
md5=11323b5d74baef36ddb0012a83c2e867
cksum=1815530444
sha1=947060891418045c7a06d165b29fbf8486f99fe2
md5=bc468c0b6934cd87f5a9ec3560adff24
cksum=124663050
2 changes: 1 addition & 1 deletion build/pkgs/configure/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
034759c8ef41f10a5f4d0925c1fe2cee1ae69ea1
df398dd79db1994aa00b43108b6f7261ecba055b
2 changes: 1 addition & 1 deletion build/pkgs/pynac/package-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.27.p3
0.7.27.p4
43 changes: 43 additions & 0 deletions build/pkgs/pynac/patches/handle_factor.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/ginac/expairseq.cpp b/ginac/expairseq.cpp
index dd87d18..556b713 100644
--- a/ginac/expairseq.cpp
+++ b/ginac/expairseq.cpp
@@ -1032,7 +1032,12 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)

if (ex_to<basic>(elem.rest).tinfo()==this->tinfo() &&
this->can_make_flat(elem)) {
- ex newrest = mf.handle_factor(elem.rest, elem.coeff);
+ ex newrest;
+ if (is_exactly_a<numeric>(elem.coeff) and elem.coeff.is_zero()) {
+ newrest = default_overall_coeff();
+ } else {
+ newrest = elem.rest;
+ }
const expairseq &subseqref = ex_to<expairseq>(newrest);
combine_overall_coeff(subseqref.overall_coeff,
ex_to<numeric>(elem.coeff));
@@ -1043,15 +1048,15 @@ void expairseq::make_flat(const epvector &v, bool do_index_renaming)
if (elem.is_canonical_numeric())
combine_overall_coeff(ex_to<numeric>(mf.handle_factor(elem.rest, _ex1)));
else {
- const ex& rest = elem.rest;
- const ex& newrest = mf.handle_factor(rest, elem.coeff);
- if (newrest.is_zero())
- combine_overall_coeff(*_num0_p);
- else if (are_ex_trivially_equal(newrest, rest))
- seq.push_back(elem);
- else
- seq.emplace_back(newrest, elem.coeff);
- }
+ if ((is_exactly_a<numeric>(elem.coeff) and elem.coeff.is_zero())
+ or (is_exactly_a<numeric>(elem.rest)
+ and (ex_to<numeric>(elem.rest).is_equal(default_overall_coeff())))) {
+ combine_overall_coeff(default_overall_coeff());
+ }
+ else {
+ seq.push_back(elem);
+ }
+ }
}
}
}
8 changes: 8 additions & 0 deletions src/sage/symbolic/expression.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5490,11 +5490,19 @@ cdef class Expression(CommutativeRingElement):
sage: integrate(f(x), x, 0, a).subs(a=cos(a))
integrate(f(x), x, 0, cos(a))
Check that :trac:`31554` is fixed::
sage: a,b,c,d,x,y = var("a b c d x y")
sage: with hold:
....: print((2*x^0*a + b*y^1).subs({x:c, y:c*d}))
b*c*d + 2*a
Check that :trac:`31530` is fixed::
sage: a, b = var("a b")
sage: (a + b*x).series(x, 2).subs(a=a, b=b)
(a) + (b)*x + Order(x^2)
"""
cdef dict sdict = {}
cdef GEx res
Expand Down

0 comments on commit c0dc957

Please sign in to comment.