Sage: Ticket #10841: piecewise integrals of 0 fail
https://trac.sagemath.org/ticket/10841
<p>
As reported in <a class="ext-link" href="http://groups.google.com/group/sage-support/browse_thread/thread/7d0fdb331d05c557"><span class="icon"></span>a sage-support thread</a>, in 4.6.1 we see that
</p>
<pre class="wiki">sage: # succeeds
sage: f = Piecewise([[(0,1),1]])
sage: f.integral(x,0,1)
1
sage: # fails
sage: f = Piecewise([[(0,1),0]])
sage: f.integral(x,0,1)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/Applications/sage/local/lib/python2.6/site-packages/sage/all_cmdline.pyc in <module>()
/Applications/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc in integral(self, x, a, b, definite)
789 """
790 if a != None and b != None:
--> 791 F = self.integral(x)
792 return F(b) - F(a)
793
/Applications/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.pyc in integral(self, x, a, b, definite)
831 if definite or end != infinity:
832 area += fun.integral(x, start, end)
--> 833 new_pieces.append([(start, end), fun_integrated.function(x)])
834
835 if definite:
/Applications/sage/local/lib/python2.6/site-packages/sage/structure/element.so in sage.structure.element.Element.__getattr__ (sage/structure/element.c:2666)()
/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.getattr_from_other_class (sage/structure/parent.c:2840)()
/Applications/sage/local/lib/python2.6/site-packages/sage/structure/parent.so in sage.structure.parent.raise_attribute_error (sage/structure/parent.c:2611)()
AttributeError: 'sage.rings.integer.Integer' object has no attribute 'function'
</pre><p>
ultimately because 0 is special-cased:
</p>
<pre class="wiki">sage: type(SR(0).integral(x))
<type 'sage.rings.integer.Integer'>
sage: type(SR(1).integral(x))
<type 'sage.symbolic.expression.Expression'>
</pre><p>
and the code path for a zero in <a class="missing wiki">PiecewisePolynomial?</a>.integral never coerces to SR, so .function fails.
</p>
<hr />
<p>
Apply only <a class="attachment" href="https://trac.sagemath.org/attachment/ticket/10841/trac_10841_fix_piecewise_integrals_of_zero.2.patch" title="Attachment 'trac_10841_fix_piecewise_integrals_of_zero.2.patch' in Ticket #10841">trac_10841_fix_piecewise_integrals_of_zero.2.patch</a><a class="trac-rawlink" href="https://trac.sagemath.org/raw-attachment/ticket/10841/trac_10841_fix_piecewise_integrals_of_zero.2.patch" title="Download"></a>
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/10841
Trac 1.2D.S. McNeilThu, 24 Feb 2011 08:20:09 GMTowner, type, component, priority changed
https://trac.sagemath.org/ticket/10841#comment:1
https://trac.sagemath.org/ticket/10841#comment:1
<ul>
<li><strong>owner</strong>
changed from <em>tbd</em> to <em>Burcin Erocal</em>
</li>
<li><strong>type</strong>
changed from <em>PLEASE CHANGE</em> to <em>defect</em>
</li>
<li><strong>component</strong>
changed from <em>PLEASE CHANGE</em> to <em>symbolics</em>
</li>
<li><strong>priority</strong>
changed from <em>major</em> to <em>minor</em>
</li>
</ul>
TicketD.S. McNeilThu, 24 Feb 2011 13:56:10 GMTattachment set
https://trac.sagemath.org/ticket/10841
https://trac.sagemath.org/ticket/10841
<ul>
<li><strong>attachment</strong>
set to <em>trac_10841_fix_piecewise_integrals_of_zero.patch</em>
</li>
</ul>
TicketD.S. McNeilThu, 24 Feb 2011 13:57:05 GMTdescription changed
https://trac.sagemath.org/ticket/10841#comment:2
https://trac.sagemath.org/ticket/10841#comment:2
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/10841?action=diff&version=2">diff</a>)
</li>
</ul>
TicketKarl-Dieter CrismanThu, 24 Feb 2011 14:49:11 GMTcc set
https://trac.sagemath.org/ticket/10841#comment:3
https://trac.sagemath.org/ticket/10841#comment:3
<ul>
<li><strong>cc</strong>
<em>Karl-Dieter Crisman</em> added
</li>
</ul>
<p>
I don't have time to review this now, but hopefully not too long. Do all long tests pass with this change?
</p>
<p>
Also, you should feel free to ask the webmaster (Harald Schilly) to add you to <a class="ext-link" href="http://www.sagemath.org/development-map.html"><span class="icon"></span>http://www.sagemath.org/development-map.html</a>.
</p>
TicketDavid JoynerThu, 24 Feb 2011 16:17:09 GMTstatus changed
https://trac.sagemath.org/ticket/10841#comment:4
https://trac.sagemath.org/ticket/10841#comment:4
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/10841#comment:3" title="Comment 3">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
I don't have time to review this now, but hopefully not too long. Do all long tests pass with this change?
</p>
<p>
Also, you should feel free to ask the webmaster (Harald Schilly) to add you to <a class="ext-link" href="http://www.sagemath.org/development-map.html"><span class="icon"></span>http://www.sagemath.org/development-map.html</a>.
</p>
</blockquote>
<p>
I've tested this on one machine on an older version of Sage and sage -testall passed, except for
failing the (presumably unrelated) R-interface file. Also, the code looks good, has the appropriate doctests
and seems to do what is claimed. I want to test it on one more machine before giving it a positive review though.
</p>
TicketDavid JoynerThu, 24 Feb 2011 19:49:14 GMTstatus changed
https://trac.sagemath.org/ticket/10841#comment:5
https://trac.sagemath.org/ticket/10841#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
</ul>
<p>
This applies fine to 4.6.2.rc0 and passes sage -testall -long. Patch reads okay and does what it claims to do.
</p>
<p>
Thanks very much for making the patch!
</p>
TicketJeroen DemeyerFri, 25 Feb 2011 08:08:14 GMTreviewer, milestone, author set
https://trac.sagemath.org/ticket/10841#comment:6
https://trac.sagemath.org/ticket/10841#comment:6
<ul>
<li><strong>reviewer</strong>
set to <em>David Joyner</em>
</li>
<li><strong>milestone</strong>
set to <em>sage-4.7</em>
</li>
<li><strong>author</strong>
set to <em>Douglas McNeil</em>
</li>
</ul>
TicketJeroen DemeyerWed, 23 Mar 2011 13:53:26 GMTstatus changed
https://trac.sagemath.org/ticket/10841#comment:7
https://trac.sagemath.org/ticket/10841#comment:7
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>needs_work</em>
</li>
</ul>
<p>
Problems while building the documentation:
</p>
<pre class="wiki">dochtml.log:/mnt/usb1/scratch/jdemeyer/merger/sage-4.7.alpha3/local/lib/python2.6/site-packages/sage/functions/piecewise.py:docstring of sage.functions.piecewise.PiecewisePolynomial.integral:83: (WARNING/2) Literal block expected; none found.
</pre>
TicketKarl-Dieter CrismanWed, 23 Mar 2011 14:39:31 GMTattachment set
https://trac.sagemath.org/ticket/10841
https://trac.sagemath.org/ticket/10841
<ul>
<li><strong>attachment</strong>
set to <em>trac_10841_fix_piecewise_integrals_of_zero.2.patch</em>
</li>
</ul>
<p>
Apply only this patch
</p>
TicketKarl-Dieter CrismanWed, 23 Mar 2011 14:40:57 GMTstatus, description changed
https://trac.sagemath.org/ticket/10841#comment:8
https://trac.sagemath.org/ticket/10841#comment:8
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/10841?action=diff&version=8">diff</a>)
</li>
</ul>
<p>
This should fix the problem.
</p>
TicketKarl-Dieter CrismanWed, 23 Mar 2011 14:42:58 GMTstatus, reviewer changed
https://trac.sagemath.org/ticket/10841#comment:9
https://trac.sagemath.org/ticket/10841#comment:9
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>reviewer</strong>
changed from <em>David Joyner</em> to <em>David Joyner, Karl-Dieter Crisman</em>
</li>
</ul>
<p>
Yes, it does.
</p>
<p>
Note to DSM: it turns out that you only need the double colon in front of doctests. So if there is verbiage between the <code>EXAMPLES</code> or <code>TESTS</code> and the actual indented tests, you only use a single colon there.
</p>
TicketD.S. McNeilWed, 23 Mar 2011 14:49:25 GMT
https://trac.sagemath.org/ticket/10841#comment:10
https://trac.sagemath.org/ticket/10841#comment:10
<p>
Okay, so just so I'm clear: you must use only one colon after EXAMPLE[S] or TESTS if you're going to follow it with text at the indentation level of EXAMPLES and TESTS and not a more deeply indented code section. If you use two colons, then what comes after *must* be an indented code section, whether you've used "EXAMPLES::" or "EXAMPLE:" and then text and then a bare "::" on a line.
</p>
<p>
[update: just read kcrisman's explanation. `:^)`]
</p>
<p>
So does this mean that the merger of my patch for trac <a class="closed ticket" href="https://trac.sagemath.org/ticket/10088" title="#10088: defect: numerical_integral fails for constant expressions (closed: fixed)">#10088</a> broke the docs?
</p>
TicketKarl-Dieter CrismanWed, 23 Mar 2011 15:12:02 GMT
https://trac.sagemath.org/ticket/10841#comment:11
https://trac.sagemath.org/ticket/10841#comment:11
<p>
Well, you'd think so, but it didn't - here's why. It doesn't 'break' them, just causes a warning. And if they aren't in the reference manual - as that file apparently isn't - it won't break them, since there is no warning, since they are never actually built.
</p>
TicketKarl-Dieter CrismanWed, 23 Mar 2011 15:12:43 GMT
https://trac.sagemath.org/ticket/10841#comment:12
https://trac.sagemath.org/ticket/10841#comment:12
<p>
That's not to say such things shouldn't be fixed eventually. But that would happen when such files are put into the reference manual; even I wouldn't do a ticket for something <em>that</em> trivial.
</p>
TicketJeroen DemeyerFri, 25 Mar 2011 12:30:32 GMTstatus changed; resolution, merged set
https://trac.sagemath.org/ticket/10841#comment:13
https://trac.sagemath.org/ticket/10841#comment:13
<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-4.7.alpha3</em>
</li>
</ul>
Ticket