Example #1
0
def Fmt_test():
    Print_Function()

    e3d = Ga('e1 e2 e3',g=[1,1,1])

    v = e3d.mv('v','vector')
    B = e3d.mv('B','bivector')
    M = e3d.mv('M','mv')

    Fmt(2)

    print '#Global $Fmt = 2$'

    print 'v =',v
    print 'B =',B
    print 'M =',M

    print '#Using $.Fmt()$ Function'

    print 'v.Fmt(3) =',v.Fmt(3)
    print 'B.Fmt(3) =',B.Fmt(3)
    print 'M.Fmt(2) =',M.Fmt(2)
    print 'M.Fmt(1) =',M.Fmt(1)

    print '#Global $Fmt = 1$'

    Fmt(1)

    print 'v =',v
    print 'B =',B
    print 'M =',M

    return
Example #2
0
def properties_of_geometric_objects():
    Print_Function()
    global n, nbar

    g = '# # # 0 0,'+ \
        '# # # 0 0,'+ \
        '# # # 0 0,'+ \
        '0 0 0 0 2,'+ \
        '0 0 0 2 0'

    c3d = Ga('p1 p2 p3 n nbar', g=g)

    (p1, p2, p3, n, nbar) = c3d.mv()

    print 'g_{ij} =\n', c3d.g

    P1 = F(p1)
    P2 = F(p2)
    P3 = F(p3)

    print 'Extracting direction of line from L = P1^P2^n'

    L = P1 ^ P2 ^ n
    delta = (L | n) | nbar
    print '(L|n)|nbar =', delta

    print 'Extracting plane of circle from C = P1^P2^P3'

    C = P1 ^ P2 ^ P3
    delta = ((C ^ n) | n) | nbar
    print '((C^n)|n)|nbar =', delta
    print '(p2-p1)^(p3-p1) =', (p2 - p1) ^ (p3 - p1)
Example #3
0
def derivatives_in_rectangular_coordinates():
    Print_Function()

    X = (x, y, z) = symbols('x y z')
    o3d = Ga('e_x e_y e_z', g=[1, 1, 1], coords=X)
    (ex, ey, ez) = o3d.mv()
    grad = o3d.grad

    f = o3d.mv('f', 'scalar', f=True)
    A = o3d.mv('A', 'vector', f=True)
    B = o3d.mv('B', 'bivector', f=True)
    C = o3d.mv('C', 'mv', f=True)
    print 'f =', f
    print 'A =', A
    print 'B =', B
    print 'C =', C

    print 'grad*f =', grad * f
    print 'grad|A =', grad | A
    print 'grad*A =', grad * A

    print '-I*(grad^A) =', -o3d.E() * (grad ^ A)
    print 'grad*B =', grad * B
    print 'grad^B =', grad ^ B
    print 'grad|B =', grad | B

    print 'grad<A =', grad < A
    print 'grad>A =', grad > A
    print 'grad<B =', grad < B
    print 'grad>B =', grad > B
    print 'grad<C =', grad < C
    print 'grad>C =', grad > C

    return
Example #4
0
def extracting_vectors_from_conformal_2_blade():
    Print_Function()

    g = '0 -1 #,'+ \
        '-1 0 #,'+ \
        '# # #'

    e2b = Ga('P1 P2 a', g=g)

    (P1, P2, a) = e2b.mv()

    print 'g_{ij} =\n', e2b.g

    B = P1 ^ P2
    Bsq = B * B
    print 'B**2 =', Bsq
    ap = a - (a ^ B) * B
    print "a' = a-(a^B)*B =", ap

    Ap = ap + ap * B
    Am = ap - ap * B

    print "A+ = a'+a'*B =", Ap
    print "A- = a'-a'*B =", Am

    print '(A+)^2 =', Ap * Ap
    print '(A-)^2 =', Am * Am

    aB = a | B
    print 'a|B =', aB
    return
Example #5
0
def extracting_vectors_from_conformal_2_blade():
    Print_Function()
    Fmt(1)
    print r'B = P1\W P2'

    g = '0 -1 #,'+ \
        '-1 0 #,'+ \
        '# # #'

    c2b = Ga('P1 P2 a',g=g)
    (P1,P2,a) = c2b.mv()

    print 'g_{ij} =',c2b.g

    B = P1^P2
    Bsq = B*B
    print '%B^{2} =',Bsq
    ap = a-(a^B)*B
    print "a' = a-(a^B)*B =",ap

    Ap = ap+ap*B
    Am = ap-ap*B

    print "A+ = a'+a'*B =",Ap
    print "A- = a'-a'*B =",Am

    print '%(A+)^{2} =',Ap*Ap
    print '%(A-)^{2} =',Am*Am

    aB = a|B
    print 'a|B =',aB
    return
Example #6
0
def properties_of_geometric_objects():
    Print_Function()
    global n, nbar
    Fmt(1)
    g = '# # # 0 0,'+ \
        '# # # 0 0,'+ \
        '# # # 0 0,'+ \
        '0 0 0 0 2,'+ \
        '0 0 0 2 0'

    c3d = Ga('p1 p2 p3 n \\bar{n}',g=g)
    (p1,p2,p3,n,nbar) = c3d.mv()

    print 'g_{ij} =',c3d.g

    P1 = F(p1)
    P2 = F(p2)
    P3 = F(p3)

    print '\\text{Extracting direction of line from }L = P1\\W P2\\W n'

    L = P1^P2^n
    delta = (L|n)|nbar
    print '(L|n)|\\bar{n} =',delta

    print '\\text{Extracting plane of circle from }C = P1\\W P2\\W P3'

    C = P1^P2^P3
    delta = ((C^n)|n)|nbar
    print '((C^n)|n)|\\bar{n}=',delta
    print '(p2-p1)^(p3-p1)=',(p2-p1)^(p3-p1)
    return
