On Friday, April 24, 2015 at 6:29:43 AM UTC-7, Peter Mueller wrote:
>
> thanks, I had indeed missed (may fault) the monomial_coefficient method
> when I looked at the coefficient doc. However, I do not agree that
> f.monomial_coefficient(X*Y^2) is ``roughly as efficient as f[1,2]''. I
> compared using timeit, and there was a huge factor (about 50 in certain
> cases). I believe it is not the smartest method that if I want to know the
> coefficient of X*Y^2, that one first has to actually compute the monomial
> X*Y^2! Unfortunately, f.monomial_coefficient({X:1, Y:2}) does not work,
> and f[1,2] is (as far as I know) undocumented.
>
The "about the same" means "the implementation is of the same order of
complexity". The ratio should be roughly constant. This is not the case
with f.coefficient, which needs to scan all the terms and hence will be
slower on polynomials with more terms.
It's not even just the construction of the monomial (although that's also
rather slow):
sage: mn=X*Y^2
sage: %timeit f.monomial_coefficient(mn)
10000 loops, best of 3: 25.5 µs per loop
sage: %timeit f.monomial_coefficient(X*Y^2)
10000 loops, best of 3: 79.7 µs per loop
sage: %timeit f[1,2]
100000 loops, best of 3: 2.16 µs per loop
For mention of the f[1,2] method: see the
sage.rings.polynomial.multi_polynomial_element module:
"""
- William Stein (2006-04-19): added e.g.,
``f[1,3]`` to get coeff of `xy^3`; added examples of the new
``R.x,y = PolynomialRing(QQ,2)`` notation.
"""
The method itself is fully documented under f.__getitem__ . This is a
special method (which contributes to why it's faster) and I think we don't
have a really good solution for making the documentation on those easily
discoverable. Mention of the feature in the class doc would help (so that
f? gives a hint), but that is hard to maintain. We're already including the
"__init__" docstring with the class doc. Perhaps we should do that with
some other common special methods too. Or in this case it should probably
appear somewhere on
http://www.sagemath.org/doc/reference/polynomial_rings/sage/rings/polynomial/multi_polynomial_element.html?highlight=multi_polynomial_element#module-sage.rings.polynomial.multi_polynomial_element
--
You received this message because you are subscribed to the Google Groups
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.