本文整理汇总了Python中sympy.adjoint函数的典型用法代码示例。如果您正苦于以下问题:Python adjoint函数的具体用法?Python adjoint怎么用?Python adjoint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了adjoint函数的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_heaviside
def test_heaviside():
assert Heaviside(0).func == Heaviside
assert Heaviside(-5) == 0
assert Heaviside(1) == 1
assert Heaviside(nan) == nan
assert Heaviside(0, x) == x
assert Heaviside(0, nan) == nan
assert Heaviside(x, None) == Heaviside(x)
assert Heaviside(0, None) == Heaviside(0)
# we do not want None in the args:
assert None not in Heaviside(x, None).args
assert adjoint(Heaviside(x)) == Heaviside(x)
assert adjoint(Heaviside(x - y)) == Heaviside(x - y)
assert conjugate(Heaviside(x)) == Heaviside(x)
assert conjugate(Heaviside(x - y)) == Heaviside(x - y)
assert transpose(Heaviside(x)) == Heaviside(x)
assert transpose(Heaviside(x - y)) == Heaviside(x - y)
assert Heaviside(x).diff(x) == DiracDelta(x)
assert Heaviside(x + I).is_Function is True
assert Heaviside(I*x).is_Function is True
raises(ArgumentIndexError, lambda: Heaviside(x).fdiff(2))
raises(ValueError, lambda: Heaviside(I))
raises(ValueError, lambda: Heaviside(2 + 3*I))
示例2: test_DiracDelta
def test_DiracDelta():
assert DiracDelta(1) == 0
assert DiracDelta(5.1) == 0
assert DiracDelta(-pi) == 0
assert DiracDelta(5, 7) == 0
assert DiracDelta(nan) == nan
assert DiracDelta(0).func is DiracDelta
assert DiracDelta(x).func is DiracDelta
assert adjoint(DiracDelta(x)) == DiracDelta(x)
assert adjoint(DiracDelta(x - y)) == DiracDelta(x - y)
assert conjugate(DiracDelta(x)) == DiracDelta(x)
assert conjugate(DiracDelta(x - y)) == DiracDelta(x - y)
assert transpose(DiracDelta(x)) == DiracDelta(x)
assert transpose(DiracDelta(x - y)) == DiracDelta(x - y)
assert DiracDelta(x).diff(x) == DiracDelta(x, 1)
assert DiracDelta(x, 1).diff(x) == DiracDelta(x, 2)
assert DiracDelta(x).is_simple(x) is True
assert DiracDelta(3*x).is_simple(x) is True
assert DiracDelta(x**2).is_simple(x) is False
assert DiracDelta(sqrt(x)).is_simple(x) is False
assert DiracDelta(x).is_simple(y) is False
assert DiracDelta(x*y).simplify(x) == DiracDelta(x)/abs(y)
assert DiracDelta(x*y).simplify(y) == DiracDelta(y)/abs(x)
assert DiracDelta(x**2*y).simplify(x) == DiracDelta(x**2*y)
assert DiracDelta(y).simplify(x) == DiracDelta(y)
assert DiracDelta((x - 1)*(x - 2)*(x - 3)).simplify(x) == \
DiracDelta(x - 3)/2 + DiracDelta(x - 2) + DiracDelta(x - 1)/2
raises(ArgumentIndexError, lambda: DiracDelta(x).fdiff(2))
raises(ValueError, lambda: DiracDelta(x, -1))
示例3: test_DiracDelta
def test_DiracDelta():
assert DiracDelta(1) == 0
assert DiracDelta(5.1) == 0
assert DiracDelta(-pi) == 0
assert DiracDelta(5, 7) == 0
assert DiracDelta(i) == 0
assert DiracDelta(j) == 0
assert DiracDelta(k) == 0
assert DiracDelta(nan) == nan
assert DiracDelta(0).func is DiracDelta
assert DiracDelta(x).func is DiracDelta
# FIXME: this is generally undefined @ x=0
# But then limit(Delta(c)*Heaviside(x),x,-oo)
# need's to be implemented.
#assert 0*DiracDelta(x) == 0
assert adjoint(DiracDelta(x)) == DiracDelta(x)
assert adjoint(DiracDelta(x - y)) == DiracDelta(x - y)
assert conjugate(DiracDelta(x)) == DiracDelta(x)
assert conjugate(DiracDelta(x - y)) == DiracDelta(x - y)
assert transpose(DiracDelta(x)) == DiracDelta(x)
assert transpose(DiracDelta(x - y)) == DiracDelta(x - y)
assert DiracDelta(x).diff(x) == DiracDelta(x, 1)
assert DiracDelta(x, 1).diff(x) == DiracDelta(x, 2)
assert DiracDelta(x).is_simple(x) is True
assert DiracDelta(3*x).is_simple(x) is True
assert DiracDelta(x**2).is_simple(x) is False
assert DiracDelta(sqrt(x)).is_simple(x) is False
assert DiracDelta(x).is_simple(y) is False
assert DiracDelta(x*y).expand(diracdelta=True, wrt=x) == DiracDelta(x)/abs(y)
assert DiracDelta(x*y).expand(diracdelta=True, wrt=y) == DiracDelta(y)/abs(x)
assert DiracDelta(x**2*y).expand(diracdelta=True, wrt=x) == DiracDelta(x**2*y)
assert DiracDelta(y).expand(diracdelta=True, wrt=x) == DiracDelta(y)
assert DiracDelta((x - 1)*(x - 2)*(x - 3)).expand(diracdelta=True, wrt=x) == (
DiracDelta(x - 3)/2 + DiracDelta(x - 2) + DiracDelta(x - 1)/2)
assert DiracDelta(2*x) != DiracDelta(x) # scaling property
assert DiracDelta(x) == DiracDelta(-x) # even function
assert DiracDelta(-x, 2) == DiracDelta(x, 2)
assert DiracDelta(-x, 1) == -DiracDelta(x, 1) # odd deriv is odd
assert DiracDelta(-oo*x) == DiracDelta(oo*x)
assert DiracDelta(x - y) != DiracDelta(y - x)
assert signsimp(DiracDelta(x - y) - DiracDelta(y - x)) == 0
with raises(SymPyDeprecationWarning):
assert DiracDelta(x*y).simplify(x) == DiracDelta(x)/abs(y)
assert DiracDelta(x*y).simplify(y) == DiracDelta(y)/abs(x)
assert DiracDelta(x**2*y).simplify(x) == DiracDelta(x**2*y)
assert DiracDelta(y).simplify(x) == DiracDelta(y)
assert DiracDelta((x - 1)*(x - 2)*(x - 3)).simplify(x) == (
DiracDelta(x - 3)/2 + DiracDelta(x - 2) + DiracDelta(x - 1)/2)
raises(ArgumentIndexError, lambda: DiracDelta(x).fdiff(2))
raises(ValueError, lambda: DiracDelta(x, -1))
raises(ValueError, lambda: DiracDelta(I))
raises(ValueError, lambda: DiracDelta(2 + 3*I))
示例4: test_conjugate_transpose
def test_conjugate_transpose():
A, B = symbols("A B", commutative=False)
p = Piecewise((A*B**2, x > 0), (A**2*B, True))
assert p.adjoint() == \
Piecewise((adjoint(A*B**2), x > 0), (adjoint(A**2*B), True))
assert p.conjugate() == \
Piecewise((conjugate(A*B**2), x > 0), (conjugate(A**2*B), True))
assert p.transpose() == \
Piecewise((transpose(A*B**2), x > 0), (transpose(A**2*B), True))
示例5: test_kronecker_delta
def test_kronecker_delta():
i, j = symbols('i j')
k = Symbol('k', nonzero=True)
assert KroneckerDelta(1, 1) == 1
assert KroneckerDelta(1, 2) == 0
assert KroneckerDelta(k, 0) == 0
assert KroneckerDelta(x, x) == 1
assert KroneckerDelta(x**2 - y**2, x**2 - y**2) == 1
assert KroneckerDelta(i, i) == 1
assert KroneckerDelta(i, i + 1) == 0
assert KroneckerDelta(0, 0) == 1
assert KroneckerDelta(0, 1) == 0
assert KroneckerDelta(i + k, i) == 0
assert KroneckerDelta(i + k, i + k) == 1
assert KroneckerDelta(i + k, i + 1 + k) == 0
assert KroneckerDelta(i, j).subs(dict(i=1, j=0)) == 0
assert KroneckerDelta(i, j).subs(dict(i=3, j=3)) == 1
assert KroneckerDelta(i, j)**0 == 1
for n in range(1, 10):
assert KroneckerDelta(i, j)**n == KroneckerDelta(i, j)
assert KroneckerDelta(i, j)**-n == 1/KroneckerDelta(i, j)
assert KroneckerDelta(i, j).is_integer is True
assert adjoint(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
assert conjugate(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
assert transpose(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
# to test if canonical
assert (KroneckerDelta(i, j) == KroneckerDelta(j, i)) == True
示例6: test_heaviside
def test_heaviside():
assert Heaviside(0) == 0.5
assert Heaviside(-5) == 0
assert Heaviside(1) == 1
assert Heaviside(nan) == nan
assert adjoint(Heaviside(x)) == Heaviside(x)
assert adjoint(Heaviside(x - y)) == Heaviside(x - y)
assert conjugate(Heaviside(x)) == Heaviside(x)
assert conjugate(Heaviside(x - y)) == Heaviside(x - y)
assert transpose(Heaviside(x)) == Heaviside(x)
assert transpose(Heaviside(x - y)) == Heaviside(x - y)
assert Heaviside(x).diff(x) == DiracDelta(x)
assert Heaviside(x + I).is_Function is True
assert Heaviside(I*x).is_Function is True
raises(ArgumentIndexError, lambda: Heaviside(x).fdiff(2))
raises(ValueError, lambda: Heaviside(I))
raises(ValueError, lambda: Heaviside(2 + 3*I))
示例7: test_levicivita
def test_levicivita():
assert Eijk(1, 2, 3) == LeviCivita(1, 2, 3)
assert LeviCivita(1, 2, 3) == 1
assert LeviCivita(1, 3, 2) == -1
assert LeviCivita(1, 2, 2) == 0
i, j, k = symbols('i j k')
assert LeviCivita(i, j, k) == LeviCivita(i, j, k, evaluate=False)
assert LeviCivita(i, j, i) == 0
assert LeviCivita(1, i, i) == 0
assert LeviCivita(i, j, k).doit() == (j - i)*(k - i)*(k - j)/2
assert LeviCivita(1, 2, 3, 1) == 0
assert LeviCivita(4, 5, 1, 2, 3) == 1
assert LeviCivita(4, 5, 2, 1, 3) == -1
assert LeviCivita(i, j, k).is_integer is True
assert adjoint(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
assert conjugate(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
assert transpose(LeviCivita(i, j, k)) == LeviCivita(i, j, k)
示例8: test_conjugate_transpose
def test_conjugate_transpose():
x = Symbol('x')
assert conjugate(transpose(x)) == adjoint(x)
assert transpose(conjugate(x)) == adjoint(x)
assert adjoint(transpose(x)) == conjugate(x)
assert transpose(adjoint(x)) == conjugate(x)
assert adjoint(conjugate(x)) == transpose(x)
assert conjugate(adjoint(x)) == transpose(x)
class Symmetric(Expr):
def _eval_adjoint(self):
return None
def _eval_conjugate(self):
return None
def _eval_transpose(self):
return self
x = Symmetric()
assert conjugate(x) == adjoint(x)
assert transpose(x) == x
示例9: test_kronecker_delta
def test_kronecker_delta():
i, j = symbols('i j')
k = Symbol('k', nonzero=True)
assert KroneckerDelta(1, 1) == 1
assert KroneckerDelta(1, 2) == 0
assert KroneckerDelta(x, x) == 1
assert KroneckerDelta(x**2 - y**2, x**2 - y**2) == 1
assert KroneckerDelta(i, i) == 1
assert KroneckerDelta(i, i + 1) == 0
assert KroneckerDelta(0, 0) == 1
assert KroneckerDelta(0, 1) == 0
assert KroneckerDelta(i + k, i) == KroneckerDelta(0, k)
assert KroneckerDelta(i + k, i + k) == 1
assert KroneckerDelta(i + k, i + 1 + k) == 0
assert KroneckerDelta(i, j).subs(dict(i=1, j=0)) == 0
assert KroneckerDelta(i, j).subs(dict(i=3, j=3)) == 1
assert KroneckerDelta(i, j).is_integer is True
assert adjoint(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
assert conjugate(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
assert transpose(KroneckerDelta(i, j)) == KroneckerDelta(i, j)
示例10: test_adjoint
def test_adjoint():
a = Symbol('a', antihermitian=True)
b = Symbol('b', hermitian=True)
assert adjoint(a) == -a
assert adjoint(I*a) == I*a
assert adjoint(b) == b
assert adjoint(I*b) == -I*b
assert adjoint(a*b) == -b*a
assert adjoint(I*a*b) == I*b*a
x, y = symbols('x y')
assert adjoint(adjoint(x)) == x
assert adjoint(x + y) == adjoint(x) + adjoint(y)
assert adjoint(x - y) == adjoint(x) - adjoint(y)
assert adjoint(x * y) == adjoint(x) * adjoint(y)
assert adjoint(x / y) == adjoint(x) / adjoint(y)
assert adjoint(-x) == -adjoint(x)
x, y = symbols('x y', commutative=False)
assert adjoint(adjoint(x)) == x
assert adjoint(x + y) == adjoint(x) + adjoint(y)
assert adjoint(x - y) == adjoint(x) - adjoint(y)
assert adjoint(x * y) == adjoint(y) * adjoint(x)
assert adjoint(x / y) == 1 / adjoint(y) * adjoint(x)
assert adjoint(-x) == -adjoint(x)
示例11: test_array_permutedims
def test_array_permutedims():
sa = symbols('a0:144')
m1 = Array(sa[:6], (2, 3))
assert permutedims(m1, (1, 0)) == transpose(m1)
assert m1.tomatrix().T == permutedims(m1, (1, 0)).tomatrix()
assert m1.tomatrix().T == transpose(m1).tomatrix()
assert m1.tomatrix().C == conjugate(m1).tomatrix()
assert m1.tomatrix().H == adjoint(m1).tomatrix()
assert m1.tomatrix().T == m1.transpose().tomatrix()
assert m1.tomatrix().C == m1.conjugate().tomatrix()
assert m1.tomatrix().H == m1.adjoint().tomatrix()
raises(ValueError, lambda: permutedims(m1, (0,)))
raises(ValueError, lambda: permutedims(m1, (0, 0)))
raises(ValueError, lambda: permutedims(m1, (1, 2, 0)))
# Some tests with random arrays:
dims = 6
shape = [random.randint(1,5) for i in range(dims)]
elems = [random.random() for i in range(tensorproduct(*shape))]
ra = Array(elems, shape)
perm = list(range(dims))
# Randomize the permutation:
random.shuffle(perm)
# Test inverse permutation:
assert permutedims(permutedims(ra, perm), _af_invert(perm)) == ra
# Test that permuted shape corresponds to action by `Permutation`:
assert permutedims(ra, perm).shape == tuple(Permutation(perm)(shape))
z = Array.zeros(4,5,6,7)
assert permutedims(z, (2, 3, 1, 0)).shape == (6, 7, 5, 4)
assert permutedims(z, [2, 3, 1, 0]).shape == (6, 7, 5, 4)
assert permutedims(z, Permutation([2, 3, 1, 0])).shape == (6, 7, 5, 4)
po = Array(sa, [2, 2, 3, 3, 2, 2])
raises(ValueError, lambda: permutedims(po, (1, 1)))
raises(ValueError, lambda: po.transpose())
raises(ValueError, lambda: po.adjoint())
assert permutedims(po, reversed(range(po.rank()))) == Array(
[[[[[[sa[0], sa[72]], [sa[36], sa[108]]], [[sa[12], sa[84]], [sa[48], sa[120]]], [[sa[24],
sa[96]], [sa[60], sa[132]]]],
[[[sa[4], sa[76]], [sa[40], sa[112]]], [[sa[16],
sa[88]], [sa[52], sa[124]]],
[[sa[28], sa[100]], [sa[64], sa[136]]]],
[[[sa[8],
sa[80]], [sa[44], sa[116]]], [[sa[20], sa[92]], [sa[56], sa[128]]], [[sa[32],
sa[104]], [sa[68], sa[140]]]]],
[[[[sa[2], sa[74]], [sa[38], sa[110]]], [[sa[14],
sa[86]], [sa[50], sa[122]]], [[sa[26], sa[98]], [sa[62], sa[134]]]],
[[[sa[6],
sa[78]], [sa[42], sa[114]]], [[sa[18], sa[90]], [sa[54], sa[126]]], [[sa[30],
sa[102]], [sa[66], sa[138]]]],
[[[sa[10], sa[82]], [sa[46], sa[118]]], [[sa[22],
sa[94]], [sa[58], sa[130]]],
[[sa[34], sa[106]], [sa[70], sa[142]]]]]],
[[[[[sa[1],
sa[73]], [sa[37], sa[109]]], [[sa[13], sa[85]], [sa[49], sa[121]]], [[sa[25],
sa[97]], [sa[61], sa[133]]]],
[[[sa[5], sa[77]], [sa[41], sa[113]]], [[sa[17],
sa[89]], [sa[53], sa[125]]],
[[sa[29], sa[101]], [sa[65], sa[137]]]],
[[[sa[9],
sa[81]], [sa[45], sa[117]]], [[sa[21], sa[93]], [sa[57], sa[129]]], [[sa[33],
sa[105]], [sa[69], sa[141]]]]],
[[[[sa[3], sa[75]], [sa[39], sa[111]]], [[sa[15],
sa[87]], [sa[51], sa[123]]], [[sa[27], sa[99]], [sa[63], sa[135]]]],
[[[sa[7],
sa[79]], [sa[43], sa[115]]], [[sa[19], sa[91]], [sa[55], sa[127]]], [[sa[31],
sa[103]], [sa[67], sa[139]]]],
[[[sa[11], sa[83]], [sa[47], sa[119]]], [[sa[23],
sa[95]], [sa[59], sa[131]]],
[[sa[35], sa[107]], [sa[71], sa[143]]]]]]])
assert permutedims(po, (1, 0, 2, 3, 4, 5)) == Array(
[[[[[[sa[0], sa[1]], [sa[2], sa[3]]], [[sa[4], sa[5]], [sa[6], sa[7]]], [[sa[8], sa[9]], [sa[10],
sa[11]]]],
[[[sa[12], sa[13]], [sa[14], sa[15]]], [[sa[16], sa[17]], [sa[18],
sa[19]]], [[sa[20], sa[21]], [sa[22], sa[23]]]],
[[[sa[24], sa[25]], [sa[26],
sa[27]]], [[sa[28], sa[29]], [sa[30], sa[31]]], [[sa[32], sa[33]], [sa[34],
sa[35]]]]],
[[[[sa[72], sa[73]], [sa[74], sa[75]]], [[sa[76], sa[77]], [sa[78],
sa[79]]], [[sa[80], sa[81]], [sa[82], sa[83]]]],
[[[sa[84], sa[85]], [sa[86],
sa[87]]], [[sa[88], sa[89]], [sa[90], sa[91]]], [[sa[92], sa[93]], [sa[94],
sa[95]]]],
[[[sa[96], sa[97]], [sa[98], sa[99]]], [[sa[100], sa[101]], [sa[102],
sa[103]]],
[[sa[104], sa[105]], [sa[106], sa[107]]]]]], [[[[[sa[36], sa[37]], [sa[38],
sa[39]]],
[[sa[40], sa[41]], [sa[42], sa[43]]],
[[sa[44], sa[45]], [sa[46],
sa[47]]]],
[[[sa[48], sa[49]], [sa[50], sa[51]]],
#.........这里部分代码省略.........
示例12: test_adjoint
def test_adjoint():
assert adjoint(A).is_commutative is False
assert adjoint(A*A) == adjoint(A)**2
assert adjoint(A*B) == adjoint(B)*adjoint(A)
assert adjoint(A*B**2) == adjoint(B)**2*adjoint(A)
assert adjoint(A*B - B*A) == adjoint(B)*adjoint(A) - adjoint(A)*adjoint(B)
assert adjoint(A + I*B) == adjoint(A) - I*adjoint(B)
assert adjoint(X) == X
assert adjoint(-I*X) == I*X
assert adjoint(Y) == -Y
assert adjoint(-I*Y) == -I*Y
assert adjoint(X) == conjugate(transpose(X))
assert adjoint(Y) == conjugate(transpose(Y))
assert adjoint(X) == transpose(conjugate(X))
assert adjoint(Y) == transpose(conjugate(Y))