Esempio n. 1
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")
Esempio n. 2
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")
Esempio n. 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
Esempio n. 4
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")
Esempio n. 5
0
def example_projectors(no_output=False):
    """Example showing how to constuct the projectors and how they act on a given state."""
    s0, sphi, spsi, sphipsi = get_fock_states()

    s = sphi
    p = construct_projector(1, 0)
    inner = (p * s).inner_product(s)
    if not no_output:
        print(integrate(inner))
Esempio n. 6
0
def example_states(no_output=False):
    """Example showing how the states can be constructed"""
    s0, sphi, spsi, sphipsi = get_fock_states()
    if not no_output:
        print(f"State is: {sphi}\n")
    inner = sphi.inner_product(sphi)
    if not no_output:
        print(f"inner product is: {inner}\n")
    simplify(inner)
    if not no_output:
        print(f"after simplify: {simplify(inner)}\n")
    inner = integrate(inner)
    if not no_output:
        print(f"after integrate: {inner}\n")
    return

    inner = simplify(sphipsi.inner_product(sphipsi))
    if not no_output:
        print(inner)
        print(integrate(inner))
Esempio n. 7
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),
    ])
Esempio n. 8
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"),
    ])
Esempio n. 9
0
    def convert_scalars(scalar):
        visibility = 0.9

        scalar = integrate(scalar)
        if is_number(scalar):
            return scalar
        for sequenced_class in [ProductOfScalars, SumOfScalars]:
            if isinstance(scalar, sequenced_class):
                return simplify(
                    sequenced_class([convert_scalars(s) for s in scalar]))
        if isinstance(scalar, InnerProductFunction):
            if set(scalar._func_names) == set(['phi', 'psi']):
                return visibility
        raise RuntimeError(f"unknown scalar {scalar} of type {type(scalar)}")
Esempio n. 10
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),
    ])
Esempio n. 11
0
    def _mul_operator(self, operator):
        new_op = Operator()
        for self_base_op, self_scalar in self._terms.items():
            for other_base_op, other_scalar in operator._terms.items():
                new_base_op = BaseOperator(self_base_op._left,
                                           other_base_op._right)
                new_scalar = self_base_op._right.inner_product(
                    other_base_op._left) * self_scalar * other_scalar

                # Integrate out variables which are not in base operator
                # TODO, should this be optional?
                scalar_variables = get_variables(new_scalar) - get_variables(
                    new_base_op)
                new_scalar = integrate(new_scalar, scalar_variables)

                if is_zero(new_scalar):
                    continue
                new_op._terms[new_base_op] += new_scalar

        return new_op
Esempio n. 12
0
def test_integrate_scalar_no_var(var):
    assert var == integrate(var, "x")