Opened 3 years ago

Last modified 7 months ago

#20824 needs_review enhancement

Add Expression.coefficient(...expand=True) keyword

Reported by: rws Owned by:
Priority: major Milestone: sage-8.2
Component: symbolics Keywords:
Cc: Merged in:
Authors: Ralf Stephan Reviewers:
Report Upstream: N/A Work issues:
Branch: u/rws/20824 (Commits) Commit: 7ab049f6e36a201ca98ad482c3c0a2d48227d614
Dependencies: Stopgaps:

Description (last modified by rws)

There is no reason why there should be different results:

sage: (x*(x*y+y^2)).coefficient(x)
y
sage: (x*(x*y+y^2)).coefficient(x,2)
0
sage: (x*(x*y+y^2)).expand().coefficient(x)
y^2
sage: (x*(x*y+y^2)).expand().coefficient(x,2)
y

This would also be unsurprising for Mma users, see http://trac.sagemath.org/ticket/9505#comment:6

Maybe add keyword expand=True.

Change History (10)

comment:1 Changed 3 years ago by rws

  • Description modified (diff)
  • Summary changed from Expression.coefficient() should expand beforehand to Expression.coefficient() problems

comment:2 Changed 3 years ago by rws

  • Description modified (diff)

comment:3 Changed 3 years ago by rws

  • Description modified (diff)

comment:4 Changed 3 years ago by rws

  • Branch set to u/rws/expression_coefficient___problems

comment:5 Changed 3 years ago by rws

  • Authors set to Ralf Stephan
  • Commit set to a45909c72aa8d561337be41a85d930f5797ccd5e
  • Milestone changed from sage-7.3 to sage-7.4
  • Status changed from new to needs_review
  • Summary changed from Expression.coefficient() problems to Add Expression.coefficient(...expand=True) keyword
  • Type changed from defect to enhancement

New commits:

a45909c20824: add Expression.coefficient(...expand=True) keyword

comment:6 Changed 2 years ago by mmezzarobba

Hmm, I don't really see the benefit compared to expr.expand().coefficient(...)...

comment:7 Changed 16 months ago by git

  • Commit changed from a45909c72aa8d561337be41a85d930f5797ccd5e to 1d6fc68cbbb9515fde79799a13d5012e0036105a

Branch pushed to git repo; I updated commit sha1. New commits:

1d6fc68Merge branch 'develop' into t/20824/expression_coefficient___problems

comment:8 Changed 12 months ago by rws

  • Branch changed from u/rws/expression_coefficient___problems to u/rws/20824

comment:9 Changed 12 months ago by rws

  • Commit changed from 1d6fc68cbbb9515fde79799a13d5012e0036105a to 7ab049f6e36a201ca98ad482c3c0a2d48227d614
  • Milestone changed from sage-7.4 to sage-8.2

New commits:

7ab049f20824 Add Expression.coefficient(...expand=True) keyword

comment:10 Changed 7 months ago by gh-bryangingechen

I had a look at the patch:

  • It looks like r is assigned in the try block but then not returned or called afterwards. Is this necessary? (I haven't completely digested the pynac interface so I may be missing something, but this looks strange...)
  • Should this be added to coefficients as well?
  • The indentation to TESTS: in the docstring was changed accidentally.
Note: See TracTickets for help on using tickets.