For several days, I've been wondering how it would be possible of computing the sine of huge numbers with magnitude around 100000!
(radians). The factorial is just an example the number itself can be any not just a factorial product ...) I obviously don't use double
but cpp_rational
from the boost multiprecision library. But I can't simply do 100000! mod 2pi
and then use the builtin function sinl
(I don't need more than 10 decimal digits..) as I'd need several million digits of pi to do this accurately.
Is there any way to achieve this?
This is in general a non trivial task, as it has many similarities with the Discrete Logarithm Problem, which implies in its turn a computationally intensive calculation.
That said, your calculation could be easier if you consider the logarithm of 100000!/pi
, as it reduces to the sum of logs of all positive integers equal or less than 100000
, and a subtraction: log(N!/pi) = \sum_{i=0}^N (log i) - log(pi)
. If you exponentiate this number, you have an approximate evaluation of (N!/pi)
. Subtract the integer part, and multiply the result by pi
. This is the estimate of your N! mod pi
.
In formula:
As you may notice, I used many times the word approximate. This is due to the following considerations:
log
s, which have some cost and errorspi
and evaluate the sin
: again errors If you think it may be beneficial, consider using the Stirling's approximation.
As a final remark, there is not an easy solution to these kind of problems, you always has to deal with them case by case.
Note: = pi
To calculate sin of a very big number in radians
(Change them to multiples of by dividing by 3.1415)
1. Observe this: sin 0 = 0, sin 0.5pi = 1, sin pi = 1, sin1.5pi = -1, sin 2pi=0
2. Even or odd integer values in front of pi, the sin is 0
3. For real values (those with decimal points), for even numbers before the decimal point, take it as the 0. something as the value of the sine, for odd, then take the 1. something as the value of the sine.
4. See examples
*Note that sin and cosine are periodic in nature, that is why it is possible to do it in this way for big or small numbers. :)
Eg. (Use your calculators to check out the calculations)
1.0 In radians: sin 100 = -0.506
Divide by 3.1415
Do in deg
Sin 31.831pi (31.831 is a real value) = sin1.831(180) =-0.506, check
2.0 In radians: sin 50 = -0.2623
Divide by 3.1415
Do in deg
Sin 15.9155pi = sin1.9155 (180) =-0.2623
3.0 In radians: sin 700 = 0.5439
Divide by 3.1415
Do in deg
Sin 222.8169pi = sin0.8169 (180) =-0.5440, check
4.0 In radians: sin 15000 = 0.8934
Divide by 3.1415
Do in deg
Sin 4774.6483pi = sin0.6483 (180) = 0.893, check
You can see that all the answers checked out with the direct calculation of the values using the calculator in radian mode. Hope this is helpful.
If you want to write out a compute program, best of luck in figuring out the algorithm.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With