You should not have to manually copy any part of the original expression into a new operator (manually, eg, cut & paste), to accomplish this. The
unapply command is useful for that kind of thing.
You started out by giving us this:
f := 12*exp(-t+4):
g := 0:
piece := piecewise(0 <= t and t < 4, g, 4 < t and t <= 6, f):
plot(piece, t = 0 .. 6, size=[200,200]);
Now let's construct an operator from that, which behaves like the supplied
piecewise, with a period of our choice.
We'll use a re-usable constructor for this purpose.
makeperiodic := proc(expr, var, skip)
local T, r;
r := skip/2;
unapply( 'eval'(expr, var=r+'frem'(T+r,skip)), [T], numeric);
Here is the construction of the periodic operator, and quick check.
foo := makeperiodic( piece, t, 6 ):
This operator returns unevaluated when its argument is not numeric, by design.
Now for some plots,
# operator form
plot(foo, -12 .. 12, size=[600,200]);
# expression form (unevaluated function call)
plot(foo(x), x=-12 .. 12, size=[600,200]);
# shift two to the left
plot(foo(x+2), x=-12 .. 12, size=[600,200]);
And we could do a similar thing for some other choice of period,
bar := makeperiodic( piece, t, 5 ):
plot(bar, -10 .. 10, size=[500,200]);
plot(bar(t), t=-10 .. 10, size=[500,200]);
# shift 4 to the right
plot(bar(t-4), t=-10 .. 10, size=[500,200]);