Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement fromBlochVector #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Q/Q-Qubit.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,21 @@ Object.assign( Q.Qubit, {
},
fromBlochVector: function( x, y, z ){

// converting back to a Qubit (a, b) only maintains the relative phase between a and b
// for convenience, I will assume a is real.

//basically from a Pauli Rotation
// this neat trick comes from considering the density matrix if a = r and b = s + ti:
// ( r*r rs-rti )
// ( rs+rti s*s+t*t )

// compare that with the density matrix in https://en.wikipedia.org/wiki/Bloch_sphere

const
aReal = ( 0.5 + 0.5 * z ) ** 0.5,
a = new Q.ComplexNumber( aReal, 0 ),
b = new Q.ComplexNumber( x / 2 / aReal, y / 2 / aReal )

return new Q.Qubit( a, b )
}

})
Expand Down