Sage: Ticket #8603: Partial sums are off for Fourier series of piecewise functions
https://trac.sagemath.org/ticket/8603
<p>
Doing
</p>
<pre class="wiki">f = Piecewise([[(-pi, pi), x]])
print f.fourier_series_partial_sum(2, pi)
print f.fourier_series_partial_sum(3, pi)
</pre><p>
we get
</p>
<pre class="wiki">2*sin(x)
-sin(2*x) + 2*sin(x)
</pre><p>
while according to the documentation we should get the second output with the first command.
</p>
<p>
Update: Same output with the new <code>piecewise</code> from <a class="closed ticket" href="https://trac.sagemath.org/ticket/14801" title="defect: Piecewise functions done right (closed: fixed)">#14801</a>. Does it agree with the documentation there?
</p>
<p>
UPDATE: this is fixed in Sage 8.1 (see <a class="closed ticket" href="https://trac.sagemath.org/ticket/23672" title="defect: Improve documentation and user interface of Fourier series (closed: fixed)">#23672</a>):
</p>
<pre class="wiki">sage: f = piecewise([[(-pi, pi), x]])
sage: f.fourier_series_partial_sum(2, pi)
-sin(2*x) + 2*sin(x)
</pre>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/8603
Trac 1.1.6kcrismanMon, 14 Mar 2011 20:25:10 GMTpriority changed
https://trac.sagemath.org/ticket/8603#comment:1
https://trac.sagemath.org/ticket/8603#comment:1
<ul>
<li><strong>priority</strong>
changed from <em>major</em> to <em>minor</em>
</li>
</ul>
<p>
This is still true, and syntax is also deprecated.
</p>
<pre class="wiki">
sage: f = Piecewise([[(-pi, pi), x]])
sage: print f.fourier_series_partial_sum(2, pi)
/Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.py:1095: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
a0 = self.fourier_series_cosine_coefficient(0,L)
/Applications/MathApps/sage/local/lib/python2.6/site-packages/sage/functions/piecewise.py:1099: DeprecationWarning: Substitution using function-call syntax and unnamed arguments is deprecated and will be removed from a future release of Sage; you can use named arguments instead, like EXPR(x=..., y=...)
for n in srange(1,N)])
2*sin(x)
sage: print f.fourier_series_partial_sum(3, pi)
-sin(2*x) + 2*sin(x)
</pre>
TicketnovoseltSat, 18 Jun 2011 00:31:32 GMTkeywords set
https://trac.sagemath.org/ticket/8603#comment:2
https://trac.sagemath.org/ticket/8603#comment:2
<ul>
<li><strong>keywords</strong>
<em>sd31</em> added
</li>
</ul>
<p>
On a related note: what is the purpose of <code>plot</code> methods for Fourier partial sums? They don't do anything except for passing arguments to the usual global <code>plot</code> function, so they seem redundant to me and perhaps can be removed (after deprecation period).
</p>
TicketkcrismanSat, 18 Jun 2011 00:41:27 GMT
https://trac.sagemath.org/ticket/8603#comment:3
https://trac.sagemath.org/ticket/8603#comment:3
<p>
You may be right. I'd have to look at it. Remember, these are all <em>really</em> old, so they probably at the time bypassed the non-existent 'plot' function, and then were subsequently changed, perhaps.
</p>
TicketwdjSat, 18 Jun 2011 10:44:59 GMTattachment set
https://trac.sagemath.org/ticket/8603
https://trac.sagemath.org/ticket/8603
<ul>
<li><strong>attachment</strong>
set to <em>trac_8603-fourier-sum-docstring.patch</em>
</li>
</ul>
<p>
one line change in docstring
</p>
TicketwdjSat, 18 Jun 2011 10:46:16 GMTstatus changed
https://trac.sagemath.org/ticket/8603#comment:4
https://trac.sagemath.org/ticket/8603#comment:4
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>needs_review</em>
</li>
</ul>
<p>
This fixes the documentation of fourier_series_partial_sum, replacing
</p>
<pre class="wiki"> f(x) \sim \frac{a_0}{2} + \sum_{n=1}^N [a_n\cos(\frac{n\pi x}{L}) +
b_n\sin(\frac{n\pi x}{L})],
</pre><p>
by
</p>
<pre class="wiki"> f(x) \sim \frac{a_0}{2} + \sum_{n=1}^{N-1} [a_n\cos(\frac{n\pi x}{L})
+ b_n\sin(\frac{n\pi x}{L})],
</pre>
TicketkcrismanSun, 19 Jun 2011 01:23:35 GMTauthor set
https://trac.sagemath.org/ticket/8603#comment:5
https://trac.sagemath.org/ticket/8603#comment:5
<ul>
<li><strong>author</strong>
set to <em>David Joyner</em>
</li>
</ul>
<p>
Thanks, David; I don't have time to review this now, but appreciate it.
</p>
<p>
Andrey and I were discussing this at Sage Days 31, and thought that maybe changing the behavior instead to match Taylor series would be good, but if this was in fact what you had intended all along, then this solution is better.
</p>
TicketburcinSun, 19 Jun 2011 02:42:25 GMT
https://trac.sagemath.org/ticket/8603#comment:6
https://trac.sagemath.org/ticket/8603#comment:6
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:5" title="Comment 5">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Thanks, David; I don't have time to review this now, but appreciate it.
</p>
<p>
Andrey and I were discussing this at Sage Days 31, and thought that maybe changing the behavior instead to match Taylor series would be good, but if this was in fact what you had intended all along, then this solution is better.
</p>
</blockquote>
<p>
The <code>.series()</code> method of symbolic expressions cut off in a pythonic way, like David's change here. If <code>.taylor()</code> does something different we should change it.
</p>
<p>
This is a trivial change. I'd be happy to give a positive review if it passes all tests but the patch bot doesn't seem to be working for some reason.
</p>
TicketnovoseltTue, 21 Jun 2011 17:48:20 GMTstatus changed; work_issues set
https://trac.sagemath.org/ticket/8603#comment:7
https://trac.sagemath.org/ticket/8603#comment:7
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>work_issues</strong>
set to <em>other instances of the typo</em>
</li>
</ul>
<p>
There are more instances of the same typo in other functions of this module, let's fix them all at once!-)
</p>
<p>
David, do you agree that plot methods can be eliminated as they are not really doing anything?
</p>
TicketkcrismanMon, 15 Aug 2011 14:30:07 GMT
https://trac.sagemath.org/ticket/8603#comment:8
https://trac.sagemath.org/ticket/8603#comment:8
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:7" title="Comment 7">novoselt</a>:
</p>
<blockquote class="citation">
<p>
There are more instances of the same typo in other functions of this module, let's fix them all at once!-)
</p>
</blockquote>
<p>
Can you be more specific?
</p>
<blockquote class="citation">
<p>
David, do you agree that plot methods can be eliminated as they are not really doing anything?
</p>
</blockquote>
<p>
I think I looked at this at Sage Days 31, but now I forgot whether that statement is true.
</p>
TicketjdemeyerTue, 13 Aug 2013 15:35:53 GMTmilestone changed
https://trac.sagemath.org/ticket/8603#comment:9
https://trac.sagemath.org/ticket/8603#comment:9
<ul>
<li><strong>milestone</strong>
changed from <em>sage-5.11</em> to <em>sage-5.12</em>
</li>
</ul>
Ticketvbraun_spamThu, 30 Jan 2014 21:20:52 GMTmilestone changed
https://trac.sagemath.org/ticket/8603#comment:10
https://trac.sagemath.org/ticket/8603#comment:10
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.1</em> to <em>sage-6.2</em>
</li>
</ul>
TicketppurkaSun, 23 Feb 2014 13:32:21 GMTdependencies set
https://trac.sagemath.org/ticket/8603#comment:11
https://trac.sagemath.org/ticket/8603#comment:11
<ul>
<li><strong>dependencies</strong>
set to <em>#14801</em>
</li>
</ul>
Ticketvbraun_spamTue, 06 May 2014 15:20:58 GMTmilestone changed
https://trac.sagemath.org/ticket/8603#comment:12
https://trac.sagemath.org/ticket/8603#comment:12
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.2</em> to <em>sage-6.3</em>
</li>
</ul>
Ticketvbraun_spamSun, 10 Aug 2014 16:51:03 GMTmilestone changed
https://trac.sagemath.org/ticket/8603#comment:13
https://trac.sagemath.org/ticket/8603#comment:13
<ul>
<li><strong>milestone</strong>
changed from <em>sage-6.3</em> to <em>sage-6.4</em>
</li>
</ul>
TicketmkoeppeMon, 27 Jun 2016 03:31:36 GMTstatus, description, milestone changed; cc set
https://trac.sagemath.org/ticket/8603#comment:14
https://trac.sagemath.org/ticket/8603#comment:14
<ul>
<li><strong>cc</strong>
<em>wdj</em> <em>jason</em> <em>jondo</em> <em>kcrisman</em> <em>vbraun</em> <em>slelievre</em> <em>mkoeppe</em> <em>eviatarbach</em> <em>rws</em> <em>novoselt</em> added
</li>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_info</em>
</li>
<li><strong>description</strong>
modified (<a href="/ticket/8603?action=diff&version=14">diff</a>)
</li>
<li><strong>milestone</strong>
changed from <em>sage-6.4</em> to <em>sage-7.3</em>
</li>
</ul>
<p>
Updated with information regarding the new <code>piecewise</code> implementation from <a class="closed ticket" href="https://trac.sagemath.org/ticket/14801" title="defect: Piecewise functions done right (closed: fixed)">#14801</a>.
</p>
TicketegourgoulhonThu, 07 Sep 2017 12:01:47 GMTstatus, milestone changed
https://trac.sagemath.org/ticket/8603#comment:15
https://trac.sagemath.org/ticket/8603#comment:15
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>positive_review</em>
</li>
<li><strong>milestone</strong>
changed from <em>sage-7.3</em> to <em>sage-duplicate/invalid/wontfix</em>
</li>
</ul>
<p>
This is fixed by <a class="closed ticket" href="https://trac.sagemath.org/ticket/23672" title="defect: Improve documentation and user interface of Fourier series (closed: fixed)">#23672</a>.
</p>
<p>
Regarding the example in the ticket description, in Sage 8.1.beta4, we have now
</p>
<pre class="wiki">sage: f = piecewise([[(-pi, pi), x]])
sage: f.fourier_series_partial_sum(2, pi)
-sin(2*x) + 2*sin(x)
</pre><p>
We even have, since the half-period is now a default argument,
</p>
<pre class="wiki">sage: f.fourier_series_partial_sum(2)
-sin(2*x) + 2*sin(x)
</pre>
TicketkcrismanThu, 07 Sep 2017 14:33:16 GMT
https://trac.sagemath.org/ticket/8603#comment:16
https://trac.sagemath.org/ticket/8603#comment:16
<p>
Excellent. Is this documented via a test?
</p>
TicketkcrismanThu, 07 Sep 2017 14:33:38 GMTstatus changed
https://trac.sagemath.org/ticket/8603#comment:17
https://trac.sagemath.org/ticket/8603#comment:17
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>needs_info</em>
</li>
</ul>
TicketegourgoulhonThu, 07 Sep 2017 14:41:41 GMT
https://trac.sagemath.org/ticket/8603#comment:18
https://trac.sagemath.org/ticket/8603#comment:18
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:16" title="Comment 16">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Excellent. Is this documented via a test?
</p>
</blockquote>
<p>
Yes this is documented, both in <a class="ext-link" href="http://doc.sagemath.org/html/en/reference/"><span class="icon"></span>Sage Reference Manual</a> and in <a class="ext-link" href="http://doc.sagemath.org/html/en/constructions/"><span class="icon"></span>Sage Constructions</a>, see <a class="ext-link" href="https://git.sagemath.org/sage.git/commit?id=ddeef52c783ef2f87c21b4b26e4410ace5007f02"><span class="icon"></span>here</a>.
</p>
TicketkcrismanThu, 07 Sep 2017 17:30:44 GMTstatus changed
https://trac.sagemath.org/ticket/8603#comment:19
https://trac.sagemath.org/ticket/8603#comment:19
<ul>
<li><strong>status</strong>
changed from <em>needs_info</em> to <em>positive_review</em>
</li>
</ul>
<p>
Sweet. Strange that it didn't cause any doctest errors then? If it didn't, we should make sure to include at least two of the examples on the ticket in the doc <em>somewhere</em>.
</p>
TicketegourgoulhonThu, 07 Sep 2017 19:30:33 GMT
https://trac.sagemath.org/ticket/8603#comment:20
https://trac.sagemath.org/ticket/8603#comment:20
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:19" title="Comment 19">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Sweet. Strange that it didn't cause any doctest errors then? If it didn't, we should make sure to include at least two of the examples on the ticket in the doc <em>somewhere</em>.
</p>
</blockquote>
<p>
I am not sure to understand what you mean. In the current version, as integrated in Sage 8.1.beta4, there are doctests like
</p>
<pre class="wiki">sage: f = piecewise([((-1,0), -1), ((0,1), 1)])
sage: f.fourier_series_partial_sum(5)
4/5*sin(5*pi*x)/pi + 4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi
</pre><p>
In Sage <= 8.0, this would have returned (*)
</p>
<pre class="wiki">4/3*sin(3*pi*x)/pi + 4*sin(pi*x)/pi
</pre><p>
(*) with the half-period added as the second argument, i.e. <code>f.fourier_series_partial_sum(5, 1)</code>)
</p>
TicketkcrismanThu, 07 Sep 2017 21:34:42 GMT
https://trac.sagemath.org/ticket/8603#comment:21
https://trac.sagemath.org/ticket/8603#comment:21
<p>
My concern was just that the <em>correct</em> nature was doctested, not the wrong one, and that we really did have that to test against regression at some point. Good!
</p>
TicketembrayTue, 12 Dec 2017 08:23:33 GMTstatus changed; resolution set
https://trac.sagemath.org/ticket/8603#comment:22
https://trac.sagemath.org/ticket/8603#comment:22
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>wontfix</em>
</li>
</ul>
TicketzimmermaTue, 12 Dec 2017 13:27:06 GMT
https://trac.sagemath.org/ticket/8603#comment:23
https://trac.sagemath.org/ticket/8603#comment:23
<p>
I wonder why "wontfix" since the issue is fixed in 8.1.beta4.
Paul
</p>
TicketegourgoulhonTue, 12 Dec 2017 13:41:20 GMT
https://trac.sagemath.org/ticket/8603#comment:24
https://trac.sagemath.org/ticket/8603#comment:24
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:23" title="Comment 23">zimmerma</a>:
</p>
<blockquote class="citation">
<p>
I wonder why "wontfix" since the issue is fixed in 8.1.beta4.
Paul
</p>
</blockquote>
<p>
Actually, as said in <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:15" title="Comment 15">comment:15</a>, the issue is fixed in another ticket: <a class="closed ticket" href="https://trac.sagemath.org/ticket/23672" title="defect: Improve documentation and user interface of Fourier series (closed: fixed)">#23672</a>, hence the "sage-duplicate/invalid/wontfix" milestone for the current one and the "wonfix" resolution.
</p>
TicketegourgoulhonTue, 12 Dec 2017 14:13:39 GMTdescription changed
https://trac.sagemath.org/ticket/8603#comment:25
https://trac.sagemath.org/ticket/8603#comment:25
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/8603?action=diff&version=25">diff</a>)
</li>
</ul>
TicketkcrismanTue, 12 Dec 2017 15:18:01 GMTresolution changed
https://trac.sagemath.org/ticket/8603#comment:26
https://trac.sagemath.org/ticket/8603#comment:26
<ul>
<li><strong>resolution</strong>
changed from <em>wontfix</em> to <em>duplicate</em>
</li>
</ul>
<p>
Hey, do non-release managers get to mark "closed"? That would be a change in protocol.
</p>
<p>
Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?
</p>
TicketegourgoulhonTue, 12 Dec 2017 15:27:29 GMT
https://trac.sagemath.org/ticket/8603#comment:27
https://trac.sagemath.org/ticket/8603#comment:27
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:26" title="Comment 26">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Hey, do non-release managers get to mark "closed"? That would be a change in protocol.
</p>
</blockquote>
<p>
This was announced in <a class="ext-link" href="https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ"><span class="icon"></span>https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ</a> with apparently the approval of the release manager.
</p>
<blockquote class="citation">
<p>
Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?
</p>
</blockquote>
<p>
Ah yes, you are right (I thought this was automatically set to "wontfix" while closing "sage-duplicate/invalid/wontfix" tickets).
</p>
TicketkcrismanTue, 12 Dec 2017 19:15:37 GMT
https://trac.sagemath.org/ticket/8603#comment:28
https://trac.sagemath.org/ticket/8603#comment:28
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:27" title="Comment 27">egourgoulhon</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/8603#comment:26" title="Comment 26">kcrisman</a>:
</p>
<blockquote class="citation">
<p>
Hey, do non-release managers get to mark "closed"? That would be a change in protocol.
</p>
</blockquote>
<p>
This was announced in <a class="ext-link" href="https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ"><span class="icon"></span>https://groups.google.com/d/msg/sage-release/4bIUu1NECwY/we3BMdkeAAAJ</a> with apparently the approval of the release manager.
</p>
</blockquote>
<p>
10 hours ago :-) but this will be welcome for obvious dupes etc.
</p>
<blockquote class="citation">
<blockquote class="citation">
<p>
Also, maybe the resolution should be "fixed" or "duplicate" if it is indeed fixed in another ticket?
</p>
</blockquote>
<p>
Ah yes, you are right (I thought this was automatically set to "wontfix" while closing "sage-duplicate/invalid/wontfix" tickets).
</p>
</blockquote>
<p>
Yeah, that might be the default, but typically we try to be precise on this. Nice.
</p>
Ticket