(*This part cannot be modified.*)

AC := {{(Subscript[N, 0])= (∑_(j=1)^n)If[α[j]==β[j],1,0],(Subscript[N, E0])=(∑_(j=1)^n)If[And[α[j]==β[j],A[j]==B[j]],1,0]};
 If[(Subscript[N, E0])>0,N[100-100*(Subscript[N, E0])/(Subscript[N, 0])]"% Anti-correlation only.  Model fails to describe anti-correlation when Alice and Bob happen to measure with the same angle.",
"Anti-correlation at equal angles OK."]};
BellT:={{(Subscript[N, U1])=(∑_(j=1)^n)If[And[β[j]-α[j]==-(π/8),A[j]≠B[j]],1,0],(Subscript[N, E2])=(∑_(j=1)^n)If[And[β[j]==(π/4),A[j]==B[j]],1,0],(Subscript[N, U3])=(∑_(j=1)^n)If[And[β[j]-α[j]==-((3π)/8),A[j]≠B[j]],1,0]},
"The Bell inequality predicts that the first number is smaller than the sum of the second and third numbers.
	It holds in all directly real models (local realism).",
If[(Subscript[N, U3])+(Subscript[N, E2])<(Subscript[N, U1]),"Bell's inequality is violated! Please play again.",
"Bell inequality is not violated, try different HV"]};
CHSH:={{(Subscript[N, 3])= (∑_(j=1)^n)If[β[j]-α[j]==-((3π)/8),1,0], (Subscript[N, E3])=(∑_(j=1)^n)If[And[β[j]-α[j]==-((3π)/8),A[j]==B[j]],1,0],
(Subscript[N, 1])= (∑_(j=1)^n)If[β[j]-α[j]==-(π/8),1,0],(Subscript[N, E1])=(∑_(j=1)^n)If[And[β[j]-α[j]==-(π/8),A[j]==B[j]],1,0],(Subscript[N, 2])= (∑_(j=1)^n)If[β[j]-α[j]==(π/4),1,0],
(Subscript[E, 0])=((2(Subscript[N, E0]))/(Subscript[N, 0]))-1,(Subscript[E, 1])=((2(Subscript[N, E1]))/(Subscript[N, 1]))-1,(Subscript[E, 2])=((2(Subscript[N, E2]))/(Subscript[N, 2]))-1,(Subscript[E, 3])=((2(Subscript[N, E3]))/(Subscript[N, 3]))-1};CHV=N[Max[Abs[(Subscript[E, 0])+(Subscript[E, 1])+(Subscript[E, 2])-(Subscript[E, 3])],Abs[(Subscript[E, 0])+(Subscript[E, 1])-(Subscript[E, 2])+(Subscript[E, 3])],Abs[(Subscript[E, 0])-(Subscript[E, 1])+(Subscript[E, 2])+(Subscript[E, 3])],Abs[(Subscript[E, 1])+(Subscript[E, 2])+(Subscript[E, 3])-(Subscript[E, 0])]]],
If[CHV>2, "CHSH inequality is violated!", "CHSH inequality is not violated."]};
n=800;
(*Random angeles and random outcomes.*)
Table[α[j]=If[Random[]<0.5,0,3](π/8),{j,n}];
Table[A[j]=If[Random[]<0.5,0,1],{j,n}];

(*Random angles also for Bob, but Bob's outcomes stay undetermined relative to Alice.*)
Table[β[j]=If[Random[]<0.5,0,2](π/8),{j,n}];

(*Bob's outcomes are correlated with Alice's angles.*)
Table[B[j]=If[Random[]<(Sin[β[j]-α[j]])^2,A[j],1-A[j]],{j,n}];

AC
MatrixForm[BellT]
CHSH
Clear[A,B,α,β]