Example #7
0
def basic_multivector_operations_3D():
    Print_Function()

    g3d = Ga('e*x|y|z')
    (ex,ey,ez) = g3d.mv()

    A = g3d.mv('A','mv')

    print A.Fmt(1,'A')
    print A.Fmt(2,'A')
    print A.Fmt(3,'A')

    print A.even().Fmt(1,'%A_{+}')
    print A.odd().Fmt(1,'%A_{-}')

    X = g3d.mv('X','vector')
    Y = g3d.mv('Y','vector')

    print 'g_{ij} = ',g3d.g

    print X.Fmt(1,'X')
    print Y.Fmt(1,'Y')

    print (X*Y).Fmt(2,'X*Y')
    print (X^Y).Fmt(2,'X^Y')
    print (X|Y).Fmt(2,'X|Y')
    print cross(X,Y).Fmt(1,r'X\times Y')
    return
Example #8
0
def derivatives_in_rectangular_coordinates():
    Print_Function()
    X = (x, y, z) = symbols('x y z')
    o3d = Ga('e_x e_y e_z', g=[1, 1, 1], coords=X)
    (ex, ey, ez) = o3d.mv()
    grad = o3d.grad

    f = o3d.mv('f', 'scalar', f=True)
    A = o3d.mv('A', 'vector', f=True)
    B = o3d.mv('B', 'bivector', f=True)
    C = o3d.mv('C', 'mv')
    print('f =', f)
    print('A =', A)
    print('B =', B)
    print('C =', C)

    print('grad*f =', grad * f)
    print('grad|A =', grad | A)
    print('grad*A =', grad * A)

    print('-I*(grad^A) =', -o3d.I() * (grad ^ A))
    print('grad*B =', grad * B)
    print('grad^B =', grad ^ B)
    print('grad|B =', grad | B)
    return
Example #9
0
def signature_test():
    Print_Function()

    e3d = Ga('e1 e2 e3', g=[1, 1, 1])
    print 'e3d.g =', e3d.g
    print 'Signature = (3,0) I =', e3d.I(), ' I**2 =', e3d.I() * e3d.I()

    e3d = Ga('e1 e2 e3', g=[2, 2, 2])
    print 'e3d.g =', e3d.g
    print 'Signature = (3,0) I =', e3d.I(), ' I**2 =', e3d.I() * e3d.I()

    sp4d = Ga('e1 e2 e3 e4', g=[1, -1, -1, -1])
    print 'e3d.g =', sp4d.g
    print 'Signature = (1,3) I =', sp4d.I(), ' I**2 =', sp4d.I() * sp4d.I()

    sp4d = Ga('e1 e2 e3 e4', g=[2, -2, -2, -2])
    print 'e3d.g =', sp4d.g
    print 'Signature = (1,3) I =', sp4d.I(), ' I**2 =', sp4d.I() * sp4d.I()

    e4d = Ga('e1 e2 e3 e4', g=[1, 1, 1, 1])
    print 'e4d.g =', e4d.g
    print 'Signature = (4,0) I =', e4d.I(), ' I**2 =', e4d.I() * e4d.I()

    cf3d = Ga('e1 e2 e3 e4 e5', g=[1, 1, 1, 1, -1])
    print 'cf4d.g =', cf3d.g
    print 'Signature = (4,1) I =', cf3d.I(), ' I**2 =', cf3d.I() * cf3d.I()

    cf3d = Ga('e1 e2 e3 e4 e5', g=[2, 2, 2, 2, -2])
    print 'cf4d.g =', cf3d.g
    print 'Signature = (4,1) I =', cf3d.I(), ' I**2 =', cf3d.I() * cf3d.I()

    return
