/**
 * Quantum gates
 * https://en.wikipedia.org/wiki/Quantum_logic_gate
 */ import Complex , { Cx } from './Complex' ; import Dimension from './Dimension' ; import Operator from './Operator' ; const isqrt2 = Cx ( Math . SQRT1_2 ) ; return export function I ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '0' , Cx ( 1 ) ] , [ '1' , '1' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } see https return export function X ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '1' , Cx ( 1 ) ] , [ '1' , '0' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } see https return export function Y ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '1' , Cx ( 0 , - 1 ) ] , [ '1' , '0' , Cx ( 0 , 1 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } see https return export function Z ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '0' , Cx ( 1 ) ] , [ '1' , '1' , Cx ( - 1 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } see https return export function H ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '0' , Cx ( 1 ) ] , [ '1' , '0' , Cx ( 1 ) ] , [ '0' , '1' , Cx ( 1 ) ] , [ '1' , '1' , Cx ( - 1 ) ] , ] , [ Dimension . qubit ( ) ] ) . mulConstant ( isqrt2 ) ; } return export function S ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '0' , Cx ( 1 ) ] , [ '1' , '1' , Cx ( 0 , 1 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } return export function T ( ) { return Operator . fromSparseCoordNames ( [ [ '0' , '0' , Cx ( 1 ) ] , [ '1' , '1' , Complex . fromPolar ( 1 , Math . PI / 4 ) ] , ] , [ Dimension . qubit ( ) ] ) ; } return export function CX ( ) { return Operator . fromSparseCoordNames ( [ [ '00' , '00' , Cx ( 1 ) ] , [ '01' , '01' , Cx ( 1 ) ] , [ '10' , '11' , Cx ( 1 ) ] , [ '11' , '10' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) , Dimension . qubit ( ) ] ) ; } return export function CZ ( ) { return Operator . fromSparseCoordNames ( [ [ '00' , '00' , Cx ( 1 ) ] , [ '01' , '01' , Cx ( 1 ) ] , [ '10' , '10' , Cx ( 1 ) ] , [ '11' , '11' , Cx ( - 1 ) ] , ] , [ Dimension . qubit ( ) , Dimension . qubit ( ) ] ) ; } return export function Swap ( ) { return Operator . fromSparseCoordNames ( [ [ '00' , '00' , Cx ( 1 ) ] , [ '10' , '01' , Cx ( 1 ) ] , [ '01' , '10' , Cx ( 1 ) ] , [ '11' , '11' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) , Dimension . qubit ( ) ] ) ; } see https return export function CCX ( ) { return Operator . fromSparseCoordNames ( [ [ '000' , '000' , Cx ( 1 ) ] , [ '001' , '001' , Cx ( 1 ) ] , [ '010' , '010' , Cx ( 1 ) ] , [ '011' , '011' , Cx ( 1 ) ] , [ '100' , '100' , Cx ( 1 ) ] , [ '101' , '101' , Cx ( 1 ) ] , [ '111' , '110' , Cx ( 1 ) ] , [ '110' , '111' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) , Dimension . qubit ( ) , Dimension . qubit ( ) ] ) ; } see https return export function CSwap ( ) { return Operator . fromSparseCoordNames ( [ [ '000' , '000' , Cx ( 1 ) ] , [ '001' , '001' , Cx ( 1 ) ] , [ '010' , '010' , Cx ( 1 ) ] , [ '011' , '011' , Cx ( 1 ) ] , [ '100' , '100' , Cx ( 1 ) ] , [ '110' , '101' , Cx ( 1 ) ] , [ '101' , '110' , Cx ( 1 ) ] , [ '111' , '111' , Cx ( 1 ) ] , ] , [ Dimension . qubit ( ) , Dimension . qubit ( ) , Dimension . qubit ( ) ] ) ; }