import { Cx } from './Complex' ; import Dimension from './Dimension' ; import Vector from './Vector' ; import Operator from './Operator' ; import { DEG_TO_RAD } from './Constants' ; const dimPol = Dimension . polarization ( ) ; export const singletState = Vector . fromSparseCoordNames ( [ [ 'HV' , Cx ( 1 ) ] , [ 'VH' , Cx ( - 1 ) ] , ] , [ dimPol , dimPol ] ) ; export const opI = Operator . identity ( [ dimPol ] ) ; export const opX = Operator . fromSparseCoordNames ( [ [ 'V' , 'H' , Cx ( 1 ) ] , [ 'H' , 'V' , Cx ( 1 ) ] , ] , [ dimPol ] ) ; export const opY = Operator . fromSparseCoordNames ( [ [ 'V' , 'H' , Cx ( 0 , 1 ) ] , [ 'H' , 'V' , Cx ( 0 , - 1 ) ] , ] , [ dimPol ] ) ; export const opZ = Operator . fromSparseCoordNames ( [ [ 'H' , 'H' , Cx ( 1 ) ] , [ 'V' , 'V' , Cx ( - 1 ) ] , ] , [ dimPol ] ) ; param alpha function linearPol ( alpha ) { return Vector . fromSparseCoordNames ( [ [ 'H' , Cx ( Math . cos ( alpha * DEG_TO_RAD ) ) ] , [ 'V' , Cx ( Math . sin ( alpha * DEG_TO_RAD ) ) ] , ] , [ dimPol ] ) ; } param alpha param vec function measurementOne ( alpha , vec ) { const res = linearPol ( alpha ) . conj ( ) . dot ( vec ) . abs2 ( ) ; return [ res , 1 - res ] ; } param p function perc ( p ) { return `${ ( 100 * p ) . toFixed ( 0 ) }%` ; } const ourState = linearPol ( 45 ) ; const angles = [ - 45 , 0 , 45 , 90 , 135 ] ; angles . forEach ( ( alpha ) => { const [ res , opRes ] = measurementOne ( alpha , ourState ) ; console . log ( `At ${ alpha } the result was: ${ perc ( res ) } vs ${ perc ( opRes ) }` ) ; } ) ;