Example #10
0
def signature_test():
    Print_Function()

    e3d = Ga('e1 e2 e3',g=[1,1,1])
    print 'g =', e3d.g
    print r'%Signature = (3,0)\: I =', e3d.I(),'\: I^{2} =', e3d.I()*e3d.I()

    e3d = Ga('e1 e2 e3',g=[2,2,2])
    print 'g =', e3d.g
    print r'%Signature = (3,0)\: I =', e3d.I(),'|; I^{2} =', e3d.I()*e3d.I()

    sp4d = Ga('e1 e2 e3 e4',g=[1,-1,-1,-1])
    print 'g =', sp4d.g
    print r'%Signature = (1,3)\: I =', sp4d.I(),'\: I^{2} =', sp4d.I()*sp4d.I()

    sp4d = Ga('e1 e2 e3 e4',g=[2,-2,-2,-2])
    print 'g =', sp4d.g
    print r'%Signature = (1,3)\: I =', sp4d.I(),'\: I^{2} =', sp4d.I()*sp4d.I()

    e4d = Ga('e1 e2 e3 e4',g=[1,1,1,1])
    print 'g =', e4d.g
    print r'%Signature = (4,0)\: I =', e4d.I(),'\: I^{2} =', e4d.I()*e4d.I()

    cf3d = Ga('e1 e2 e3 e4 e5',g=[1,1,1,1,-1])
    print 'g =', cf3d.g
    print r'%Signature = (4,1)\: I =', cf3d.I(),'\: I^{2} =', cf3d.I()*cf3d.I()

    cf3d = Ga('e1 e2 e3 e4 e5',g=[2,2,2,2,-2])
    print 'g =', cf3d.g
    print r'%Signature = (4,1)\: I =', cf3d.I(),'\: I^{2} =', cf3d.I()*cf3d.I()

    return
    def on_run_pb_clicked(self):
        self.chart.removeAllSeries()
        min_function = 421.0
        ga_answer = 0.0
        correct = 0
        incorrect = 0

        ga = Ga(self.population_sb.value(), self.crossover_dsb.value(),
                self.mutation_dsb.value(), self.generation_sb.value(),
                self.elitism_cb.isChecked())

        progress_dialog = QProgressDialog('Repetitions...', 'Cancel', 0,
                                          self.repetitions_sb.value(),
                                          self.window)
        progress_dialog.setWindowModality(Qt.WindowModal)
        ga_output = ()
        for i in range(self.repetitions_sb.value()):
            ga_output = ga.run_generation()
            ga_answer = ga_output[0]

            if ga_answer == min_function:
                correct += 1
            else:
                incorrect += 1
            progress_dialog.setValue(i)

            if progress_dialog.wasCanceled():
                break

        progress_dialog.setValue(self.repetitions_sb.value())

        if self.single_run_rb.isChecked():
            self.x_result_l.setText(str(ga_answer))
            self.fx_l.setText('{0:.2f}'.format(ga.calc_function(ga_answer)))
            if ga_answer == min_function:
                self.icon_result_l.setPixmap('correct-icon.png')
            else:
                self.icon_result_l.setPixmap('incorrect-icon.png')

            # Graph
            series_1 = QLineSeries()
            series_1.setName('Average Fit')
            series_2 = QLineSeries()
            series_2.setName('Best Fit')
            for i in range(len(ga_output[1])):
                series_1.append(ga_output[1][i], ga_output[2][i])
                series_2.append(ga_output[1][i], ga_output[3][i])
            self.chart.addSeries(series_1)
            self.chart.addSeries(series_2)
            self.chart.createDefaultAxes()

        else:
            self.correct_results_l.setText(str(correct))
            self.incorrect_results_l.setText(str(incorrect))
Example #12
0
def rounding_numerical_components():
    Print_Function()
    o3d = Ga('e_x e_y e_z',g=[1,1,1])
    (ex,ey,ez) = o3d.mv()

    X = 1.2*ex+2.34*ey+0.555*ez
    Y = 0.333*ex+4*ey+5.3*ez

    print 'X =',X
    print 'Nga(X,2) =',Nga(X,2)
    print 'X*Y =',X*Y
    print 'Nga(X*Y,2) =',Nga(X*Y,2)
    return
Example #13
0
def check_generalized_BAC_CAB_formulas():
    Print_Function()
    g4d = Ga('a b c d')
    (a,b,c,d) = g4d.mv()

    print 'g_{ij} =',g4d.g

    print '\\bm{a|(b*c)} =',a|(b*c)
    print '\\bm{a|(b^c)} =',a|(b^c)
    print '\\bm{a|(b^c^d)} =',a|(b^c^d)
    print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',(a|(b^c))+(c|(a^b))+(b|(c^a))
    print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',a*(b^c)-b*(a^c)+c*(a^b)
    print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)
    print '\\bm{(a^b)|(c^d)} =',(a^b)|(c^d)
    print '\\bm{((a^b)|c)|d} =',((a^b)|c)|d
    print '\\bm{(a^b)\\times (c^d)} =',com(a^b,c^d)
    return
Example #14
0
def basic_multivector_operations_2D():
    Print_Function()
    g2d = Ga('e*x|y')
    (ex,ey) = g2d.mv()

    print 'g_{ij} =',g2d.g

    X = g2d.mv('X','vector')
    A = g2d.mv('A','spinor')

    print X.Fmt(1,'X')
    print A.Fmt(1,'A')

    print (X|A).Fmt(2,'X|A')
    print (X<A).Fmt(2,'X<A')
    print (A>X).Fmt(2,'A>X')
    return
Example #15
0
def derivatives_in_spherical_coordinates():
    Print_Function()
    X = (r,th,phi) = symbols('r theta phi')
    s3d = Ga('e_r e_theta e_phi',g=[1,r**2,r**2*sin(th)**2],coords=X,norm=True)
    (er,eth,ephi) = s3d.mv()
    grad = s3d.grad

    f = s3d.mv('f','scalar',f=True)
    A = s3d.mv('A','vector',f=True)
    B = s3d.mv('B','bivector',f=True)

    print 'f =',f
    print 'A =',A
    print 'B =',B

    print 'grad*f =',grad*f
    print 'grad|A =',grad|A
    print '-I*(grad^A) =',(-s3d.E()*(grad^A)).simplify()
    print 'grad^B =',grad^B
