According to my textbook:
$$\int\_{-L}^{L} \cos\frac{n \pi x}{L} \cos\frac{m \pi x}{L} dx =
\begin{cases} 0 & \mbox{if } n \neq m \\
 L & \mbox{if } n = m \neq 0 \\
 2L& \mbox{if } n = m = 0
 \end{cases}
$$

According to the trig identity given on [this cheat sheet](http://www.google.com/url?sa=t&source=web&cd=1&ved=0CBcQFjAA&url=http%3A%2F%2Ftutorial.math.lamar.edu%2Fpdf%2FTrig_Cheat_Sheet.pdf&ei=2SgtTcD8IMWqlAejs6nzCw&usg=AFQjCNEQ_WVPcXrkrKzSIa7Ta9sPXFW1QA&sig2=u9BxMF-Oo0TVR8kprApmOA):

$$
\cos{\alpha}\cos{\beta} =
 \frac{1}{2}\left [ \cos \left (\alpha -\beta \right ) + 
 \cos \left(\alpha +\beta \right ) \right ]
$$

Substituting this trig identity in and integrating from $-L \mbox{ to } L$ gives:

$$\int\_{-L}^{L} \cos\frac{n \pi x}{L} \cos\frac{m \pi x}{L} dx =
\frac{L}{\pi} \left [\frac{\sin \left ( \pi (n - m) \right )}{n - m} + \frac{\sin \left ( \pi (n+m) \right )}{n + m}\right ] $$

Evaluating the right side at $n = m$ gives a zero denominator, making the whole expression undefined. Evaluating the right hand side at $n \neq m$ gives $0$ because the sine function is always $0$ for all integer multiples of $\pi$ as can be clearly seen with the unit circle. None of these results jive with the first equation.

Could you explain what mistakes I am making with my thinking?