How to calculate the sine of huge numbers

For several days I was wondering how you can calculate the sine of huge numbers with a value of about 100000! (radian). Factorial is just an example of how the number itself can be any not only a factor product ...) I obviously do not use double , but cpp_rational from the boost multiprecision library. But I can’t just do 100000! mod 2pi 100000! mod 2pi , and then use the built-in sinl function (I don’t need more than ten decimal digits ..), since I would need several million digits pi to do this for sure.

Is there any way to achieve this?

+8
c ++ math boost sine
source share
4 answers

This is generally a non-trivial task, since it has much in common with the Discrete Logarithm problem , which in turn implies computationally intensive calculation.
However, your calculation might be simpler if you consider the logarithm of 100000!/pi , since it reduces to the sum of the logarithms of all positive integers equal to or less than 100000 , and subtraction: log(N!/pi) = \sum_{i=0}^N (log i) - log(pi) . If you specify this number, you will get a rough estimate (N!/pi) . Subtract the integer part and multiply the result by pi . This is an estimate of your N! mod pi N! mod pi .
In the formula:

3mcpz.png

As you can see, I have used the approximate word many times. This is due to the following considerations:

  • you need to calculate a lot of log s that have some cost and errors.
  • You can change the base of your journal depending on the size of your problem; this will again affect the accuracy and accuracy of your result.
  • you need to increase the speed: small errors can lead to large
  • subtract large numbers: can lead to large reductions
  • multiply by pi and evaluate sin : errors again

If you think this might be useful, consider using the Stirling approximation .

As a final note, there is no easy solution to these problems; you always have to deal with them in each case.

+5
source share

Wikipedia lists many trigonometric identities. Some of them include arguments, such as the Chebyshev method , which is recursive, but recursion can be reduced using Chebyshev polynomials and / or memories. If your argument is as simple as factorial, then this may be a feasible method.

0
source share

Note:  = pi

To calculate the sin of a very large number in radians (Change them to multiples of , dividing them by 3.1415)
1. Note the following: sin 0 = 0, sin 0.5pi = 1, sin pi = 1, sin1.5pi = -1, sin 2pi = 0
2. The even or odd integer values ​​before pi, sin is 0 3. For real values ​​(with decimal points) for even numbers before the decimal point, take it as 0. something like the sine value, for odd, then take 1. something- then how is the sine value.
4. See Examples * Note that sin and cosine are periodic in nature, so you can do it this way for large or small numbers. :)

Eg. (Use calculators to verify calculations)

1.0 In radians: sin 100 = -0.506
Divide by 3.1415
Make in deg
Sin 31.831pi (31.831 - real value) = sin1.831 (180) = -0.506, check

2.0 In radians: sin 50 = -0.2623
Divide by 3.1415
Make in deg
Sin 15.9155pi = sin1.9155 (180) = -0.2623

3.0 In radians: sin 700 = 0.5439
Divide by 3.1415
Make in deg
Sin 222.8169pi = sin0.8169 (180) = -0.5440, check

4.0 In radians: sin 15000 = 0.8934
Divide by 3.1415
Make in deg
Sin 4774.6483pi = sin0.6483 (180) = 0.883, check

You can see that all answers are verified with direct calculation of values ​​using a calculator in radian mode. Hope this will be helpful.

If you want to write a computing program, good luck with defining the algorithm.

0
source share

Perhaps you can use cpp_rational to calculate the sine directly from your very large number:

 sin(x): x/1! - x^3/3! + x^5/5! - x^7/7! + ... 

Repeat this series until there are (for your application) significant changes. This way you completely avoid the pi number.

-2
source share

All Articles