本文整理汇总了Python中sympy.physics.quantum.operator.Operator类的典型用法代码示例。如果您正苦于以下问题:Python Operator类的具体用法?Python Operator怎么用?Python Operator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Operator类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_operator
def test_operator():
a = Operator('A')
b = Operator('B', Symbol('t'), S(1)/2)
inv = a.inv()
f = Function('f')
x = symbols('x')
d = DifferentialOperator(Derivative(f(x), x), f(x))
op = OuterProduct(Ket(), Bra())
assert str(a) == 'A'
assert pretty(a) == 'A'
assert upretty(a) == u('A')
assert latex(a) == 'A'
sT(a, "Operator(Symbol('A'))")
assert str(inv) == 'A**(-1)'
ascii_str = \
"""\
-1\n\
A \
"""
ucode_str = \
u("""\
-1\n\
A \
""")
assert pretty(inv) == ascii_str
assert upretty(inv) == ucode_str
assert latex(inv) == r'\left(A\right)^{-1}'
sT(inv, "Pow(Operator(Symbol('A')), Integer(-1))")
assert str(d) == 'DifferentialOperator(Derivative(f(x), x),f(x))'
ascii_str = \
"""\
/d \\\n\
DifferentialOperator|--(f(x)),f(x)|\n\
\dx /\
"""
ucode_str = \
u("""\
⎛d ⎞\n\
DifferentialOperator⎜──(f(x)),f(x)⎟\n\
⎝dx ⎠\
""")
assert pretty(d) == ascii_str
assert upretty(d) == ucode_str
assert latex(d) == \
r'DifferentialOperator\left(\frac{d}{d x} f{\left (x \right )},f{\left (x \right )}\right)'
sT(d, "DifferentialOperator(Derivative(Function('f')(Symbol('x')), Symbol('x')),Function('f')(Symbol('x')))")
assert str(b) == 'Operator(B,t,1/2)'
assert pretty(b) == 'Operator(B,t,1/2)'
assert upretty(b) == u('Operator(B,t,1/2)')
assert latex(b) == r'Operator\left(B,t,\frac{1}{2}\right)'
sT(b, "Operator(Symbol('B'),Symbol('t'),Rational(1, 2))")
assert str(op) == '|psi><psi|'
assert pretty(op) == '|psi><psi|'
assert upretty(op) == u('❘ψ⟩⟨ψ❘')
assert latex(op) == r'{\left|\psi\right\rangle }{\left\langle \psi\right|}'
sT(op, "OuterProduct(Ket(Symbol('psi')),Bra(Symbol('psi')))")
示例2: test_operator
def test_operator():
a = Operator("A")
b = Operator("B", Symbol("t"), S(1) / 2)
inv = a.inv()
f = Function("f")
x = symbols("x")
d = DifferentialOperator(Derivative(f(x), x), f(x))
op = OuterProduct(Ket(), Bra())
assert str(a) == "A"
assert pretty(a) == "A"
assert upretty(a) == u"A"
assert latex(a) == "A"
sT(a, "Operator(Symbol('A'))")
assert str(inv) == "A**(-1)"
ascii_str = """\
-1\n\
A \
"""
ucode_str = u(
"""\
-1\n\
A \
"""
)
assert pretty(inv) == ascii_str
assert upretty(inv) == ucode_str
assert latex(inv) == r"A^{-1}"
sT(inv, "Pow(Operator(Symbol('A')), Integer(-1))")
assert str(d) == "DifferentialOperator(Derivative(f(x), x),f(x))"
ascii_str = """\
/d \\\n\
DifferentialOperator|--(f(x)),f(x)|\n\
\dx /\
"""
ucode_str = u(
"""\
⎛d ⎞\n\
DifferentialOperator⎜──(f(x)),f(x)⎟\n\
⎝dx ⎠\
"""
)
assert pretty(d) == ascii_str
assert upretty(d) == ucode_str
assert latex(d) == r"DifferentialOperator\left(\frac{d}{d x} f{\left (x \right )},f{\left (x \right )}\right)"
sT(d, "DifferentialOperator(Derivative(Function('f')(Symbol('x')), Symbol('x')),Function('f')(Symbol('x')))")
assert str(b) == "Operator(B,t,1/2)"
assert pretty(b) == "Operator(B,t,1/2)"
assert upretty(b) == u"Operator(B,t,1/2)"
assert latex(b) == r"Operator\left(B,t,\frac{1}{2}\right)"
sT(b, "Operator(Symbol('B'),Symbol('t'),Rational(1, 2))")
assert str(op) == "|psi><psi|"
assert pretty(op) == "|psi><psi|"
assert upretty(op) == u"❘ψ⟩⟨ψ❘"
assert latex(op) == r"{\left|\psi\right\rangle }{\left\langle \psi\right|}"
sT(op, "OuterProduct(Ket(Symbol('psi')),Bra(Symbol('psi')))")
示例3: _eval_anticommutator
def _eval_anticommutator(self, other, **hints):
if isinstance(other, OneQubitGate):
if self.targets != other.targets or self.__class__ == other.__class__:
return Integer(2)*self*other
return Operator._eval_anticommutator(self, other, **hints)
示例4: test_operator_inv
def test_operator_inv():
A = Operator('A')
assert A*A.inv() == 1
assert A.inv()*A == 1
示例5: HermitianOperator
from sympy.physics.quantum.dagger import Dagger
A = HermitianOperator('A')
B = HermitianOperator('B')
C = Operator('C')
D = Operator('D')
#E = Operator('E')
F = Operator('F')
G = Operator('G')
H = HermitianOperator('H')
I = IdentityOperator('I')
J = Operator('J')
K = Operator('K')
K_1 = Operator('K_1')
K_2 = Operator('K_2')
L = Operator('L')
L_1 = Operator('L_1')
L_2 = Operator('L_2')
M = Operator('M')
M_1 = Operator('M_1')
M_2 = Operator('M_2')
N = Operator('N')
O = Operator('O')
P = Operator('P')
#Q = Operator('Q')
Q_1 = Operator('Q_1')
Q_2 = Operator('Q_2')
R = Operator('R')
S = Operator('S')