[CHSH inequality](http://en.wikipedia.org/wiki/CHSH_inequality) requires both *locality* and *realism*. I will equate here realism with [counterfactual definiteness](https://en.wikipedia.org/wiki/Counterfactual_definiteness).


Now counterfactual definiteness tells us that given two different measurements on the same object, described by random variables $C\_1$ and $C\_2$, there exists a joint probability distribution for $C\_1$ and $C\_2$ (this is not always the case, search for the marginal problem and indeed we know that outcomes of measurements of noncommuting observables do not posses a joint probability distribution). Now if we can assume the existence of a joint probability distribution, then expectation values $E(C\_1) + E(C\_2)$ may be joined together to have $E(C\_1 + C\_2)$. 


So suppose that we now have four random variables $A\_1$ and $B\_1$ local to Alice and $A\_2$ and $B\_2$ for Bob, which can take values $\pm 1$. The expression in the CHSH inequality is
$$
 |E(A\_1 A\_2) + E(A\_1 B\_2) + E(B\_1 A\_2) - E(B\_1 B\_2)|
$$
Now if we can assume realism (counterfactual definiteness), there exists a joint probability distribution for the outcomes of all four random variables, and we can join the expectation values in the above together to get 
$$
 \Bigl\lvert E\bigl(A\_1 (A\_2 + B\_2) + B\_1 (A\_2 -B\_2)\bigr)\Bigr\rvert
$$
So now we do the standard trick where either $A\_2$ and $B\_2$ are equal or they are opposite, so that the first term is either $\pm 2$ and same for the second term. 


Now to my question. I obviously used the realism assumption in the above. I assume locality means that the marginal distributions for $A\_1$ and $B\_1$ are independent of the choice of random variables Bob makes, $A\_2$ or $B\_2$ (but I otherwise allow for the correlation of outcomes, as long as it's independent of measurement choice, as there may be hidden variables that were encoded at the source of the state that produce correlations). Where did I use the locality assumption in this derivation? I would like if you either point out precisely where this assumption is needed in this calculation or argue that it is not needed with a convincing justification. 



Tracking down locality assumption in CHSH inequality
Suppose that:


1) $A\_2$ and $B\_2$ have some fixed joint probability distribution.


2) When $A\_2$ is measured, we have $A\_1=B\_1=A\_2$. This gives a well-defined joint probability distribution for $(A\_1,B\_1)$.


3) When $B\_2$ is measured, we have $A\_1=-B\_1=B\_2$. This also gives a well-defined joint probability distribution for $(A\_1,B\_1$). 


So these assumptions seem to satisfy your notion of "realism". But your expression now becomes
$$E(A\_1A\_2)+E(A\_1B\_2)+E(B\_1A\_2)-E(B\_1B\_2)=4$$
which violates the desired inequality. So your realism assumption can't be enough.


The problem is that you are treating $A\_1(A\_2+B\_2)$ as a well-defined classical random variable, which (implicitly) assumes that the probability distribution of $A\_1$ is independent of which of $A\_2,B\_2$ is measured.


