In Mathematica everything is specified via patterns. So are, of course, Piecewise
functions. To obtain a standardized form for nested Piecewise
functions you were right to apply PiecewiseExpand
first. So let's take a look at an example of a nested Piecewise
function:
(*definition*)
pw = Piecewise[{{g[x],x > 5}, {Piecewise[{{h1[x],x < 1},
{h2[x],x > 2}}, h3[x]], x < 3}}, f[x]];
(*expansion*)
pwe = PiecewiseExpand[pw];
Remember my remark about patterns before. Let's take a look at the underlying pattern (form) of the expanded Piecewise
function:
pwe // FullForm
This gives you a clue on how to extract all the functions via using the Part
operator, here is one possibility to do it:
Flatten[{pwe[[1, ;; , 1]], pwe[[2]]}]
{f[x], g[x], h1[x], h2[x], h3[x]}
Have fun playing around with this.