For building a recommendation system, I also use the Pearson correlation coefficient. This is the definition:

$r(x, y)=\frac{\sum_{i=1}^n (x_i-\bar{x})(y_i-\bar{y})}{\sqrt{\sum_{i=1}^n (x_i-\bar{x})^2 \cdot \sum_{i=1}^n (y_i-\bar{y})^2}}$

$x$ and $y$ are part of $\mathbb{R}$.

Now for coding, it is important to take care of all potential outcomes. For example, if the denominator is zero, you will have to filter that or throw an exception.

I came up with some arguments, one of them being that if all values of $x_i$ and/or $y_i$ were equal to the average of $x$ and/or $y$, then the denominator would be zero.

But how can I prove that the coefficient is either undefined (zero denominator) or in between -1 and 1? What is the best approach?