def test_equivalent_internal_lines_VT2conjT2_ambiguous_order():
    # These diagrams invokes _determine_ambiguous() because the
    # dummies can not be ordered unambiguously by the key alone
    i, j, k, l, m, n = symbols('i j k l m n', below_fermi=True, cls=Dummy)
    a, b, c, d, e, f = symbols('a b c d e f', above_fermi=True, cls=Dummy)
    p1, p2, p3, p4 = symbols('p1 p2 p3 p4', above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols('h1 h2 h3 h4', below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    # v(abcd)t(abij)t(cdij)
    template = v(p1, p2, p3, p4)*t(p1, p2, i, j)*t(p3, p4, i, j)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = v(p1, p2, p3, p4)*t(p1, p2, j, i)*t(p3, p4, i, j)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
def test_index_permutations_with_dummies():
    a, b, c, d = symbols('a b c d')
    p, q, r, s = symbols('p q r s', cls=Dummy)
    f, g = map(Function, 'fg')
    P = PermutationOperator

    # No dummy substitution necessary
    expr = f(a, b, p, q) - f(b, a, p, q)
    assert simplify_index_permutations(
        expr, [P(a, b)]) == P(a, b)*f(a, b, p, q)

    # Cases where dummy substitution is needed
    expected = P(a, b)*substitute_dummies(f(a, b, p, q))

    expr = f(a, b, p, q) - f(b, a, q, p)
    result = simplify_index_permutations(expr, [P(a, b)])
    assert expected == substitute_dummies(result)

    expr = f(a, b, q, p) - f(b, a, p, q)
    result = simplify_index_permutations(expr, [P(a, b)])
    assert expected == substitute_dummies(result)

    # A case where nothing can be done
    expr = f(a, b, q, p) - g(b, a, p, q)
    result = simplify_index_permutations(expr, [P(a, b)])
    assert expr == result
def test_dummy_order_inner_outer_lines_VT1T1T1T1_AT():
    ii, jj = symbols('i j', below_fermi=True)
    aa, bb = symbols('a b', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    # Coupled-Cluster T2 terms with V*T1*T1*T1*T1
    # non-equivalent substitutions (change of sign)
    exprs = [
        # permut t <=> swapping external lines
        atv(k, l, c, d)*att(c, ii)*att(d, jj)*att(aa, k)*att(bb, l),
        atv(k, l, c, d)*att(c, jj)*att(d, ii)*att(aa, k)*att(bb, l),
        atv(k, l, c, d)*att(c, ii)*att(d, jj)*att(bb, k)*att(aa, l),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == -substitute_dummies(permut)

    # equivalent substitutions
    exprs = [
        atv(k, l, c, d)*att(c, ii)*att(d, jj)*att(aa, k)*att(bb, l),
        # permut t <=> swapping external lines
        atv(k, l, c, d)*att(c, jj)*att(d, ii)*att(bb, k)*att(aa, l),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#4
0
def test_equivalent_internal_lines_VT2conjT2_ambiguous_order_AT():
    # These diagrams invokes _determine_ambiguous() because the
    # dummies can not be ordered unambiguously by the key alone
    i, j, k, l, m, n = symbols("i j k l m n", below_fermi=True, cls=Dummy)
    a, b, c, d, e, f = symbols("a b c d e f", above_fermi=True, cls=Dummy)
    p1, p2, p3, p4 = symbols("p1 p2 p3 p4", above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols("h1 h2 h3 h4", below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations

    # atv(abcd)att(abij)att(cdij)
    template = atv(p1, p2, p3, p4) * att(p1, p2, i, j) * att(p3, p4, i, j)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = atv(p1, p2, p3, p4) * att(p1, p2, j, i) * att(p3, p4, i, j)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#5
0
def test_equivalent_internal_lines_VT1T1_AT():
    i, j, k, l = symbols('i j k l', below_fermi=True, cls=Dummy)
    a, b, c, d = symbols('a b c d', above_fermi=True, cls=Dummy)

    exprs = [  # permute v.  Different dummy order. Not equivalent.
        atv(i, j, a, b) * att(a, i) * att(b, j),
        atv(j, i, a, b) * att(a, i) * att(b, j),
        atv(i, j, b, a) * att(a, i) * att(b, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v.  Different dummy order. Equivalent
        atv(i, j, a, b) * att(a, i) * att(b, j),
        atv(j, i, b, a) * att(a, i) * att(b, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)

    exprs = [  # permute t.  Same dummy order, not equivalent.
        atv(i, j, a, b) * att(a, i) * att(b, j),
        atv(i, j, a, b) * att(b, i) * att(a, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Different dummy order, equivalent
        atv(i, j, a, b) * att(a, i) * att(b, j),
        atv(j, i, a, b) * att(a, j) * att(b, i),
        atv(i, j, b, a) * att(b, i) * att(a, j),
        atv(j, i, b, a) * att(b, j) * att(a, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def test_equivalent_internal_lines_VT1T1_AT():
    i, j, k, l = symbols('i j k l', below_fermi=True, cls=Dummy)
    a, b, c, d = symbols('a b c d', above_fermi=True, cls=Dummy)

    exprs = [  # permute v.  Different dummy order. Not equivalent.
        atv(i, j, a, b)*att(a, i)*att(b, j),
        atv(j, i, a, b)*att(a, i)*att(b, j),
        atv(i, j, b, a)*att(a, i)*att(b, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v.  Different dummy order. Equivalent
        atv(i, j, a, b)*att(a, i)*att(b, j),
        atv(j, i, b, a)*att(a, i)*att(b, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)

    exprs = [  # permute t.  Same dummy order, not equivalent.
        atv(i, j, a, b)*att(a, i)*att(b, j),
        atv(i, j, a, b)*att(b, i)*att(a, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Different dummy order, equivalent
        atv(i, j, a, b)*att(a, i)*att(b, j),
        atv(j, i, a, b)*att(a, j)*att(b, i),
        atv(i, j, b, a)*att(b, i)*att(a, j),
        atv(j, i, b, a)*att(b, j)*att(a, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def test_internal_external_pqrs_AT():
    ii, jj = symbols('i j')
    aa, bb = symbols('a b')
    k, l = symbols('k l', cls=Dummy)
    c, d = symbols('c d', cls=Dummy)

    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def test_internal_external_pqrs_AT():
    ii, jj = symbols('i j')
    aa, bb = symbols('a b')
    k, l = symbols('k l', cls=Dummy)
    c, d = symbols('c d', cls=Dummy)

    exprs = [
        atv(k, l, c, d)*att(aa, c, ii, k)*att(bb, d, jj, l),
        atv(l, k, c, d)*att(aa, c, ii, l)*att(bb, d, jj, k),
        atv(k, l, d, c)*att(aa, d, ii, k)*att(bb, c, jj, l),
        atv(l, k, d, c)*att(aa, d, ii, l)*att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#9
0
def test_substitute_dummies_substitution_order():
    i, j, k, l = symbols("i j k l", below_fermi=True, cls=Dummy)
    f = Function("f")
    from sympy.utilities.iterables import variations

    for permut in variations([i, j, k, l], 4):
        assert substitute_dummies(f(*permut) - f(i, j, k, l)) == 0
示例#10
0
def test_substitute_dummies_substitution_order():
    i, j, k, l = symbols("i j k l", below_fermi=True, cls=Dummy)
    f = Function("f")
    from sympy.utilities.iterables import variations

    for permut in variations([i, j, k, l], 4):
        assert substitute_dummies(f(*permut) - f(i, j, k, l)) == 0
示例#11
0
def test_dummy_order_inner_outer_lines_VT1T1T1_AT():
    ii = symbols('i', below_fermi=True)
    aa = symbols('a', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    # Coupled-Cluster T1 terms with V*T1*T1*T1
    # t^{a}_{k} t^{c}_{i} t^{d}_{l} v^{lk}_{dc}
    exprs = [
        # permut v and t <=> swapping internal lines, equivalent
        # irrespective of symmetries in v
        atv(k, l, c, d)*att(c, ii)*att(d, l)*att(aa, k),
        atv(l, k, c, d)*att(c, ii)*att(d, k)*att(aa, l),
        atv(k, l, d, c)*att(d, ii)*att(c, l)*att(aa, k),
        atv(l, k, d, c)*att(d, ii)*att(c, k)*att(aa, l),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#12
0
def test_dummy_order_inner_outer_lines_VT1T1T1_AT():
    ii = symbols("i", below_fermi=True)
    aa = symbols("a", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    # Coupled-Cluster T1 terms with V*T1*T1*T1
    # t^{a}_{k} t^{c}_{i} t^{d}_{l} v^{lk}_{dc}
    exprs = [
        # permut v and t <=> swapping internal lines, equivalent
        # irrespective of symmetries in v
        atv(k, l, c, d) * att(c, ii) * att(d, l) * att(aa, k),
        atv(l, k, c, d) * att(c, ii) * att(d, k) * att(aa, l),
        atv(k, l, d, c) * att(d, ii) * att(c, l) * att(aa, k),
        atv(l, k, d, c) * att(d, ii) * att(c, k) * att(aa, l),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def get_two_body_equation(equation_h, equation_u):
    two_body_eq = wicks(
        Fd(j) * F(b) * Fd(i) * F(a) * equation_u, **wicks_kwargs)

    p = PermutationOperator
    two_body_eq = simplify_index_permutations(two_body_eq, [p(i, j), p(a, b)])
    two_body_eq = substitute_dummies(two_body_eq, **sub_kwargs)

    return two_body_eq
def get_one_body_equation(equation_h, equation_u):
    one_body_eq = wicks(
        Fd(j) * F(b) * Fd(i) * F(a) * equation_h, **wicks_kwargs)

    p = PermutationOperator
    one_body_eq = simplify_index_permutations(one_body_eq, [p(a, b), p(i, j)])
    one_body_eq = substitute_dummies(one_body_eq, **sub_kwargs)

    return one_body_eq
示例#15
0
文件: BCH.py 项目: sgulania/SQ2EOM
def level(H, expr):

    pretty_dummies_dict = {
        'above': 'defg',
        'below': 'lmno',
        'general': 'pqrst'
    }

    #display(Markdown
    #    (rf"""Calculating 4 nested commutators"""))
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq,
                            new_indices=True,
                            pretty_indices=pretty_dummies_dict)

    return eq
示例#16
0
def test_internal_external_pqrs():
    ii, jj = symbols("i j")
    aa, bb = symbols("a b")
    k, l = symbols("k l", cls=Dummy)
    c, d = symbols("c d", cls=Dummy)

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d) * t(aa, c, ii, k) * t(bb, d, jj, l),
        v(l, k, c, d) * t(aa, c, ii, l) * t(bb, d, jj, k),
        v(k, l, d, c) * t(aa, d, ii, k) * t(bb, c, jj, l),
        v(l, k, d, c) * t(aa, d, ii, l) * t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def computeHausdorff(H):

    print("Calculating 4 nested commutators")
    C = Commutator

    T1, T2 = get_T_operators()
    T = T2
    print("commutator 1...")
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_T_operators()
    T = T2
    print("commutator 2...")
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_T_operators()
    T = T2
    print("commutator 3...")
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_T_operators()
    T = T2
    print("commutator 4...")
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    print("construct Hausdorff expansion...")
    eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq,
                            new_indices=True,
                            pretty_indices=pretty_dummies_dict)
    print("*********************")
    print()
    return eq
示例#18
0
def test_internal_external_pqrs():
    ii, jj = symbols("i j")
    aa, bb = symbols("a b")
    k, l = symbols("k l", cls=Dummy)
    c, d = symbols("c d", cls=Dummy)

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d) * t(aa, c, ii, k) * t(bb, d, jj, l),
        v(l, k, c, d) * t(aa, c, ii, l) * t(bb, d, jj, k),
        v(k, l, d, c) * t(aa, d, ii, k) * t(bb, c, jj, l),
        v(l, k, d, c) * t(aa, d, ii, l) * t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#19
0
def test_internal_external_pqrs():
    ii, jj = symbols('i j')
    aa, bb = symbols('a b')
    k, l = symbols('k l', cls=Dummy)
    c, d = symbols('c d', cls=Dummy)

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d)*t(aa, c, ii, k)*t(bb, d, jj, l),
        v(l, k, c, d)*t(aa, c, ii, l)*t(bb, d, jj, k),
        v(k, l, d, c)*t(aa, d, ii, k)*t(bb, c, jj, l),
        v(l, k, d, c)*t(aa, d, ii, l)*t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#20
0
def test_internal_external_pqrs():
    ii, jj = symbols('i j')
    aa, bb = symbols('a b')
    k, l = symbols('k l', cls=Dummy)
    c, d = symbols('c d', cls=Dummy)

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d)*t(aa, c, ii, k)*t(bb, d, jj, l),
        v(l, k, c, d)*t(aa, c, ii, l)*t(bb, d, jj, k),
        v(k, l, d, c)*t(aa, d, ii, k)*t(bb, c, jj, l),
        v(l, k, d, c)*t(aa, d, ii, l)*t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
def compute_hausdorff(h, cluster_func, num_terms=4):
    commutator = Commutator
    comm_term = h

    equation = comm_term

    for i in range(num_terms):
        t = sum(cluster_func())

        comm_term = wicks(commutator(comm_term, t))
        comm_term = substitute_dummies(evaluate_deltas(comm_term))

        equation += comm_term / factorial(i + 1)

    equation = equation.expand()
    equation = evaluate_deltas(equation)
    equation = substitute_dummies(equation,
                                  new_indices=True,
                                  pretty_indices=pretty_dummies)

    return equation
示例#22
0
def test_equivalent_internal_lines_VT2_AT():
    i, j, k, l = symbols("i j k l", below_fermi=True, cls=Dummy)
    a, b, c, d = symbols("a b c d", above_fermi=True, cls=Dummy)

    exprs = [
        # permute v. Same dummy order, not equivalent.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(j, i, a, b) * att(a, b, i, j),
        atv(i, j, b, a) * att(a, b, i, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [
        # permute t.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(i, j, a, b) * att(b, a, i, j),
        atv(i, j, a, b) * att(a, b, j, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Relabelling of dummies should be equivalent.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(j, i, a, b) * att(a, b, j, i),
        atv(i, j, b, a) * att(b, a, i, j),
        atv(j, i, b, a) * att(b, a, j, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#23
0
def test_internal_external_VT2T2_AT():
    ii, jj = symbols("i j", below_fermi=True)
    aa, bb = symbols("a b", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    dums = _get_ordered_dummies

    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(d, bb, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(d, bb, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(c, bb, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(c, aa, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(c, aa, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(d, aa, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(d, aa, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#24
0
def test_internal_external_VT2T2_AT():
    ii, jj = symbols('ij', below_fermi=True)
    aa, bb = symbols('ab', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    dums = _get_ordered_dummies

    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(d, bb, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(d, bb, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(c, bb, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(c, aa, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(c, aa, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(d, aa, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(d, aa, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#25
0
def test_internal_external_VT2T2_AT():
    ii, jj = symbols("i j", below_fermi=True)
    aa, bb = symbols("a b", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(aa, c, ii, k) * att(d, bb, jj, l),
        atv(l, k, c, d) * att(aa, c, ii, l) * att(d, bb, jj, k),
        atv(k, l, d, c) * att(aa, d, ii, k) * att(c, bb, jj, l),
        atv(l, k, d, c) * att(aa, d, ii, l) * att(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d) * att(c, aa, ii, k) * att(bb, d, jj, l),
        atv(l, k, c, d) * att(c, aa, ii, l) * att(bb, d, jj, k),
        atv(k, l, d, c) * att(d, aa, ii, k) * att(bb, c, jj, l),
        atv(l, k, d, c) * att(d, aa, ii, l) * att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#26
0
def test_equivalent_internal_lines_VT2_AT():
    i, j, k, l = symbols("i j k l", below_fermi=True, cls=Dummy)
    a, b, c, d = symbols("a b c d", above_fermi=True, cls=Dummy)

    exprs = [
        # permute v. Same dummy order, not equivalent.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(j, i, a, b) * att(a, b, i, j),
        atv(i, j, b, a) * att(a, b, i, j),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [
        # permute t.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(i, j, a, b) * att(b, a, i, j),
        atv(i, j, a, b) * att(a, b, j, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Relabelling of dummies should be equivalent.
        atv(i, j, a, b) * att(a, b, i, j),
        atv(j, i, a, b) * att(a, b, j, i),
        atv(i, j, b, a) * att(b, a, i, j),
        atv(j, i, b, a) * att(b, a, j, i),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#27
0
def test_internal_external_VT2T2_AT():
    ii, jj = symbols('i j', below_fermi=True)
    aa, bb = symbols('a b', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    exprs = [
        atv(k, l, c, d)*att(aa, c, ii, k)*att(bb, d, jj, l),
        atv(l, k, c, d)*att(aa, c, ii, l)*att(bb, d, jj, k),
        atv(k, l, d, c)*att(aa, d, ii, k)*att(bb, c, jj, l),
        atv(l, k, d, c)*att(aa, d, ii, l)*att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d)*att(aa, c, ii, k)*att(d, bb, jj, l),
        atv(l, k, c, d)*att(aa, c, ii, l)*att(d, bb, jj, k),
        atv(k, l, d, c)*att(aa, d, ii, k)*att(c, bb, jj, l),
        atv(l, k, d, c)*att(aa, d, ii, l)*att(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        atv(k, l, c, d)*att(c, aa, ii, k)*att(bb, d, jj, l),
        atv(l, k, c, d)*att(c, aa, ii, l)*att(bb, d, jj, k),
        atv(k, l, d, c)*att(d, aa, ii, k)*att(bb, c, jj, l),
        atv(l, k, d, c)*att(d, aa, ii, l)*att(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#28
0
def test_equivalent_internal_lines_VT2conjT2():
    # this diagram requires special handling in TCE
    i, j, k, l, m, n = symbols('i j k l m n', below_fermi=True, cls=Dummy)
    a, b, c, d, e, f = symbols('a b c d e f', above_fermi=True, cls=Dummy)
    p1, p2, p3, p4 = symbols('p1 p2 p3 p4', above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols('h1 h2 h3 h4', below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    # v(abcd)t(abij)t(ijcd)
    template = v(p1, p2, p3, p4)*t(p1, p2, i, j)*t(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = v(p1, p2, p3, p4)*t(p1, p2, j, i)*t(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # v(abcd)t(abij)t(jicd)
    template = v(p1, p2, p3, p4)*t(p1, p2, i, j)*t(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = v(p1, p2, p3, p4)*t(p1, p2, j, i)*t(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#29
0
def test_equivalent_internal_lines_VT2conjT2():
    # this diagram requires special handling in TCE
    i, j, k, l, m, n = symbols("i j k l m n", below_fermi=True, cls=Dummy)
    a, b, c, d, e, f = symbols("a b c d e f", above_fermi=True, cls=Dummy)
    p1, p2, p3, p4 = symbols("p1 p2 p3 p4", above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols("h1 h2 h3 h4", below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    # v(abcd)t(abij)t(ijcd)
    template = v(p1, p2, p3, p4) * t(p1, p2, i, j) * t(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = v(p1, p2, p3, p4) * t(p1, p2, j, i) * t(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # v(abcd)t(abij)t(jicd)
    template = v(p1, p2, p3, p4) * t(p1, p2, i, j) * t(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = v(p1, p2, p3, p4) * t(p1, p2, j, i) * t(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], next(permutator)))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert dums(base) != dums(expr)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#30
0
def test_dummy_order_inner_outer_lines_VT1T1T1():
    ii = symbols('i', below_fermi=True)
    aa = symbols('a', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    # Coupled-Cluster T1 terms with V*T1*T1*T1
    # t^{a}_{k} t^{c}_{i} t^{d}_{l} v^{lk}_{dc}
    exprs = [
        # permut v and t <=> swapping internal lines, equivalent
        # irrespective of symmetries in v
        v(k, l, c, d)*t(c, ii)*t(d, l)*t(aa, k),
        v(l, k, c, d)*t(c, ii)*t(d, k)*t(aa, l),
        v(k, l, d, c)*t(d, ii)*t(c, l)*t(aa, k),
        v(l, k, d, c)*t(d, ii)*t(c, k)*t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#31
0
def test_dummy_order_inner_outer_lines_VT1T1T1():
    ii = symbols("i", below_fermi=True)
    aa = symbols("a", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    # Coupled-Cluster T1 terms with V*T1*T1*T1
    # t^{a}_{k} t^{c}_{i} t^{d}_{l} v^{lk}_{dc}
    exprs = [
        # permut v and t <=> swapping internal lines, equivalent
        # irrespective of symmetries in v
        v(k, l, c, d) * t(c, ii) * t(d, l) * t(aa, k),
        v(l, k, c, d) * t(c, ii) * t(d, k) * t(aa, l),
        v(k, l, d, c) * t(d, ii) * t(c, l) * t(aa, k),
        v(l, k, d, c) * t(d, ii) * t(c, k) * t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#32
0
def test_equivalent_internal_lines_VT1T1():
    i, j, k, l = symbols('i j k l', below_fermi=True, cls=Dummy)
    a, b, c, d = symbols('a b c d', above_fermi=True, cls=Dummy)

    f = Function('f')
    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    exprs = [  # permute v.  Different dummy order. Not equivalent.
        v(i, j, a, b) * t(a, i) * t(b, j),
        v(j, i, a, b) * t(a, i) * t(b, j),
        v(i, j, b, a) * t(a, i) * t(b, j),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v.  Different dummy order. Equivalent
        v(i, j, a, b) * t(a, i) * t(b, j),
        v(j, i, b, a) * t(a, i) * t(b, j),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)

    exprs = [  # permute t.  Same dummy order, not equivalent.
        v(i, j, a, b) * t(a, i) * t(b, j),
        v(i, j, a, b) * t(b, i) * t(a, j),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Different dummy order, equivalent
        v(i, j, a, b) * t(a, i) * t(b, j),
        v(j, i, a, b) * t(a, j) * t(b, i),
        v(i, j, b, a) * t(b, i) * t(a, j),
        v(j, i, b, a) * t(b, j) * t(a, i),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#33
0
def test_equivalent_internal_lines_VT1T1():
    i,j,k,l = symbols('i j k l',below_fermi=True, cls=Dummy)
    a,b,c,d = symbols('a b c d',above_fermi=True, cls=Dummy)

    f = Function('f')
    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    exprs = [ # permute v.  Different dummy order. Not equivalent.
            v(i, j, a, b)*t(a, i)*t(b, j),
            v(j, i, a, b)*t(a, i)*t(b, j),
            v(i, j, b, a)*t(a, i)*t(b, j),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [ # permute v.  Different dummy order. Equivalent
            v(i, j, a, b)*t(a, i)*t(b, j),
            v(j, i, b, a)*t(a, i)*t(b, j),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)

    exprs = [ # permute t.  Same dummy order, not equivalent.
            v(i, j, a, b)*t(a, i)*t(b, j),
            v(i, j, a, b)*t(b, i)*t(a, j),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [ # permute v and t.  Different dummy order, equivalent
            v(i, j, a, b)*t(a, i)*t(b, j),
            v(j, i, a, b)*t(a, j)*t(b, i),
            v(i, j, b, a)*t(b, i)*t(a, j),
            v(j, i, b, a)*t(b, j)*t(a, i),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#34
0
def test_equivalent_internal_lines_VT2conjT2_AT():
    # this diagram requires special handling in TCE
    i,j,k,l,m,n = symbols('i j k l m n',below_fermi=True, cls=Dummy)
    a,b,c,d,e,f = symbols('a b c d e f',above_fermi=True, cls=Dummy)
    p1,p2,p3,p4 = symbols('p1 p2 p3 p4',above_fermi=True, cls=Dummy)
    h1,h2,h3,h4 = symbols('h1 h2 h3 h4',below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations


    # atv(abcd)att(abij)att(ijcd)
    template = atv(p1, p2, p3, p4)*att(p1, p2, i, j)*att(i, j, p3, p4)
    permutator = variations([a,b,c,d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = atv(p1, p2, p3, p4)*att(p1, p2, j, i)*att(j, i, p3, p4)
    permutator = variations([a,b,c,d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # atv(abcd)att(abij)att(jicd)
    template = atv(p1, p2, p3, p4)*att(p1, p2, i, j)*att(j, i, p3, p4)
    permutator = variations([a,b,c,d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = atv(p1, p2, p3, p4)*att(p1, p2, j, i)*att(i, j, p3, p4)
    permutator = variations([a,b,c,d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#35
0
def test_dummy_order_inner_outer_lines_VT1T1T1T1():
    ii, jj = symbols('i j', below_fermi=True)
    aa, bb = symbols('a b', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    # Coupled-Cluster T2 terms with V*T1*T1*T1*T1
    exprs = [
        # permut t <=> swapping external lines, not equivalent
        # except if v has certain symmetries.
        v(k, l, c, d)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
        v(k, l, c, d)*t(c, jj)*t(d, ii)*t(aa, k)*t(bb, l),
        v(k, l, c, d)*t(c, ii)*t(d, jj)*t(bb, k)*t(aa, l),
        v(k, l, c, d)*t(c, jj)*t(d, ii)*t(bb, k)*t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)
    exprs = [
        # permut v <=> swapping external lines, not equivalent
        # except if v has certain symmetries.
        #
        # Note that in contrast to above, these permutations have identical
        # dummy order.  That is because the proximity to external indices
        # has higher influence on the canonical dummy ordering than the
        # position of a dummy on the factors.  In fact, the terms here are
        # similar in structure as the result of the dummy substitions above.
        v(k, l, c, d)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
        v(l, k, c, d)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
        v(k, l, d, c)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
        v(l, k, d, c)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)
    exprs = [
        # permut t and v <=> swapping internal lines, equivalent.
        # Canonical dummy order is different, and a consistent
        # substitution reveals the equivalence.
        v(k, l, c, d)*t(c, ii)*t(d, jj)*t(aa, k)*t(bb, l),
        v(k, l, d, c)*t(c, jj)*t(d, ii)*t(aa, k)*t(bb, l),
        v(l, k, c, d)*t(c, ii)*t(d, jj)*t(bb, k)*t(aa, l),
        v(l, k, d, c)*t(c, jj)*t(d, ii)*t(bb, k)*t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#36
0
def test_dummy_order_inner_outer_lines_VT1T1T1T1():
    ii, jj = symbols("i j", below_fermi=True)
    aa, bb = symbols("a b", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    # Coupled-Cluster T2 terms with V*T1*T1*T1*T1
    exprs = [
        # permut t <=> swapping external lines, not equivalent
        # except if v has certain symmetries.
        v(k, l, c, d) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
        v(k, l, c, d) * t(c, jj) * t(d, ii) * t(aa, k) * t(bb, l),
        v(k, l, c, d) * t(c, ii) * t(d, jj) * t(bb, k) * t(aa, l),
        v(k, l, c, d) * t(c, jj) * t(d, ii) * t(bb, k) * t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)
    exprs = [
        # permut v <=> swapping external lines, not equivalent
        # except if v has certain symmetries.
        #
        # Note that in contrast to above, these permutations have identical
        # dummy order.  That is because the proximity to external indices
        # has higher influence on the canonical dummy ordering than the
        # position of a dummy on the factors.  In fact, the terms here are
        # similar in structure as the result of the dummy substitutions above.
        v(k, l, c, d) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
        v(l, k, c, d) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
        v(k, l, d, c) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
        v(l, k, d, c) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)
    exprs = [
        # permut t and v <=> swapping internal lines, equivalent.
        # Canonical dummy order is different, and a consistent
        # substitution reveals the equivalence.
        v(k, l, c, d) * t(c, ii) * t(d, jj) * t(aa, k) * t(bb, l),
        v(k, l, d, c) * t(c, jj) * t(d, ii) * t(aa, k) * t(bb, l),
        v(l, k, c, d) * t(c, ii) * t(d, jj) * t(bb, k) * t(aa, l),
        v(l, k, d, c) * t(c, jj) * t(d, ii) * t(bb, k) * t(aa, l),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#37
0
def test_equivalent_internal_lines_VT2conjT2_AT():
    # this diagram requires special handling in TCE
    i, j, k, l, m, n = symbols("i j k l m n", below_fermi=True, cls=Dummy)
    a, b, c, d, e, f = symbols("a b c d e f", above_fermi=True, cls=Dummy)
    p1, p2, p3, p4 = symbols("p1 p2 p3 p4", above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols("h1 h2 h3 h4", below_fermi=True, cls=Dummy)

    from sympy.utilities.iterables import variations

    # atv(abcd)att(abij)att(ijcd)
    template = atv(p1, p2, p3, p4) * att(p1, p2, i, j) * att(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = atv(p1, p2, p3, p4) * att(p1, p2, j, i) * att(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # atv(abcd)att(abij)att(jicd)
    template = atv(p1, p2, p3, p4) * att(p1, p2, i, j) * att(j, i, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
    template = atv(p1, p2, p3, p4) * att(p1, p2, j, i) * att(i, j, p3, p4)
    permutator = variations([a, b, c, d], 4)
    base = template.subs(zip([p1, p2, p3, p4], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#38
0
def test_equivalent_internal_lines_VT2():
    i, j, k, l = symbols('i j k l', below_fermi=True, cls=Dummy)
    a, b, c, d = symbols('a b c d', above_fermi=True, cls=Dummy)

    f = Function('f')
    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies
    exprs = [
        # permute v. Same dummy order, not equivalent.
        #
        # This test show that the dummy order may not be sensitive to all
        # index permutations.  The following expressions have identical
        # structure as the resulting terms from of the dummy subsitutions
        # in the test above.  Here, all expressions have the same dummy
        # order, so they cannot be simplified by means of dummy
        # substitution.  In order to simplify further, it is necessary to
        # exploit symmetries in the objects, for instance if t or v is
        # antisymmetric.
        v(i, j, a, b) * t(a, b, i, j),
        v(j, i, a, b) * t(a, b, i, j),
        v(i, j, b, a) * t(a, b, i, j),
        v(j, i, b, a) * t(a, b, i, j),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [
        # permute t.
        v(i, j, a, b) * t(a, b, i, j),
        v(i, j, a, b) * t(b, a, i, j),
        v(i, j, a, b) * t(a, b, j, i),
        v(i, j, a, b) * t(b, a, j, i),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [  # permute v and t.  Relabelling of dummies should be equivalent.
        v(i, j, a, b) * t(a, b, i, j),
        v(j, i, a, b) * t(a, b, j, i),
        v(i, j, b, a) * t(b, a, i, j),
        v(j, i, b, a) * t(b, a, j, i),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#39
0
def test_equivalent_internal_lines_VT2():
    i,j,k,l = symbols('i j k l',below_fermi=True, cls=Dummy)
    a,b,c,d = symbols('a b c d',above_fermi=True, cls=Dummy)

    f = Function('f')
    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies
    exprs = [
            # permute v. Same dummy order, not equivalent.
            #
            # This test show that the dummy order may not be sensitive to all
            # index permutations.  The following expressions have identical
            # structure as the resulting terms from of the dummy subsitutions
            # in the test above.  Here, all expressions have the same dummy
            # order, so they cannot be simplified by means of dummy
            # substitution.  In order to simplify further, it is necessary to
            # exploit symmetries in the objects, for instance if t or v is
            # antisymmetric.
            v(i, j, a, b)*t(a, b, i, j),
            v(j, i, a, b)*t(a, b, i, j),
            v(i, j, b, a)*t(a, b, i, j),
            v(j, i, b, a)*t(a, b, i, j),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) == dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [
            # permute t.
            v(i, j, a, b)*t(a, b, i, j),
            v(i, j, a, b)*t(b, a, i, j),
            v(i, j, a, b)*t(a, b, j, i),
            v(i, j, a, b)*t(b, a, j, i),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) != substitute_dummies(permut)

    exprs = [ # permute v and t.  Relabelling of dummies should be equivalent.
            v(i, j, a, b)*t(a, b, i, j),
            v(j, i, a, b)*t(a, b, j, i),
            v(i, j, b, a)*t(b, a, i, j),
            v(j, i, b, a)*t(b, a, j, i),
            ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#40
0
def test_dummy_order_ambiguous():
    aa, bb = symbols('ab', above_fermi=True)
    i, j, k, l, m = symbols('i j k l m', below_fermi=True, cls=Dummy)
    a, b, c, d, e = symbols('a b c d e', above_fermi=True, cls=Dummy)
    p, q = symbols('p q', cls=Dummy)
    p1, p2, p3, p4 = symbols('p1 p2 p3 p4', above_fermi=True, cls=Dummy)
    p5, p6, p7, p8 = symbols('p5 p6 p7 p8', above_fermi=True, cls=Dummy)
    h1, h2, h3, h4 = symbols('h1 h2 h3 h4', below_fermi=True, cls=Dummy)
    h5, h6, h7, h8 = symbols('h5 h6 h7 h8', below_fermi=True, cls=Dummy)

    A = Function('A')
    B = Function('B')
    dums = _get_ordered_dummies

    from sympy.utilities.iterables import variations

    # A*A*A*A*B  --  ordering of p5 and p4 is used to figure out the rest
    template = A(p1, p2) * A(p4, p1) * A(p2, p3) * A(p3, p5) * B(p5, p4)
    permutator = variations([a, b, c, d, e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # A*A*A*A*A  --  an arbitrary index is assigned and the rest are figured out
    template = A(p1, p2) * A(p4, p1) * A(p2, p3) * A(p3, p5) * A(p5, p4)
    permutator = variations([a, b, c, d, e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # A*A*A  --  ordering of p5 and p4 is used to figure out the rest
    template = A(p1, p2, p4, p1) * A(p2, p3, p3, p5) * A(p5, p4)
    permutator = variations([a, b, c, d, e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#41
0
def test_dummy_order_ambiguous():
    aa, bb = symbols('ab', above_fermi=True)
    i, j, k, l, m = symbols('i j k l m', below_fermi=True, cls=Dummy)
    a, b, c, d, e = symbols('a b c d e', above_fermi=True, cls=Dummy)
    p, q = symbols('p q', cls=Dummy)
    p1,p2,p3,p4 = symbols('p1 p2 p3 p4',above_fermi=True, cls=Dummy)
    p5,p6,p7,p8 = symbols('p5 p6 p7 p8',above_fermi=True, cls=Dummy)
    h1,h2,h3,h4 = symbols('h1 h2 h3 h4',below_fermi=True, cls=Dummy)
    h5,h6,h7,h8 = symbols('h5 h6 h7 h8',below_fermi=True, cls=Dummy)

    A = Function('A')
    B = Function('B')
    dums = _get_ordered_dummies

    from sympy.utilities.iterables import variations

    # A*A*A*A*B  --  ordering of p5 and p4 is used to figure out the rest
    template = A(p1, p2)*A(p4, p1)*A(p2, p3)*A(p3, p5)*B(p5, p4)
    permutator = variations([a,b,c,d,e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # A*A*A*A*A  --  an arbitrary index is assigned and the rest are figured out
    template = A(p1, p2)*A(p4, p1)*A(p2, p3)*A(p3, p5)*A(p5, p4)
    permutator = variations([a,b,c,d,e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)

    # A*A*A  --  ordering of p5 and p4 is used to figure out the rest
    template = A(p1, p2, p4, p1)*A(p2, p3, p3, p5)*A(p5, p4)
    permutator = variations([a,b,c,d,e], 5)
    base = template.subs(zip([p1, p2, p3, p4, p5], permutator.next()))
    for permut in permutator:
        subslist = zip([p1, p2, p3, p4, p5], permut)
        expr = template.subs(subslist)
        assert substitute_dummies(expr) == substitute_dummies(base)
示例#42
0
def test_internal_external_VT2T2():
    ii, jj = symbols('i j', below_fermi=True)
    aa, bb = symbols('a b', above_fermi=True)
    k, l = symbols('k l', below_fermi=True, cls=Dummy)
    c, d = symbols('c d', above_fermi=True, cls=Dummy)

    v = Function('v')
    t = Function('t')
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d)*t(aa, c, ii, k)*t(bb, d, jj, l),
        v(l, k, c, d)*t(aa, c, ii, l)*t(bb, d, jj, k),
        v(k, l, d, c)*t(aa, d, ii, k)*t(bb, c, jj, l),
        v(l, k, d, c)*t(aa, d, ii, l)*t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        v(k, l, c, d)*t(aa, c, ii, k)*t(d, bb, jj, l),
        v(l, k, c, d)*t(aa, c, ii, l)*t(d, bb, jj, k),
        v(k, l, d, c)*t(aa, d, ii, k)*t(c, bb, jj, l),
        v(l, k, d, c)*t(aa, d, ii, l)*t(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        v(k, l, c, d)*t(c, aa, ii, k)*t(bb, d, jj, l),
        v(l, k, c, d)*t(c, aa, ii, l)*t(bb, d, jj, k),
        v(k, l, d, c)*t(d, aa, ii, k)*t(bb, c, jj, l),
        v(l, k, d, c)*t(d, aa, ii, l)*t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#43
0
def test_internal_external_VT2T2():
    ii, jj = symbols("i j", below_fermi=True)
    aa, bb = symbols("a b", above_fermi=True)
    k, l = symbols("k l", below_fermi=True, cls=Dummy)
    c, d = symbols("c d", above_fermi=True, cls=Dummy)

    v = Function("v")
    t = Function("t")
    dums = _get_ordered_dummies

    exprs = [
        v(k, l, c, d) * t(aa, c, ii, k) * t(bb, d, jj, l),
        v(l, k, c, d) * t(aa, c, ii, l) * t(bb, d, jj, k),
        v(k, l, d, c) * t(aa, d, ii, k) * t(bb, c, jj, l),
        v(l, k, d, c) * t(aa, d, ii, l) * t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        v(k, l, c, d) * t(aa, c, ii, k) * t(d, bb, jj, l),
        v(l, k, c, d) * t(aa, c, ii, l) * t(d, bb, jj, k),
        v(k, l, d, c) * t(aa, d, ii, k) * t(c, bb, jj, l),
        v(l, k, d, c) * t(aa, d, ii, l) * t(c, bb, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
    exprs = [
        v(k, l, c, d) * t(c, aa, ii, k) * t(bb, d, jj, l),
        v(l, k, c, d) * t(c, aa, ii, l) * t(bb, d, jj, k),
        v(k, l, d, c) * t(d, aa, ii, k) * t(bb, c, jj, l),
        v(l, k, d, c) * t(d, aa, ii, l) * t(bb, c, jj, k),
    ]
    for permut in exprs[1:]:
        assert dums(exprs[0]) != dums(permut)
        assert substitute_dummies(exprs[0]) == substitute_dummies(permut)
示例#44
0
def test_substitute_dummies_without_dummies():
    i, j = symbols('i,j')
    assert substitute_dummies(att(i, j) + 2) == att(i, j) + 2
    assert substitute_dummies(att(i, j) + 1) == att(i, j) + 1
示例#45
0
def main():
    print
    print "Calculates the Coupled-Cluster energy- and amplitude equations"
    print "See 'An Introduction to Coupled Cluster Theory' by"
    print "T. Daniel Crawford and Henry F. Schaefer III"
    print "http://www.ccc.uga.edu/lec_top/cc/html/review.html"
    print

    # setup hamiltonian
    p, q, r, s = symbols("pqrs", dummy=True)
    f = AntiSymmetricTensor("f", (p,), (q,))
    pr = NO((Fd(p) * F(q)))
    v = AntiSymmetricTensor("v", (p, q), (r, s))
    pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r))

    H = f * pr

    # Uncomment the next line to use a 2-body hamiltonian:
    # H=f*pr + Number(1,4)*v*pqsr

    print "Using the hamiltonian:", latex(H)

    print "Calculating nested commutators"
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print "comm1..."
    comm1 = wicks(C(H, T), simplify_dummies=True, simplify_kronecker_deltas=True)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print "comm2..."
    comm2 = wicks(C(comm1, T), simplify_dummies=True, simplify_kronecker_deltas=True)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print "comm3..."
    comm3 = wicks(C(comm2, T), simplify_dummies=True, simplify_kronecker_deltas=True)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print "comm4..."
    comm4 = wicks(C(comm3, T), simplify_dummies=True, simplify_kronecker_deltas=True)

    print "construct Hausdoff expansion..."
    eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq, new_indices=True, reverse_order=False, pretty_indices=pretty_dummies_dict)
    print "*********************"
    print

    print "extracting CC equations from full Hbar"
    i, j, k, l = symbols("ijkl", below_fermi=True)
    a, b, c, d = symbols("abcd", above_fermi=True)
    print
    print "CC Energy:"
    print latex(wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True))
    print
    print "CC T1:"
    eqT1 = wicks(NO(Fd(i) * F(a)) * eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True)
    eqT1 = substitute_dummies(eqT1, reverse_order=False)
    print latex(eqT1)
    print
    print "CC T2:"
    eqT2 = wicks(
        NO(Fd(i) * Fd(j) * F(b) * F(a)) * eq,
        simplify_dummies=True,
        keep_only_fully_contracted=True,
        simplify_kronecker_deltas=True,
    )
    P = PermutationOperator
    eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)])
    print latex(eqT2)
示例#46
0
def test_substitute_dummies_new_indices():
    i, j = symbols("i j", below_fermi=True, cls=Dummy)
    a, b = symbols("a b", above_fermi=True, cls=Dummy)
    p, q = symbols("p q", cls=Dummy)
    f = Function("f")
    assert substitute_dummies(f(i, a, p) - f(j, b, q), new_indices=True) == 0
示例#47
0
def test_substitute_dummies_SQ_operator():
    i, j = symbols("i j", cls=Dummy)
    assert substitute_dummies(att(i, j) * Fd(i) * F(j) - att(j, i) * Fd(j) * F(i)) == 0
示例#48
0
def test_substitute_dummies_without_dummies():
    i, j = symbols("i,j")
    assert substitute_dummies(att(i, j) + 2) == att(i, j) + 2
    assert substitute_dummies(att(i, j) + 1) == att(i, j) + 1
示例#49
0
def test_substitute_dummies_SQ_operator():
    i, j = symbols('i j', cls=Dummy)
    assert substitute_dummies(att(i, j)*Fd(i)*F(j)
                - att(j, i)*Fd(j)*F(i)) == 0
示例#50
0
T_2 = sum(get_ccsd_t_operators())
T_t = sum(get_ccsd_t_operators(ast_symb="t(t)"))
T_t_2 = sum(get_ccsd_t_operators(ast_symb="t(t)"))
L = sum(get_ccsd_lambda_operators())
L_t = sum(get_ccsd_lambda_operators(ast_symb="l(t)"))

tilde_t_eq = Rational(1, 1)
tilde_t_eq += eval_equation(-L_t * T_t)
tilde_t_eq += eval_equation(L_t * T)
tilde_t_eq += eval_equation(-L_t * T_t * T)
tilde_t_eq += eval_equation(Rational(1, 2) * L_t * T_t * T_t_2)
tilde_t_eq += eval_equation(Rational(1, 2) * L_t * T * T_2)

tilde_t_eq = tilde_t_eq.expand()
tilde_t_eq = evaluate_deltas(tilde_t_eq)
tilde_t_eq = substitute_dummies(tilde_t_eq, **sub_kwargs)

tilde_eq = Rational(1, 1)
tilde_eq += eval_equation(-L * T)
tilde_eq += eval_equation(L * T_t)
tilde_eq += eval_equation(-L * T * T_t)
tilde_eq += eval_equation(Rational(1, 2) * L * T * T_2)
tilde_eq += eval_equation(Rational(1, 2) * L * T_t * T_t_2)

tilde_eq = tilde_eq.expand()
tilde_eq = evaluate_deltas(tilde_eq)
tilde_eq = substitute_dummies(tilde_eq, **sub_kwargs)

print(latex(tilde_t_eq))
print(latex(tilde_eq))
示例#51
0
def test_substitute_dummies_new_indices():
    i, j = symbols("i j", below_fermi=True, cls=Dummy)
    a, b = symbols("a b", above_fermi=True, cls=Dummy)
    p, q = symbols("p q", cls=Dummy)
    f = Function("f")
    assert substitute_dummies(f(i, a, p) - f(j, b, q), new_indices=True) == 0
示例#52
0
def test_substitute_dummies_NO_operator():
    i, j = symbols("i j", cls=Dummy)
    assert substitute_dummies(att(i, j) * NO(Fd(i) * F(j)) - att(j, i) * NO(Fd(j) * F(i))) == 0
示例#53
0
def test_substitute_dummies_new_indices():
    i, j = symbols('i j', below_fermi=True, cls=Dummy)
    a, b = symbols('a b', above_fermi=True, cls=Dummy)
    p, q = symbols('p q', cls=Dummy)
    f = Function('f')
    assert substitute_dummies(f(i, a, p) - f(j, b, q), new_indices=True) == 0
示例#54
0
def test_substitute_dummies_NO_operator():
    i, j = symbols('i j', cls=Dummy)
    assert substitute_dummies(att(i, j)*NO(Fd(i)*F(j))
                - att(j, i)*NO(Fd(j)*F(i))) == 0
示例#55
0
def main():
    print()
    print("Calculates the Coupled-Cluster energy- and amplitude equations")
    print("See 'An Introduction to Coupled Cluster Theory' by")
    print("T. Daniel Crawford and Henry F. Schaefer III")
    print("http://www.ccc.uga.edu/lec_top/cc/html/review.html")
    print()

    # setup hamiltonian
    p, q, r, s = symbols('p,q,r,s', cls=Dummy)
    f = AntiSymmetricTensor('f', (p,), (q,))
    pr = NO((Fd(p)*F(q)))
    v = AntiSymmetricTensor('v', (p, q), (r, s))
    pqsr = NO(Fd(p)*Fd(q)*F(s)*F(r))

    H = f*pr + Rational(1, 4)*v*pqsr
    print("Using the hamiltonian:", latex(H))

    print("Calculating 4 nested commutators")
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 1...")
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 2...")
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 3...")
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 4...")
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    print("construct Hausdoff expansion...")
    eq = H + comm1 + comm2/2 + comm3/6 + comm4/24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq, new_indices=True,
            pretty_indices=pretty_dummies_dict)
    print("*********************")
    print()

    print("extracting CC equations from full Hbar")
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    print()
    print("CC Energy:")
    print(latex(wicks(eq, simplify_dummies=True,
        keep_only_fully_contracted=True)))
    print()
    print("CC T1:")
    eqT1 = wicks(NO(Fd(i)*F(a))*eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True)
    eqT1 = substitute_dummies(eqT1)
    print(latex(eqT1))
    print()
    print("CC T2:")
    eqT2 = wicks(NO(Fd(i)*Fd(j)*F(b)*F(a))*eq, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True)
    P = PermutationOperator
    eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)])
    print(latex(eqT2))
示例#56
0
T1,T2 = get_CC_operators()
T = T1+ T2
print "comm3..."
comm3 = wicks(C(comm2,T),simplify_dummies=True, simplify_kronecker_deltas=True)

T1,T2 = get_CC_operators()
T = T1+ T2
print "comm4..."
comm4 = wicks(C(comm3,T),simplify_dummies=True, simplify_kronecker_deltas=True)

print "construct Hausdoff expansion..."
eq = H + comm1+comm2/2+comm3/6+comm4/24
eq = eq.expand()
eq = evaluate_deltas(eq)
eq = substitute_dummies(eq, new_indices=True, reverse_order=False)
print "*********************"
print

print "extracting CC equations from full Hbar"
i,j,k,l = symbols('ijkl',below_fermi=True)
a,b,c,d = symbols('abcd',above_fermi=True)
print
print "CC Energy:"
print latex(wicks(eq, simplify_dummies=True,
    keep_only_fully_contracted=True))
print
print "CC T1:"
eqT1 = wicks(NO(Fd(i)*F(a))*eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True)
eqT1 = substitute_dummies(eqT1,reverse_order=False)
print latex(eqT1)
示例#57
0
def test_substitute_dummies_new_indices():
    i, j = symbols('i j', below_fermi=True, cls=Dummy)
    a, b = symbols('a b', above_fermi=True, cls=Dummy)
    p, q = symbols('p q', cls=Dummy)
    f = Function('f')
    assert substitute_dummies(f(i, a, p) - f(j, b, q), new_indices=True) == 0
示例#58
0
def main():
    print()
    print("Calculates the Coupled-Cluster energy- and amplitude equations")
    print("See 'An Introduction to Coupled Cluster Theory' by")
    print("T. Daniel Crawford and Henry F. Schaefer III")
    print(
        "Reference to a Lecture Series: http://vergil.chemistry.gatech.edu/notes/sahan-cc-2010.pdf"
    )
    print()

    # setup hamiltonian
    p, q, r, s = symbols('p,q,r,s', cls=Dummy)
    f = AntiSymmetricTensor('f', (p, ), (q, ))
    pr = NO(Fd(p) * F(q))
    v = AntiSymmetricTensor('v', (p, q), (r, s))
    pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r))

    H = f * pr + Rational(1, 4) * v * pqsr
    print("Using the hamiltonian:", latex(H))

    print("Calculating 4 nested commutators")
    C = Commutator

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 1...")
    comm1 = wicks(C(H, T))
    comm1 = evaluate_deltas(comm1)
    comm1 = substitute_dummies(comm1)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 2...")
    comm2 = wicks(C(comm1, T))
    comm2 = evaluate_deltas(comm2)
    comm2 = substitute_dummies(comm2)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 3...")
    comm3 = wicks(C(comm2, T))
    comm3 = evaluate_deltas(comm3)
    comm3 = substitute_dummies(comm3)

    T1, T2 = get_CC_operators()
    T = T1 + T2
    print("commutator 4...")
    comm4 = wicks(C(comm3, T))
    comm4 = evaluate_deltas(comm4)
    comm4 = substitute_dummies(comm4)

    print("construct Hausdorff expansion...")
    eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24
    eq = eq.expand()
    eq = evaluate_deltas(eq)
    eq = substitute_dummies(eq,
                            new_indices=True,
                            pretty_indices=pretty_dummies_dict)
    print("*********************")
    print()

    print("extracting CC equations from full Hbar")
    i, j, k, l = symbols('i,j,k,l', below_fermi=True)
    a, b, c, d = symbols('a,b,c,d', above_fermi=True)
    print()
    print("CC Energy:")
    print(
        latex(wicks(eq, simplify_dummies=True,
                    keep_only_fully_contracted=True)))

    # print("HERE")
    # print("HERE")
    # print("HERE")
    # print(pycode(wicks(eq, simplify_dummies=True,
    #     keep_only_fully_contracted=True)))
    # with open("cc_energy.py", "w") as f:
    # f.
    with open("ccsd.jl", "w") as f:
        eq_energy = wicks(eq,
                          simplify_dummies=True,
                          keep_only_fully_contracted=True)
        f.write(julia_code(eq_energy))

    print()
    print("CC T1:")
    eqT1 = wicks(NO(Fd(i) * F(a)) * eq,
                 simplify_kronecker_deltas=True,
                 keep_only_fully_contracted=True)
    eqT1 = substitute_dummies(eqT1)
    print(latex(eqT1))
    print()
    print("CC T2:")
    eqT2 = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * eq,
                 simplify_dummies=True,
                 keep_only_fully_contracted=True,
                 simplify_kronecker_deltas=True)
    # P = PermutationOperator
    # eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)])
    print(latex(eqT2))
    print(latex(simplify(eqT2)))