Skip to content

Commit

Permalink
Update Controlled
Browse files Browse the repository at this point in the history
  • Loading branch information
itsubaki committed Jan 4, 2025
1 parent 47b79d2 commit 3fd641d
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions quantum/gate/gate.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,52 +143,47 @@ func Controlled(u matrix.Matrix, n int, c []int, t int) matrix.Matrix {
for i := range g {
row := []rune(fmt.Sprintf(f, strconv.FormatInt(int64(i), 2)))

found := false
active := true
for _, j := range c {
if row[j] == '0' {
found = true
active = false
break
}
}

if found {
if !active {
continue
}

for j := range g[i] {
col := []rune(fmt.Sprintf(f, strconv.FormatInt(int64(j), 2)))

found := false
active := true
for _, k := range c {
if col[k] == '0' {
found = true
active = false
break
}
}

if found {
if !active {
continue
}

diff := false
same := true
for i := range row {
if i == t {
continue
}

if row[i] != col[i] {
diff = true
if i != t && row[i] != col[i] {
same = false
break
}
}

if diff {
if !same {
continue
}

r := number.Must(strconv.Atoi(string(row[t])))
c := number.Must(strconv.Atoi(string(col[t])))

g[j][i] = u[c][r]
}
}
Expand Down

0 comments on commit 3fd641d

Please sign in to comment.