I've been tweaking the examples in prob.dem to be a little more accurate and mathematically correct visually. And it occurs to me that it might be nice for gnuplot to handle discontinuities in an elegant way.
When a person is writing on a chalk board or scribbling on paper, a lot of time we just treat a discontinuity as though it is some kind of sharp transition, i.e., we connect the left and right limits and take it as understood as a discontinuity. But on second thought, why shouldn't a plotting program be able to leave out the line connecting the left and right limits of a discontinuity?
Here's an example and a couple thoughts. Here's an attempt to plot a function for which f(x) = 0 for x < 1 and f(x) = 1/x for x >= 1; first with a plot for such a definition and second in a piecewise fashion that works, but some might consider a hack:
f(x) = x<1?0:1/x
set xrange [-1:4]
set yrange [-0.1:1.1]
set samples (4-(-1))*50 + 1
set term x11 1
set term x11 2
plot x<1?f(x):x==1?0:1/0 with lines lc rgb "red", x>=1?f(x):1/0 with lines lc rgb "red"
Notice that in the above I set the number of samples and limits so that x=1.0, the discontinuity is selected as a plot point.
Wouldn't it be nice if one could somehow define some function g(x) so that
produced just what the second plot did? (This may not work... so bear with me.) For example, say that one could attach left and right limits to the value 1/0. (I'll do this with some concocted syntax for now.)
g(x) = x<1?0:x>1?1/x:(1/0,0,1/x)
which means that if the value x==1 is encountered in this case the point is treated as 0 connecting the point to the left and 1/1 = 1 when connecting the point to the right. The f(x) as defined at top would still plot the way it currently does, and if one simply put 1/0 rather than (1/0,<left limit>,<right limit>) things would still plot the way they currently do.
I'm not sure what the container class looks like in general, but with all the extra fields in gnuplot, you'd think that when the value is 1/0 and other fields like xhigh and xlow make no sense, they could be use instead for left and right limits.
The only problem is choosing the plot range and samples correctly so that the discontinuity ends up being selected. So in some sense, this might not be a feature that any but the most informed users would be able to figure out. Maybe we can conclude defining discontinuities as part of a function is a bad idea, I don't know.
OK, well, then here is something else that would make plotting discontinuities a little nicer. Say f(x) is defined as above
f(x) = x<1?0:1/x
and I were able to plot subranges in my plot
plot [x=-1:1-epsilon] f(x) with lines lc rgb "red", [x=1+epsilon:4] f(x) with lines lc rgb "red"
where epsilon is either a constant defined to be the resolution of real numbers or it is command syntax meaning the same thing. The evaluation of f(1-epsilon) would of course be 0, but when all is said in done in the plotting process 1-epsilon is basically cast to 1.0. (BTW, why does putting the range in the plot override the "set xrange [#,#]" command? You'd think if it were autoscale, then yes override, but otherwise why should it?)
Alright, well can this be improved upon? Could the syntax of a plot range be extended as, say,
plot [x=-1:1-epsilon:1+epsilon:4] f(x)
? Which means to draw two red segments, one from -1 to 1-epsilon and from 1+epsilon to 4. That way we get rid of the multiple sections of "lc "red"" stuff.
But that too is limiting, let's say we want two functions with discontinuities. I'd say combine the previous two suggestions and you'd get
plot [x=-1:1-epsilon:1+epsilon:4] f(x), [x=-1:2-epsilon:2+epsilon:4] f(x-1)
being a red function with a discontinuity and a green, delayed function with a discontinuity. [I say delayed because in engineering we usually think of the x axis as time and f(x-D) as a delay of D.]
plot [x=-1:1-eps:1+eps:2-eps:2+eps:4] ff(x)
and so on. I kind of like the latter syntax now that I write it.