State¶
Dirac notation for states.

class
sympy.physics.quantum.state.
KetBase
[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.

class
sympy.physics.quantum.state.
BraBase
[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.

class
sympy.physics.quantum.state.
StateBase
[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.

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

property

class
sympy.physics.quantum.state.
State
[source]¶ General abstract quantum state used as a base class for Ket and Bra.

class
sympy.physics.quantum.state.
Ket
[source]¶ A general timeindependent Ket in quantum mechanics.
Inherits from State and KetBase. This class should be used as the base class for all physical, timeindependent Kets in a system. This class and its subclasses will be the main classes that users will use for expressing Kets in Dirac notation [R598].
 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 timedependent state, this will include the time.
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>
References

class
sympy.physics.quantum.state.
Bra
[source]¶ A general timeindependent Bra in quantum mechanics.
Inherits from State and BraBase. A Bra is the dual of a Ket [R599]. 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 timedependent state, this will include the time.
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
References

class
sympy.physics.quantum.state.
TimeDepState
[source]¶ Base class for a general timedependent quantum state.
This class is used as a base class for any timedependent state. The main difference between this class and the timeindependent 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 timedependent state, this will include the time as the final argument.

property
label
¶ The label of the state.

property
time
¶ The time of the state.

class
sympy.physics.quantum.state.
TimeDepBra
[source]¶ General timedependent 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 timedependent 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>

class
sympy.physics.quantum.state.
TimeDepKet
[source]¶ General timedependent Ket in quantum mechanics.
This inherits from
TimeDepState
andKetBase
and is the main class that should be used for Kets that vary with time. Its dual is aTimeDepBra
. 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 timedependent 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'>

class
sympy.physics.quantum.state.
Wavefunction
[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(L1) 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)

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
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,)