## NOT^k = Id if k even
cnotwrapper <- function(c, j, x, t) {
if(j == 1) return(CNOT(c(c, t)) * x)
return(Id(t) * x)
}
x <- X(1) * qstate(3)
## X has eigenvalues lambda=1 and lambda=-1
## thus phases 0 and 1/2
x <- phase_estimation(bitmas=c(2:3), FUN=cnotwrapper, x=x, t=1)
x
Run the code above in your browser using DataLab