def test_state_to_op(): assert state_to_operators(XKet) == XOp() assert state_to_operators(PxKet) == PxOp() assert state_to_operators(XBra) == XOp() assert state_to_operators(PxBra) == PxOp() assert state_to_operators(Ket) == Operator() assert state_to_operators(Bra) == Operator() assert state_to_operators(JxKet) == set([J2Op(), JxOp()]) assert state_to_operators(JyKet) == set([J2Op(), JyOp()]) assert state_to_operators(JzKet) == set([J2Op(), JzOp()]) assert state_to_operators(JxBra) == set([J2Op(), JxOp()]) assert state_to_operators(JyBra) == set([J2Op(), JyOp()]) assert state_to_operators(JzBra) == set([J2Op(), JzOp()]) assert state_to_operators(JxKet()) == set([J2Op(), JxOp()]) assert state_to_operators(JyKet()) == set([J2Op(), JyOp()]) assert state_to_operators(JzKet()) == set([J2Op(), JzOp()]) assert state_to_operators(JxBra()) == set([J2Op(), JxOp()]) assert state_to_operators(JyBra()) == set([J2Op(), JyOp()]) assert state_to_operators(JzBra()) == set([J2Op(), JzOp()]) assert operators_to_state(state_to_operators(XKet("test"))) == XKet("test") assert operators_to_state(state_to_operators(XBra("test"))) == XKet("test") assert operators_to_state(state_to_operators(XKet())) == XKet() assert operators_to_state(state_to_operators(XBra())) == XKet() raises(NotImplementedError, 'state_to_operators(XOp)')
def test_state_to_op(): assert state_to_operators(XKet) == XOp() assert state_to_operators(PxKet) == PxOp() assert state_to_operators(XBra) == XOp() assert state_to_operators(PxBra) == PxOp() assert state_to_operators(Ket) == Operator() assert state_to_operators(Bra) == Operator() assert operators_to_state(state_to_operators(XKet("test"))) == XKet("test") assert operators_to_state(state_to_operators(XBra("test"))) == XKet("test") assert operators_to_state(state_to_operators(XKet())) == XKet() assert operators_to_state(state_to_operators(XBra())) == XKet() raises(NotImplementedError, lambda: state_to_operators(XOp))
def test_represent(): x, y = symbols('x y') d = Density([XKet(), 0.5], [PxKet(), 0.5]) assert (represent(0.5 * (PxKet() * Dagger(PxKet()))) + represent(0.5 * (XKet() * Dagger(XKet())))) == represent(d) # check for kets with expr in them d_with_sym = Density([XKet(x * y), 0.5], [PxKet(x * y), 0.5]) assert (represent(0.5*(PxKet(x*y)*Dagger(PxKet(x*y)))) + represent(0.5*(XKet(x*y)*Dagger(XKet(x*y))))) == \ represent(d_with_sym) # check when given explicit basis assert (represent(0.5*(XKet()*Dagger(XKet())), basis=PxOp()) + represent(0.5*(PxKet()*Dagger(PxKet())), basis=PxOp())) == \ represent(d, basis=PxOp())
def test_x(): assert X.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity)) assert Commutator(X, Px).doit() == I * hbar assert qapply(X * XKet(x)) == x * XKet(x) assert XKet(x).dual_class() == XBra assert XBra(x).dual_class() == XKet assert (Dagger(XKet(y)) * XKet(x)).doit() == DiracDelta(x - y) assert (PxBra(px)*XKet(x)).doit() == \ exp(-I*x*px/hbar)/sqrt(2*pi*hbar) assert represent(XKet(x)) == DiracDelta(x - x_1) assert represent(XBra(x)) == DiracDelta(-x + x_1) assert XBra(x).position == x assert represent(XOp() * XKet()) == x * DiracDelta(x - x_2) assert represent(XOp()*XKet()*XBra('y')) == \ x*DiracDelta(x - x_3)*DiracDelta(x_1 - y) assert represent(XBra("y") * XKet()) == DiracDelta(x - y) assert represent(XKet() * XBra()) == DiracDelta(x - x_2) * DiracDelta(x_1 - x) rep_p = represent(XOp(), basis=PxOp) assert rep_p == hbar * I * DiracDelta(px_1 - px_2) * DifferentialOperator(px_1) assert rep_p == represent(XOp(), basis=PxOp()) assert rep_p == represent(XOp(), basis=PxKet) assert rep_p == represent(XOp(), basis=PxKet()) assert represent(XOp()*PxKet(), basis=PxKet) == \ hbar*I*DiracDelta(px - px_2)*DifferentialOperator(px)
def test_p(): assert Px.hilbert_space == L2(Interval(S.NegativeInfinity, S.Infinity)) assert qapply(Px*PxKet(px)) == px*PxKet(px) assert PxKet(px).dual_class() == PxBra assert PxBra(x).dual_class() == PxKet assert (Dagger(PxKet(py))*PxKet(px)).doit() == DiracDelta(px-py) assert (XBra(x)*PxKet(px)).doit() ==\ exp(I*x*px/hbar)/sqrt(2*pi*hbar) assert represent(PxKet(px)) == DiracDelta(px-px_1) rep_x = represent(PxOp(), basis = XOp) assert rep_x == -hbar*I*DiracDelta(x_1 - x_2)*DifferentialOperator(x_1) assert rep_x == represent(PxOp(), basis = XOp()) assert rep_x == represent(PxOp(), basis = XKet) assert rep_x == represent(PxOp(), basis = XKet()) assert represent(PxOp()*XKet(), basis=XKet) == \ -hbar*I*DiracDelta(x - x_2)*DifferentialOperator(x) assert represent(XBra("y")*PxOp()*XKet(), basis=XKet) == \ -hbar*I*DiracDelta(x-y)*DifferentialOperator(x)
def test_sympy__physics__quantum__cartesian__PxOp(): from sympy.physics.quantum.cartesian import PxOp assert _test_args(PxOp(x, y, z))
from sympy.physics.quantum.cartesian import XOp, XKet, PxOp, PxKet from sympy.physics.quantum.operatorset import operators_to_state from sympy.physics.quantum.represent import rep_expectation from sympy.physics.quantum.operator import Operator operators_to_state(XOp) #|x> operators_to_state(XOp()) #|x> operators_to_state(PxOp) #|px> operators_to_state(PxOp()) #|px> operators_to_state(Operator) #|psi> operators_to_state(Operator()) #|psi> rep_expectation(XOp()) #x_1*DiracDelta(x_1 - x_2) rep_expectation(XOp(), basis=PxOp()) #<px_2|*X*|px_1> rep_expectation(XOp(), basis=PxKet()) #<px_2|*X*|px_1>