(*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.
	So to violate Bell, the first number must be larger than the sum of the second two.",
If[(Subscript[N, U3])+(Subscript[N, E2])<(Subscript[N, U1]),"Bell's inequality is violated! Please play again.", "Bell's 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]==-((3π)/8),1,0],(Subscript[N, E1])=(∑_(j=1)^n)If[And[β[j]-α[j]==-((3π)/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."]};

(* Hidden Variable Section; all can be modified except Tables for α and β.*)
n=1000; Table[e[j]=2π Random[],{j,n}];
Table[t[j]=(0.5)π Random[],{j,n}];
Table[p[j]=0.5(Sin[t[j]])^2,{j,n}];

Table[α[j]=If[Random[]<0.5,0,3](π/8),{j,n}];
Table[H[j]=If[Abs[Cos[α[j]-e[j]]]>p[j],Sign[-Cos[α[j]-e[j]]]+1,0],{j,n}];
Table[A[j]=If[H[j]==2,1,0],{j,n}];
(*The above just takes the Sign function to values of 1 and 0*)
Table[β[j]=If[Random[]<0.5,0,2](π/8),{j,n}];
Table[L[j]=If[Abs[Cos[β[j]-(e[j]+π)]]>p[j],Sign[Cos[β[j]-(e[j]+π)]]+1,0],{j,n}];
Table[B[j]=If[L[j]==2,0,1],{j,n}];
(* End HV Section.*)
AC
MatrixForm[BellT]
CHSH
Clear[A,B,α,β]