Hacker News new | ask | show | jobs
by adrian_b 1359 days ago
The simplicity of the Taylor series of sine and cosine is irrelevant, there are no important applications for those series.

There is only one consequence of those series that matters in practice, which is that when the angles are expressed in radians, for very small angles the angle, its sinus and its tangent are approximately equal.

While this relationship between small angles, sinuses and tangents looks like an argument pro radians, in practice it isn't. There are no precise methods for measuring an angle in radians. All angle measurements are done using an unit that is an integer divisor of a right angle, and then the angles in radian are computed using a multiplication with a number proportional with the reciprocal of Pi.

So the rule about the approximate equality of angles, sinuses and tangents is at best a mnemonic rule, because to apply the rule one must convert the measured angles into radians, so no arithmetic operations can be saved.

"Turns" generalize perfectly to higher dimensions.

To the 3 important units for the plane angle, i.e. right angle, cycle and radian, there are 3 corresponding units for the solid angle, i.e. the right trihedron (i.e. an octant of a sphere), the sphere and the steradian.

The ratio between the right trihedron and the steradian is the same as between the right angle and the radian, i.e. (Pi / 2).

The ratio between the sphere and the right trihedron is 2^3, while that between cycle and right angle is 2^2. In N dimensions the ratio between the corresponding angle units becomes 2^N.

Moreover, while in 2 dimensions there are a few cases when the radian is useful, in 3 dimensions the steradian is really useless. Its use in photometry causes a lot of multiplications or divisions by Pi that have no useful effect.

There is only one significant advantage of the radian, which is the same as for using the Neper as a logarithmic unit, the derivative of the exponential with the logarithms measured in Nepers is the same function as the primitive, and that has as a consequence similarly simple relationships between the trigonometric functions with arguments measured in radians and their derivatives.

Everywhere else where the radian is convenient is a consequence of the invariance of the exponential function under derivation, when the Neper and radian units are used.

This invariance is very convenient in the symbolic manipulation of differential equations, but it does not translate into simpler computations when numeric methods are used.

So the use of the radian can simplify a lot many pen and paper symbolic transformations, but it is rarely, if ever, beneficial in numeric algorithms.

5 comments

> The simplicity of the Taylor series of sine and cosine is irrelevant, there are no important applications for those series.

The addition theorems for trigonometric functions can easily be shown by the multiplication theorem for Taylor series (and adding two Taylor series). This proof would be more convoluted if the Taylor series were not so easy.

Also, because of the simplicity of their Taylor series, one immediately sees that sin and cos are solutions of the ODE y'' = -y.

Another application of the Taylor series is that by their mere existence, sin and cos (as real functions) have a holomorphic extension.

The proof of any property of the trigonometric functions is trivial when the sine and the cosine are defined as the odd and even parts of the exponential function of an imaginary argument, and the proof uses the properties of exponentiation.

Any proof that uses the expansion in the Taylor series is a serious overkill.

Moreover, those proofs become even a little simpler when the right angle is used as the angle unit, instead of the radian.

In this case, the sine and the cosine can be defined as the odd and even parts of the function i ^ x.

Those are useful symbolically, but not computationally.
> there are no important applications for those series.

Excuse me? Have you done any computation in Physics? Have a look at the pendulum equation, for a start...

Only in school exercises you can solve a differential equation by expanding a sine function into a Taylor series.

In practical physics computations, the solution of differential equations requires numerical methods that do not use the Taylor series of specific functions, even if the theory used for developing the algorithms may use the Taylor series development of arbitrary functions.

For accurate prediction, the simple pendulum equation also requires in practice such numerical methods, which do not rely on the small-angle approximation that enables the use of the Taylor series of the trigonometric functions, for didactic purposes.

> Only in school exercises you can solve a differential equation by expanding a sine function into a Taylor series.

> In practical physics computations, the solution of differential equations requires numerical methods that do not use the Taylor series of specific functions, even if the theory used for developing the algorithms may use the Taylor series development of arbitrary functions.

I'm sorry, but you have no idea what you're talking about. Series expansions is one of the most widely used techniques in Physics. Obviously some equations require full blown numerical methods to be solved, but one can do a whole lot with analytical techniques by doing series expansions and using perturbation theory.

Saying that this is only used "in school exercises" shows that you're completely out of touch with reality.

You have replied to something that I have not said.

I have said that the Taylor series of arbitrary functions have various uses, but there is no benefit in knowing which are the specific Taylor expansions of the trigonometric functions, with the exception of knowing that the first term of the sine and tangent expansions when the argument is in radians is just X.

Solving physics problems using the expansion of an unknown function in the Taylor series has nothing to do with knowing which is the Taylor series of the sine function.

> with the exception of knowing that the first term of the sine and tangent expansions when the argument is in radians is just X.

There are more terms in the expansion that you can use, that's the whole point of using an expansion...

> Solving physics problems using the expansion of an unknown function in the Taylor series has nothing to do with knowing which is the Taylor series of the sine function.

I hope you're aware that the sine function appears quite often in Physics problems.

> there are no important applications for those series.

I cannot believe I just read this.

When have you ever used the Taylor series of sine and cosine for anything (outside school) ?

