func main() {
	qreg := quantum.NewQReg(3, 1)
	quantum.HadamardReg(qreg)
	quantum.NewRealArrayGate([]float64{
		0, 1, 0, 0, 0, 0, 0, 0,
		1, 0, 0, 0, 0, 0, 0, 0,
		0, 0, 0, 1, 0, 0, 0, 0,
		0, 0, 1, 0, 0, 0, 0, 0,
		0, 0, 0, 0, 1, 0, 0, 0,
		0, 0, 0, 0, 0, 1, 0, 0,
		0, 0, 0, 0, 0, 0, 1, 0,
		0, 0, 0, 0, 0, 0, 0, 1,
	}).ApplyReg(qreg)
	quantum.HadamardRange(qreg, 1, 3)
	if qreg.Measure()>>1 == 0 {
		fmt.Println("constant")
	} else {
		fmt.Println("balanced")
	}
	os.Exit(0)
}
示例#2
0
func main() {
	n := 3
	qreg := quantum.NewQReg(n+1, 0)
	quantum.HadamardRange(qreg, 1, n+1)
	h := quantum.NewHadamardGate(1)
	u_f := quantum.NewClassicalGate(func(x int) int {
		if x>>1 == 5 {
			return x ^ 1
		}
		return x
	},
		n+1)
	states := 1 << uint(n)
	d := quantum.NewDiffusionGate(n)
	iterations := int((math.Pi * math.Sqrt(float64(states))) / 4.0)
	for i := 0; i < iterations; i++ {
		qreg.BSet(0, 1)
		h.ApplyRange(qreg, 0)
		u_f.ApplyReg(qreg)
		d.ApplyRange(qreg, 1)
	}
	fmt.Printf("Found %d\n", qreg.Measure()>>1)
	os.Exit(0)
}