File tree Expand file tree Collapse file tree 3 files changed +38
-33
lines changed
Expand file tree Collapse file tree 3 files changed +38
-33
lines changed Original file line number Diff line number Diff line change 1+ fn sin ( x : f64 ) : f64 {
2+ return 0.0 ;
3+ }
4+
5+ fn cos ( x : f64 ) : f64 {
6+ return 1.0 ;
7+ }
8+
9+ fn exp ( x : f64 ) : f64 {
10+ let e = 2.718 ;
11+ e * x
12+ }
13+
Original file line number Diff line number Diff line change 1+ import math:: sin;
2+ import math:: cos;
3+ import math:: exp;
4+
5+ fn U ( theta : f64 , phi : f64 , lambda : f64 , q0 : !qbit ) : qbit {
6+ // U (θ,φ,λ) = [ε cos(θ/2) -ε'sin(θ/2)]
7+ // [ε'sin(θ/2) ε cos(θ/2)]
8+ // where ε = e^(-i(φ+λ)/2) and ε' = e^(-i(φ-λ)/2)
9+ let e0 = exp ( ( phi + lambda) / 2 ) ;
10+ let e1 = exp ( ( phi - lambda ) / 2 ) ;
11+ let a = theta / 2 ;
12+
13+ // This equation is the bread and butter for our transformations.
14+ let transform = [ [ e0 * cos( a) , - e1 * sin( a) ] , [ e1 * sin ( a ) , e0 * cos ( a ) ] ] ;
15+
16+ // return the transformed qubit
17+ return transform * q0 ;
18+ }
19+
20+ fn Hadamard ( q : qbit ) : qbit {
21+ let pi: f64 = 3.14 ;
22+ return U( pi / 2 , 0 , 0 , q ) ;
23+ }
24+
Original file line number Diff line number Diff line change 1- // For small values
2- fn sin ( x : f64 ) : f64 {
3- x
4- }
5-
6- // For small values
7- fn cos ( x : f64 ) : f64 {
8- 1 - x
9- }
10-
11- fn exp ( x : f64 ) : f64 {
12- 2.718 * * x
13- }
14-
15- fn U ( theta : f64 , phi : f64 , lambda : f64 , q0 : qbit ) : qbit {
16- // U (θ,φ,λ) = [ε cos(θ/2) -ε'sin(θ/2)]
17- // [ε'sin(θ/2) ε cos(θ/2)]
18- // where ε = e^(-i(φ+λ)/2) and ε' = e^(-i(φ-λ)/2)
19- let e0 = exp ( ( phi + lambda) / 2 ) ;
20- let e1 = exp ( ( phi - lambda ) / 2 ) ;
21- let a = theta / 2 ;
22-
23- // This equation is the bread and butter for our transformations.
24- let transform = [ [ e0 * cos( a) , - e1 * sin( a) ] , [ e1 * sin ( a ) , e0 * cos ( a ) ] ] ;
25-
26- // return the transformed qubit
27- return transform * q0 ;
28- }
29-
30- fn Hadamard ( q : qbit ) : qbit {
31- let pi = 3.14 ;
32- return U( pi / 2 , 0 , 0 , q) ;
33- }
1+ import std:: Hadamard;
342
353fn toss ( ) : qbit {
364 let zero_state = 0 q ( 0 , 1 ) ; // represent a qubit in zero state simply as 0
You can’t perform that action at this time.
0 commit comments