Example #16
0
def conformal_representations_of_circles_lines_spheres_and_planes():
    global n, nbar
    Print_Function()

    g = '1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 2,0 0 0 2 0'

    cnfml3d = Ga('e_1 e_2 e_3 n nbar', g=g)

    (e1, e2, e3, n, nbar) = cnfml3d.mv()

    print 'g_{ij} =\n', cnfml3d.g

    e = n + nbar
    #conformal representation of points

    A = make_vector(e1, ga=cnfml3d)  # point a = (1,0,0)  A = F(a)
    B = make_vector(e2, ga=cnfml3d)  # point b = (0,1,0)  B = F(b)
    C = make_vector(-e1, ga=cnfml3d)  # point c = (-1,0,0) C = F(c)
    D = make_vector(e3, ga=cnfml3d)  # point d = (0,0,1)  D = F(d)
    X = make_vector('x', 3, ga=cnfml3d)

    print 'F(a) =', A
    print 'F(b) =', B
    print 'F(c) =', C
    print 'F(d) =', D
    print 'F(x) =', X

    print 'a = e1, b = e2, c = -e1, and d = e3'
    print 'A = F(a) = 1/2*(a*a*n+2*a-nbar), etc.'
    print 'Circle through a, b, and c'
    print 'Circle: A^B^C^X = 0 =', (A ^ B ^ C ^ X)
    print 'Line through a and b'
    print 'Line  : A^B^n^X = 0 =', (A ^ B ^ n ^ X)
    print 'Sphere through a, b, c, and d'
    print 'Sphere: A^B^C^D^X = 0 =', (((A ^ B) ^ C) ^ D) ^ X
    print 'Plane through a, b, and d'
    print 'Plane : A^B^n^D^X = 0 =', (A ^ B ^ n ^ D ^ X)

    L = (A ^ B ^ e) ^ X

    print L.Fmt(3, 'Hyperbolic Circle: (A^B^e)^X = 0 =')
    return
Example #17
0
def conformal_representations_of_circles_lines_spheres_and_planes():
    Print_Function()
    global n, nbar
    Fmt(1)
    g = '1 0 0 0 0,0 1 0 0 0,0 0 1 0 0,0 0 0 0 2,0 0 0 2 0'

    c3d = Ga('e_1 e_2 e_3 n \\bar{n}', g=g)
    (e1, e2, e3, n, nbar) = c3d.mv()

    print('g_{ij} =', c3d.g)

    e = n + nbar
    #conformal representation of points

    A = make_vector(e1, ga=c3d)  # point a = (1,0,0)  A = F(a)
    B = make_vector(e2, ga=c3d)  # point b = (0,1,0)  B = F(b)
    C = make_vector(-e1, ga=c3d)  # point c = (-1,0,0) C = F(c)
    D = make_vector(e3, ga=c3d)  # point d = (0,0,1)  D = F(d)
    X = make_vector('x', 3, ga=c3d)

    print('F(a) =', A)
    print('F(b) =', B)
    print('F(c) =', C)
    print('F(d) =', D)
    print('F(x) =', X)

    print('#a = e1, b = e2, c = -e1, and d = e3')
    print('#A = F(a) = 1/2*(a*a*n+2*a-nbar), etc.')
    print('#Circle through a, b, and c')
    print('Circle: A^B^C^X = 0 =', (A ^ B ^ C ^ X))
    print('#Line through a and b')
    print('Line  : A^B^n^X = 0 =', (A ^ B ^ n ^ X))
    print('#Sphere through a, b, c, and d')
    print('Sphere: A^B^C^D^X = 0 =', (((A ^ B) ^ C) ^ D) ^ X)
    print('#Plane through a, b, and d')
    print('Plane : A^B^n^D^X = 0 =', (A ^ B ^ n ^ D ^ X))

    L = (A ^ B ^ e) ^ X

    L.Fmt(3, 'Hyperbolic\\;\\; Circle: (A^B^e)^X = 0')
    return
Example #18
0
def check_generalized_BAC_CAB_formulas():
    Print_Function()

    g5d = Ga('a b c d e')

    (a, b, c, d, e) = g5d.mv()

    print('g_{ij} =\n', g5d.g)

    print('a|(b*c) =', a | (b * c))
    print('a|(b^c) =', a | (b ^ c))
    print('a|(b^c^d) =', a | (b ^ c ^ d))
    print('a|(b^c)+c|(a^b)+b|(c^a) =', (a | ( b ^ c)) + (c | (a ^ b)) + (b | (c ^ a)))
    print('a*(b^c)-b*(a^c)+c*(a^b) =',a*(b^c)-b*(a^c)+c*(a^b))
    print('a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c) =',a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c))
    print('(a^b)|(c^d) =',(a^b)|(c^d))
    print('((a^b)|c)|d =',((a^b)|c)|d)
    print('(a^b)x(c^d) =',com(a^b,c^d))
    print('(a|(b^c))|(d^e) =',(a|(b^c))|(d^e))

    return
Example #19
0
def basic_multivector_operations_2D_orthogonal():
    Print_Function()
    o2d = Ga('e*x|y',g=[1,1])
    (ex,ey) = o2d.mv()
    print 'g_{ii} =',o2d.g

    X = o2d.mv('X','vector')
    A = o2d.mv('A','spinor')

    print X.Fmt(1,'X')
    print A.Fmt(1,'A')

    print (X*A).Fmt(2,'X*A')
    print (X|A).Fmt(2,'X|A')
    print (X<A).Fmt(2,'X<A')
    print (X>A).Fmt(2,'X>A')

    print (A*X).Fmt(2,'A*X')
    print (A|X).Fmt(2,'A|X')
    print (A<X).Fmt(2,'A<X')
    print (A>X).Fmt(2,'A>X')
    return