When you approximate functions by polynomials, including the trigonometric functions, the Taylor series are never used, because they are inefficient (too much computation for a given error). Other kinds of polynomials are used for function approximations.

The Taylor series are a tool used in some symbolic computations, e.g. for symbolic derivation or symbolic integration, but even in that case it is extremely unlikely for the Taylor series of the trigonometric functions to be ever used. What may be used are the derivative formulas for trigonometric functions, in order to expand an input function into its Taylor series.

The Taylor series of arbitrary functions (more precisely, the first few terms) may be used in the conception of various numeric algorithms, but here there are also no opportunities to need the Taylor series of specific functions, like the trigonometric functions.

The Taylor series obviously have uses, but the specific Taylor series for the trigonometric functions do not have practical applications, even if they are interesting in mathematical theory.

> When you approximate functions by polynomials, including the trigonometric functions, the Taylor series are never used, because they are inefficient (too much computation for a given error). Other kinds of polynomials are used for function approximations.

Can you point me to some implementation of sin that’s not actually using Taylor expansion in some form? Because most that I am aware of do in fact use Taylor series (others are just table lookup). See glibc for example:

https://github.com/bminor/glibc/blob/release/2.34/master/sys...

And here is musl

https://git.musl-libc.org/cgit/musl/tree/src/math/__sin.c

(The constants are easily checked to be -1/3!, 1/5! Etc)

This might have something to do with the Taylor’s theorem. You know, that the Taylor’s polynomial of the order n is the only polynomial of order n that satisfies |f(x)-T(x)|/(x-a)^(n+1) -> 0 as x -> a. In other words, the Taylor polynomial of order n is the unique polynomial approximation to f around a to the order n+1. This means you cannot get any better than Taylor close to the origin of the expansion. This causes implementers to focus on argument reductions instead of selecting polynomials.

If any of those libraries uses the Taylor expansion for approximation, that is a big mistake, because the approximation error becomes large at the upper end of the argument interval, even if it is small close to zero.

What is much more likely is that if you will carefully compare the polynomial coefficients with those of the Taylor series, you will see that the last decimals are different and the difference from the Taylor series increases towards the coefficients corresponding to higher degrees.

Towards zero, any approximation polynomial begins to resemble the Taylor series in the low-degree terms, because the high-degree terms become negligible and the limit of the Taylor series and of the approximation polynomial is the same.

So when looking at the polynomial coefficients, they should resemble those of the Taylor series in the low-degree coefficients, but an accurate coefficient computation should demonstrate that the polynomials are different.

I did some testing, and you are correct that they are slightly different:

  >>> print("{:.30f}".format(sin(pi/4, 0, 0, *standard_coeff)))
  0.707106781186567889818661569734
  >>> print("{:.30f}".format(sin(pi/4, 0, 0, *musl_coeff)))
  0.707106781186547461715008466854
The difference at the very edge of the interval occurs at the 14th digit of decimal expansion, and it's at the edge of accuracy of double, at 16th digit: after ...6547, the exact value starts with ...6547_5244, instead of 4617. I wouldn't exactly call it a big mistake, as the difference would not be relevant in almost all practical uses, but that would be a mistake nevertheless, and I'm sure someone would be bitten by this. Thanks, I learned something new today!
> When have you ever used the Taylor series of sine and cosine for anything (outside school) ?

I've used them a few times, mostly in the embedded space, and mostly in conjunction with lookup tables and/or Newton's method, but yes I've absolutely used them outside school (years ago, I forget the exact details).

- implementing my own trig functions for embedded applications where I wanted fine control over the computation-vs-precision tradeoff

- implementing my own functions for hypercomplex numbers (quaternions, duals, dual quaternions, and friends).

- automatic differentiation

Does the Taylor series form survive to the final application? Usually not, usually it gets optimized to something else, but "start with Taylor series and get back to basics to get a slow but accurate function" has gotten me out of several pickles. And the final form usually has some chunks of the Taylor series.

I agree that using the Taylor series can be easier, especially during development, mainly because convenient tools for generating approximation polynomials or other kinds of approximating functions are not widespread.

However, the performance when using Taylor series is guaranteed to be worse than when using optimal approximation polynomials, according to appropriate criteria.

Still I cannot see when you would want to use the Taylor series of the trigonometric functions, even if for less usual functions it could be handy.

There are plenty of open-source libraries with good approximations of the trigonometric functions, so there is no need to develop one's own.

In the case of a very weak embedded CPU there is the alternative to use CORDIC for the trigonometric functions, instead of polynomial approximations. CORDIC can be very accurate, even if on CPUs with fast multipliers it is slower than polynomial approximation.

> So the use of the radian can simplify a lot many pen and paper symbolic transformations, but it is rarely, if ever, beneficial in numeric algorithms.

If only computers could do a bit of symbolic algebraic manipulations before issuing the machine code.

Wait, isn't that what optimizing compilers can do? That requires an optimization across library calls and thus a form of inlining, which doesn't see far fetched for a math library call. Or some optimizations can't be done due to floating point error propagation (which could be relaxed)?

A simple example: suppose we want to compute cos(x)-1 near x=0, with high accuracy, in single precision fp. How to do this? Its very easy: google "taylor series for cosine", lobb off the fist term (1), and you're done.