Simplify expression for faster calculation

• Nov 15th 2013, 11:40 PM
Encircled
Simplify expression for faster calculation
Is there any way to simplify the expression below? I want to calculate it many times in real time so speedier is better. What I really want is m, but it cannot be solved for, so I use a numerical method.

The simplification I can think of is to calculate recurring parts of the expression only once, like R-Sqrt[-1+R^2] and Tan[(-m+pi)/2]. But is there any trick to do with the five trigonometric functions in it? Four of them have the same parameter (-m+pi)/2, must I independantly calculate Tan, Csc and Sec for it, or are they connected in a simpler way?

http://i41.tinypic.com/54xiy1.jpg
Sec[x] is secant=1/Cos[x] and Csc[x] is cosecant=1/Sin[x].

The same expression in different formats if you want to copy it to Mathematica:
Spoiler:
2 ArcSin[Sqrt[
1 - (R - Sqrt[-1 + R^2])^2 Tan[
1/2 (-m + \[Pi])]^2]/(\[Sqrt](1 + (-(R - Sqrt[-1 + R^2]) Sec[
1/2 (-m + \[Pi])] +
R Csc[1/2 (-m + \[Pi])] Sin[m])^2 - (R -
Sqrt[-1 + R^2])^2 Tan[1/2 (-m + \[Pi])]^2))]

2 \sin ^{-1}\left(\frac{\sqrt{1-\left(R-\sqrt{R^2-1}\right)^2 \tan ^2\left(\frac{\pi -m}{2}\right)}}{\sqrt{-\left(R-\sqrt{R^2-1}\right)^2 \tan ^2\left(\frac{\pi -m}{2}\right)+\left(R \sin (m) \csc \left(\frac{\pi -m}{2}\right)-\left(R-\sqrt{R^2-1}\right) \sec \left(\frac{\pi -m}{2}\right)\right)^2+1}}\right)

2ArcSin[Sqrt[1-(R-Sqrt[-1+R^2])^2 Tan[1/2 (-m+\[Pi])]^2]/(\[Sqrt](1+(-(R-Sqrt[-1+R^2]) Sec[1/2 (-m+\[Pi])]+R Csc[1/2 (-m+\[Pi])] Sin[m])^2-(R-Sqrt[-1+R^2])^2 Tan[1/2 (-m+\[Pi])]^2))]
• Nov 16th 2013, 01:03 AM
chiro
Re: Simplify expression for faster calculation
Hey Encircled.

One way that 3d video games used to do was use look-up tables where values would be stored in memory and the computation just looks them up when they need it. You might want to consider using this especially if you have limited values that can be put in memory (or a file that can be loaded into memory).

Apart from this, I'd suggest you look at things like a Taylor series expansion and other representations where you can evaluate a function with some known error that executes the code in a guaranteed number of clock cycles.

Hopefully you can build on these hints if need be.
• Nov 16th 2013, 01:57 AM
Encircled
Re: Simplify expression for faster calculation
Yes, a table could have sufficient precision and still be small enough, most of the time I can constrain the range of that m variable. If you have any kind of reference to that kind of method, I'd be grateful. Though it seems to be a simple enough concept to just improvise.

And thinking about it, calculating Sin[x] really takes no time nowadays, does it? Haven't ordinary CPU:s got hardware which does that in one or two clock cycles? I'm starting to realize that my expression is very trivial for computing power. It's benign to numerical methods, even the simple secant method narrows it down after just a handful of steps.
• Nov 16th 2013, 02:40 PM
chiro
Re: Simplify expression for faster calculation
It's not just for the sine terms, but for all terms so that you get a table for arc-sine with varying values of m and R with whatever precision you need.