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 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 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 TensorProduct(u *matrix.Matrix, n int, idx []int) *matrix.Matrix
- func Theta(k int) float64
- 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.Seq2() {
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. u is a (2x2) unitary matrix and returns a (2**n x 2**n) matrix.
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 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.Seq2() {
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.Seq2() {
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.Seq2() {
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 TensorProduct ¶ added in v0.0.5
TensorProduct returns the tensor product of 'u' at specified indices over 'n' qubits.
Example ¶
package main
import (
"fmt"
"github.com/itsubaki/q/quantum/gate"
)
func main() {
for _, r := range gate.TensorProduct(gate.X(), 2, []int{1}).Seq2() {
fmt.Printf("%.4v\n", r)
}
fmt.Println()
for _, r := range gate.TensorProduct(gate.X(), 2, []int{0}).Seq2() {
fmt.Printf("%.4v\n", r)
}
}
Output: [(0+0i) (1+0i) (0+0i) (0+0i)] [(1+0i) (0+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) (1+0i) (0+0i)] [(0+0i) (0+0i) (0+0i) (1+0i)] [(1+0i) (0+0i) (0+0i) (0+0i)] [(0+0i) (1+0i) (0+0i) (0+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.Seq2() {
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.Seq2() {
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.