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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use num_complex::Complex32;
use std::f32::consts::FRAC_1_SQRT_2;
use std::fmt;
#[derive(Debug, Clone, Copy)]
pub struct Gate {
pub a: Complex32,
pub b: Complex32,
pub c: Complex32,
pub d: Complex32,
}
impl fmt::Display for Gate {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "[[{}, {}], [{}, {}]]", self.a, self.b, self.c, self.d)
}
}
#[inline]
pub fn h() -> Gate {
Gate {
a: Complex32::new(FRAC_1_SQRT_2, 0.0),
b: Complex32::new(FRAC_1_SQRT_2, 0.0),
c: Complex32::new(FRAC_1_SQRT_2, 0.0),
d: Complex32::new(-FRAC_1_SQRT_2, 0.0),
}
}
#[inline]
pub fn x() -> Gate {
Gate {
a: Complex32::new(0.0, 0.0),
b: Complex32::new(1.0, 0.0),
c: Complex32::new(1.0, 0.0),
d: Complex32::new(0.0, 0.0),
}
}
#[inline]
pub fn y() -> Gate {
Gate {
a: Complex32::new(0.0, 0.0),
b: Complex32::new(0.0, -1.0),
c: Complex32::new(0.0, 1.0),
d: Complex32::new(0.0, 0.0),
}
}
#[inline]
pub fn z() -> Gate {
Gate {
a: Complex32::new(1.0, 0.0),
b: Complex32::new(0.0, 0.0),
c: Complex32::new(0.0, 0.0),
d: Complex32::new(-1.0, 0.0),
}
}