Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR from abrombo/galgebra:master for reference (with merge conflicts solved) #62

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c4ec678
Modified printer.py so that printer api follows python 3 api for print
abrombo Oct 11, 2019
d8a1661
Added comments to several modules and fixed problems in mv.py for Pdop
abrombo Nov 12, 2019
d802096
Remove executable bits that were erroneously added in the last commits
eric-wieser Nov 21, 2019
0f0c3ad
Delete some unwanted files
eric-wieser Apr 21, 2020
6727464
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser Nov 21, 2019
7184d82
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser Apr 21, 2020
7bf587e
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser Apr 22, 2020
3182784
Revert some unwanted changes
eric-wieser Apr 22, 2020
7988e73
Add back the executable bit
eric-wieser Apr 22, 2020
c811dac
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser Apr 23, 2020
bfeaddb
Fix flake8 issues
eric-wieser Apr 23, 2020
9f8a1ec
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser Apr 25, 2020
1234445
Move methods down to reduce the overall diff
eric-wieser Apr 29, 2020
956e006
Remove commented-out code
eric-wieser May 15, 2020
9aa5005
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser May 15, 2020
c676643
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser May 17, 2020
309bbd7
Remove self-import flagged by LGTM
eric-wieser May 17, 2020
6fca038
Merge commit '677360f1b5d5b4b4cdb3e5da9731fc9198f89f20' into abrombo-…
eric-wieser May 26, 2020
53ca57a
Merge commit '61763a038e90c766206c9c7f65f96d39a540411d' into abrombo-…
eric-wieser May 26, 2020
76315e4
Merge remote-tracking branch 'upstream/master' into abrombo-master-merge
eric-wieser May 26, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified examples/LaTeX/4Derr.pdf
Binary file not shown.
24 changes: 12 additions & 12 deletions examples/LaTeX/4Derr.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
from __future__ import print_function
from sympy import *
from galgebra.printer import Format,xpdf,xdvi
from galgebra.printer import Format,xtex
from galgebra.ga import Ga

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')
sk4coords = (e1,e2,e3,e4) = symbols('e1 e2 e3 e4', real=True)
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)
print('g =',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())
print(r'x_1\lfloor x_1==',x1<x1)
print('x_1\lfloor x_2==',x1<x2)
print('x_2\lfloor x_1==',x2<x1)
print('x_2\lfloor x_2==',x2<x2)
print(r'-\infty < v < \infty')
print(r'e^{-v(x_1\W x_2)/2} ==',(-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())
print(r'0\le v \le \infty')
print(r'e^{-v(x_1\W x_2)/2)} ==',(-v*(x1^x2)/2).exp())

xpdf(pdfprog=None)
xtex()
return

if __name__ == "__main__":
Expand Down
Binary file modified examples/LaTeX/Dop.pdf
Binary file not shown.
28 changes: 12 additions & 16 deletions examples/LaTeX/Dop.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
from sympy import symbols, sin
from galgebra.printer import Format, xpdf, Fmt
from galgebra.printer import Format, xpdf, Fmt, xtex
from galgebra.ga import Ga
import sys

Expand All @@ -10,25 +10,21 @@
f = o3d.mv('f', 'scalar', f=True)
lap = o3d.grad*o3d.grad
print(r'\nabla =', o3d.grad)
print(r'%\nabla^{2} = \nabla . \nabla =', lap)
print(r'%\lp\nabla^{2}\rp f =', lap*f)
print(r'%\nabla\cdot\lp\nabla f\rp =', o3d.grad | (o3d.grad * f))
print(r'\nabla^{2} = \nabla . \nabla =', lap)
print(r'\lp\nabla^{2}\rp f =', lap*f)
print(r'\nabla\cdot\lp\nabla f\rp =', o3d.grad | (o3d.grad * f))

sph_coords = (r, th, phi) = symbols('r theta phi', real=True)
(sp3d, er, eth, ephi) = Ga.build('e', g=[1, r**2, r**2 * sin(th)**2], coords=sph_coords, norm=True)
f = sp3d.mv('f', 'scalar', f=True)
lap = sp3d.grad*sp3d.grad
print(r'%\nabla^{2} = \nabla\cdot\nabla =', lap)
print(r'%\lp\nabla^{2}\rp f =', lap*f)
print(r'%\nabla\cdot\lp\nabla f\rp =', sp3d.grad | (sp3d.grad * f))
print(r'\nabla^{2} = \nabla\cdot\nabla =', lap)
print(r'\lp\nabla^{2}\rp f =', lap*f)
print(r'\nabla\cdot\lp\nabla f\rp =', sp3d.grad | (sp3d.grad * f))
print(Fmt([o3d.grad, o3d.grad]))
F = sp3d.mv('F', 'vector', f=True)
print(F.title)
print(F)
F.fmt = 3
print(F.title)
print(F)
print(F.title)
print(Fmt((F,F)))
# xpdf(paper=(6, 7))
xpdf(pdfprog=None, paper=(6, 7))
print('F =',F)
print('F =',F.xFmt(3))
print('F =',Fmt((F,F)))
#xtex(tex='texmaker')
xtex()
198 changes: 198 additions & 0 deletions examples/LaTeX/chap11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
import unittest
from functools import reduce
from sympy import simplify, sqrt, Rational, Symbol
from galgebra.ga import Ga
from galgebra.mv import Mv
from galgebra.printer import Format, xtex
Format()
class TestChapter11(unittest.TestCase):

def assertEquals(self, first, second, msg=None):
"""
Compare two expressions are equals.
"""

if isinstance(first, Mv):
first = first.obj

if isinstance(second, Mv):
second = second.obj

diff = simplify(first - second)

self.assertTrue(diff == 0, "\n%s\n==\n%s\n%s" % (first, second, diff))

def assertNotEquals(self, first, second, msg=None):
"""
Compare two expressions are equals.
"""

if isinstance(first, Mv):
first = first.obj

if isinstance(second, Mv):
second = second.obj

diff = simplify(first - second)

self.assertTrue(diff != 0, "\n%s\n!=\n%s\n%s" % (first, second, diff))

def test11_4(self):
"""
All planes are 3-blades.
"""
GA, e_0, e_1, e_2, e_3 = Ga.build("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1')

p0 = Symbol('p0')
q0 = Symbol('q0')
r0 = Symbol('r0')

p = GA.mv((p0, Symbol('p1'), Symbol('p2'), Symbol('p3')), 'vector')
q = GA.mv((q0, Symbol('q1'), Symbol('q2'), Symbol('q3')), 'vector')
r = GA.mv((r0, Symbol('r1'), Symbol('r2'), Symbol('r3')), 'vector')

p_inf = p.subs(p0,0)
q_inf = q.subs(q0,0)
r_inf = r.subs(r0,0)

p = p.subs(p0,1)
q = q.subs(q0,1)
r = r.subs(r0,1)

self.assertEquals(p ^ q ^ r, p ^ (q - p) ^ (r - p))
self.assertEquals(p ^ q ^ r, p ^ (q_inf - p_inf) ^ (r_inf - p_inf))
self.assertEquals(p ^ q ^ r, ((p + q + r) / 3) ^ ((p ^ q) + (q ^ r) + (r ^ p)))

def test11_6(self):
"""
Dual representation.
"""
Ga.dual_mode('Iinv+')

GA_list = [
Ga("e*0|1|2", g='-1 0 0, 0 1 0, 0 0 1'),
Ga("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1'),
Ga("e*0|1|2|3|5", g='-1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0, 0 0 0 0 1'),
]

for GA in GA_list:
e_0 = GA.mv_basis[0]
e_0_inv = e_0.inv()

Ip = GA.I()
Ip_inv = Ip.inv()
Ir = e_0_inv < Ip
Ir_inv = Ir.inv()
self.assertEquals(Ip, e_0 ^ Ir)
self.assertEquals(Ip, e_0 * Ir)

p = GA.mv([1] + [Symbol('p%d' % i) for i in range(1, GA.n)], 'vector')

v = [
GA.mv([0] + [Symbol('q%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('r%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('s%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('t%d' % i) for i in range(1, GA.n)], 'vector'),
]

# We test available finite k-flats
for k in range(1, GA.n):
A = reduce(Mv.__xor__, v[:k])
X = (p ^ A)
self.assertNotEquals(X, 0)
M = e_0_inv < (e_0 ^ X)
# Very slow
d = (e_0_inv < (e_0 ^ X)) / (e_0_inv < X)
print('d =',d.Fmt(3))
#d_inv = d.inv()

def hat(A):
return ((-1) ** A.pure_grade()) * A

self.assertEquals(hat(A < Ir_inv), ((-1) ** (GA.n - 1)) * (hat(A) < Ir_inv))

Xd = (p ^ A).dual()
self.assertEquals(Xd, (p ^ A) < Ip_inv)
self.assertEquals(Xd, p < (A < Ip_inv))
self.assertEquals(Xd, p < ((A < Ir_inv) * e_0_inv))
self.assertEquals(Xd, hat(A < Ir_inv) - e_0_inv * (p < hat(A < Ir_inv)))
# Very slow
#self.assertEquals(Xd, hat(A < Ir_inv) + e_0_inv * hat(M < Ir_inv))
#self.assertEquals(Xd, (e_0_inv - d_inv) * hat(M < Ir_inv))
xtex()

Ga.dual_mode()

def test11_12_1(self):
"""
Compute the 2-blades corresponding to the lines gives by the data below. Which of
the lines are the same, considered as weighted oriented elements of geometry, which
are the same as offset subspaces ?
"""
GA, e_0, e_1, e_2, e_3 = Ga.build("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1')

p = e_0 + e_1
q = e_0 + e_2
d = e_2 - e_1
self.assertEquals(p ^ q, p ^ d)
self.assertEquals(p ^ q, q ^ d)

r = e_0 + 2 * (e_2 - e_1)
e = 2 * (e_2 - e_1)
s = e_0 + 3 * (e_2 - e_1)
t = 2 * (e_0 + e_2)
self.assertEquals(2 * (p ^ q), p ^ e)
self.assertEquals(2 * (p ^ q), p ^ t)

def test11_12_2_1(self):
"""
Let an orthonormal coordinate system be given in 3-dimensional Euclidean space.
Compute the support vector of the line with direction u = e1 + 2 e2 - e3, through the point p = e1 - 3 e2.
What is the distance of the line to the origin ?
"""
GA, e_0, e_1, e_2, e_3 = Ga.build("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1')

L = (e_1 + 2 * e_2 - e_3) ^ (e_0 + e_1 - 3 * e_2)
d = (e_0.inv() < (e_0 ^ L)) / (e_0.inv() < L)
self.assertEquals(d.norm(), sqrt(Rational(35, 6)))

"""
def test11_12_2_2(self):

#Convert the line of the previous exercise into a parametric equation x = p + t * u; express t as a function of x
#for a point x on the line.

GA, e0, e1, e2, e3 = Ga.build("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1')

u = e1 + 2*e2 - e3
p = e0 + e1 - 3*e2
L = u ^ p

t = Symbol('t')
x1 = Symbol('x_1')
x2 = Symbol('x_2')
x3 = Symbol('x_3')
x = e0 + x1 * e1 + x2 * e2 + x3 * e3

# x(t)
x_t = (e0 + e1 - 3 * e2) + t * (e1 + 2 * e2 - e3)

d = e1 + 2 * e2 - e3
d_inv = d.inv()

# t(x)
#t_x = (x - (e_0 + e_1 - 3 * e_2)) / (e_1 + 2 * e_2 - e_3)
t_x = (x - (e0 + e1 - 3 * e2)) * d_inv

for i in range(11):
t_value = Rational(i, 10)
x_value = x_t.subs(t,t_value)
x_c = x_value.blade_coefs([e1, e2, e3])
print(t_x.subs([x1,x2,x3],x_value.blade_coefs([e1, e2, e3])),' = ',t_value)
self.assertEquals(x_value ^ L, 0)
self.assertEquals(t_x.subs([x1, x2, x3], x_value.blade_coefs([e1, e2, e3])), t_value)
"""

if __name__ == '__main__':
unittest.main()

108 changes: 108 additions & 0 deletions examples/LaTeX/chap11slow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import unittest
from functools import reduce
from sympy import simplify, sqrt, Rational, Symbol
from galgebra.ga import Ga
from galgebra.mv import Mv
from galgebra.printer import Format, xtex
Format()
class TestChapter11(unittest.TestCase):

def assertEquals(self, first, second, msg=None):
"""
Compare two expressions are equals.
"""

if isinstance(first, Mv):
first = first.obj

if isinstance(second, Mv):
second = second.obj

diff = simplify(first - second)

self.assertTrue(diff == 0, "\n%s\n==\n%s\n%s" % (first, second, diff))

def assertNotEquals(self, first, second, msg=None):
"""
Compare two expressions are equals.
"""

if isinstance(first, Mv):
first = first.obj

if isinstance(second, Mv):
second = second.obj

diff = simplify(first - second)

self.assertTrue(diff != 0, "\n%s\n!=\n%s\n%s" % (first, second, diff))

def test11_6(self):
"""
Dual representation.
"""
Ga.dual_mode('Iinv+')

GA_list = [
Ga("e*0|1|2", g='-1 0 0, 0 1 0, 0 0 1'),
Ga("e*0|1|2|3", g='-1 0 0 0, 0 1 0 0, 0 0 1 0, 0 0 0 1'),
Ga("e*0|1|2|3|5", g='-1 0 0 0 0, 0 1 0 0 0, 0 0 1 0 0, 0 0 0 1 0, 0 0 0 0 1'),
]
"""
-1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
"""

for GA in GA_list:
e_0 = GA.mv_basis[0]
e_0_inv = e_0.inv()

Ip = GA.I()
Ip_inv = Ip.inv()
Ir = e_0_inv < Ip
Ir_inv = Ir.inv()
self.assertEquals(Ip, e_0 ^ Ir)
self.assertEquals(Ip, e_0 * Ir)

p = GA.mv([1] + [Symbol('p%d' % i) for i in range(1, GA.n)], 'vector')

v = [
GA.mv([0] + [Symbol('q%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('r%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('s%d' % i) for i in range(1, GA.n)], 'vector'),
GA.mv([0] + [Symbol('t%d' % i) for i in range(1, GA.n)], 'vector'),
]

# We test available finite k-flats
for k in range(1, GA.n):
A = reduce(Mv.__xor__, v[:k])
X = (p ^ A)
self.assertNotEquals(X, 0)
M = e_0_inv < (e_0 ^ X)
# Very slow
d = (e_0_inv < (e_0 ^ X)) / (e_0_inv < X)
print('d =',d.Fmt(3))
#d_inv = d.inv()

def hat(A):
return ((-1) ** A.pure_grade()) * A

self.assertEquals(hat(A < Ir_inv), ((-1) ** (GA.n - 1)) * (hat(A) < Ir_inv))

Xd = (p ^ A).dual()
self.assertEquals(Xd, (p ^ A) < Ip_inv)
self.assertEquals(Xd, p < (A < Ip_inv))
self.assertEquals(Xd, p < ((A < Ir_inv) * e_0_inv))
self.assertEquals(Xd, hat(A < Ir_inv) - e_0_inv * (p < hat(A < Ir_inv)))
# Very slow
#self.assertEquals(Xd, hat(A < Ir_inv) + e_0_inv * hat(M < Ir_inv))
#self.assertEquals(Xd, (e_0_inv - d_inv) * hat(M < Ir_inv))

Ga.dual_mode()

if __name__ == '__main__':
unittest.main()

Binary file modified examples/LaTeX/christoffel_symbols.pdf
Binary file not shown.
Loading