# what type of object is a function defined with the piecewise command?

I understand that in Sage, there are three function-like things: functions, expressions, and python functions. How do you classify functions defined with the piecewise command?

Functions defined with the piecewise command seem to be a separate class. When I use the parent() command on a piecewise function, Sage says it is an "instance." Can you help me understand what that means? Thanks!

edit retag close merge delete

Sort by ยป oldest newest most voted

As you know, instance is a given case, a given version, of a class. When parent returns instance, that simply means that there's nothing particularly Sage-specific about the structure and it's not living within Sage's Category structure, so it's basically returning Python type information.

sage: class fred: pass
....:
sage: parent(fred)
<type 'classobj'>
sage: a = fred()
sage: parent(a)
<type 'instance'>


which is why we have

sage: f(x) = x^2
sage: parent(f)
Callable function ring with arguments (x,)
sage: g = Piecewise([[(0,1),x], [(1,2),x^2]], x)
sage: g
Piecewise defined function with 2 parts, [[(0, 1), x |--> x], [(1, 2), x |--> x^2]]

sage: parent(g)
<type 'instance'>


And if you type sage.functions.piecewise?? at the console to see the source of the module, you see that PiecewisePolynomial is defined purely as a Python class:

class PiecewisePolynomial:
"""
Returns a piecewise function from a list of (interval, function)
pairs.

more

Yup. A fantastic thing would be to redo our piecewise functions, but it's just big enough of a job to really require some dedicated time to do (it would have to be done all at once), and many of the people who would have the expertise or interest simply don't have the time. Sorry we don't have those fit in with our expression framework yet.

( 2012-06-07 09:09:35 -0500 )edit

Use lambda functions it worked for me.

more