3
$\begingroup$

This is very much not my area so apologies if this is an obvious no.

Suppose values have been calculated for $\sin\theta$ and $\cos\theta$. Is it possible to test their correctness, without referring to the trigonometric functions, imaginary numbers, or performing an infinite number of operations?

$\endgroup$
6
  • $\begingroup$ How have these values been calculated? (The method in which they were calculated can give insight on how to test for correctness) $\endgroup$
    – apnorton
    Jul 4, 2013 at 14:58
  • 1
    $\begingroup$ There are "well known" formulas for trigonometric functions of multiplied angles. So, for example, if you are given $\sin \theta$ and $\cos \theta$, you can compute $\cos k \theta$ in a very elementary way. If $\theta$ is a rational multiple of $\pi$, say $\theta = \frac{a}{b} \pi$, then you can use this to compute, say $\cos a \pi$ and $\sin a \pi$. A possible test is to verify if these values come out right ($\pm 1$ and $0$ respectively). $\endgroup$ Jul 4, 2013 at 14:59
  • $\begingroup$ @anorton: if I understand correctly, the idea is that $\sin \theta$ and $\cos \theta$ are provided by some "black box" that we don't know much about, and the objective is to verify if the answers the "box" produced are correct. Alec: is my understanding correct? $\endgroup$ Jul 4, 2013 at 15:01
  • $\begingroup$ @Feanor Yep, you are correct. $\endgroup$
    – Max
    Jul 4, 2013 at 15:02
  • $\begingroup$ Do we also know the angle in question? $\endgroup$
    – apnorton
    Jul 4, 2013 at 15:03

1 Answer 1

3
$\begingroup$
  1. Assign $t\leftarrow\frac{2\theta}\pi$, $s\leftarrow\sin\theta$, $c\leftarrow\cos\theta$

  2. Test if $s^2+c^2=1$ (within desired precision).

  3. Let $r= \lfloor t \rfloor$. If $r\equiv 0\pmod 4$, verify that $s\ge 0, c\ge 0$. If $r\equiv 1\pmod 4$, verify that $s\ge 0, c\le 0$. If $r\equiv 2\pmod 4$, verify that $s\le 0, c\le 0$. If $r\equiv 3\pmod 4$, verifiy that $s\le 0,c\le 0$.

  4. Assign $t\leftarrow 2t$, $s\leftarrow 2sc$, $c\leftarrow 2c^2-1$ and go back to step 3

If any of the tests in 2 or 3 fails, the values are falsified. In principle, the loop in steps 3 and 4 may be executed infinitely often, but you should break out of it after just a few iterations (ten, say) when you are satisfied with the precision achieved.

The test in 3 checks if the values are in the correct quadrant and step 4 doubles the angle, thereby effectivekly refining the partition into quadrants into something finer.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .