-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharithmetic.go
47 lines (40 loc) · 970 Bytes
/
arithmetic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package qrad
func ApplyIncrement(c *Circuit, start, stop int) {
controls := []int{}
for i := start; i < stop; i++ {
controls = append(controls, i)
}
for i := stop; i > start; i-- {
c.AppendControl(X, controls, i)
controls = controls[0 : len(controls)-1]
}
c.Append(X, []int{start})
}
func ApplyDecrement(c *Circuit, start, stop int) {
controls := []int{}
for i := start; i <= stop; i++ {
c.AppendControl(X, controls, i)
controls = append(controls, i)
}
}
func ApplyAdd(c *Circuit, startA, stopA, startB, stopB int) {
for b := startB; b <= stopB; b++ {
bOffset := b - startB
r := Range(startA+bOffset, stopA)
r = append(r, b)
for g := stopA; g >= startA+bOffset; g-- {
c.AppendControl(X, r[:], g)
if len(r) != 1 {
r = append([]int{}, r...)
r = append(r[0:len(r)-2], r[len(r)-1:]...)
}
}
}
}
func Range(start, stop int) []int {
out := []int{}
for i := start; i < stop; i++ {
out = append(out, i)
}
return out
}