State

Dirac notation for states.

class sympy.physics.quantum.state.Bra(*args, **old_assumptions)[source]

A general time-independent Bra in quantum mechanics.

Inherits from State and BraBase. A Bra is the dual of a Ket [R442]. This class and its subclasses will be the main classes that users will use for expressing Bras in Dirac notation.

Parameters

args : tuple

The list of numbers or parameters that uniquely specify the ket. This will usually be its symbol or its quantum numbers. For time-dependent state, this will include the time.

References

R442(1,2)

http://en.wikipedia.org/wiki/Bra-ket_notation

Examples

Create a simple Bra and look at its properties:

>>> from sympy.physics.quantum import Ket, Bra
>>> from sympy import symbols, I
>>> b = Bra('psi')
>>> b
<psi|
>>> b.hilbert_space
H
>>> b.is_commutative
False

Bra’s know about their dual Ket’s:

>>> b.dual
|psi>
>>> b.dual_class()
<class 'sympy.physics.quantum.state.Ket'>

Like Kets, Bras can have compound labels and be manipulated in a similar manner:

>>> n, m = symbols('n,m')
>>> b = Bra(n,m) - I*Bra(m,n)
>>> b
-I*<mn| + <nm|

Symbols in a Bra can be substituted using .subs:

>>> b.subs(n,m)
<mm| - I*<mm|
classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.BraBase(*args, **old_assumptions)[source]

Base class for Bras.

This class defines the dual property and the brackets for printing. This is an abstract base class and you should not instantiate it directly, instead use Bra.

classmethod default_args()[source]

If no arguments are specified, then this will return a default set of arguments to be run through the constructor.

NOTE: Any classes that override this MUST return a tuple of arguments. Should be overidden by subclasses to specify the default arguments for kets and operators

classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.Ket(*args, **old_assumptions)[source]

A general time-independent Ket in quantum mechanics.

Inherits from State and KetBase. This class should be used as the base class for all physical, time-independent Kets in a system. This class and its subclasses will be the main classes that users will use for expressing Kets in Dirac notation [R443].

Parameters

args : tuple

The list of numbers or parameters that uniquely specify the ket. This will usually be its symbol or its quantum numbers. For time-dependent state, this will include the time.

References

R443(1,2)

http://en.wikipedia.org/wiki/Bra-ket_notation

Examples

Create a simple Ket and looking at its properties:

>>> from sympy.physics.quantum import Ket, Bra
>>> from sympy import symbols, I
>>> k = Ket('psi')
>>> k
|psi>
>>> k.hilbert_space
H
>>> k.is_commutative
False
>>> k.label
(psi,)

Ket’s know about their associated bra:

>>> k.dual
<psi|
>>> k.dual_class()
<class 'sympy.physics.quantum.state.Bra'>

Take a linear combination of two kets:

>>> k0 = Ket(0)
>>> k1 = Ket(1)
>>> 2*I*k0 - 4*k1
2*I*|0> - 4*|1>

Compound labels are passed as tuples:

>>> n, m = symbols('n,m')
>>> k = Ket(n,m)
>>> k
|nm>
classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.KetBase(*args, **old_assumptions)[source]

Base class for Kets.

This class defines the dual property and the brackets for printing. This is an abstract base class and you should not instantiate it directly, instead use Ket.

classmethod default_args()[source]

If no arguments are specified, then this will return a default set of arguments to be run through the constructor.

NOTE: Any classes that override this MUST return a tuple of arguments. Should be overidden by subclasses to specify the default arguments for kets and operators

classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.State(*args, **old_assumptions)[source]

General abstract quantum state used as a base class for Ket and Bra.

class sympy.physics.quantum.state.StateBase(*args, **old_assumptions)[source]

Abstract base class for general abstract states in quantum mechanics.

All other state classes defined will need to inherit from this class. It carries the basic structure for all other states such as dual, _eval_adjoint and label.

This is an abstract base class and you should not instantiate it directly, instead use State.

property dual

