Opened 11 months ago
Last modified 9 days ago
#30520 closed defect
Error in the sign of a product — at Version 11
Reported by: | tmonteil | Owned by: | |
---|---|---|---|
Priority: | minor | Milestone: | sage-9.4 |
Component: | symbolics | Keywords: | maxima |
Cc: | gh-DaveWitteMorris, gh-macrakis, gh-robert-dodier, kcrisman, nbruin, slelievre | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description (last modified by )
Reported at Ask Sage question 53345.
Observed: incorrect leading minus sign:
sage: N, q, k = SR.var('N, q, k') sage: product(1 - q^k, k, 1, N) -(-1)^N*product(q^k - 1, k, 1, N)
Expected:
sage: N, q, k = SR.var('N, q, k') sage: product(1 - q^k, k, 1, N) (-1)^N*product(q^k - 1, k, 1, N)
Change History (11)
comment:1 Changed 11 months ago by
comment:2 Changed 11 months ago by
for what it's worth, it's either in the interface to maxima in maxima_eval
or in maxima itself, what ultimately gets called is:
sage: var('n,q,i') (n, q, i) sage: expr = 1 - q**i sage: from sage.interfaces import maxima_lib sage: sage.interfaces.maxima_lib.maxima.sr_prod(expr, i, 1, n) -(-1)^n*product(q^i - 1, i, 1, n)
I couldn't reproduce this on pure maxima, but I have never used it before, so it may well be there.
EDIT: it may also be in the final conversion max_to_sr
comment:3 Changed 11 months ago by
A simple case
sage: from sage.calculus.calculus import symbolic_product sage: var('x,n') (x, n) sage: symbolic_product(-x**2,x,1,n) -(-1)^n*factorial(n)^2
comment:4 Changed 11 months ago by
This seems to happen in max_simplify_prod
. Before:
ipdb> p maxima_eval(([max_prod],[sr_to_max(SR(a)) for a in args])) <ECL: ((%PRODUCT SIMP) ((MTIMES SIMP) -1 ((MEXPT SIMP) |$_SAGE_VAR_x| 2)) |$_SAGE_VAR_x| 1 |$_SAGE_VAR_n|)>
and after:
ipdb> p maxima_eval([max_simplify_prod, ([max_prod],[sr_to_max(SR(a)) for a in a rgs])]) <ECL: ((MTIMES SIMP) ((MEXPT SIMP) -1 ((MPLUS SIMP) -1 |$_SAGE_VAR_n|)) ((MEXPT SIMP) ((MFACTORIAL SIMP) |$_SAGE_VAR_n|) 2))>
comment:5 Changed 9 months ago by
- Milestone changed from sage-9.2 to sage-9.3
comment:6 Changed 4 months ago by
- Cc gh-DaveWitteMorris gh-macrakis gh-robert-dodier slelievre added
- Description modified (diff)
Any insights from Maxima or Sage symbolics experts?
comment:7 follow-up: ↓ 9 Changed 4 months ago by
Hi, thanks for the Maxima problem report.
I was unable to reproduce this in Maxima 5.44.0/SBCL 2.0.0/Windows 10.
Could you please report the details necessary to reproduce the problem:
- The exact version of Maxima/SBCL/OS you're using.
- The exact commands that were passed to Maxima.
- Any non-default global settings that Sage uses when calling Maxima.
- What does max_simplify_product do?
- What the var(...) declaration/statement does in Maxima terms. Does it declare anything special about those variables?
- What does "before this ticket" and "after this ticket" mean? Was it run on different versions of Maxima? If so, which ones?
Thanks,
-s
comment:8 Changed 4 months ago by
- Cc kcrisman nbruin added
- Keywords maxima added
Apologies for cc-ing you. Rather than in Maxima, the bug might well be in Sage's interface to it.
In Sage, the bug can lead to wrong results as in
sage: from sage.calculus.calculus import symbolic_product sage: x, n = SR.var('x,n') sage: symbolic_product(-x**2, x, 1, n) -(-1)^n*factorial(n)^2
or cause an error to be raised as in
sage: symbolic_product(-x, x, 1, n) Traceback (most recent call last) ... RuntimeError: ECL says: Error executing code in Maxima: factorial: factorial of negative integer -1 not defined.
Not sure what exactly gets sent to Maxima in those cases.
I have Maxima 5.44.0, ECL 21.2.1, macOS 10.14.6.
sage: pv = installed_packages() # package versions sage: print(', '.join(f'{p} {pv[p]}' for p in ['maxima', 'ecl'])) maxima 5.44.0, ecl 21.2.1
Sage calls Maxima with the following global settings:
besselexpand : true ; display2d : false ; domain : complex ; keepfloat : true ; load(to_poly_solve) ; load(simplify_sum) ; load(diag) ; nolabels : true ;
"Before this ticket" is the observed bug. "After this ticket" is the goal (so far not reached).
comment:9 in reply to: ↑ 7 Changed 4 months ago by
- What does max_simplify_product do?
max_simplify_prod=EclObject("$SIMPLIFY_PRODUCT")
which is presumably in the contributed simplify_sum
package, more precisely here. I had trouble finding references in the official documentation, though.
- What the var(...) declaration/statement does in Maxima terms. Does it declare anything special about those variables?
No.
comment:10 Changed 4 months ago by
"Before this ticket" is the observed bug. "After this ticket" is the goal (so far not reached).
I know this is just a convention, but, um, this is pretty confusing; I don't see how anyone who was not already among the cognoscenti would know what it means. "Observed" and "expected behavior" seems adequate.
I can't be sure about what's going on here, but I speculate the error is coming out of simplify_product
in the simplify_sum
code.
simplify_product ('product(1 - f(k), k, 1, N)); => (-1)^(N-1)*'product(f(k)-1,k,1,N)
The leading term is off by 1 (right?) -- I think this is the origin of the stray -1 which was observed.
comment:11 Changed 4 months ago by
- Description modified (diff)
Thanks for the rephrasing suggestion and your thoughts on the problem.
FWIW, Sympy doesn't seem to be able to pull this one:
Mathematica isn't more helpful:
Giac's answer can't be believed :
HTH, but doubting it...