Opened 5 years ago
Closed 12 months ago
#9505 closed defect (fixed)
coeff(f,x*y) does not work
Reported by: | zimmerma | Owned by: | burcin |
---|---|---|---|
Priority: | critical | Milestone: | sage-6.2 |
Component: | symbolics | Keywords: | pynac |
Cc: | Merged in: | ||
Authors: | Paul Zimmermann | Reviewers: | Ralf Stephan |
Report Upstream: | N/A | Work issues: | |
Branch: | 06b3fc1 (Commits) | Commit: | 06b3fc1ae37916b9a69842e7f148d252bad5069d |
Dependencies: | Stopgaps: | #12699 |
Description
The following is ok:
sage: var('x,y,z') sage: f=x*y*z^2 sage: f.coeff(z^2) x*y
However the following is not:
sage: f.coeff(x*y) 0
Attachments (1)
Change History (20)
comment:1 Changed 5 years ago by zimmerma
comment:2 Changed 4 years ago by burcin
- Cc malb removed
- Component changed from commutative algebra to symbolics
- Keywords pynac added
- Owner changed from malb to burcin
I'm switching the component to symbolics since the problem involves symbolic expressions.
It seems that we inherited this behavior from GiNaC:
ginsh - GiNaC Interactive Shell (ginac V1.5.7) __, _______ Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, (__) * | Germany. This is free software with ABSOLUTELY NO WARRANTY. ._) i N a C | You are welcome to redistribute it under certain conditions. <-------------' For details type `warranty;'. Type ?? for a list of help topics. > f = x*y*z^2; y*z^2*x > coeff(f, z^2,1); y*x > coeff(f, x*y,1); 0
I will report this to the ginac-list.
comment:3 Changed 3 years ago by jen
- Stopgaps set to #12699
comment:4 Changed 3 years ago by was
Since I don't know how to fix this, at least I can point out some related facts.
Maxima does exactly the same thing as GINAC (and Sage):
sage: !maxima ;;; Loading #P"/Users/wstein/sage/install/sage-5.0.beta2/local/lib/ecl/sb-bsd-sockets.fas" ;;; Loading #P"/Users/wstein/sage/install/sage-5.0.beta2/local/lib/ecl/sockets.fas" ;;; Loading #P"/Users/wstein/sage/install/sage-5.0.beta2/local/lib/ecl/defsystem.fas" ;;; Loading #P"/Users/wstein/sage/install/sage-5.0.beta2/local/lib/ecl/cmp.fas" Maxima 5.24.0 http://maxima.sourceforge.net using Lisp ECL 11.1.1 Distributed under the GNU Public License. See the file COPYING. Dedicated to the memory of William Schelter. The function bug_report() provides bug reporting information. (%i1) f : x*y*z; (%o1) x y z (%i2) coeff(f, x); (%o2) y z (%i3) coeff(f, x*y); (%o3) 0
Maple raises an error in this case:
> f := x*y*z > ; f := x y z > coeff(f, x); y z > coeff(f, x*y); Error, invalid input: coeff received x*y, which is not valid for its 2nd argument, x
Mathematica does what you expect:
In[1]:= f := x*y*z; In[2]:= Coefficient[f,x] Out[2]= y z In[3]:= Coefficient[f,x*y] Out[3]= z
Sage multivariate polynomials (hence Singular) do what you expect:
sage: R.<x,y,z>=QQ[] sage: f = x*y*z^2 sage: f.coefficient(x) y*z^2 sage: f.coefficient(x*y) z^2
comment:5 Changed 3 years ago by zimmerma
a possible fix would be that f.coeff(x^n*y^m) automatically calls
f.coeff(x,n).coeff(y,m) which gives the expected answer:
sage: var('x,y,z') (x, y, z) sage: f=x*y*z^2 sage: f.coeff(x,1).coeff(y,1) z^2
Paul
comment:6 Changed 3 years ago by burcin
We might need to expand the expression before doing recursive calls to coefficient():
sage: var('x,y,z') (x, y, z) sage: g = x*y*(z^2 + y*z) sage: g.coeff(x,1).coeff(y,1) z
Compare to MMA:
In[12]:= Coefficient[x*y*(z^2 + y*z), x*y] 2 Out[12]= z
comment:7 Changed 19 months ago by jdemeyer
- Milestone changed from sage-5.11 to sage-5.12
Changed 18 months ago by zimmerma
comment:8 Changed 18 months ago by zimmerma
- Status changed from new to needs_review
attached is a temporary fix that calls coeff in turn for each term x^n in s.
In addition it checks the extra argument n is only used for a single symbol.
Paul
comment:9 Changed 13 months ago by vbraun_spam
- Milestone changed from sage-6.1 to sage-6.2
comment:10 Changed 13 months ago by rws
- Branch set to u/rws/ticket/9505
- Modified changed from 01/30/14 13:20:52 to 01/30/14 13:20:52
comment:11 Changed 13 months ago by rws
- Commit set to 850abdcc3ce6d76d04d2bf9cbefc6aa7a2aec603
- Status changed from needs_review to positive_review
Patch applies cleanly, looks good, tests OK in symbolics/
Not sure if the stopgap is still necessary. My tests were satisfying but hey.
New commits:
850abdc | trac 9505: coeff(f,x*y) does not work |
comment:12 Changed 12 months ago by git
- Commit changed from 850abdcc3ce6d76d04d2bf9cbefc6aa7a2aec603 to 0c57d9a12ff6c9ae2541700dd2aee59cdb31cefc
- Status changed from positive_review to needs_review
Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:
0c57d9a | Merge branch 'develop' into ticket/9505 |
comment:13 Changed 12 months ago by rws
- Status changed from needs_review to positive_review
comment:14 Changed 12 months ago by vbraun
- Reviewers set to Ralf Stephan
comment:15 Changed 12 months ago by vbraun
Documentation does not build
[calculus ] docstring of sage.symbolic.expression.Expression.coeff:57: WARNING: Literal block expected; none found. [calculus ] docstring of sage.symbolic.expression.Expression.coeff:57: WARNING: Literal block expected; none found. Traceback (most recent call last): File "/home/buildslave-sage/slave/sage_git/build/src/doc/common/builder.py", line 83, in f execfile(sys.argv[0]) File "/home/buildslave-sage/slave/sage_git/build/src/doc/common/custom-sphinx-build.py", line 185, in <module> sphinx.cmdline.main(sys.argv) File "/home/buildslave-sage/slave/sage_git/build/local/lib/python2.7/site-packages/Sphinx-1.1.2-py2.7.egg/sphinx/cmdline.py", line 206, in main print >>error File "/home/buildslave-sage/slave/sage_git/build/src/doc/common/custom-sphinx-build.py", line 165, in write self._write(str) File "/home/buildslave-sage/slave/sage_git/build/src/doc/common/custom-sphinx-build.py", line 139, in _write self._log_line(line) File "/home/buildslave-sage/slave/sage_git/build/src/doc/common/custom-sphinx-build.py", line 108, in _log_line raise OSError(line) OSError: [calculus ] docstring of sage.symbolic.expression.Expression.coeff:57: WARNING: Literal block expected; none found.
comment:16 Changed 12 months ago by zimmerma
sorry with the change to git I don't know how yet how to submit a patch, thus I won't be able to work on this in the near future.
Paul
comment:17 Changed 12 months ago by git
- Commit changed from 0c57d9a12ff6c9ae2541700dd2aee59cdb31cefc to 06b3fc1ae37916b9a69842e7f148d252bad5069d
- Status changed from positive_review to needs_review
Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:
06b3fc1 | Trac #9505: reviewer's patch: fix doc |
comment:18 Changed 12 months ago by rws
- Status changed from needs_review to positive_review
comment:19 Changed 12 months ago by vbraun
- Branch changed from u/rws/ticket/9505 to 06b3fc1ae37916b9a69842e7f148d252bad5069d
- Resolution set to fixed
- Status changed from positive_review to closed
PS: I'm sorry if this is a duplicate. The trac search for "coeff" gives 295 entries!