Beispiel #1
0
def test_substitution():

    MV.setup('e_x e_y e_z','1 0 0, 0 1 0, 0 0 1',offset=1)
    make_symbols('x y z')

    X = x*e_x+y*e_y+z*e_z
    Y = X.subs([(x,2),(y,3),(z,4)])
    assert Y == 2*e_x+3*e_y+4*e_z
Beispiel #2
0
def test_substitution():

    MV.setup('e_x e_y e_z','1 0 0, 0 1 0, 0 0 1',offset=1)
    make_symbols('x y z')

    X = x*e_x+y*e_y+z*e_z
    Y = X.subs([(x,2),(y,3),(z,4)])
    assert Y == 2*e_x+3*e_y+4*e_z
Beispiel #3
0
def test_substitution():

    MV.setup("e_x e_y e_z", "1 0 0, 0 1 0, 0 0 1", offset=1)
    make_symbols("x y z")

    X = x * e_x + y * e_y + z * e_z
    Y = X.subs([(x, 2), (y, 3), (z, 4)])
    assert Y == 2 * e_x + 3 * e_y + 4 * e_z
Beispiel #4
0
def test_rmul():
    """
    Test for commutative scalar multiplication.  Leftover from when sympy and
    numpy were not working together and __mul__ and __rmul__ would not give the
    same answer.
    """
    MV.setup('x y z')
    make_symbols('a b c')
    assert 5*x == x*5
    assert HALF*x == x*HALF
    assert a*x == x*a
Beispiel #5
0
def test_rmul():
    """
    Test for communitive scalar multiplication.  Leftover from when sympy and
    numpy were not working together and __mul__ and __rmul__ would not give the
    same answer.
    """
    MV.setup('x y z')
    make_symbols('a b c')
    assert 5*x == x*5
    assert HALF*x == x*HALF
    assert a*x == x*a
Beispiel #6
0
def test_constructor():
    """
    Test various multivector constructors
    """
    MV.setup('e_1 e_2 e_3','[1,1,1]')
    make_symbols('x')
    assert str(S(1)) == '1'
    assert str(S(x)) == 'x'
    assert str(MV('a','scalar')) == 'a'
    assert str(MV('a','vector')) == 'a__0*e_1+a__1*e_2+a__2*e_3'
    assert str(MV('a','pseudo')) == 'a*e_1e_2e_3'
    assert str(MV('a','spinor')) == 'a+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
    assert str(MV('a')) == 'a+a__0*e_1+a__1*e_2+a__2*e_3+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3+a__012*e_1e_2e_3'
    assert str(MV([2,'a'],'grade')) == 'a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
    assert str(MV('a','grade2')) == 'a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
Beispiel #7
0
def test_constructor():
    """
    Test various multivector constructors
    """
    MV.setup('e_1 e_2 e_3','[1,1,1]')
    make_symbols('x')
    assert str(S(1)) == '1'
    assert str(S(x)) == 'x'
    assert str(MV('a','scalar')) == 'a'
    assert str(MV('a','vector')) == 'a__0*e_1+a__1*e_2+a__2*e_3'
    assert str(MV('a','pseudo')) == 'a*e_1e_2e_3'
    assert str(MV('a','spinor')) == 'a+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
    assert str(MV('a')) == 'a+a__0*e_1+a__1*e_2+a__2*e_3+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3+a__012*e_1e_2e_3'
    assert str(MV([2,'a'],'grade')) == 'a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
    assert str(MV('a','grade2')) == 'a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3'
Beispiel #8
0
def test_constructor():
    """
    Test various multivector constructors
    """
    MV.setup("e_1 e_2 e_3", "[1,1,1]")
    make_symbols("x")
    assert str(S(1)) == "1"
    assert str(S(x)) == "x"
    assert str(MV("a", "scalar")) == "a"
    assert str(MV("a", "vector")) == "a__0*e_1+a__1*e_2+a__2*e_3"
    assert str(MV("a", "pseudo")) == "a*e_1e_2e_3"
    assert str(MV("a", "spinor")) == "a+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3"
    assert str(MV("a")) == "a+a__0*e_1+a__1*e_2+a__2*e_3+a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3+a__012*e_1e_2e_3"
    assert str(MV([2, "a"], "grade")) == "a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3"
    assert str(MV("a", "grade2")) == "a__01*e_1e_2+a__02*e_1e_3+a__12*e_2e_3"
