Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Periodic piecewise functions #21215

Open
mkoeppe opened this issue Aug 10, 2016 · 13 comments
Open

Periodic piecewise functions #21215

mkoeppe opened this issue Aug 10, 2016 · 13 comments

Comments

@mkoeppe
Copy link
Member

mkoeppe commented Aug 10, 2016

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:

Depends on #21232

CC: @kcrisman @tscrim @sagetrac-ares @novoselt @rwst @vbraun @pjbruin @burcin @jdemeyer

Component: symbolics

Issue created by migration from https://trac.sagemath.org/ticket/21215

@rwst
Copy link

rwst commented Aug 11, 2016

comment:1

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

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 11, 2016

comment:2

Replying to @rwst:

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).

@rwst
Copy link

rwst commented Aug 12, 2016

comment:3

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.

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 12, 2016

comment:4

Replying to @rwst:

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 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.

@rwst
Copy link

rwst commented Aug 12, 2016

comment:5

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?

@rwst
Copy link

rwst commented Aug 12, 2016

comment:6

Or did you mean decomposition into piecewise+linear. Better question: how should the piecewise quasiperiodic be represented textually? What preferred way to input them?

@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 12, 2016

comment:7

Replying to @rwst:

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.

@rwst
Copy link

rwst commented Aug 12, 2016

Dependencies: #21232

@rwst rwst added this to the sage-7.4 milestone Aug 12, 2016
@mkoeppe
Copy link
Member Author

mkoeppe commented Aug 12, 2016

comment:9

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.

@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

@mkoeppe

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants