Am Mittwoch, 22. April 2015 20:25:22 UTC+2 schrieb Nils Bruin:
>
> On Wednesday, April 22, 2015 at 9:06:16 AM UTC-7, Peter Mueller wrote:
>>
>> While that is what the doc of .coefficient tells, is there any *sane*
>> reason why the parent of a coefficient isn't the field (or ring) of
>> coefficients?
>>
>
> With your earlier definitions:
>
> sage: (f+Y*f).coefficient({X:1})
> 2*a*Y^3 + 2*a*Y^2
>
> As documented, the parent used is required to represent all possible
> outputs. It would be really bad for f.coefficient to change the parent of
> its return value depending on what the result happens to fit in.
>
> I think in your case the most transparent way of obtaining the desired
> coefficient is to use the routine monomial_coefficient, which is referenced
> in the documentation of coefficient.
>
> sage: f.monomial_coefficient(X*Y^2)
> 2*a
>
> which should be roughly as efficient as f[2,1]. If you need to shave off
> more overhead, you'd probably have to drill into the implementation and
> work with the polynomials using the dictionaries via which they're
> implemented.
>
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.
> - what steps did you take to read the documentation on "coefficients"?
> Where did you read it (if at all)?
> - did you notice the phrase about "monomial_coefficient"? did you look it
> up? why (not)?
>
well, I missed that. I believe that I had the old-fashioned meaning of
monomial in mind, and expected that this method would give the coefficient
of the thing which today is called a term. So I didn't look it up.
> It might be that "monomial_coefficient" would stand out better if it were
> a hyperlink, but many of our ways of displaying documentation don't make
> use of hyperlinks.
>
OK, that could be difficult in the ipython text console. Actually, the doc
of monomial_coefficient is one of the rare cases which includes a `SEE
ALSO'.
-- Peter Mueller
--
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.