Skip to content

Commit

Permalink
Rename gate.CModExp2 -> gate.ControlledModExp2
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed May 16, 2022
1 parent 4473b87 commit 94812a3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions pkg/quantum/gate/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ func QFT(n int) matrix.Matrix {
return g
}

// CModExp2 returns unitary matrix of controlled modular exponentiation operation. |j>|k> -> |j>|a**(2**j) * k mod N>
// ControlledModExp2 returns unitary matrix of controlled modular exponentiation operation. |j>|k> -> |j>|a**(2**j) * k mod N>
// len(t) must be larger than log2(N)
func CModExp2(n, a, j, N, c int, t []int) matrix.Matrix {
func ControlledModExp2(n, a, j, N, c int, t []int) matrix.Matrix {
m := I([]int{n}...)
d, _ := m.Dimension()

Expand Down
8 changes: 4 additions & 4 deletions pkg/quantum/gate/gate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ func ExampleEmpty() {
// [[] [] []]
}

func ExampleCModExp2() {
func ExampleControlledModExp2() {
n, a, j, N := 5, 7, 0, 15
g := gate.CModExp2(n, a, j, N, 0, []int{1, 2, 3, 4})
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() {
Expand Down Expand Up @@ -146,7 +146,7 @@ func ExampleCModExp2() {
// 1:1110=14 1:1000= 8 8
}

func TestCModExp2(t *testing.T) {
func TestControlledModExp2(t *testing.T) {
g1 := matrix.Apply(
gate.CNOT(7, 3, 5),
gate.CCNOT(7, 1, 5, 3),
Expand All @@ -170,7 +170,7 @@ func TestCModExp2(t *testing.T) {
}

for _, c := range cases {
got := gate.CModExp2(c.n, c.a, c.j, c.N, c.c, c.t)
got := gate.ControlledModExp2(c.n, c.a, c.j, c.N, c.c, c.t)
if !got.IsUnitary() {
t.Errorf("modexp is not unitary")
}
Expand Down
2 changes: 1 addition & 1 deletion q.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (q *Q) ConditionZ(condition bool, qb ...Qubit) *Q {

func (q *Q) ControlledModExp2(a, j, N int, control Qubit, target []Qubit) *Q {
n := q.NumberOfBit()
g := gate.CModExp2(n, a, j, N, control.Index(), Index(target...))
g := gate.ControlledModExp2(n, a, j, N, control.Index(), Index(target...))
q.qb.Apply(g)
return q
}
Expand Down

0 comments on commit 94812a3

Please sign in to comment.