Example #20
0
def main():
    Format()
    snr=1
    g = '0 0 1 0 ,0 0 0 1 ,1 0 0 0 ,0 1 0 0'
    sk4coords = (e1,e2,e3,e4) = symbols('e1 e2 e3 e4')
    sk4 = Ga('e_1 e_2 e_3 e_4', g=g, coords=sk4coords)
    (e1,e2,e3,e4) = sk4.mv()
    print 'g_{ii} =',sk4.g

    v = symbols('v', real=True)
    x1=(e1+e3)/sqrt(2)
    x2=(e2+e4)/sqrt(2)
    print 'x_1<x_1==',x1<x1
    print 'x_1<x_2==',x1<x2
    print 'x_2<x_1==',x2<x1
    print 'x_2<x_2==',x2<x2
    print r'#$-\infty < v < \infty$'
    print '(-v*(x_1^x_2)/2).exp()==',(-v*(x1^x2)/2).exp()
    v = symbols('v', real=True, positive=True)
    print r'#$0\le v < \infty$'
    print '(-v*(x_1^x_2)/2).exp()==',(-v*(x1^x2)/2).exp()

    xpdf()
    return
Example #21
0
from sympy import symbols, sin, pi, latex
from ga import Ga
from printer import Format, xpdf

Format()
coords = (r, th, phi) = symbols('r,theta,phi', real=True)
sp3d = Ga('e_r e_th e_ph', g=[1, r**2, r**2*sin(th)**2],\
          coords=coords, norm=True)

sph_uv = (u, v) = symbols('u,v', real=True)
sph_map = [1, u, v]  # Coordinate map for sphere of r = 1
sph2d = sp3d.sm(sph_map, sph_uv)

print(r'(u,v)\rightarrow (r,\theta,\phi) = ', latex(sph_map))
print('g =', latex(sph2d.g))
F = sph2d.mv('F', 'vector', f=True)  #scalar function
f = sph2d.mv('f', 'scalar', f=True)  #vector function
print(r'\nabla f =', sph2d.grad * f)
print('F =', F)
print(r'\nabla F = ', sph2d.grad * F)

cir_s = s = symbols('s', real=True)
cir_map = [pi / 8, s]
cir1d = sph2d.sm(cir_map, (cir_s, ))

print('g =', latex(cir1d.g))
h = cir1d.mv('h', 'scalar', f=True)
H = cir1d.mv('H', 'vector', f=True)
print(r'(s)\rightarrow (u,v) = ', latex(cir_map))
print('H =', H)
print(latex(H))
Example #22
0

def norm(X):
    Y = sqrt((X * X).scalar())
    return Y


Get_Program(True)
Eprint()

g = '1 0 0 0, \
   0 1 0 0, \
   0 0 0 2, \
   0 0 2 0'

c2d = Ga('e_1 e_2 n \\bar{n}', g=g)
(e1, e2, n, nbar) = c2d.mv()

global n, nbar, I


def F(x):
    global n, nbar
    Fx = ((x * x) * n + 2 * x - nbar) / 2
    return (Fx)


e = (n + nbar) / 2
ebar = n - e
I = e1 * e2 * e * ebar
Example #23
0
from sympy import expand,simplify
from printer import Format,xpdf
from ga import Ga

g = '1 # #,'+ \
    '# 1 #,'+ \
    '# # 1'

Format()

ng3d = Ga('e1 e2 e3',g=g)
(e1,e2,e3) = ng3d.mv()
print 'g_{ij} =',ng3d.g
E = e1^e2^e3
Esq = (E*E).scalar()
print 'E =',E
print '%E^{2} =',Esq
Esq_inv = 1/Esq
E1 = (e2^e3)*E
E2 = (-1)*(e1^e3)*E
E3 = (e1^e2)*E
print 'E1 = (e2^e3)*E =',E1
print 'E2 =-(e1^e3)*E =',E2
print 'E3 = (e1^e2)*E =',E3
w = (E1|e2)
w = w.expand()
print 'E1|e2 =',w
w = (E1|e3)
w = w.expand()
print 'E1|e3 =',w
w = (E2|e1)
Example #24
0
def basic_multivector_operations():
    Print_Function()
    g3d = Ga('e*x|y|z')
    (ex, ey, ez) = g3d.mv()

    A = g3d.mv('A', 'mv')

    print A.Fmt(1, 'A')
    print A.Fmt(2, 'A')
    print A.Fmt(3, 'A')

    X = g3d.mv('X', 'vector')
    Y = g3d.mv('Y', 'vector')

    print 'g_{ij} =\n', g3d.g

    print X.Fmt(1, 'X')
    print Y.Fmt(1, 'Y')

    print(X * Y).Fmt(2, 'X*Y')
    print(X ^ Y).Fmt(2, 'X^Y')
    print(X | Y).Fmt(2, 'X|Y')

    g2d = Ga('e*x|y')

    (ex, ey) = g2d.mv()

    print 'g_{ij} =\n', g2d.g

    X = g2d.mv('X', 'vector')
    A = g2d.mv('A', 'spinor')

    print X.Fmt(1, 'X')
    print A.Fmt(1, 'A')

    print(X | A).Fmt(2, 'X|A')
    print(X < A).Fmt(2, 'X<A')
    print(A > X).Fmt(2, 'A>X')

    o2d = Ga('e*x|y', g=[1, 1])

    (ex, ey) = o2d.mv()

    print 'g_{ii} =\n', o2d.g

    X = o2d.mv('X', 'vector')
    A = o2d.mv('A', 'spinor')

    print X.Fmt(1, 'X')
    print A.Fmt(1, 'A')

    print(X * A).Fmt(2, 'X*A')
    print(X | A).Fmt(2, 'X|A')
    print(X < A).Fmt(2, 'X<A')
    print(X > A).Fmt(2, 'X>A')

    print(A * X).Fmt(2, 'A*X')
    print(A | X).Fmt(2, 'A|X')
    print(A < X).Fmt(2, 'A<X')
    print(A > X).Fmt(2, 'A>X')
    return
