Ejemplo n.º 1
0
def test_has_any():
    x, y, z, t, u = symbols('x y z t u')
    f = Function("f")
    g = Function("g")
    p = Wild('p')

    assert sin(x).has(x)
    assert sin(x).has(sin)
    assert not sin(x).has(y)
    assert not sin(x).has(cos)
    assert f(x).has(x)
    assert f(x).has(f)
    assert not f(x).has(y)
    assert not f(x).has(g)

    assert f(x).diff(x).has(x)
    assert f(x).diff(x).has(f)
    assert f(x).diff(x).has(Derivative)
    assert not f(x).diff(x).has(y)
    assert not f(x).diff(x).has(g)
    assert not f(x).diff(x).has(sin)

    assert (x**2).has(Symbol)
    assert not (x**2).has(Wild)
    assert (2 * p).has(Wild)

    i = Integer(4400)

    assert i.has(x) is False

    assert (i * x**i).has(x)
    assert (i * y**i).has(x) is False
    assert (i * y**i).has(x, y)

    expr = x**2 * y + sin(2**t + log(z))

    assert expr.has(u) is False

    assert expr.has(x)
    assert expr.has(y)
    assert expr.has(z)
    assert expr.has(t)

    assert expr.has(x, y, z, t)
    assert expr.has(x, y, z, t, u)

    from sympy.physics.units import m, s

    assert (x * m / s).has(x)
    assert (x * m / s).has(y, z) is False

    poly = Poly(x**2 + x * y * sin(z), x, y, t)

    assert poly.has(x)
    assert poly.has(x, y, z)
    assert poly.has(x, y, z, t)

    assert FockState((x, y)).has(x)
Ejemplo n.º 2
0
def test_basic_state():
    i, j, n, m = var('i j n m')
    s = FockState([0,1,2,3,4])
    assert len(s) == 5
    assert s.args[0] == tuple(range(5))
    assert s.up(0) == FockState([1,1,2,3,4])
    assert s.down(4) == FockState([0,1,2,3,3])
    for i in range(5):
        assert s.up(i).down(i) == s
    assert s.down(0) == 0
    for i in range(5):
        assert s[i] == i
    s = FockState([n,m])
    assert s.down(0) == FockState([n-1,m])
    assert s.up(0) == FockState([n+1,m])
Ejemplo n.º 3
0
def test_has_all():
    x,y,z,t,u = symbols('xyztu')
    u = symbols('u')

    i = Integer(4400)

    assert i.has(x, all=True) is False

    assert (i*x**i).has(x, all=True)
    assert (i*y**i).has(x, all=True) is False

    expr = x**2*y + sin(2**t + log(z))

    assert expr.has(y, z, t, all=True)
    assert expr.has(x, z, t, all=True)
    assert expr.has(x, y, t, all=True)
    assert expr.has(x, y, z, all=True)

    assert expr.has(y, u, t, all=True) is False
    assert expr.has(x, z, u, all=True) is False
    assert expr.has(u, y, z, all=True) is False

    assert expr.has(x, y, z, t, all=True)
    assert expr.has(x, y, z, t, u, all=True) is False

    from sympy.physics.units import m, s

    assert (x*m/s).has(x, all=True)
    assert (x*m/s).has(x, y, all=True) is False

    poly = Poly(x**2 + x*y*sin(z), x, y, t)

    assert poly.has(x, y, z, all=True)
    assert poly.has(x, y, z, t, all=True) is False

    f = FockState((x, y))
    assert f.has(x, y, all=True)
    assert f.has(x, y, z, all=True) is False
Ejemplo n.º 4
0
def test_sympy__physics__secondquant__FockState():
    from sympy.physics.secondquant import FockState
    assert _test_args(FockState((0, 1)))
Ejemplo n.º 5
0
def test_has_physics():
    assert FockState((x, y)).has(x)
Ejemplo n.º 6
0
def test_basic_state():
    i, j, n, m = var('i j n m')
    s = FockState([0, 1, 2, 3, 4])
    assert len(s) == 5
    assert s.args[0] == tuple(range(5))
    assert s.up(0) == FockState([1, 1, 2, 3, 4])
    assert s.down(4) == FockState([0, 1, 2, 3, 3])
    for i in range(5):
        assert s.up(i).down(i) == s
    assert s.down(0) == 0
    for i in range(5):
        assert s[i] == i
    s = FockState([n, m])
    assert s.down(0) == FockState([n - 1, m])
    assert s.up(0) == FockState([n + 1, m])