Return the dual state of this one.

classmethod dual_class()[source]

Return the class used to construt the dual.

property operators

Return the operator(s) that this state is an eigenstate of

class sympy.physics.quantum.state.TimeDepBra(*args, **old_assumptions)[source]

General time-dependent Bra in quantum mechanics.

This inherits from TimeDepState and BraBase and is the main class that should be used for Bras that vary with time. Its dual is a TimeDepBra.

Parameters

args : tuple

The list of numbers or parameters that uniquely specify the ket. This will usually be its symbol or its quantum numbers. For time-dependent state, this will include the time as the final argument.

Examples

>>> from sympy.physics.quantum import TimeDepBra
>>> from sympy import symbols, I
>>> b = TimeDepBra('psi', 't')
>>> b
<psi;t|
>>> b.time
t
>>> b.label
(psi,)
>>> b.hilbert_space
H
>>> b.dual
|psi;t>
classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.TimeDepKet(*args, **old_assumptions)[source]

General time-dependent Ket in quantum mechanics.

This inherits from TimeDepState and KetBase and is the main class that should be used for Kets that vary with time. Its dual is a TimeDepBra.

Parameters

args : tuple

The list of numbers or parameters that uniquely specify the ket. This will usually be its symbol or its quantum numbers. For time-dependent state, this will include the time as the final argument.

Examples

Create a TimeDepKet and look at its attributes:

>>> from sympy.physics.quantum import TimeDepKet
>>> k = TimeDepKet('psi', 't')
>>> k
|psi;t>
>>> k.time
t
>>> k.label
(psi,)
>>> k.hilbert_space
H

TimeDepKets know about their dual bra:

>>> k.dual
<psi;t|
>>> k.dual_class()
<class 'sympy.physics.quantum.state.TimeDepBra'>
classmethod dual_class()[source]

Return the class used to construt the dual.

class sympy.physics.quantum.state.TimeDepState(*args, **old_assumptions)[source]

Base class for a general time-dependent quantum state.

This class is used as a base class for any time-dependent state. The main difference between this class and the time-independent state is that this class takes a second argument that is the time in addition to the usual label argument.

Parameters

args : tuple

The list of numbers or parameters that uniquely specify the ket. This will usually be its symbol or its quantum numbers. For time-dependent state, this will include the time as the final argument.

classmethod default_args()[source]

If no arguments are specified, then this will return a default set of arguments to be run through the constructor.

NOTE: Any classes that override this MUST return a tuple of arguments. Should be overidden by subclasses to specify the default arguments for kets and operators

property label

The label of the state.

property time

The time of the state.

class sympy.physics.quantum.state.Wavefunction(*args)[source]

Class for representations in continuous bases

This class takes an expression and coordinates in its constructor. It can be used to easily calculate normalizations and probabilities.

Parameters

expr : Expr

The expression representing the functional form of the w.f.

coords : Symbol or tuple

The coordinates to be integrated over, and their bounds

Examples

Particle in a box, specifying bounds in the more primitive way of using Piecewise:

