For some reason I wanted to construct polynomials approximating this piecewise constant function :

Of course approximation cannot be uniform, since the function is not continuous. But it can be achieved in the sense of convergence of graphs in the Hausdorff metric: their limit should be the “graph” shown above, with the vertical line included. In concrete terms, this means for every there is such that for the polynomial satisfies

and also

How to get such explicitly? I started with the functions when is large. The idea is that as , the limit of is what is wanted: when , when . Also, for each there is a Taylor polynomial that approximates uniformly on . Since the Taylor series is alternating, it is not hard to find suitable . Let’s shoot for in the Taylor remainder and see where this leads:

- Degree polynomial for
- Degree polynomial for
- Degree polynomial for
- Degree polynomial for
- Degree polynomial for

The results are unimpressive, though:

To get within of the desired square-ness, we need . This means . Then, to have the Taylor remainder bounded by at , we need . Instead of messing with Stirling’s formula, just observe that does not even begin to decrease until exceeds , which is more than . That’s a … high degree polynomial. I would not try to ask a computer algebra system to plot it.

Bernstein polynomials turn out to work better. On the interval they are given by

To avoid dealing with , it is better to use odd degrees. For comparison, I used the same or smaller degrees as above: .

Looks good. But I don’t know of a way to estimate the degree of Bernstein polynomial required to obtain Hausdorff distance less than a given (say, ) from the square function.