Hello, For some application I have in mind (related to ticket #26471 for those who are interested), I need to have support for piecewise affine functions in Sage. More precisely, what I mostly need is: . to add, compose, take the sup/inf of these functions . to check continuity, convexity, bijectivity . to compute the inverse (for composition) when appropriate
I'd be happy to implement this but I'm unsure how it should fit in the current framework. Notably, I noticed that there already exists support for piecewise defined functions: http://doc.sagemath.org/html/en/reference/functions/sage/functions/piecewise.html So I guess that I should derive from this class. But I'm unsure because I realized that the behavior of piecewise defined functions is sometimes a bit different for what I'd like to have. For instance, if f and g are PiecewiseAffineFunction, I would expect f + g to be a PiecewiseAffineFunction as well. And f.derivative() as well, etc. It's not exactly the case for piecewise defined function: sage: f = piecewise([((0,1), 2*x), ([-1,0], 3*x)]) sage: type(f) == type(f + f) False sage: type(f) == type(f.derivative()) False (I saw that there is a method piecewise_add() but I would expect it to be the default __add__; why isn't it the case?) Moreover it seems that composition of piecewise defined functions is presumably broken[#] (or not implemented): sage: f(f) Traceback (most recent call last): ... TypeError: __call__() takes exactly 2 arguments (3 given) sage: f(f(x)) Traceback (most recent call last): ... TypeError: __call__() takes exactly 2 arguments (3 given) So my question is: what should I do in order to implement piecewise affine functions and the features I would like to have? Do you have any good advise? Best, --Xavier [#] By the way, I noticed: sage: f(x) = 2*x + 3 sage: f(f) 4*x + 9 Shouldn't it x |--> 4*x + 9 instead? -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.
