2011|08|
2013|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|05|06|07|08|09|10|11|12|
2016|01|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|

2020-04-06 量子ゲート(トライアル) [長年日記]

package main
 
import "fmt"
import "math"
 
func Xgate(in complex128) complex128{
	 return in * complex(-1,0)
}
 
func Zgate(in complex128) complex128{
	 return in * complex(0,-1)
}
 
func Hgate(in complex128) complex128{
	 a := real(in)
	 b := imag(in)
 
	 c := (a + b) / math.Sqrt(2)
	 d := (a - b) / math.Sqrt(2)
 
	 return complex(c, d)
}
 
func CNOTgate(in1 complex128, in2 complex128) (complex128, complex128){
	 out1 := in1
	 out2 := complex(imag(in2), real(in2))
 
	 return out1, out2
} 
	 
 
 
 
 
func main() {
	 a :=  1 + 3i
	 b :=  3 + 2i
	 c :=  1i
 
	 fmt.Println(a * b)
	 fmt.Println(a / b)
	 fmt.Println(c)
 
	 d := Hgate(a)
 
	 fmt.Println(d)
 
	 e,f := CNOTgate(a,b)
 
	 fmt.Println(e)
	 fmt.Println(f)
 
}