Opened 3 years ago

Closed 3 years ago

#22340 closed enhancement (fixed)

Coefficient of an AsymptoticExpansion

Reported by: cheuberg Owned by:
Priority: major Milestone: sage-7.6
Component: asymptotic expansions Keywords:
Cc: dkrenn, behackl Merged in:
Authors: Clemens Heuberger Reviewers: Daniel Krenn
Report Upstream: N/A Work issues:
Branch: f04154b (Commits) Commit: f04154b6f47d6510503e8fcc5af6e7b2bfd28269
Dependencies: Stopgaps:

Description

The following would be convenient:

sage: R.<m, n> = AsymptoticRing("m^QQ*n^QQ", ZZ)
sage: ae = 1 + 42/n + 2/n/m + O(n^-2)
sage: ae.monomial_coefficient(1/n)
42

The choice of the method name monomial_coefficient is motivated by the homonymous method of multivariate polynomial rings.

Change History (10)

comment:1 Changed 3 years ago by cheuberg

  • Branch set to u/cheuberg/coefficient-asymptotic-expansion

comment:2 Changed 3 years ago by cheuberg

  • Authors set to Clemens Heuberger
  • Commit set to 6242878592c4c313a14d94e531684004f75c301e
  • Status changed from new to needs_review

New commits:

6242878Trac #22340: Coefficient of an AsymptoticExpansion

comment:3 Changed 3 years ago by dkrenn

  • Reviewers set to Daniel Krenn

Looks good; I only have very small things to discuss:

1.

+        - ``monomial`` -- a monomial element which can be converted
+          into the parent of this element.

What about rephrasing this to the following, so that the technical term "parent" is avoided

a monomial element which can be converted into the asymptotic ring of this element
  1. Remove period after "element." above (convention in SageMath; not used in the asymptotic_ring file much...).

3.

+            raise ValueError("non-exact monomial")
+            raise ValueError("not a monomial")

Within the asymptotic ring module usually error messages include the element (in the above, the monimial), i.e.

raise ValueError('non-exact monimal {}'.format(monomial))
raise ValueError('{} not a monomial'.format(monomial))

(Maybe inserting "is" in the latter, but not sure.)

comment:4 Changed 3 years ago by dkrenn

  1. The method in the multivariate polynomial ring returns 0 if the monomial is not in the polynomial. Here a KeyError will be raised. If there is no reason against 0, I think the behavior should coincide.

comment:5 Changed 3 years ago by dkrenn

  1. FYI, the following (undocumented) feature of a polynomial is present:
    sage: P.<x,y> = ZZ[]
    sage: a=(1+2*x*y+3*x^2)
    sage: a[x*y]
    2
    sage: a[x^2]
    3
    

So maybe __getitem__ should have this behavior as well...

comment:6 Changed 3 years ago by git

  • Commit changed from 6242878592c4c313a14d94e531684004f75c301e to f04154b6f47d6510503e8fcc5af6e7b2bfd28269

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

b6f670bTrac #22340.1+2 rephrase input documentation
621a006Trac #22340.3: Mention monomial in error message
f04154bTrac #22340.4: return 0 when appropriate

comment:7 follow-up: Changed 3 years ago by cheuberg

1.-4. done

  1. I am not convinced: If this is not a documented and tested behaviour of polynomial rings, I am slightly hesitant to introduce this here. I am not against the concept, but IMHO it should be done in the polynomial ring first (and not on this ticket).

comment:8 in reply to: ↑ 7 Changed 3 years ago by dkrenn

Replying to cheuberg:

1.-4. done

Thank you.

  1. I am not convinced: If this is not a documented and tested behaviour of polynomial rings, I am slightly hesitant to introduce this here. I am not against the concept, but IMHO it should be done in the polynomial ring first (and not on this ticket).

Fine for me not to do this now.

Patch LGTM; positive_review modulo non-finished patchbot

comment:9 Changed 3 years ago by dkrenn

  • Status changed from needs_review to positive_review

Two patchbot tested this ticket now; each timed out on a single, but different doctest, and these tests are not related to this ticket. Thus I set it to positive review

comment:10 Changed 3 years ago by vbraun

  • Branch changed from u/cheuberg/coefficient-asymptotic-expansion to f04154b6f47d6510503e8fcc5af6e7b2bfd28269
  • Resolution set to fixed
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.