Documentation
¶
Index ¶
- func C(u matrix.Matrix, n int, c int, t int) matrix.Matrix
- func CCNOT(n, c0, c1, t int) matrix.Matrix
- func CNOT(n, c, t int) matrix.Matrix
- func CR(theta float64, n, c, t int) matrix.Matrix
- func CS(n, c, t int) matrix.Matrix
- func CZ(n, c, t int) matrix.Matrix
- func Controlled(u matrix.Matrix, n int, c []int, t int) matrix.Matrix
- func ControlledModExp2(n, a, j, N, c int, t []int) matrix.Matrix
- func ControlledNot(n int, c []int, t int) matrix.Matrix
- func ControlledR(theta float64, n int, c []int, t int) matrix.Matrix
- func ControlledS(n int, c []int, t int) matrix.Matrix
- func ControlledZ(n int, c []int, t int) matrix.Matrix
- func Empty(n ...int) []matrix.Matrix
- func Fredkin(n, c, t0, t1 int) matrix.Matrix
- func H(n ...int) matrix.Matrix
- func I(n ...int) matrix.Matrix
- func New(v ...[]complex128) matrix.Matrix
- func QFT(n int) matrix.Matrix
- func R(theta float64) matrix.Matrix
- func RX(theta float64) matrix.Matrix
- func RY(theta float64) matrix.Matrix
- func RZ(theta float64) matrix.Matrix
- func S(n ...int) matrix.Matrix
- func Swap(n, c, t int) matrix.Matrix
- func T(n ...int) matrix.Matrix
- func Theta(k int) float64
- func Toffoli(n, c0, c1, t int) matrix.Matrix
- func U(theta, phi, lambda float64) matrix.Matrix
- func X(n ...int) matrix.Matrix
- func Y(n ...int) matrix.Matrix
- func Z(n ...int) matrix.Matrix
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CNOT ¶
CNOT returns a controlled-not gate.
Example ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.CNOT(2, 0, 1) for _, r := range g { fmt.Println(r) } }
Output: [(1+0i) (0+0i) (0+0i) (0+0i)] [(0+0i) (1+0i) (0+0i) (0+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)] [(0+0i) (0+0i) (1+0i) (0+0i)]
func Controlled ¶
Controlled returns a controlled-u gate.
func ControlledModExp2 ¶
ControlledModExp2 returns gate of controlled modular exponentiation operation. |j>|k> -> |j>|a**(2**j) * k mod N>. len(t) must be larger than log2(N).
Example ¶
package main import ( "fmt" "strconv" "github.com/itsubaki/q/math/number" "github.com/itsubaki/q/quantum/gate" ) func main() { n, a, j, N := 5, 7, 0, 15 g := gate.ControlledModExp2(n, a, j, N, 0, []int{1, 2, 3, 4}) f := fmt.Sprintf("%s%s%s", "%0", strconv.Itoa(n), "s") for i, r := range g.Transpose() { bin := fmt.Sprintf(f, strconv.FormatInt(int64(i), 2)) if bin[:1] == "0" { // control qubit is |0> continue } // decimal number representation of target qubits k := number.Must(strconv.ParseInt(bin[1:], 2, 64)) if k >= int64(N) { continue } for ii, e := range r { if e == complex(0, 0) { continue } // decimal number representation of a^2^j * k mod N a2jkmodNs := fmt.Sprintf(f, strconv.FormatInt(int64(ii), 2)[1:]) a2jkmodN := number.Must(strconv.ParseInt(a2jkmodNs, 2, 64)) got := (int64(number.ModExp2(a, j, N)) * k) % int64(N) fmt.Printf("%s:%s=%2d %s:%s=%2d %2d\n", bin[:1], bin[1:], k, bin[:1], a2jkmodNs[1:], a2jkmodN, got) } } }
Output: 1:0000= 0 1:0000= 0 0 1:0001= 1 1:0111= 7 7 1:0010= 2 1:1110=14 14 1:0011= 3 1:0110= 6 6 1:0100= 4 1:1101=13 13 1:0101= 5 1:0101= 5 5 1:0110= 6 1:1100=12 12 1:0111= 7 1:0100= 4 4 1:1000= 8 1:1011=11 11 1:1001= 9 1:0011= 3 3 1:1010=10 1:1010=10 10 1:1011=11 1:0010= 2 2 1:1100=12 1:1001= 9 9 1:1101=13 1:0001= 1 1 1:1110=14 1:1000= 8 8
func ControlledNot ¶
ControlledNot returns a controlled-not gate.
func ControlledR ¶
ControlledR returns a controlled-r gate.
func ControlledS ¶
ControlledS returns a controlled-s gate.
func ControlledZ ¶
ControlledZ returns a controlled-z gate.
func Empty ¶
Empty returns a list of empty gate.
Example ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g0 := gate.Empty() fmt.Println(g0) g1 := gate.Empty(3) fmt.Println(g1) }
Output: [] [[] [] []]
func H ¶
H returns a Hadamard gate.
Example ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.H() for _, r := range g { fmt.Printf("%.4v\n", r) } }
Output: [(0.7071+0i) (0.7071+0i)] [(0.7071+0i) (-0.7071+0i)]
Example (HH) ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.H(2) for _, r := range g { fmt.Printf("%.4v\n", r) } }
Output: [(0.5+0i) (0.5+0i) (0.5+0i) (0.5+0i)] [(0.5+0i) (-0.5+0i) (0.5+0i) (-0.5+0i)] [(0.5+0i) (0.5+0i) (-0.5+0i) (-0.5+0i)] [(0.5+0i) (-0.5+0i) (-0.5+0i) (0.5-0i)]
func Swap ¶
Swap returns a swap gate.
Example ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.Swap(2, 0, 1) for _, r := range g { fmt.Println(r) } }
Output: [(1+0i) (0+0i) (0+0i) (0+0i)] [(0+0i) (0+0i) (1+0i) (0+0i)] [(0+0i) (1+0i) (0+0i) (0+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)]
func X ¶
X returns a Pauli-X gate.
Example ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.X() for _, r := range g { fmt.Println(r) } }
Output: [(0+0i) (1+0i)] [(1+0i) (0+0i)]
Example (XX) ¶
package main import ( "fmt" "github.com/itsubaki/q/quantum/gate" ) func main() { g := gate.X(2) for _, r := range g { fmt.Println(r) } }
Output: [(0+0i) (0+0i) (0+0i) (1+0i)] [(0+0i) (0+0i) (1+0i) (0+0i)] [(0+0i) (1+0i) (0+0i) (0+0i)] [(1+0i) (0+0i) (0+0i) (0+0i)]
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.