Sage: Ticket #14120: Add constant_coefficient method for Laurent polynomials
https://trac.sagemath.org/ticket/14120
<p>
There is no (easy) way to obtain the coefficient on the constant term for an element in the Laurent polynomial ring. This just adds a method <code>constant_coefficient()</code>.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/14120
Trac 1.2Travis ScrimshawThu, 14 Feb 2013 16:04:23 GMTstatus changed
https://trac.sagemath.org/ticket/14120#comment:1
https://trac.sagemath.org/ticket/14120#comment:1
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
TicketTravis ScrimshawFri, 15 Feb 2013 22:46:12 GMT
https://trac.sagemath.org/ticket/14120#comment:2
https://trac.sagemath.org/ticket/14120#comment:2
<p>
Fixed doctests and added a general <code>__getitem__()</code> to retrieve the coefficient by exponent value:
</p>
<pre class="wiki">sage: P.<x,y> = LaurentPolynomialRing(QQ)
sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3; f
-x^6 - 7*x^-2*y^3 + 5*x^-2*y + x^-3*y^2
sage: f[-2,3]
-7
sage: f.coefficient(x^-2*y^3)
-7
</pre>
TicketKannappan SampathSat, 23 Feb 2013 16:26:06 GMTstatus changed; reviewer set
https://trac.sagemath.org/ticket/14120#comment:3
https://trac.sagemath.org/ticket/14120#comment:3
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>reviewer</strong>
set to <em>Kannappan Sampath</em>
</li>
</ul>
<p>
I thought, I'd review this ticket.
</p>
<p>
The docstring claims that, if the number of inputs is less than the number of variables, all the remaining[trailing] variables would have their exponent set to zero. But, for some reason, the implementation (and hence the examples) raises a <code>TypeError</code>.
</p>
<p>
IMHO, it would be nice to implement the behaviour suggested by the docstring. (of course, the other case, where no. of variables <= no. of inputs is being handled correctly.)
</p>
<p>
And, could we also please document that multivariate laurent polynomials are not iterable, as implemented, by adding an example, before we get complaints "like" <a class="ext-link" href="http://trac.sagemath.org/sage_trac/ticket/14124"><span class="icon"></span>this</a>.
</p>
<p>
Building documentation, there is a warning, which is fairly easy to fix: I think the complaint is about the method <code>__call__</code>
</p>
<pre class="wiki"><autodoc>:0: WARNING: Block quote ends without a blank line; unexpected unindent.
</pre><hr />
<p>
Finally, that we are changing this file, one might as well go ahead and clean up all the codifications: self is almost never codified, for instance and such documentation stuff...
</p>
<p>
The already extant method <code>cofficient()</code> would benefit from adding r: <code>r"""</code> just so that the <code>\frac</code> with backslash is picked up properly by Sphinx. There is a misspelt word in the Note that is already there too. (constnat...)
</p>
<hr />
<p>
Regards,
~KnS
</p>
TicketTravis ScrimshawSat, 23 Feb 2013 18:44:47 GMTattachment set
https://trac.sagemath.org/ticket/14120
https://trac.sagemath.org/ticket/14120
<ul>
<li><strong>attachment</strong>
set to <em>trac_14120-constant_coeff_laurent_poly-ts.patch</em>
</li>
</ul>
TicketTravis ScrimshawSat, 23 Feb 2013 18:46:42 GMTstatus changed
https://trac.sagemath.org/ticket/14120#comment:4
https://trac.sagemath.org/ticket/14120#comment:4
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
<p>
First off, thank you for doing the review.
</p>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/14120#comment:3" title="Comment 3">knsam</a>:
</p>
<blockquote class="citation">
<p>
The docstring claims that, if the number of inputs is less than the number of variables, all the remaining[trailing] variables would have their exponent set to zero. But, for some reason, the implementation (and hence the examples) raises a <code>TypeError</code>.
</p>
<p>
IMHO, it would be nice to implement the behaviour suggested by the docstring. (of course, the other case, where no. of variables <= no. of inputs is being handled correctly.)
</p>
</blockquote>
<p>
I made it consistent with other multivariate polynomial rings, however I forgot to correct the doc. This is done. I've also added in two more methods for consistancy and changed the output of the iterator.
</p>
<blockquote class="citation">
<p>
And, could we also please document that multivariate laurent polynomials are not iterable, as implemented, by adding an example, before we get complaints "like" <a class="ext-link" href="http://trac.sagemath.org/sage_trac/ticket/14124"><span class="icon"></span>this</a>.
</p>
</blockquote>
<p>
This does not make sense to me. They are iterable with this patch.
</p>
<blockquote class="citation">
<p>
Building documentation, there is a warning, which is fairly easy to fix: I think the complaint is about the method <code>__call__</code>
</p>
<pre class="wiki"><autodoc>:0: WARNING: Block quote ends without a blank line; unexpected unindent.
</pre></blockquote>
<p>
I do not get this with the revised patch.
</p>
<blockquote class="citation">
<p>
Finally, that we are changing this file, one might as well go ahead and clean up all the codifications: self is almost never codified, for instance and such documentation stuff...
</p>
</blockquote>
<p>
You are welcome to do so on another ticket. That is outside of the purview of this one. I did it in the methods this patch touches.
</p>
<blockquote class="citation">
<p>
The already extant method <code>cofficient()</code> would benefit from adding r: <code>r"""</code> just so that the <code>\frac</code> with backslash is picked up properly by Sphinx. There is a misspelt word in the Note that is already there too. (constnat...)
</p>
</blockquote>
<p>
Fixed.
</p>
<p>
Best,
Travis
</p>
TicketKannappan SampathSun, 24 Feb 2013 03:35:00 GMTstatus changed
https://trac.sagemath.org/ticket/14120#comment:5
https://trac.sagemath.org/ticket/14120#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<blockquote class="citation">
<blockquote class="citation">
<p>
And, could we also please document that multivariate laurent polynomials are not
iterable, as implemented, by adding an example, before we get complaints "like" this.
</p>
</blockquote>
<p>
This does not make sense to me. They are iterable with this patch.
</p>
</blockquote>
<p>
I meant more along the following lines: you cannot iterate through using slice notation:
</p>
<pre class="wiki"> sage: P.<x,y,z> = LaurentPolynomialRing(QQ)
sage: f = (y^2 - x^9 - 7*x*y^3 + 5*x*y)*x^-3 + x*z; f
-x^6 + x*z - 7*x^-2*y^3 + 5*x^-2*y + x^-3*y^2
sage: f[6,0,0]
-1
sage:f[5:6]
[snip]
TypeError: Multivariate Laurent polynomials are not iterable
</pre><p>
But, well, this does not even make sense, given the current implementation. So, I'll set this to positive review.
</p>
<p>
~KnS
</p>
TicketJeroen DemeyerThu, 28 Feb 2013 10:33:46 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/14120#comment:6
https://trac.sagemath.org/ticket/14120#comment:6
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-5.8.beta2</em>
</li>
</ul>
Ticket