Class Gates::ControlledU
In: rquantum.rb
Parent: Object

Universal control gate - it takes two parameters: 2x2 matrix and control qubit.

 control = Qubit.new
 target = Qubit.new
 control.reset
 target.reset

 gate = Gates::ControlledU.new [Matrices::NOT, control]
 gate.compute target.to_vector   # -> Vector[1+0i, 0i]
 control.not
 gate.compute target.to_vector   # -> Vector[0i, 1+0i]
 control.hadamard
 gate.compute target.to_vector   # -> Vector[0.707106781186547+0.0i, -0.707106781186547+0.0i]

Methods

compute   new  

Public Class methods

Creates any controlled gate, using given Matrix and control qubit.

 q = Qubit.new
 m = Matrix[[0, 1], [1, 0]]
 g = ControlledU [m, q]

Public Instance methods

Takes vector with two complex numbers (amplitudes), perform gate operation and returns new vector.

[Validate]