# Which types of mathematical functions are the least complex for a computer to compute ?

Let's consider these four function types : Polynomial, Exponential, Logarithmic and Trigonometric.

Considering that both input and output values are floating point numbers.

How do they rank in terms of time complexity (of computing an output value for a given input value) ?

• This is a question that doesn't have a single answer. It depends on (1) how a compiler would translate something like $y=sin(x)$ into machine language and that would depend on (2) what the machine language would have built in to deal with the result. I don't know of any machine language that is equipped to deal with trig functions, but I can imagine a special-purpose computer that has a special trig processor, for example. By the way, welcome to the site! Don't be upset by the possibility that your question might be closed as too broad. – Rick Decker Jan 20 '16 at 1:59
• 1. What are your thoughts? What analysis have you done? Have you tried analyzing the running time of any of these function types? What did you come up with? 2. It's going to be difficult to answer this, as the running time of evaluating a polynomial depends on the degree of the polynomial. For a high-degree polynomial it might be very slow (much slower than the other three); for a low-degree polynomial it might be very fast. – D.W. Jan 20 '16 at 5:22
• Usually when speaking of complexity in CS, there is an input size as a parameter. Although for polynomial I can see the degree used as such, for the other functions I wonder. – AProgrammer Jan 20 '16 at 10:35
• @AProgrammer: you are quite right. In this case, one could use the input argument as the complexity parameter, and the answer is essentially $O(1)$ ! – Yves Daoust Jan 20 '16 at 14:43
• Do you want an answer from theory or from practice ? These would be very different. – Yves Daoust Jan 20 '16 at 14:45

To evaluate polynomial you use Horners scheme, or if you do not know how to compute it, still straightforward naive approach works. It depends on "how big" is this polynomial...

For logarithm and exponent you could use BKM and for trigonometric functions CORDIC.
So ranking by time polynomial is the fastest, and the rest is equally time consuming.
It is hard to tell apart, as basically the same algorithm can compute all these functions.

Using floating point numbers (so inexact results are obvious) the time complexity of special functions is $O(1)$, because underneath you have constant number of rounds no matter what the input was.
Number of iterations is fixed for given precision, so it does not depend on particular input (although angle reduction is time consuming for huge input value).
Polynomial evaluation is $O(n)$ in number of given coefficients using Horner, otherwise it is $O(n^2)$.

• I believe the question is asking about evaluating functions, not solving equations involving those functions. – David Richerby Jan 20 '16 at 7:28
• @DavidRicherby and to the upvoters: you should read past the first two words. – Yves Daoust Jan 20 '16 at 14:39
• @DavidRicherby I belive that solving in given point is evaluating. Edited, but still Horner Scheme, CORDIC, BKM - this are evaluation methods I belive. – Evil Jan 20 '16 at 15:18

If by "computer" you mean e.g. a bog-standard PC, polynomials are harder to compute. The basic elementary functions (square root, sin, cos, natural logarithm, exponential) are computed in hardware, by specialized instructions.

To compute a polynomial, the best technique is Horner's method. It can be shown optimal if the coefficients aren't known beforehand.