But it's not that hard to do. Rather than
$f_graph = FEQ("$f for x in [$xmin,$xmax] using color:red and weight:3"); add_functions( $graph,$f_graph);use
$f_graph = new Fun($f->perlFunction,$graph); $f_graph->steps(10); $f_graph->color("red"); $f_graph->weight(3);Here steps is chosen so that the corners of your function will be guaranteed to be plotted (otherwise you can get rounded-off corners). Since the function is linear in between the points, you can let the plotting routine do the interpolation between the grid lines. This speeds up the plotting.
Note, however, that your piecewise function will not be defined on the complete range that you have specified of -5 to 5 (since $fxnum can be at most 4). That means you will get an error when trying to plot values higher than that. So you should probably make sure your function is defined over a wider range. Say
$f = PiecewiseFunction( "[-6,$fxnum)" => $fynum, "[$fxnum,$fxnum)" => $f_parts, "[$fxnum,$fxnum)" => $f_parts, "[$fxnum,$fxnum)" => $f_parts, "[$fxnum,$fxnum)" => $f_parts, "[$fxnum,6]" => $fynum, );which has the function being constant below $fxnum and above $fxnum.
That should do it for you.