Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coeff(f,x*y) does not work #9505

Closed
zimmermann6 opened this issue Jul 15, 2010 · 20 comments
Closed

coeff(f,x*y) does not work #9505

zimmermann6 opened this issue Jul 15, 2010 · 20 comments

Comments

@zimmermann6
Copy link

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

Component: symbolics

Keywords: pynac

Stopgaps: #12699

Author: Paul Zimmermann

Branch/Commit: 06b3fc1

Reviewer: Ralf Stephan

Issue created by migration from https://trac.sagemath.org/ticket/9505

@zimmermann6
Copy link
Author

comment:1

PS: I'm sorry if this is a duplicate. The trac search for "coeff" gives 295 entries!

@burcin
Copy link

burcin commented Sep 19, 2010

Changed keywords from none to pynac

@burcin
Copy link

burcin commented Sep 19, 2010

comment:2

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.

@jbalakrishnan
Copy link

Stopgaps: #12699

@williamstein
Copy link
Contributor

comment:4

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

@zimmermann6
Copy link
Author

comment:5

a possible fix would be that f.coeff(x<sup>n*y</sup>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

@burcin
Copy link

burcin commented Mar 26, 2012

comment:6

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

@jdemeyer jdemeyer modified the milestones: sage-5.11, sage-5.12 Aug 13, 2013
@zimmermann6
Copy link
Author

Author: Paul Zimmermann

@zimmermann6
Copy link
Author

comment:8

Attachment: trac_9505.patch.gz

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

@rwst
Copy link

rwst commented Feb 17, 2014

Branch: u/rws/ticket/9505

@rwst
Copy link

rwst commented Feb 17, 2014

Commit: 850abdc

@rwst
Copy link

rwst commented Feb 17, 2014

comment:11

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:

850abdctrac 9505: coeff(f,x*y) does not work

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 20, 2014

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

0c57d9aMerge branch 'develop' into ticket/9505

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 20, 2014

Changed commit from 850abdc to 0c57d9a

@vbraun
Copy link
Member

vbraun commented Feb 20, 2014

Reviewer: Ralf Stephan

@vbraun
Copy link
Member

vbraun commented Feb 21, 2014

comment:15

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.

@zimmermann6
Copy link
Author

comment:16

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

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 21, 2014

Changed commit from 0c57d9a to 06b3fc1

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented Feb 21, 2014

Branch pushed to git repo; I updated commit sha1 and set ticket back to needs_review. New commits:

06b3fc1Trac #9505: reviewer's patch: fix doc

@vbraun
Copy link
Member

vbraun commented Feb 22, 2014

Changed branch from u/rws/ticket/9505 to 06b3fc1

@vbraun vbraun closed this as completed in 2202e18 Feb 22, 2014
tscrim pushed a commit to tscrim/sage that referenced this issue Jun 1, 2023
* develop: (100 commits)
  Updated Sage version to 6.2.beta4
  added documentation, patchlevel bump
  trac sagemath#15894 modif of two warnings
  delete cruft from the guava package
  trac sagemath#15893 review patch
  trac sagemath#15894 another backward change
  trac sagemath#15894 changin back the category names
  trac #15xxx proper names should start by a capital letter
  Fix changelog entry for ell_wp
  trac sagemath#15893: graphs.petersen_family
  Fixes to code from sagemath#9505.
  Fix the banner displayed by sage -h
  trac sagemath#15466: remove dead import
  trac sagemath#15795 line wrap
  trac sagemath#15795 redone with ( ::)
  Fraction to power series: doctests
  Fraction to power series conversion when the fraction coerces into the base ring
  15698: Allow construction of power series from fractions
  Create *unevaluated* integrals when converting sage integrals to sympy
  Use evaluate=False in SympyConverter too
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants