# Function with simple formula that looks like cubic Bezier curve

I need a function that I can to evaluate it at arbitrary values of x. I want to control the shape of that function by two endpoints and two directions. A simple cubic polynomial fits that requirement, but is significantly more "rigid" than a 2D Cubic Bezier curve.

2D cubic Bezier curve is a parametric curve described by two cubic polynomials: $$x(t) = X_0*(1-t)^3 + X_1*3t(1-t)^2 + X_2*3t^2(1-t) + X_3*t^3$$ $$y(t) = Y_0*(1-t)^3 + Y_1*3t(1-t)^2 + Y_2*3t^2(1-t) + Y_3*t^3$$

If $$X_0 \le X_1 \le X_2 \le X_3$$ (and not $$X_0 = X_1 = X_2$$ or $$X_1 = X_2 = X_3$$) then the curve is a function $$y(x)$$.

However the symbolical formula for $$y(x)$$ is big and hard to use due to $$t(x)$$ being a solution to a cubic equation.

I want to find a function with simple representation such that it's graph is similar to the 2D cubic bezier graph. The function should be mainly parametrized by two endpoints ($$X_0$$, $$Y_0$$, $$X_3$$, $$Y_3$$) and two "directions" ($$X_1 - X_0$$, $$Y_1 - Y_0$$, $$X_3 - X_2$$, $$Y_3 - Y_2$$). It's OK to have some additional parameter if necessary.

Some Bezier properties that I like:

• "Monotonicity" - Does not introduce as much extra local minima as Fourier or high-order polynomial approximations
• The range of Y values between endpoints is easily bounded: $$min(Y_i) \le min(y(x)) \le max(y(x)) \le max(Y_i)$$
• Infinite derivatives are possible at end points

Use case: I want to use a parametrized function $$f(x)$$ to approximate some regions of other functions ($$tanh$$, $$exp(x)$$, $$log(x)$$, $$max(0, exp(x))$$, $$1/x$$, $$max(0, x)$$, etc) with continuous transformation between them. This is needed to represent trainable neural network activation functions.

• Out of curiosity: Why do you need $y(x)$ i.e. $y\circ x^{-1}$? Dec 18, 2019 at 23:24
• I need a function, not a curve. I need to evaluate it at arbitrary values of x. I want to control the shape of that function by two endpoints and two directions. A simple cubic polynomial fits that requirement, but is significantly more "rigid" than a 2D Cubic Bezier curve. P.S. The real world application of the function is to serve as an activation function for neural networks. Dec 18, 2019 at 23:37
• Let me know how it does as an activation function, that seems interesting Dec 18, 2019 at 23:38
• I already did some experiments on trainable activation functions (I think I used ELU polynomials) and I liked the results - the activation function for different layers were different, but understandable (e.g. the last layer trained an almost linear function while some intermediate layer trained something like a low-slope downward line that starts raising parabolically or exponentially after x=0). Still, a better "basis" would be nice. Dec 18, 2019 at 23:49
• Your need for infinite derivatives will make the problem much harder, it seems to me. It certainly rules out polynomials, for example. Would you accept very large end derivatives, rather than infinite ones? Dec 19, 2019 at 1:05

What you're asking about is just classical approximation of real-valued functions. There are decades of research devoted to this problem. You can start learning here.

For software that does this for you, a good choice is the Chebfun system. It does a very good job of approximating pretty much any continuous functions using polynomial or rational functions.

To approximate special functions like the ones you listed, people often use the CORDIC algorithms.

• Thank you for the answer. I'll refresh my knowledge by studying your links. Although my problem is definitely related to approximation, I think that my problem is different. I do not need to approximate the functions myself. I need a "basis" that can possibly approximate most "small-formula" functions (on an interval) with continuous transformation possible between any of them. Of course I can use simple polynomials as a basis. I just thought there might be something more "efficient". Dec 19, 2019 at 10:24
• More strictly, I'm searching for a k-parameter (say, k=8) function f which "optimally" (say, integral of square of error) approximates all continuous functions from the function set F on the [0, 1] interval. The function set F is the continuous subset of all functions defined by an evaluation tree with up to n nodes (say, n=6) taken from the following set: {+, -, *, /, ^, exp, log, sin, cos, constant}. I'm not sure that k-degree polynomial would be the best approximation. I'm not sure about the Fourier basis either. Dec 19, 2019 at 10:25
• The Bezier function is a mixture of polynomials and roots. This helps it approximate functions that have infinite derivatives at some points. It cannot approximate functions that go to infinity though. Some other approximation function might be better. Now that I think about it, maybe what I seek is just something like $f(x,p_{0..7}) = P_3(x, p_{0..3}) + P_2(x, p_{4..6})^{p_7}$ Dec 19, 2019 at 10:25
• If you use polynomials or rational functions, you can take advantage of decades of research and some very good software packages. If you do something different, you're on your own. Have you tried chebfun? Do you think you can do better? Dec 22, 2019 at 1:16
• Of course, polynomials are the default choice. Polynomials are not the only are that has been researched. Since I need approximation on an interval, I could use Fourier series. Which are not polynomials, but also have decades of research. Or wavelets. These common areas are researched pretty well. Dec 23, 2019 at 10:05

I wrote a smooth transition between linear functions in a previous answer that you could use https://math.stackexchange.com/q/2496273 . It is simply a cubic polynomial.

That said, Bezier curves have the property that they are stable with respect to affine transformation, which means that the transform of a Bezier curve is the Bezier curve of the transforms of the control points. This property will most likely not be available for "simpler" curves.