# shift picewise functions

Suppose I define a piecewise function f for example:

f = Piecewise([[(-infinity,1),1],[(1,+infinity),x]])


How to define the shifted function g with g(x) = f(x-2) for all x?

Or more generally: If h is another function. How to define $g = f\circ h$ in sage?

edit retag close merge delete

Sort by » oldest newest most voted

The following works as expected:

f1(x)=0
f2(x)=exp(-1/(x^2))
f=Piecewise([[(-10,0),f1],[(0,10),f2]])
h(x)=x-2
c = compose(f, h)
plot(c, -8, 12)

more

sage: f(x) = x^2+5
sage: g(x) = 25*sqrt(x+1)
sage: g(f(x))
25*sqrt(x^2 + 6)
sage: f(g(x))
625*x + 630
sage: h(x) = f(g(x))
sage: h
x |--> 625*x + 630


The first one is harder, because Piecewise functions were implemented long before we even had symbolic functions, and hence are missing a lot of functionality. This is a long-standing need, but it takes a certain expertise in both the old and new code, as well as Ginac, to do this.

(To the cognoscenti - sympy seems to have piecewise functions, but I can't find much documentation, just obscure hints that they are there. How powerful are theirs?)

more

So there is no workaround to compose piecewise-defined functions?

There may be, but I can't think of one offhand. That doesn't mean it doesn't exist, just that I can't think of it right now.