Sage: Ticket #21215: Periodic piecewise functions
https://trac.sagemath.org/ticket/21215
<p>
I propose to add periodic piecewise functions (for now, of a single real variable).
</p>
<p>
I see two main ways of doing so:
</p>
<blockquote>
<p>
(1) By extending <code>piecewise</code>.
</p>
</blockquote>
<blockquote>
<p>
(2) By making a suitably general symbolic mod function (<a class="new ticket" href="https://trac.sagemath.org/ticket/9935" title="defect: Make a symbolic mod function (new)">#9935</a>) and having the user combine it with a piecewise function. (This is how it is done in Mathematica, it appears - <a class="ext-link" href="http://community.wolfram.com/groups/-/m/t/156025"><span class="icon"></span>http://community.wolfram.com/groups/-/m/t/156025</a>; see also <a class="ext-link" href="https://reference.wolfram.com/language/ref/Piecewise.html"><span class="icon"></span>https://reference.wolfram.com/language/ref/Piecewise.html</a>)
</p>
</blockquote>
<p>
Some literature on piecewise:
</p>
<ul><li>MARTIN VON MOHRENSCHILDT, A Normal Form for Function Rings of Piecewise Functions, J. Symbolic Computation (1998) 26, 607–619, <a class="ext-link" href="http://www.sciencedirect.com/science/article/pii/S0747717198902292"><span class="icon"></span>http://www.sciencedirect.com/science/article/pii/S0747717198902292</a>
</li><li>Jacques Carette, A canonical form for some piecewise defined functions, <a class="ext-link" href="https://arxiv.org/pdf/cs/0702010.pdf"><span class="icon"></span>https://arxiv.org/pdf/cs/0702010.pdf</a>
</li><li>Dilated floor functions having nonnegative commutator <a class="ext-link" href="https://arxiv.org/abs/1806.00579v1"><span class="icon"></span>https://arxiv.org/abs/1806.00579v1</a>
</li></ul>en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/21215
Trac 1.1.6rwsThu, 11 Aug 2016 07:53:10 GMT
https://trac.sagemath.org/ticket/21215#comment:1
https://trac.sagemath.org/ticket/21215#comment:1
<p>
My vote is for 1). As you seem to have a use case can you be please more detailed?
</p>
TicketmkoeppeThu, 11 Aug 2016 23:41:21 GMT
https://trac.sagemath.org/ticket/21215#comment:2
https://trac.sagemath.org/ticket/21215#comment:2
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:1" title="Comment 1">rws</a>:
</p>
<blockquote class="citation">
<p>
My vote is for 1).
</p>
</blockquote>
<p>
Glad to hear; this is what I would strongly prefer too.
</p>
<p>
Right now the result of <code>piecewise</code> has SR as its parent. Can this be changed so that it is in a more specific parent or category?
</p>
<blockquote class="citation">
<p>
As you seem to have a use case can you be please more detailed?
</p>
</blockquote>
<p>
My first use case is in subadditive periodic piecewise linear functions, the periodic extensions of what can be seen here:
<a class="ext-link" href="https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/compendium.png"><span class="icon"></span>https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/compendium.png</a>
They appear in integer optimization. See <a class="ext-link" href="https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/"><span class="icon"></span>https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/</a> for more info if you're interested. I have some existing Sage code.
</p>
<p>
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
Examples are <code>ceil</code> and <code>floor</code>.
</p>
<p>
There is an algebraic viewpoint using group actions on this as well, which is useful for further generalizations, in particular for piecewise functions of several variables (<a class="new ticket" href="https://trac.sagemath.org/ticket/20877" title="task: Meta-ticket: Piecewise functions, polyhedral complexes, piecewise ... (new)">#20877</a>).
</p>
TicketrwsFri, 12 Aug 2016 07:25:32 GMT
https://trac.sagemath.org/ticket/21215#comment:3
https://trac.sagemath.org/ticket/21215#comment:3
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:2" title="Comment 2">mkoeppe</a>:
</p>
<blockquote class="citation">
<p>
Right now the result of <code>piecewise</code> has SR as its parent. Can this be changed so that it is in a more specific parent or category?
</p>
</blockquote>
<p>
Possibly we can enforce Sage's convention to give back the same type as the type of the input. Meanwhile you can do <code>ret = f(); if ret.is_numeric(): ret = ret.pyobject()</code> because the type is already preserved.
</p>
<blockquote class="citation">
<p>
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
</p>
</blockquote>
<p>
You are certainly aware that if they have one periodic piece they can be all expressed in terms of <code>floor</code>. Multiple pieces can be done by a combination of <code>floor</code> and <code>piecewise</code> I think.
</p>
TicketmkoeppeFri, 12 Aug 2016 07:40:07 GMT
https://trac.sagemath.org/ticket/21215#comment:4
https://trac.sagemath.org/ticket/21215#comment:4
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:3" title="Comment 3">rws</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:2" title="Comment 2">mkoeppe</a>:
</p>
<blockquote class="citation">
<p>
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
</p>
</blockquote>
<p>
You are certainly aware that if they have one periodic piece they can be all expressed in terms of <code>floor</code>. Multiple pieces can be done by a combination of <code>floor</code> and <code>piecewise</code> I think.
</p>
</blockquote>
<p>
I guess it depends on the application whether one should consider a quasiperiodic function as a periodic+floor or as a periodic+linear. The latter is better for asymptotics. This matters for my second application, certain counting functions (<a class="ext-link" href="http://arxiv.org/pdf/1011.6002v1.pdf"><span class="icon"></span>http://arxiv.org/pdf/1011.6002v1.pdf</a> page 21).
Sage should provide easy access to the corresponding direct sum decompositions of quasiperiodic functions.
</p>
TicketrwsFri, 12 Aug 2016 08:16:07 GMT
https://trac.sagemath.org/ticket/21215#comment:5
https://trac.sagemath.org/ticket/21215#comment:5
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:4" title="Comment 4">mkoeppe</a>:
</p>
<blockquote class="citation">
<p>
Sage should provide easy access to the corresponding direct sum decompositions of quasiperiodic functions.
</p>
</blockquote>
<p>
Can you please help a computer scientist, where for example in that paper is such a decomposition?
</p>
TicketrwsFri, 12 Aug 2016 08:24:47 GMT
https://trac.sagemath.org/ticket/21215#comment:6
https://trac.sagemath.org/ticket/21215#comment:6
<p>
Or did you mean decomposition into piecewise+linear. Better question: how should the piecewise quasiperiodic be represented textually? What preferred way to input them?
</p>
TicketmkoeppeFri, 12 Aug 2016 09:00:03 GMT
https://trac.sagemath.org/ticket/21215#comment:7
https://trac.sagemath.org/ticket/21215#comment:7
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/21215#comment:6" title="Comment 6">rws</a>:
</p>
<blockquote class="citation">
<p>
Or did you mean decomposition into piecewise+linear.
</p>
</blockquote>
<p>
Take as an example the floor function.
It can be written as x - frac(x). This is the unique way of writing it as a sum of a linear function and a periodic function (whose value is 0 at 0 - a normalization to make it unique).
This kind of direct sum decomposition should be accessible by methods of a quasiperiodic.
</p>
<blockquote class="citation">
<p>
Better question: how should the piecewise quasiperiodic be represented textually?
</p>
</blockquote>
<p>
Good enough for me if is printed as a sum of periodic and linear.
The periodic piecewise function could print like a piecewise function, followed by "extended periodically to R".
</p>
<blockquote class="citation">
<p>
What preferred way to input them?
</p>
</blockquote>
<p>
No clear preference. The linear part could perhaps just be an optional argument in the constructor.
In the continuous piecewise linear case, I suppose one could have a shortcut to build quasiperiodic extensions of the given function, but this is not very important.
</p>
TicketrwsFri, 12 Aug 2016 12:49:15 GMTdependencies, milestone set
https://trac.sagemath.org/ticket/21215#comment:8
https://trac.sagemath.org/ticket/21215#comment:8
<ul>
<li><strong>dependencies</strong>
set to <em>#21232</em>
</li>
<li><strong>milestone</strong>
set to <em>sage-7.4</em>
</li>
</ul>
TicketmkoeppeFri, 12 Aug 2016 19:17:22 GMT
https://trac.sagemath.org/ticket/21215#comment:9
https://trac.sagemath.org/ticket/21215#comment:9
<p>
By the way, I have some existing code for piecewise linear and quasiperiodic piecewise linear that could probably be adapted. It is based on the old piecewise implementation.
</p>
<ul><li><a class="ext-link" href="https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/functions.sage#L1183"><span class="icon"></span>https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/functions.sage#L1183</a>
</li><li><a class="ext-link" href="https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/quasi_periodic.sage"><span class="icon"></span>https://github.com/mkoeppe/infinite-group-relaxation-code/blob/master/quasi_periodic.sage</a>
</li></ul>
TicketmkoeppeSat, 13 Aug 2016 21:29:06 GMTdescription changed
https://trac.sagemath.org/ticket/21215#comment:10
https://trac.sagemath.org/ticket/21215#comment:10
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/21215?action=diff&version=10">diff</a>)
</li>
</ul>
TicketmkoeppeThu, 18 Aug 2016 01:13:49 GMTdescription changed
https://trac.sagemath.org/ticket/21215#comment:11
https://trac.sagemath.org/ticket/21215#comment:11
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/21215?action=diff&version=11">diff</a>)
</li>
</ul>
TicketmkoeppeSat, 15 Oct 2016 18:39:00 GMTdescription changed
https://trac.sagemath.org/ticket/21215#comment:12
https://trac.sagemath.org/ticket/21215#comment:12
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/21215?action=diff&version=12">diff</a>)
</li>
</ul>
TicketmkoeppeSat, 09 Jun 2018 18:40:30 GMTdescription changed
https://trac.sagemath.org/ticket/21215#comment:13
https://trac.sagemath.org/ticket/21215#comment:13
<ul>
<li><strong>description</strong>
modified (<a href="/ticket/21215?action=diff&version=13">diff</a>)
</li>
</ul>
Ticket