Example #25
0
def noneuclidian_distance_calculation():
    from sympy import solve, sqrt
    Print_Function()

    g = '0 # #,# 0 #,# # 1'
    necl = Ga('X Y e', g=g)
    (X, Y, e) = necl.mv()

    print 'g_{ij} =', necl.g

    print '(X^Y)**2 =', (X ^ Y) * (X ^ Y)

    L = X ^ Y ^ e
    B = (L * e).expand().blade_rep()  # D&L 10.152
    print 'B =', B
    Bsq = B * B
    print 'B**2 =', Bsq.obj
    Bsq = Bsq.scalar()
    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 =', B * B
    print 'L**2 =', L * L  # D&L 10.153
    (s, c, Binv, M, S, C, alpha) = symbols('s c (1/B) M S C alpha')

    XdotY = necl.g[0, 1]
    Xdote = necl.g[0, 2]
    Ydote = necl.g[1, 2]

    Bhat = Binv * B  # D&L 10.154
    R = c + s * Bhat  # Rotor R = exp(alpha*Bhat/2)
    print 's = sinh(alpha/2) and c = cosh(alpha/2)'
    print 'exp(alpha*B/(2*|B|)) =', R

    Z = R * X * R.rev()  # D&L 10.155
    Z.obj = expand(Z.obj)
    Z.obj = Z.obj.collect([Binv, s, c, XdotY])
    print Z.Fmt(3, 'R*X*R.rev()')
    W = Z | Y  # Extract scalar part of multivector
    # From this point forward all calculations are with sympy scalars
    print 'Objective is to determine value of C = cosh(alpha) such that W = 0'
    W = W.scalar()
    print 'Z|Y =', W
    W = expand(W)
    W = simplify(W)
    W = W.collect([s * Binv])

    M = 1 / Bsq
    W = W.subs(Binv**2, M)
    W = simplify(W)
    Bmag = sqrt(XdotY**2 - 2 * XdotY * Xdote * Ydote)
    W = W.collect([Binv * c * s, XdotY])

    #Double angle substitutions

    W = W.subs(2 * XdotY**2 - 4 * XdotY * Xdote * Ydote, 2 / (Binv**2))
    W = W.subs(2 * c * s, S)
    W = W.subs(c**2, (C + 1) / 2)
    W = W.subs(s**2, (C - 1) / 2)
    W = simplify(W)
    W = W.subs(1 / Binv, Bmag)
    W = expand(W)

    print 'S = sinh(alpha) and C = cosh(alpha)'

    print 'W =', W

    Wd = collect(W, [C, S], exact=True, evaluate=False)
    print 'Wd =', Wd
    Wd_1 = Wd[one]
    Wd_C = Wd[C]
    Wd_S = Wd[S]

    print 'Scalar Coefficient =', Wd_1
    print 'Cosh Coefficient =', Wd_C
    print 'Sinh Coefficient =', Wd_S

    print '|B| =', Bmag
    Wd_1 = Wd_1.subs(Bmag, 1 / Binv)
    Wd_C = Wd_C.subs(Bmag, 1 / Binv)
    Wd_S = Wd_S.subs(Bmag, 1 / Binv)

    lhs = Wd_1 + Wd_C * C
    rhs = -Wd_S * S
    lhs = lhs**2
    rhs = rhs**2
    W = expand(lhs - rhs)
    W = expand(W.subs(1 / Binv**2, Bmag**2))
    W = expand(W.subs(S**2, C**2 - 1))
    W = W.collect([C, C**2], evaluate=False)

    a = simplify(W[C**2])
    b = simplify(W[C])
    c = simplify(W[one])

    print 'Require a*C**2+b*C+c = 0'

    print 'a =', a
    print 'b =', b
    print 'c =', c

    x = Symbol('x')
    C = solve(a * x**2 + b * x + c, x)[0]
    print 'cosh(alpha) = C = -b/(2*a) =', expand(simplify(expand(C)))
    return
Example #26
0
def reciprocal_frame_test():
    Print_Function()

    g = '1 # #,'+ \
        '# 1 #,'+ \
        '# # 1'

    g3dn = Ga('e1 e2 e3', g=g)

    (e1, e2, e3) = g3dn.mv()

    print 'g_{ij} =\n', g3dn.g

    E = e1 ^ e2 ^ e3
    Esq = (E * E).scalar()
    print 'E =', E
    print 'E**2 =', Esq
    Esq_inv = 1 / Esq

    E1 = (e2 ^ e3) * E
    E2 = (-1) * (e1 ^ e3) * E
    E3 = (e1 ^ e2) * E

    print 'E1 = (e2^e3)*E =', E1
    print 'E2 =-(e1^e3)*E =', E2
    print 'E3 = (e1^e2)*E =', E3

    w = (E1 | e2)
    w = w.expand()
    print 'E1|e2 =', w

    w = (E1 | e3)
    w = w.expand()
    print 'E1|e3 =', w

    w = (E2 | e1)
    w = w.expand()
    print 'E2|e1 =', w

    w = (E2 | e3)
    w = w.expand()
    print 'E2|e3 =', w

    w = (E3 | e1)
    w = w.expand()
    print 'E3|e1 =', w

    w = (E3 | e2)
    w = w.expand()
    print 'E3|e2 =', w

    w = (E1 | e1)
    w = (w.expand()).scalar()
    Esq = expand(Esq)
    print '(E1|e1)/E**2 =', simplify(w / Esq)

    w = (E2 | e2)
    w = (w.expand()).scalar()
    print '(E2|e2)/E**2 =', simplify(w / Esq)

    w = (E3 | e3)
    w = (w.expand()).scalar()
    print '(E3|e3)/E**2 =', simplify(w / Esq)

    return
