Opened 5 years ago

# Periodic piecewise functions

Reported by: Owned by: mkoeppe major sage-7.4 symbolics kcrisman, tscrim, ares, novoselt, rws, vbraun, pbruin, burcin, jdemeyer N/A #21232

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:

### comment:1 follow-up: ↓ 2 Changed 5 years ago by rws

My vote is for 1). As you seem to have a use case can you be please more detailed?

### comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 5 years ago by mkoeppe

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 5 years ago by rws

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 5 years ago by 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 of `floor` and `piecewise` 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 5 years ago by rws

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 5 years ago by rws

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 5 years ago by mkoeppe

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 5 years ago by rws

• Dependencies set to #21232
• Milestone set to sage-7.4

### comment:9 Changed 5 years ago by mkoeppe

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 5 years ago by mkoeppe

• Description modified (diff)

### comment:11 Changed 5 years ago by mkoeppe

• Description modified (diff)

### comment:12 Changed 5 years ago by mkoeppe

• Description modified (diff)

### comment:13 Changed 3 years ago by mkoeppe

• Description modified (diff)
Note: See TracTickets for help on using tickets.