def test_dagger():
    i, j, n, m = symbols('i,j,n,m')
    assert Dagger(1) == 1
    assert Dagger(1.0) == 1.0
    assert Dagger(2 * I) == -2 * I
    assert Dagger(Rational(1, 2) * I / 3.0) == -Rational(1, 2) * I / 3.0
    assert Dagger(BKet([n])) == BBra([n])
    assert Dagger(B(0)) == Bd(0)
    assert Dagger(Bd(0)) == B(0)
    assert Dagger(B(n)) == Bd(n)
    assert Dagger(Bd(n)) == B(n)
    assert Dagger(B(0) + B(1)) == Bd(0) + Bd(1)
    assert Dagger(n * m) == Dagger(n) * Dagger(m)  # n, m commute
    assert Dagger(B(n) * B(m)) == Bd(m) * Bd(n)
    assert Dagger(B(n)**10) == Dagger(B(n))**10
Ejemplo n.º 2
0
def test_commutation():
    n, m = symbols("n m", above_fermi=True)
    c = Commutator(B(0), Bd(0))
    assert c == 1
    c = Commutator(Bd(0), B(0))
    assert c == -1
    c = Commutator(B(n), Bd(0))
    assert c == KroneckerDelta(n, 0)
    c = Commutator(B(0), Bd(0))
    e = simplify(apply_operators(c * BKet([n])))
    assert e == BKet([n])
    c = Commutator(B(0), B(1))
    e = simplify(apply_operators(c * BKet([n, m])))
    assert e == 0

    c = Commutator(F(m), Fd(m))
    assert c == +1 - 2 * NO(Fd(m) * F(m))
    c = Commutator(Fd(m), F(m))
    assert c == -1 + 2 * NO(Fd(m) * F(m))

    C = Commutator
    X, Y, Z = symbols('XYZ', commutative=False)
    assert C(C(X, Y), Z) != 0
    assert C(C(X, Z), Y) != 0
    assert C(Y, C(X, Z)) != 0
    # assert (C(C(Y,Z),X).eval_nested() + C(C(Z,X),Y).eval_nested() + C(C(X,Y),Z).eval_nested()) == 0
    # assert (C(X,C(Y,Z)).eval_nested() + C(Y,C(Z,X)).eval_nested() + C(Z,C(X,Y)).eval_nested()) == 0

    i, j, k, l = symbols('ijkl', below_fermi=True)
    a, b, c, d = symbols('abcd', above_fermi=True)
    p, q, r, s = symbols('pqrs')
    D = KroneckerDelta

    assert C(Fd(a), F(i)) == -2 * NO(F(i) * Fd(a))
    assert C(Fd(j), NO(Fd(a) * F(i))).doit() == -D(j, i) * Fd(a)
    assert C(Fd(a) * F(i), Fd(b) * F(j)).doit() == 0
Ejemplo n.º 3
0
def test_dagger():
    i, j, n, m = symbols("i,j,n,m")
    assert Dagger(1) == 1
    assert Dagger(1.0) == 1.0
    assert Dagger(2 * I) == -2 * I
    assert Dagger(S.Half * I / 3.0) == I * Rational(-1, 2) / 3.0
    assert Dagger(BKet([n])) == BBra([n])
    assert Dagger(B(0)) == Bd(0)
    assert Dagger(Bd(0)) == B(0)
    assert Dagger(B(n)) == Bd(n)
    assert Dagger(Bd(n)) == B(n)
    assert Dagger(B(0) + B(1)) == Bd(0) + Bd(1)
    assert Dagger(n * m) == Dagger(n) * Dagger(m)  # n, m commute
    assert Dagger(B(n) * B(m)) == Bd(m) * Bd(n)
    assert Dagger(B(n) ** 10) == Dagger(B(n)) ** 10
    assert Dagger("a") == Dagger(Symbol("a"))
    assert Dagger(Dagger("a")) == Symbol("a")
Ejemplo n.º 4
0
def test_number_operator():
    n = symbols("n")
    o = Bd(0) * B(0)
    e = apply_operators(o * BKet([n]))
    assert e == n * BKet([n])
Ejemplo n.º 5
0
def test_complex_apply():
    n, m = symbols("n,m")
    o = Bd(0) * B(0) * Bd(1) * B(0)
    e = apply_operators(o * BKet([n, m]))
    answer = sqrt(n) * sqrt(m + 1) * (-1 + n) * BKet([-1 + n, 1 + m])
    assert expand(e) == expand(answer)
Ejemplo n.º 6
0
def test_basic_apply():
    n = symbols("n")
    e = B(0) * BKet([n])
    assert apply_operators(e) == sqrt(n) * BKet([n - 1])
    e = Bd(0) * BKet([n])
    assert apply_operators(e) == sqrt(n + 1) * BKet([n + 1])