My quick-n-dirty (meaning pretty untested on anything but simple cases):
toif = With[{if = If @@@ (Reverse /@ #[[1]]), l = #[[2]]},
Nest[{Insert[#[[1]], if[[Length@#[[2]] + 1]], #[[2]]],
Append[#[[2]], -1]} &, {if[[1]], {-1}}, Length@if - 1] //
Insert[#[[1]], l, #[[2]]] &] &;
Seems a bit more robust than your solution:
f1 = Piecewise[{{x^3, x < -1}, {-x^2, -1 <= x < 0}, {x,
0 <= x < 1}, {Sqrt[x], 1 <= x}}];
f2 = Piecewise[{{x*2, x[1] == 2}, {x*3, x[2] == 3}}];
f3 = Piecewise[{{2, x == {1, 2, 3}}, {{1, 2, 3}, x == {3, 2, 1}}, {x,
True}}];
Column[{toif[f1],pwti[f1]," ",
toif[f2],pwti[f2]," ",
toif[f3],pwti[f3]}]
(*
If[x<-1,x^3,If[-1<=x<0,-x^2,If[0<=x<1,x,If[1<=x,Sqrt[x],0]]]]
If[x<-1,x^3,If[-1<=x<0,-x^2,If[0<=x<1,x,If[1<=x,Sqrt[x],0]]]]
If[x[1]==2,2 x,If[x[2]==3,3 x,0]]
0
If[x=={1,2,3},2,If[x=={3,2,1},{1,2,3},x]]
x
*)
I'll ponder further when lounging later, gut tells me there's an elegant way to do this.
Much prettier:
toif2 = Fold[Insert[#2, #1, {-1}] &, Prepend[If @@@ Reverse /@ #[[1]], #[[2]]]] &;
toif2[f3]
(* If[x == {3, 2, 1}, {1, 2, 3}, If[x == {1, 2, 3}, 2, x]] *)
N.b.: this reorders terms, end result is the same. Completely untested - gotta go eat!