Пример #1
0
def test_product_of_scalars():
    f1 = SingleVarFunctionScalar("f", "x")
    f2 = SingleVarFunctionScalar("f", "y")
    d = DeltaFunction("x", "y")
    expr = f1 * f2.conjugate() * d
    print(expr)
    assert set(expr) == set([f1, f2.conjugate(), d])
Пример #2
0
def test_integrate_single_function():
    f = SingleVarFunctionScalar("f", "x")
    d = DeltaFunction("x", "y")
    expr = f * d
    res = integrate(expr, "x")
    print(res)
    assert res == SingleVarFunctionScalar("f", "y")
Пример #3
0
def test_integrate_same_function():
    fx = SingleVarFunctionScalar("f", "x")
    fy = SingleVarFunctionScalar("f", "y").conjugate()
    d = DeltaFunction("x", "y")
    expr = fx * fy * d
    res = integrate(expr)
    print(res)
    assert res == 1
Пример #4
0
def test_has_variable():
    fx = SingleVarFunctionScalar("f", "x")
    fy = SingleVarFunctionScalar("f", "y").conjugate()
    expr = fx * fy
    res = integrate(expr, "x")
    print(res)
    assert not has_variable(res, "x")
    assert has_variable(res, "y")
Пример #5
0
def test_integrate_all_vars():
    f = SingleVarFunctionScalar("f", "x")
    g = SingleVarFunctionScalar("g", "y").conjugate()
    d = DeltaFunction("x", "y")
    expr = f * g * d
    res = integrate(expr)
    print(res)
    assert res == InnerProductFunction("f", "g")
Пример #6
0
def test_atoms_product():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')

    prod = 2 * a * b

    print(prod)
    atoms = prod.atoms()
    assert set([2, a, b]) == set(atoms)
Пример #7
0
def test_atoms_sum():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')

    sm = 2 + a + b

    print(sm)
    atoms = sm.atoms()
    assert set([2, a, b]) == set(atoms)
Пример #8
0
def test_atoms_nested():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')

    sm = 2 + a + (b * c)

    print(sm)
    atoms = sm.atoms()
    assert set([2, a, b, c]) == set(atoms)
Пример #9
0
def test_sum_vars():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'y')

    sm = a + b + c
    assert get_variables(sm) == set(['x', 'y'])
    sm = replace_var(sm, 'y', 'x')
    assert get_variables(sm) == set(['x'])
    assert not has_variable(sm, 'y')
Пример #10
0
def test_combine_factors():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')

    prod = a * b * c
    prod[0] = 2
    prod[2] = 5
    prod = simplify(prod)
    assert prod == 10 * b
Пример #11
0
def test_sum_commutative():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')
    d = SingleVarFunctionScalar('d', 'x')

    sm1 = a * b + c * d
    sm2 = d * c + b * a

    assert sm1 == sm2
Пример #12
0
def test_iszero_prod():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')

    prod = a * b
    prod[1] = 1e-17
    prod = simplify(prod)

    assert prod == 0
    assert is_zero(prod)
Пример #13
0
def test_integrate_sum():
    f1 = SingleVarFunctionScalar("f", "x")
    f2 = SingleVarFunctionScalar("g", "x")
    d = DeltaFunction("x", "y")
    expr = (f1 + f2) * d
    res = integrate(expr, "x")
    print(res)
    assert isinstance(res, SumOfScalars)
    assert set(res) == set([
        SingleVarFunctionScalar("f", "y"),
        SingleVarFunctionScalar("g", "y"),
    ])
Пример #14
0
def test_simplify():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')

    expr = (a + b) * (c + 0)
    expr = expr.simplify()
    print(expr)
    assert isinstance(expr, SumOfScalars)
    assert len(expr) == 2
    print(expr[0])
    assert len(expr[0]) == 2
Пример #15
0
def test_expand():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')
    d = SingleVarFunctionScalar('d', 'x')

    expr = (a + b) * (c + d)
    expr = simplify(expr.expand())
    print(expr)
    assert isinstance(expr, SumOfScalars)
    assert len(expr) == 4
    print(expr[0])
    assert len(expr[0]) == 2
Пример #16
0
def test_sum_scalar():
    a = SingleVarFunctionScalar('a', 'x')
    b = SingleVarFunctionScalar('b', 'x')
    c = SingleVarFunctionScalar('c', 'x')
    d = SingleVarFunctionScalar('d', 'x')

    sm1 = a + b
    sm2 = c + d
    tot = sm1 + sm2
    assert len(tot) == 4
    assert set(tot) == set([a, b, c, d])

    tot += 2
    assert len(tot) == 5
    assert set(tot) == set([2, a, b, c, d])
Пример #17
0
def test_setitem():
    a = SingleVarFunctionScalar('a', 'x')

    sm = 2 + a
    sm[1] = 1
    print(sm)
    sm = simplify(sm)

    assert sm == 3
Пример #18
0
def get_fock_states():
    """Construct the fock states (eq. (42)-(45) in https://arxiv.org/abs/1903.09778)"""
    bs0 = BaseFockState()
    bsc = BaseFockState([FockOp("c", "w1")])
    bsd = BaseFockState([FockOp("d", "w1")])
    phi = SingleVarFunctionScalar("phi", "w1")
    psi = SingleVarFunctionScalar("psi", "w1")

    s0 = bs0.to_state()
    f = 1 / np.sqrt(2)
    sphi = f * phi * (bsc.to_state() + bsd.to_state())
    spsi = f * psi * (bsc.to_state() - bsd.to_state())

    bscc = BaseFockState([FockOp("c", "w1"), FockOp("c", "w2")])
    bscd = BaseFockState([FockOp("c", "w1"), FockOp("d", "w2")])
    bsdc = BaseFockState([FockOp("d", "w1"), FockOp("c", "w2")])
    bsdd = BaseFockState([FockOp("d", "w1"), FockOp("d", "w2")])
    phipsi = SingleVarFunctionScalar("phi", "w1") * SingleVarFunctionScalar(
        "psi", "w2")
    sphipsi = (1 / 2) * phipsi * (bscc.to_state() + bsdc.to_state() -
                                  bscd.to_state() - bsdd.to_state())

    return s0, sphi, spsi, sphipsi
Пример #19
0
def test_integrate():
    f1 = SingleVarFunctionScalar("f", "x")
    f2 = SingleVarFunctionScalar("f", "y")
    d = DeltaFunction("x", "y")
    expr = f1 * f2.conjugate() * d
    res = integrate(expr, "x")
    print(res)
    assert set(res) == set([
        SingleVarFunctionScalar("f", "y", False),
        SingleVarFunctionScalar("f", "y", True),
    ])
Пример #20
0
def test_integrate_equal_terms():
    f1 = SingleVarFunctionScalar("f", "x")
    f2 = SingleVarFunctionScalar("f", "y")
    f3 = f1 * f2.conjugate()
    d = DeltaFunction("x", "y")
    expr = (f3 + f3) * d
    res = integrate(expr, "x")
    print(res)
    assert isinstance(res, ProductOfScalars)
    assert set(res) == set([
        2,
        SingleVarFunctionScalar("f", "y", False),
        SingleVarFunctionScalar("f", "y", True),
    ])