代表#
在各种基中表示状态运算符的逻辑。
TODO:
使用连续hilbert空间得到表示。
文档默认基础功能。
- sympy.physics.quantum.represent.enumerate_states(*args, **options)[源代码]#
返回附加伪索引的给定状态的实例
在两种不同的模式下运行:
向它传递了两个参数。第一个参数是要索引的基态,第二个参数是要附加的索引列表。
传递了三个参数。第一个是要索引的基态。二是计数的起始指标。最后一个参数是您希望接收的ket数。
尝试调用状态。枚举状态。如果失败,则返回一个空列表
- 参数:
args :列表
说明见上述操作模式列表
实例
>>> from sympy.physics.quantum.cartesian import XBra, XKet >>> from sympy.physics.quantum.represent import enumerate_states >>> test = XKet('foo') >>> enumerate_states(test, 1, 3) [|foo_1>, |foo_2>, |foo_3>] >>> test2 = XBra('bar') >>> enumerate_states(test2, [4, 5, 10]) [<bar_4|, <bar_5|, <bar_10|]
- sympy.physics.quantum.represent.get_basis(expr, *, basis=None, replace_none=True, **options)[源代码]#
返回与options=s中指定的基相对应的基状态实例。如果未指定基,函数将尝试形成给定表达式的默认基状态。
有三种行为:
选项中指定的基础已经是StateBase的实例。如果是这种情况,则只返回它。如果指定了类而不是实例,则返回默认实例。
指定的基是一个运算符或一组运算符。如果使用的是state-to-state的映射方法,则为u。
未指定依据。如果expr是一个状态,则返回其类的默认实例。如果expr是运算符,则将其映射到相应的状态。如果两者都不是,那么我们就不能得到基态。
如果基础无法映射,则不会更改。
这将从representation内部调用,而represent只传递QExpr的。
托多(?):支持mul和其他类型的表达式?
- 参数:
expr :运算符或StateBase
寻求其基础的表达式
实例
>>> from sympy.physics.quantum.represent import get_basis >>> from sympy.physics.quantum.cartesian import XOp, XKet, PxOp, PxKet >>> x = XKet() >>> X = XOp() >>> get_basis(x) |x> >>> get_basis(X) |x> >>> get_basis(x, basis=PxOp()) |px> >>> get_basis(x, basis=PxKet) |px>
- sympy.physics.quantum.represent.integrate_result(orig_expr, result, **options)[源代码]#
返回对任何单位进行积分的结果
(|x><x|)
在给定的表达式中。用于在连续基上对表示结果进行积分。此函数对可能已插入量子表达式的任何单位进行积分并返回结果。它使用传递给它的基态的Hilbert空间的间隔来计算积分的极限。必须指定unities选项才能使其工作。
注意:这主要由representation()在内部使用。给出的示例仅仅是为了展示用例。
- 参数:
orig_expr :量子表达式
要表示的原始表达式
结果:Expr
我们希望整合的结果表示
实例
>>> from sympy import symbols, DiracDelta >>> from sympy.physics.quantum.represent import integrate_result >>> from sympy.physics.quantum.cartesian import XOp, XKet >>> x_ket = XKet() >>> X_op = XOp() >>> x, x_1, x_2 = symbols('x, x_1, x_2') >>> integrate_result(X_op*x_ket, x*DiracDelta(x-x_1)*DiracDelta(x_1-x_2)) x*DiracDelta(x - x_1)*DiracDelta(x_1 - x_2) >>> integrate_result(X_op*x_ket, x*DiracDelta(x-x_1)*DiracDelta(x_1-x_2), ... unities=[1]) x*DiracDelta(x - x_2)
- sympy.physics.quantum.represent.rep_expectation(expr, **options)[源代码]#
返回一个
<x'|A|x>
给定运算符的类型表示形式。- 参数:
expr :运算符
以指定基础表示的运算符
实例
>>> from sympy.physics.quantum.cartesian import XOp, PxOp, PxKet >>> from sympy.physics.quantum.represent import rep_expectation >>> 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>
- sympy.physics.quantum.represent.rep_innerproduct(expr, **options)[源代码]#
返回一个类似innerproduct的表示(例如。
<x'|x>
)对于给定的状态。尝试从指定的基础上计算胸罩的内积。只应传递KetBase或BraBase的实例
- 参数:
expr :KetBase或BraBase
要表示的表达式
实例
>>> from sympy.physics.quantum.represent import rep_innerproduct >>> from sympy.physics.quantum.cartesian import XOp, XKet, PxOp, PxKet >>> rep_innerproduct(XKet()) DiracDelta(x - x_1) >>> rep_innerproduct(XKet(), basis=PxOp()) sqrt(2)*exp(-I*px_1*x/hbar)/(2*sqrt(hbar)*sqrt(pi)) >>> rep_innerproduct(PxKet(), basis=XOp()) sqrt(2)*exp(I*px*x_1/hbar)/(2*sqrt(hbar)*sqrt(pi))
- sympy.physics.quantum.represent.represent(expr, **options)[源代码]#
表示给定基的量子表达式。
在量子力学中,抽象的状态和算符可以用不同的基集来表示。在此操作下,将发生以下转换:
Ket->列向量或函数
Bra->函数的行向量
运算符->矩阵或微分运算符
此函数是此操作的顶级接口。
This function walks the SymPy expression tree looking for
QExpr
instances that have a_represent
method. This method is then called and the object is replaced by the representation returned by this method. By default, the_represent
method will dispatch to other methods that handle the representation logic for a particular basis set. The naming convention for these methods is the following:def _represent_FooBasis(self, e, basis, **options)
此函数将具有在具有名为的类的基集中表示其类实例的逻辑
FooBasis
.- 参数:
expr :表达式
要表示的表达式。
基础 :运算符,基集
包含基集信息的对象。如果使用一个算子,则假定基是该算子的正交特征向量。不过,一般来说,basis参数可以是任何包含基集信息的对象。
选项 :dict命令
传递给查找表示形式的基础方法的选项的键/值对。这些选项可用于控制表示方式。例如,这是设置基集大小的地方。
- 返回:
e :表达式
表示的量子表达式的同调表达式。
实例
在这里我们子类
Operator
和Ket
创建z自旋算符及其自旋1/2向上本征态。通过定义_represent_SzOp
方法,则ket可以用z自旋基表示。>>> from sympy.physics.quantum import Operator, represent, Ket >>> from sympy import Matrix
>>> class SzUpKet(Ket): ... def _represent_SzOp(self, basis, **options): ... return Matrix([1,0]) ... >>> class SzOp(Operator): ... pass ... >>> sz = SzOp('Sz') >>> up = SzUpKet('up') >>> represent(up, basis=sz) Matrix([ [1], [0]])
这里我们看到一个连续基表示的例子。我们看到,表示笛卡尔位置算子和kets的各种组合的结果给出了包含DiracDelta函数的连续表达式。
>>> from sympy.physics.quantum.cartesian import XOp, XKet, XBra >>> X = XOp() >>> x = XKet() >>> y = XBra('y') >>> represent(X*x) x*DiracDelta(x - x_2) >>> represent(X*x*y) x*DiracDelta(x - x_3)*DiracDelta(x_1 - y)