Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Use the doit() method, as in:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0
click to hide/show revision 2
No.2 Revision

Use The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method, as in:method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0
click to hide/show revision 3
No.3 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application of the qapply method.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but remember to qapply:

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(sympify(x*e0)). Alternatively you may sympify the Sage expressions.

click to hide/show revision 4
No.4 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application of the qapply method.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but remember to qapply:

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(sympify(x*e0)). Alternatively Alternatively, you may sympify the Sage expressions.

click to hide/show revision 5
No.5 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application of the qapply method.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but remember to qapply:

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(sympify(x*e0))qapply(x*e0). Alternatively, you may sympify the Sage expressions.

click to hide/show revision 6
No.6 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application of the qapply method.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H

sage: # the argument passed to H is the target qubit (starting at 0, as usual)
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]
e1]]    
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but remember to qapply:

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(x*e0). Alternatively, you may sympify the Sage expressions.

Since the Pauli matrices X, Y, Z can also be imported, it is possible to perform an arbitrary operation on a qubit. Multiple qubits can be handled similarly; there are some examples in the package's documentation.

click to hide/show revision 7
No.7 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application of the qapply method.

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H

sage: # the argument passed to H is the target qubit (starting at 0, as usual)
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]    
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but remember to qapply:

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(x*e0). Alternatively, you may sympify the Sage expressions.

Since the Pauli matrices X, Y, Z can also be imported, it is possible to perform an arbitrary operation on a qubit. Multiple qubits can be handled similarly; there are some examples in the package's package documentation.

click to hide/show revision 8
No.8 Revision

The Qubit constructor can be used to define an orthonormal basis. The scalar product can be actually computed with the doit() method. For example:

sage: from sympy.physics.quantum.qubit import Qubit
sage: from sympy.physics.quantum import Dagger
sage: e0 = Qubit('0'); e1 = Qubit('1')
sage: c = Dagger(e0)*e1; c
<0|1>
sage: c.doit()
0
sage: (Dagger(e1)*e1).doit()
1
sage: (Dagger(e1)*e0).doit()
0

Edit: The functionality actually exists, but it requires a systematic application use of the qapply method..

First, suppose that we want to just rotate the qubit. We can apply the Hadamard coin as follows:

sage: from sympy.physics.quantum import qapply
sage: from sympy.physics.quantum.gate import H

sage: # the argument passed to H is the target qubit (starting at 0, as usual)
sage: [e0r, e1r] = [qapply(H(0)*ei) for ei in [e0, e1]]    
sage: e0r, e1r
(sqrt(2)*|0>/2 + sqrt(2)*|1>/2, sqrt(2)*|0>/2 - sqrt(2)*|1>/2)

and

sage: qapply(Dagger(e0r)*e0r)
1
sage: qapply(Dagger(e0r)*e1r) 
0
sage: qapply(Dagger(e1r)*e0r) 
0
sage: qapply(Dagger(e1r)*e1r) 
1

Linear combinations are also valid, but valid (but remember to qapply:):

sage: from sympy import Symbol, cos, sin, exp, I
sage: theta = Symbol('theta', real=True); phi = Symbol('varphi', real=True)
sage: Q = cos(theta)*e0 + exp(I*phi)*sin(theta)*e1; Q
exp(I*phi)*sin(theta)*|1> + cos(theta)*|0>
sage: simplify(qapply(Dagger(Q)*Q))
1

Those imports are to avoid the missing conversion (AttributeError) for the Qubit class, for instance if you type qapply(x*e0). Alternatively, you may sympify the Sage expressions.

Since the Pauli matrices X, Y, Z can also be imported, it is possible to perform an arbitrary operation on a qubit. Multiple qubits can be handled similarly; there are some examples in the package documentation.