Example #27
0
import sys
from sympy import symbols, sin, latex, diff, Function, expand
from ga import Ga
from lt import Mlt
from printer import Eprint, Format, xpdf

Format()

#Define spherical coordinate system in 3-d

coords = (r, th, phi) = symbols('r,theta,phi', real=True)

sp3d = Ga('e_r,e_th,e_ph', g=[1, r**2, r**2 * sin(th)**2], coords=coords)
(er, eth, ephi) = sp3d.mv()

#Define coordinates for 2-d (u,v) and 1-d (s) manifolds

u, v, s, alpha = symbols('u v s alpha', real=True)

sub_coords = (u, v)

smap = [1, u, v]  # Coordinate map for sphere of r = 1 in 3-d

print r'(u,v)\rightarrow (r,\theta,\phi) = ', smap

#Define unit sphere manifold

sph2d = sp3d.sm(smap, sub_coords)

print '#Unit Sphere Manifold:'
Example #28
0
File: main.py Project: Icorp/cosum
kmeans = K_means(K, max_iterations=100000)
for i in range(1000):
    try:
        kmeans.fit(vector, metric="similarity")
        break
    except ZeroDivisionError:
        print("Попытка #", i)
print("Класстеризация завершена ...")

# X = [1,2,4,1,2,3,5,7,2]  This is number of cluster
X = kmeans.labels
clusterSentence = clusteringSentence(X)

# Start compute genetic algorithm
print("Старт генетического алгоритма ...")
genetic = Ga(t_max=1000, pop_size=200)
genetic.fit(vector, kmeans.cq, kmeans.centroids, l_avg, clusterSentence, K)
print("Рассчет генетического алгоритма завершена ...")

# Convert genomes to normal summary text
indexs = genetic.best_summary

summary = ""
fx = genetic.F
for i in indexs:
    summary += (sentences[i])

print("\nЛучший набор предложении")
print(indexs)

