toqito.state_opt.bell_notation_conversions¶
Conversions between Bell inequality notations.
Module Contents¶
- toqito.state_opt.bell_notation_conversions.cg_to_fc(cg_mat, behavior=False)[source]¶
Convert a Bell functional or behavior from Collins-Gisin (CG) to Full Correlator (FC) notation.
The Collins-Gisin (CG) notation for a Bell functional or behavior is represented by a matrix:
[ text{CG} = begin{pmatrix}
K & p_B(0|1) & p_B(0|2) & dots \ p_A(0|1) & p(00|11) & p(00|12) & dots \ p_A(0|2) & p(00|21) & p(00|22) & dots \ vdots & vdots & vdots & ddots
end{pmatrix} ]
The Full Correlator (FC) notation is represented by:
[ text{FC} = begin{pmatrix}
K & langle B_1 rangle & langle B_2 rangle & dots \ langle A_1 rangle & langle A_1 B_1 rangle & langle A_1 B_2 rangle & dots \ langle A_2 rangle & langle A_2 B_1 rangle & langle A_2 B_2 rangle & dots \ vdots & vdots & vdots & ddots
end{pmatrix} ]
This function converts between these two notations.
Examples
Consider the CHSH inequality in CG notation for a functional:
[ text{CHSH}_{CG} = begin{pmatrix}
0 & 0 & 0 \ 0 & 1 & -1 \ 0 & -1 & 1
end{pmatrix} ]
Converting to FC notation:
```python exec=”1” source=”above” import numpy as np from toqito.state_opt.bell_notation_conversions import cg_to_fc
chsh_cg = np.array([[0, 0, 0], [0, 1, -1], [0, -1, 1]]) print(cg_to_fc(chsh_cg)) ```
Consider a behavior (probability distribution) in CG notation:
[ P_{CG} = begin{pmatrix}
1 & 0.5 & 0.5 \ 0.5 & 0.25 & 0.25 \ 0.5 & 0.25 & 0.25
end{pmatrix} ]
Converting to FC notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import cg_to_fc p_cg = np.array([[1, 0.5, 0.5], [0.5, 0.25, 0.25], [0.5, 0.25, 0.25]]) print(cg_to_fc(p_cg, behavior=True)) `- Parameters:
cg_mat (numpy.ndarray) – The matrix in Collins-Gisin notation.
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The matrix in Full Correlator notation.
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
CG2FC.
- toqito.state_opt.bell_notation_conversions.fc_to_cg(fc_mat, behavior=False)[source]¶
Convert a Bell functional or behavior from Full Correlator (FC) to Collins-Gisin (CG) notation.
The Full Correlator (FC) notation is represented by:
[ text{FC} = begin{pmatrix}
K & langle B_1 rangle & langle B_2 rangle & dots \ langle A_1 rangle & langle A_1 B_1 rangle & langle A_1 B_2 rangle & dots \ langle A_2 rangle & langle A_2 B_1 rangle & langle A_2 B_2 rangle & dots \ vdots & vdots & vdots & ddots
end{pmatrix} ]
The Collins-Gisin (CG) notation for a Bell functional or behavior is represented by a matrix:
[ text{CG} = begin{pmatrix}
K & p_B(0|1) & p_B(0|2) & dots \ p_A(0|1) & p(00|11) & p(00|12) & dots \ p_A(0|2) & p(00|21) & p(00|22) & dots \ vdots & vdots & vdots & ddots
end{pmatrix} ]
This function converts between these two notations.
Examples
Consider the CHSH inequality in FC notation for a functional:
[ text{CHSH}_{FC} = begin{pmatrix}
0 & 0 & 0 \ 0 & 1/4 & -1/4 \ 0 & -1/4 & 1/4
end{pmatrix} ]
Converting to CG notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fc_to_cg chsh_fc = np.array([[0, 0, 0], [0, 0.25, -0.25], [0, -0.25, 0.25]]) print(fc_to_cg(chsh_fc)) `Consider a behavior (correlation matrix) in FC notation:
[ P_{FC} = begin{pmatrix}
1 & 0 & 0 \ 0 & 0 & 0 \ 0 & 0 & 0
end{pmatrix} ]
Converting to CG notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fc_to_cg p_fc = np.array([[1, 0, 0], [0, 0, 0], [0, 0, 0]]) print(fc_to_cg(p_fc, behavior=True)) `- Parameters:
fc_mat (numpy.ndarray) – The matrix in Full Correlator notation.
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The matrix in Collins-Gisin notation.
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
FC2CG.
- toqito.state_opt.bell_notation_conversions.cg_to_fp(cg_mat, desc, behavior=False)[source]¶
Convert a Bell functional or behavior from Collins-Gisin (CG) to Full Probability (FP) notation.
The Collins-Gisin (CG) notation for a Bell functional or behavior is represented by a matrix (see
cg_to_fc()). The Full Probability (FP) notation represents the full probability distribution (V(a, b, x, y) = P(a, b | x, y)), the probability of Alice getting outcome (a) (0 to oa-1) and Bob getting outcome (b) (0 to ob-1) given inputs (x) (0 to ia-1) and (y) (0 to ib-1). This is stored as a 4D numpy array with indices V[a, b, x, y].This function converts from CG to FP notation.
Examples
Consider the CHSH inequality functional in CG notation:
[ text{CHSH}_{CG} = begin{pmatrix}
0 & 0 & 0 \ 0 & 1 & -1 \ 0 & -1 & 1
end{pmatrix} ]
Converting to FP notation (desc = [2, 2, 2, 2]):
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import cg_to_fp chsh_cg = np.array([[0, 0, 0], [0, 1, -1], [0, -1, 1]]) desc = [2, 2, 2, 2] # oa, ob, ia, ib print(cg_to_fp(chsh_cg, desc)) `Consider a behavior (probability distribution) in CG notation (desc = [2, 2, 2, 2]):
[ P_{CG} = begin{pmatrix}
1 & 0.5 & 0.5 \ 0.5 & 0.25 & 0.25 \ 0.5 & 0.25 & 0.25
end{pmatrix} ]
Converting to FP notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import cg_to_fp p_cg = np.array([[1, 0.5, 0.5], [0.5, 0.25, 0.25], [0.5, 0.25, 0.25]]) desc = [2, 2, 2, 2] print(cg_to_fp(p_cg, desc, behavior=True)) `- Parameters:
cg_mat (numpy.ndarray) – The matrix in Collins-Gisin notation.
desc (list[int]) – A list [(oa), (ob), (ia), (ib)] describing the number of outputs ((oa), (ob)) and inputs ((ia), (ib)).
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The probability tensor (V[a, b, x, y]) in Full Probability notation.
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
CG2FP.
- toqito.state_opt.bell_notation_conversions.fc_to_fp(fc_mat, behavior=False)[source]¶
Convert a Bell functional or behavior from Full Correlator (FC) to Full Probability (FP) notation.
Assumes binary outcomes ((oa=2), (ob=2)) corresponding to physical values +1 and -1. The FP tensor indices (a, b = 0, 1) correspond to outcomes (+1, -1) respectively.
The Full Correlator (FC) notation is represented by a matrix (see
fc_to_cg()). The Full Probability (FP) notation represents the full probability distribution (V(a, b, x, y) = P(text{out}_A=a’, text{out}_B=b’ | x, y)), where (a=0 rightarrow a’=+1), (a=1 rightarrow a’=-1) (similarly for (b)), stored as a 4D numpy array (V[a, b, x, y]).This function converts from FC to FP notation.
Examples
Consider the CHSH inequality functional in FC notation:
[ text{CHSH}_{FC} = begin{pmatrix}
0 & 0 & 0 \ 0 & 1/4 & -1/4 \ 0 & -1/4 & 1/4
end{pmatrix} ]
Converting to FP notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fc_to_fp chsh_fc = np.array([[0, 0, 0], [0, 0.25, -0.25], [0, -0.25, 0.25]]) print(fc_to_fp(chsh_fc)) `Consider a behavior (correlation matrix) in FC notation (e.g., from PR box): Note: This FC matrix corresponds to the PR box after applying
fp_to_fc(pr_box, behavior=True), which uses the QETLAB convention of averaging marginal correlators.[ P_{FC} = begin{pmatrix}
1 & 0 & 0 \ 0 & 1/sqrt{2} & 1/sqrt{2} \ 0 & 1/sqrt{2} & -1/sqrt{2}
end{pmatrix} ]
Converting to FP notation:
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fc_to_fp p_fc = np.array([[1, 0, 0], [0, 1/np.sqrt(2), 1/np.sqrt(2)], [0, 1/np.sqrt(2), -1/np.sqrt(2)]]) print(fc_to_fp(p_fc, behavior=True)) `- Parameters:
fc_mat (numpy.ndarray) – The matrix in Full Correlator notation.
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The probability tensor (V[a, b, x, y]) in Full Probability notation (oa=2, ob=2).
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
FC2FP[@QETLAB]. For behavior=True, it applies the standard formula relating probabilities to correlators: (P(a’, b’ | x, y) = (1 + a’langle A_x rangle + b’langle B_y rangle +) (a’b’langle A_x B_y rangle) / 4), where (a’, b’ in {+1, -1}). Crucially, it uses the values (langle A_x rangle) and (langle B_y rangle) directly from the inputfc_mat. If this input matrix was generated using a convention where these entries represent averaged marginal correlators (like the output offp_to_fc(..., behavior=True)), the resulting FP tensor might not represent a valid probability distribution (e.g., entries could be negative).
- toqito.state_opt.bell_notation_conversions.fp_to_cg(v_mat, behavior=False)[source]¶
Convert a Bell functional or behavior from Full Probability (FP) to Collins-Gisin (CG) notation.
The Full Probability (FP) notation represents the full probability distribution (V(a, b, x, y) = P(a, b | x, y)), where (a) (0 to (oa-1)), (b) (0 to (ob-1)) are outcomes and (x) (0 to (ia-1)), (y) (0 to (ib-1)) are inputs. It’s stored as a 4D numpy array (V[a, b, x, y]). The Collins-Gisin (CG) notation for a Bell functional or behavior is represented by a matrix (see :[cg_to_fc][toqito.state_opt.bell_notation_conversions.cg_to_fc]).
This function converts from FP to CG notation.
Examples
Consider the CHSH inequality functional in FP notation: (Here V represents coefficients, not probabilities)
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fp_to_cg chsh_fp = np.zeros((2, 2, 2, 2)) chsh_fp[0, 0, 0, 0] = 1 chsh_fp[0, 0, 0, 1] = -1 chsh_fp[0, 0, 1, 0] = -1 chsh_fp[0, 0, 1, 1] = 1 print(fp_to_cg(chsh_fp)) `Consider a behavior (probability distribution) in FP notation (standard PR box):
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fp_to_cg pr_box = np.zeros((2, 2, 2, 2)) pr_box[0, 0, 0, 0] = 0.5 # p(0,0|0,0) pr_box[1, 1, 0, 0] = 0.5 # p(1,1|0,0) pr_box[0, 0, 0, 1] = 0.5 # p(0,0|0,1) pr_box[1, 1, 0, 1] = 0.5 # p(1,1|0,1) pr_box[0, 0, 1, 0] = 0.5 # p(0,0|1,0) pr_box[1, 1, 1, 0] = 0.5 # p(1,1|1,0) pr_box[0, 1, 1, 1] = 0.5 # p(0,1|1,1) pr_box[1, 0, 1, 1] = 0.5 # p(1,0|1,1) print(fp_to_cg(pr_box, behavior=True)) `- Parameters:
v_mat (numpy.ndarray) – The probability tensor (V[a, b, x, y]) in Full Probability notation.
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The matrix in Collins-Gisin notation.
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
FP2CG. Forbehavior=True, it uses the QETLAB convention for calculating marginal probabilities, summing over the other party’s outcomes for a fixed input setting of the other party ((y=0) for Alice’s marginal (p_A(a|x)), (x=0) for Bob’s marginal (p_B(b|y))).
- toqito.state_opt.bell_notation_conversions.fp_to_fc(v_mat, behavior=False)[source]¶
Convert a Bell functional or behavior from Full Probability (FP) to Full Correlator (FC) notation.
Assumes binary outcomes ((oa=2), (ob=2)). The FP tensor indices (a, b = 0, 1) correspond to physical outcomes (+1, -1) respectively.
The Full Probability (FP) notation represents the full probability distribution (V(a, b, x, y) = P(text{out}_A=a’, text{out}_B=b’ | x, y)), where (a=0 rightarrow a’=+1), (a=1 rightarrow a’=-1) (similarly for (b)), stored as a 4D numpy array (V[a, b, x, y]). The Full Correlator (FC) notation is represented by a matrix (see [fc_to_cg][toqito.state_opt.bell_notation_conversions.fc_to_cg]).
This function converts from FP to FC notation.
Examples
Consider the CHSH inequality functional in FP notation: (Here V represents coefficients, not probabilities)
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fp_to_fc, fc_to_fp chsh_fc = np.array([[0, 0, 0], [0, 0.25, -0.25], [0, -0.25, 0.25]]) chsh_fp = fc_to_fp(chsh_fc) print(fp_to_fc(chsh_fp)) `Consider a behavior (probability distribution) in FP notation (standard PR box):
`python exec="1" source="above" import numpy as np from toqito.state_opt.bell_notation_conversions import fp_to_fc pr_box = np.zeros((2, 2, 2, 2)) pr_box[0, 0, 0, 0] = 0.5 # p(0,0|0,0) pr_box[1, 1, 0, 0] = 0.5 # p(1,1|0,0) pr_box[0, 0, 0, 1] = 0.5 # p(0,0|0,1) pr_box[1, 1, 0, 1] = 0.5 # p(1,1|0,1) pr_box[0, 0, 1, 0] = 0.5 # p(0,0|1,0) pr_box[1, 1, 1, 0] = 0.5 # p(1,1|1,0) pr_box[0, 1, 1, 1] = 0.5 # p(0,1|1,1) pr_box[1, 0, 1, 1] = 0.5 # p(1,0|1,1) print(fp_to_fc(pr_box, behavior=True)) `- Parameters:
v_mat (numpy.ndarray) – The probability tensor (V[a, b, x, y]) in Full Probability notation (\(oa=2\), \(ob=2\)).
behavior (bool) – If True, assume input is a behavior (default: False, assume functional).
- Returns:
The matrix in Full Correlator notation.
- Return type:
numpy.ndarray
- !!! Note
This function is adapted from the QETLAB MATLAB package function
FP2FC. Forbehavior=True, it calculates the average marginal correlators (langle A_x rangle) and (langle B_y rangle) by summing over the other party’s inputs and dividing by the number of inputs ((ib) or (ia)). The joint correlators (langle A_x B_y rangle) are calculated directly for each ((x), (y)).