Opened 4 years ago
Last modified 2 years ago
#21215 new enhancement
Periodic piecewise functions
Reported by: | mkoeppe | Owned by: | |
---|---|---|---|
Priority: | major | Milestone: | sage-7.4 |
Component: | symbolics | Keywords: | |
Cc: | kcrisman, tscrim, ares, novoselt, rws, vbraun, pbruin, burcin, jdemeyer | Merged in: | |
Authors: | Reviewers: | ||
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | #21232 | Stopgaps: |
Description (last modified by )
I propose to add periodic piecewise functions (for now, of a single real variable).
I see two main ways of doing so:
(1) By extending
piecewise
.
(2) By making a suitably general symbolic mod function (#9935) and having the user combine it with a piecewise function. (This is how it is done in Mathematica, it appears - http://community.wolfram.com/groups/-/m/t/156025; see also https://reference.wolfram.com/language/ref/Piecewise.html)
Some literature on piecewise:
- MARTIN VON MOHRENSCHILDT, A Normal Form for Function Rings of Piecewise Functions, J. Symbolic Computation (1998) 26, 607–619, http://www.sciencedirect.com/science/article/pii/S0747717198902292
- Jacques Carette, A canonical form for some piecewise defined functions, https://arxiv.org/pdf/cs/0702010.pdf
- Dilated floor functions having nonnegative commutator https://arxiv.org/abs/1806.00579v1
Change History (13)
comment:1 follow-up: ↓ 2 Changed 4 years ago by
comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 4 years ago by
Replying to rws:
My vote is for 1).
Glad to hear; this is what I would strongly prefer too.
Right now the result of piecewise
has SR as its parent. Can this be changed so that it is in a more specific parent or category?
As you seem to have a use case can you be please more detailed?
My first use case is in subadditive periodic piecewise linear functions, the periodic extensions of what can be seen here: https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/compendium.png They appear in integer optimization. See https://www.math.ucdavis.edu/~mkoeppe/art/infinite-group/ for more info if you're interested. I have some existing Sage code.
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
Examples are ceil
and floor
.
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 (#20877).
comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 4 years ago by
Replying to mkoeppe:
Right now the result of
piecewise
has SR as its parent. Can this be changed so that it is in a more specific parent or category?
Possibly we can enforce Sage's convention to give back the same type as the type of the input. Meanwhile you can do ret = f(); if ret.is_numeric(): ret = ret.pyobject()
because the type is already preserved.
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
You are certainly aware that if they have one periodic piece they can be all expressed in terms of floor
. Multiple pieces can be done by a combination of floor
and piecewise
I think.
comment:4 in reply to: ↑ 3 ; follow-up: ↓ 5 Changed 4 years ago by
Replying to rws:
Replying to mkoeppe:
Generalizing slightly, I would actually like support for quasiperiodic piecewise functions -- that is, periodic plus a linear function.
You are certainly aware that if they have one periodic piece they can be all expressed in terms of
floor
. Multiple pieces can be done by a combination offloor
andpiecewise
I think.
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 (http://arxiv.org/pdf/1011.6002v1.pdf page 21). Sage should provide easy access to the corresponding direct sum decompositions of quasiperiodic functions.
comment:5 in reply to: ↑ 4 Changed 4 years ago by
Replying to mkoeppe:
Sage should provide easy access to the corresponding direct sum decompositions of quasiperiodic functions.
Can you please help a computer scientist, where for example in that paper is such a decomposition?
comment:6 follow-up: ↓ 7 Changed 4 years ago by
Or did you mean decomposition into piecewise+linear. Better question: how should the piecewise quasiperiodic be represented textually? What preferred way to input them?
comment:7 in reply to: ↑ 6 Changed 4 years ago by
Replying to rws:
Or did you mean decomposition into piecewise+linear.
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.
Better question: how should the piecewise quasiperiodic be represented textually?
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".
What preferred way to input them?
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.
comment:8 Changed 4 years ago by
- Dependencies set to #21232
- Milestone set to sage-7.4
comment:9 Changed 4 years ago by
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.
comment:10 Changed 4 years ago by
- Description modified (diff)
comment:11 Changed 4 years ago by
- Description modified (diff)
comment:12 Changed 4 years ago by
- Description modified (diff)
comment:13 Changed 2 years ago by
- Description modified (diff)
My vote is for 1). As you seem to have a use case can you be please more detailed?