@@ -99,23 +99,23 @@ export const bilateralCNOT = (control: DensityMatrix, target: DensityMatrix): {
9999 // In the BBPSSW protocol with |Φ⁺⟩ as the target state after exchange,
100100 // the success probability depends on the fidelity F
101101 const f = control . get ( 0 , 0 ) . re ;
102+
103+ // Calculate improved fidelity after successful purification
104+ // F' = (f^2 + (1-f)^2/9) / (f^2 + 2f(1-f)/3 + 5(1-f)^2/9)
105+ const numerator = f * f + Math . pow ( 1 - f , 2 ) / 9 ;
106+ const denominator = f * f + 2 * f * ( 1 - f ) / 3 + 5 * Math . pow ( 1 - f , 2 ) / 9 ;
107+ // Handle potential division by zero or NaN
108+ const fPrime = denominator === 0 ? 0 : numerator / denominator ;
102109
103- // Success probability is p_success = f^2 + (1-f)^2 /9
104- const successProbability = f * f + ( 1 - f ) * ( 1 - f ) / 9 ;
110+ // Success probability is p_success = f^2 + 2 f (1-f) / 3 + 5 (1-f)^2 /9
111+ const successProbability = denominator
105112
106113 // Determine success based on probability
107114 const successful = Math . random ( ) < successProbability ;
108115
109116 let controlPair : DensityMatrix ;
110117
111118 if ( successful ) {
112- // Calculate improved fidelity after successful purification
113- // F' = (f^2 + (1-f)^2/9) / (f^2 + 2f(1-f)/3 + 5(1-f)^2/9)
114- const numerator = f * f + Math . pow ( 1 - f , 2 ) / 9 ;
115- const denominator = f * f + 2 * f * ( 1 - f ) / 3 + 5 * Math . pow ( 1 - f , 2 ) / 9 ;
116- // Handle potential division by zero or NaN
117- const fPrime = denominator === 0 ? 0 : numerator / denominator ;
118-
119119 // Create new density matrix directly and set elements
120120 const controlPairResult = new DensityMatrix ( Array ( 4 ) . fill ( 0 ) . map ( ( ) => Array ( 4 ) . fill ( 0 ) . map ( ( ) => ComplexNum . zero ( ) ) ) ) ;
121121 controlPairResult . set ( 0 , 0 , new ComplexNum ( fPrime , 0 ) ) ;
@@ -168,4 +168,4 @@ export const preparePairsForCNOT = (pairs: QubitPair[]): {
168168 targetPairs,
169169 hasUnpairedPair
170170 } ;
171- } ;
171+ } ;
0 commit comments