# calculate Rouge
Example #29
0
def main():
    Format()
    (g3d,ex,ey,ez) = Ga.build('e*x|y|z')
    A = g3d.mv('A','mv')
    print r'\bm{A} =',A
    A.Fmt(2,r'\bm{A}')
    A.Fmt(3,r'\bm{A}')

    X = (x,y,z) = symbols('x y z',real=True)
    o3d = Ga('e_x e_y e_z',g=[1,1,1],coords=X)
    (ex,ey,ez) = o3d.mv()

    f = o3d.mv('f','scalar',f=True)
    A = o3d.mv('A','vector',f=True)
    B = o3d.mv('B','bivector',f=True)

    print r'\bm{A} =',A
    print r'\bm{B} =',B

    print 'grad*f =',o3d.grad*f
    print r'grad|\bm{A} =',o3d.grad|A
    print r'grad*\bm{A} =',o3d.grad*A

    print r'-I*(grad^\bm{A}) =',-o3d.i*(o3d.grad^A)
    print r'grad*\bm{B} =',o3d.grad*B
    print r'grad^\bm{B} =',o3d.grad^B
    print r'grad|\bm{B} =',o3d.grad|B

    g4d = Ga('a b c d')

    (a,b,c,d) = g4d.mv()

    print 'g_{ij} =',g4d.g

    print '\\bm{a|(b*c)} =',a|(b*c)
    print '\\bm{a|(b^c)} =',a|(b^c)
    print '\\bm{a|(b^c^d)} =',a|(b^c^d)
    print '\\bm{a|(b^c)+c|(a^b)+b|(c^a)} =',(a|(b^c))+(c|(a^b))+(b|(c^a))
    print '\\bm{a*(b^c)-b*(a^c)+c*(a^b)} =',a*(b^c)-b*(a^c)+c*(a^b)
    print '\\bm{a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)} =',a*(b^c^d)-b*(a^c^d)+c*(a^b^d)-d*(a^b^c)
    print '\\bm{(a^b)|(c^d)} =',(a^b)|(c^d)
    print '\\bm{((a^b)|c)|d} =',((a^b)|c)|d
    print '\\bm{(a^b)\\times (c^d)} =',Com(a^b,c^d)

    g = '1 # #,'+ \
         '# 1 #,'+ \
         '# # 1'

    ng3d = Ga('e1 e2 e3',g=g)
    (e1,e2,e3) = ng3d.mv()

    E = e1^e2^e3
    Esq = (E*E).scalar()
    print 'E =',E
    print '%E^{2} =',Esq
    Esq_inv = 1/Esq

    E1 = (e2^e3)*E
    E2 = (-1)*(e1^e3)*E
    E3 = (e1^e2)*E

    print 'E1 = (e2^e3)*E =',E1
    print 'E2 =-(e1^e3)*E =',E2
    print 'E3 = (e1^e2)*E =',E3

    print 'E1|e2 =',(E1|e2).expand()
    print 'E1|e3 =',(E1|e3).expand()
    print 'E2|e1 =',(E2|e1).expand()
    print 'E2|e3 =',(E2|e3).expand()
    print 'E3|e1 =',(E3|e1).expand()
    print 'E3|e2 =',(E3|e2).expand()
    w = ((E1|e1).expand()).scalar()
    Esq = expand(Esq)
    print '%(E1\\cdot e1)/E^{2} =',simplify(w/Esq)
    w = ((E2|e2).expand()).scalar()
    print '%(E2\\cdot e2)/E^{2} =',simplify(w/Esq)
    w = ((E3|e3).expand()).scalar()
    print '%(E3\\cdot e3)/E^{2} =',simplify(w/Esq)

    X = (r,th,phi) = symbols('r theta phi')
    s3d = Ga('e_r e_theta e_phi',g=[1,r**2,r**2*sin(th)**2],coords=X,norm=True)
    (er,eth,ephi) = s3d.mv()

    f = s3d.mv('f','scalar',f=True)
    A = s3d.mv('A','vector',f=True)
    B = s3d.mv('B','bivector',f=True)

    print 'A =',A
    print 'B =',B

    print 'grad*f =',s3d.grad*f
    print 'grad|A =',s3d.grad|A
    print '-I*(grad^A) =',-s3d.i*(s3d.grad^A)
    print 'grad^B =',s3d.grad^B

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords)
    (g0,g1,g2,g3) = m4d.mv()
    I = m4d.i

    B = m4d.mv('B','vector',f=True)
    E = m4d.mv('E','vector',f=True)
    B.set_coef(1,0,0)
    E.set_coef(1,0,0)
    B *= g0
    E *= g0
    J = m4d.mv('J','vector',f=True)
    F = E+I*B

    print 'B = \\bm{B\\gamma_{t}} =',B
    print 'E = \\bm{E\\gamma_{t}} =',E
    print 'F = E+IB =',F
    print 'J =',J
    gradF = m4d.grad*F
    gradF.Fmt(3,'grad*F')

    print 'grad*F = J'
    (gradF.get_grade(1)-J).Fmt(3,'%\\grade{\\nabla F}_{1} -J = 0')
    (gradF.get_grade(3)).Fmt(3,'%\\grade{\\nabla F}_{3} = 0')

    (alpha,beta,gamma) = symbols('alpha beta gamma')

    (x,t,xp,tp) = symbols("x t x' t'")
    m2d = Ga('gamma*t|x',g=[1,-1])
    (g0,g1) = m2d.mv()

    R = cosh(alpha/2)+sinh(alpha/2)*(g0^g1)
    X = t*g0+x*g1
    Xp = tp*g0+xp*g1
    print 'R =',R

    print r"#%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} = t'\bm{\gamma'_{t}}+x'\bm{\gamma'_{x}} = R\lp t'\bm{\gamma_{t}}+x'\bm{\gamma_{x}}\rp R^{\dagger}"

    Xpp = R*Xp*R.rev()
    Xpp = Xpp.collect()
    Xpp = Xpp.trigsimp()
    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp
    Xpp = Xpp.subs({sinh(alpha):gamma*beta,cosh(alpha):gamma})

    print r'%\f{\sinh}{\alpha} = \gamma\beta'
    print r'%\f{\cosh}{\alpha} = \gamma'

    print r"%t\bm{\gamma_{t}}+x\bm{\gamma_{x}} =",Xpp.collect()

    coords = symbols('t x y z')
    m4d = Ga('gamma*t|x|y|z',g=[1,-1,-1,-1],coords=coords)
    (g0,g1,g2,g3) = m4d.mv()
    I = m4d.i
    (m,e) = symbols('m e')

    psi = m4d.mv('psi','spinor',f=True)
    A = m4d.mv('A','vector',f=True)
    sig_z = g3*g0
    print '\\bm{A} =',A
    print '\\bm{\\psi} =',psi

    dirac_eq = (m4d.grad*psi)*I*sig_z-e*A*psi-m*psi*g0
    dirac_eq.simplify()

    dirac_eq.Fmt(3,r'\nabla \bm{\psi} I \sigma_{z}-e\bm{A}\bm{\psi}-m\bm{\psi}\gamma_{t} = 0')

    xpdf()
    return
Example #30
0
B2d = g2d.lt('B')

print('B =', B2d)
print('A + B =', A2d + B2d)
print('AB =', A2d * B2d)
print('A - B =', A2d - B2d)

a = g2d.mv('a', 'vector')
b = g2d.mv('b', 'vector')

print(r'a|\f{\overline{A}}{b}-b|\f{\underline{A}}{a} =',
      ((a | A2d.adj()(b)) - (b | A2d(a))).simplify())

m4d = Ga('e_t e_x e_y e_z',
         g=[1, -1, -1, -1],
         coords=symbols('t,x,y,z', real=True))

T = m4d.lt('T')

print('#$T$ is a linear transformation in Minkowski space')
print(r'\underline{T} =', T)
print(r'\overline{T} =', T.adj())
print(r'\f{\mbox{tr}}{\underline{T}} =', T.tr())

a = m4d.mv('a', 'vector')
b = m4d.mv('b', 'vector')

print(r'a|\f{\overline{T}}{b}-b|\f{\underline{T}}{a} =',
      ((a | T.adj()(b)) - (b | T(a))).simplify())