>>> from sympy import Symbol, Piecewise, pi, N
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x = Symbol('x', real=True)
>>> n = 1
>>> L = 1
>>> g = Piecewise((0, x < 0), (0, x > L), (sqrt(2//L)*sin(n*pi*x/L), True))
>>> f = Wavefunction(g, x)
>>> f.norm
1
>>> f.is_normalized
True
>>> p = f.prob()
>>> p(0)
0
>>> p(L)
0
>>> p(0.5)
2
>>> p(0.85*L)
2*sin(0.85*pi)**2
>>> N(p(0.85*L))
0.412214747707527

Additionally, you can specify the bounds of the function and the indices in a more compact way:

>>> from sympy import symbols, pi, diff
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
1
>>> f(L+1)
0
>>> f(L-1)
sqrt(2)*sin(pi*n*(L - 1)/L)/sqrt(L)
>>> f(-1)
0
>>> f(0.85)
sqrt(2)*sin(0.85*pi*n/L)/sqrt(L)
>>> f(0.85, n=1, L=1)
sqrt(2)*sin(0.85*pi)
>>> f.is_commutative
False

All arguments are automatically sympified, so you can define the variables as strings rather than symbols:

>>> expr = x**2
>>> f = Wavefunction(expr, 'x')
>>> type(f.variables[0])
<class 'sympy.core.symbol.Symbol'>

Derivatives of Wavefunctions will return Wavefunctions:

>>> diff(f, x)
Wavefunction(2*x, x)
classmethod eval(*args)[source]

Returns a canonical form of cls applied to arguments args.

The eval() method is called when the class cls is about to be instantiated and it should return either some simplified instance (possible of some other class), or if the class cls should be unmodified, return None.

Examples Of Eval() For The Function “sign”

@classmethod def eval(cls, arg):

if arg is S.NaN:

return S.NaN

if arg is S.Zero: return S.Zero if arg.is_positive: return S.One if arg.is_negative: return S.NegativeOne if isinstance(arg, Mul):

coeff, terms = arg.as_coeff_Mul(rational=True) if coeff is not S.One:

return cls(coeff) * cls(terms)

property expr

Return the expression which is the functional form of the Wavefunction

Examples

>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x, y = symbols('x, y')
>>> f = Wavefunction(x**2, x)
>>> f.expr
x**2
property free_symbols

Return from the atoms of self those which are free symbols.

For most expressions, all symbols are free symbols. For some classes this is not true. e.g. Integrals use Symbols for the dummy variables which are bound variables, so Integral has a method to return all symbols except those. Derivative keeps track of symbols with respect to which it will perform a derivative; those are bound variables, too, so it has its own free_symbols method.

Any other method that uses bound variables should implement a free_symbols method.

property is_commutative

Override Function’s is_commutative so that order is preserved in represented expressions

property is_normalized

Returns true if the Wavefunction is properly normalized

Examples

>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.is_normalized
True
property limits

Return the limits of the coordinates which the w.f. depends on If no limits are specified, defaults to (-oo, oo).

Examples

>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x, y = symbols('x, y')
>>> f = Wavefunction(x**2, (x, 0, 1))
>>> f.limits
{x: (0, 1)}
>>> f = Wavefunction(x**2, x)
>>> f.limits
{x: (-oo, oo)}
>>> f = Wavefunction(x**2 + y**2, x, (y, -1, 2))
>>> f.limits
{x: (-oo, oo), y: (-1, 2)}
property norm

Return the normalization of the specified functional form.

This function integrates over the coordinates of the Wavefunction, with the bounds specified.

Examples

>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sqrt(2/L)*sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
1
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.norm
sqrt(2)*sqrt(L)/2
normalize()[source]

Return a normalized version of the Wavefunction

Examples

>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x = symbols('x', real=True)
>>> L = symbols('L', positive=True)
>>> n = symbols('n', integer=True, positive=True)
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.normalize()
Wavefunction(sqrt(2)*sin(pi*n*x/L)/sqrt(L), (x, 0, L))
prob()[source]

Return the absolute magnitude of the w.f., \(|\psi(x)|^2\)

Examples

>>> from sympy import symbols, pi
>>> from sympy.functions import sqrt, sin
>>> from sympy.physics.quantum.state import Wavefunction
>>> x, L = symbols('x,L', real=True)
>>> n = symbols('n', integer=True)
>>> g = sin(n*pi*x/L)
>>> f = Wavefunction(g, (x, 0, L))
>>> f.prob()
Wavefunction(sin(pi*n*x/L)**2, x)
property variables

Return the coordinates which the wavefunction depends on

Examples

>>> from sympy.physics.quantum.state import Wavefunction
>>> from sympy import symbols
>>> x,y = symbols('x,y')
>>> f = Wavefunction(x*y, x, y)
>>> f.variables
(x, y)
>>> g = Wavefunction(x*y, x)
>>> g.variables
(x,)