Beispiel #9
0
def make_vector(a,n = 3):
    if type(a) == str:
        sym_str = ''
        for i in range(n):
            sym_str += a+str(i)+' '
        sym_lst = make_symbols(sym_str)
        sym_lst.append(ZERO)
        sym_lst.append(ZERO)
        a = MV(sym_lst,'vector')
    return(F(a))
Beispiel #10
0
def test_derivative():
    coords = make_symbols('x y z')
    MV.setup('e','1 0 0, 0 1 0, 0 0 1',coords=coords)
    X = x*e_x+y*e_y+z*e_z
    a = MV('a','vector')

    assert ((X|a).grad()) == a
    assert ((X*X).grad()) == 2*X
    assert (X*X*X).grad() == 5*X*X
    assert X.grad_int() == 3
Beispiel #11
0
def make_vector(a,n = 3):
    if type(a) == types.StringType:
        sym_str = ''
        for i in range(n):
            sym_str += a+str(i)+' '
        sym_lst = make_symbols(sym_str)
        sym_lst.append(ZERO)
        sym_lst.append(ZERO)
        a = MV(sym_lst,'vector')
    return(F(a))
Beispiel #12
0
def test_derivative():
    coords = make_symbols('x y z')
    MV.setup('e','1 0 0, 0 1 0, 0 0 1',coords=coords)
    X = x*e_x+y*e_y+z*e_z
    a = MV('a','vector')

    assert ((X|a).grad()) == a
    assert ((X*X).grad()) == 2*X
    assert (X*X*X).grad() == 5*X*X
    assert X.grad_int() == 3
Beispiel #13
0
def make_vector(a, n=3):
    if type(a) == str:
        sym_str = ""
        for i in range(n):
            sym_str += a + str(i) + " "
        sym_lst = make_symbols(sym_str)
        sym_lst.append(ZERO)
        sym_lst.append(ZERO)
        a = MV(sym_lst, "vector")
    return F(a)
Beispiel #14
0
def test_derivative():
    coords = make_symbols("x y z")
    MV.setup("e", "1 0 0, 0 1 0, 0 0 1", coords=coords)
    X = x * e_x + y * e_y + z * e_z
    a = MV("a", "vector")

    assert ((X | a).grad()) == a
    assert ((X * X).grad()) == 2 * X
    assert (X * X * X).grad() == 5 * X * X
    assert X.grad_int() == 3
Beispiel #15
0
    print 'Example: non-euclidian distance calculation'

    metric = '0 # #,# 0 #,# # 1'
    MV.setup('X Y e',metric)
    MV.set_str_format(1)
    L = X^Y^e
    B = L*e
    Bsq = (B*B)()
    print 'L = X^Y^e is a non-euclidian line'
    print 'B = L*e =',B
    BeBr =B*e*B.rev()
    print 'B*e*B.rev() =',BeBr
    print 'B^2 =',Bsq
    print 'L^2 =',(L*L)()
    make_symbols('s c Binv M S C alpha')
    Bhat = Binv*B # Normalize translation generator
    R = c+s*Bhat # Rotor R = exp(alpha*Bhat/2)
    print 's = sinh(alpha/2) and c = cosh(alpha/2)'
    print 'R = exp(alpha*B/(2*|B|)) =',R
    Z = R*X*R.rev()
    Z.expand()
    Z.collect([Binv,s,c,XdotY])
    print 'R*X*R.rev() =',Z
    W = Z|Y
    W.expand()
    W.collect([s*Binv])
    print '(R*X*rev(R)).Y =',W
    M = 1/Bsq
    W.subs(Binv**2,M)
    W.simplify()