3

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?

Max
  • 466
  • 2
  • 12
  • How have these values been calculated? (The method in which they were calculated can give insight on how to test for correctness) – apnorton Jul 04 '13 at 14:58
  • 1
    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). – Jakub Konieczny Jul 04 '13 at 14:59
  • @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? – Jakub Konieczny Jul 04 '13 at 15:01
  • @Feanor Yep, you are correct. – Max Jul 04 '13 at 15:02
  • Do we also know the angle in question? – apnorton Jul 04 '13 at 15:03
  • @anorton Yes. We know $\theta$, $\sin\theta$, $\cos\theta$ and any mathematical constants, just not $i$. – Max Jul 04 '13 at 15:04

1 Answers1

3
  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.