Changes between Version 11 and Version 14 of Ticket #30520


Ignore:
Timestamp:
03/25/21 03:09:56 (3 months ago)
Author:
gh-robert-dodier
Comment:

I've come to the same conclusion. I think this patch fixes it:

$ git diff
diff --git a/share/solve_rec/solve_rec.mac b/share/solve_rec/solve_rec.mac
index 2727db808..8979e3f1d 100644
--- a/share/solve_rec/solve_rec.mac
+++ b/share/solve_rec/solve_rec.mac
@@ -1109,7 +1109,7 @@ simplify_product(prod) := block(
         prod
     )
     else if part(term, 0)="-" and length(args(term))=1 then
-      (-1)^(hi-lo)*simplify_product(apply(nounify('product), [-term, %n, lo, hi]))
+      (-1)^(hi-lo+1)*simplify_product(apply(nounify('product), [-term, %n, lo, hi]))
     /* Give up! */
     else
       p%*apply(nounify('product), [factor(term), %n, lo, hi])

Although the existing, incorrect code is exercised by the unit tests (rtest_simplify_sum and rtest_solve_rec), fixing it does not change any results! Not sure what's going on there; I guess it is a happy accident. Or not.

Anyway I will add a few unit tests and commit the patch.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30520 – Description

    v11 v14  
    11Reported at [https://ask.sagemath.org/question/53345 Ask Sage question 53345].
    22
    3 Observed: incorrect leading minus sign:
     3Before this ticket, the output for this product
     4has an incorrect leading minus sign:
    45{{{
    56sage: N, q, k = SR.var('N, q, k')
     
    89}}}
    910
    10 Expected:
     11After this ticket, the output is correct:
    1112{{{
    1213sage: N, q, k = SR.var('N, q, k')