Ondrej Certik wrote:
> On Tue, Dec 30, 2008 at 12:26 PM, Ondrej Certik <[email protected]> wrote:
>
>>> Trying again.
>>>
>> Now it works, thanks! If all tests pass, I'll push it in.
>>
>
> This test failed:
>
>
> sympy/utilities/tests/test_code_quality.py:test_no_trailing_whitespace_and_no_tabs
> File "/home/ondra/repos/sympy/sympy/utilities/tests/test_code_quality.py",
> line 63, in test_no_trailing_whitespace_and_no_tabs
> check_directory_tree(sympy_path)
> File "/home/ondra/repos/sympy/sympy/utilities/tests/test_code_quality.py",
> line 43, in check_directory_tree
> assert False, message_space % (fname, idx+1)
> AssertionError: File contains trailing whitespace:
> /home/ondra/repos/sympy/sympy/galgebra/GAsympy.py, line 437.
>
> tests finished: 1268 passed, 1 failed, 4 skipped, 26 xfailed, 3
> xpassed in 126.70 seconds
> DO *NOT* COMMIT!
>
>
> and these doctests failed:
>
> ________________________ sympy.galgebra.latex_ex.LaTeX
> _________________________
> File "/home/ondra/repos/sympy/sympy/galgebra/latex_ex.py", line 889,
> in sympy.galgebra.latex_ex.LaTeX
> Failed example:
> latex((2*tau)**Rational(7,2))
> Expected:
> '$8 \sqrt{2} \sqrt[7]{\tau}$'
> Got:
> '$8 \\sqrt{2} \\sqrt[7]{\\tau}$'
> **********************************************************************
> File "/home/ondra/repos/sympy/sympy/galgebra/latex_ex.py", line 892,
> in sympy.galgebra.latex_ex.LaTeX
> Failed example:
> latex((2*mu)**Rational(7,2), inline=False)
> Expected:
> '\begin{equation*}8 \sqrt{2} \sqrt[7]{\mu}\end{equation*}'
> Got:
> '\\begin{equation*}8 \\sqrt{2} \\sqrt[7]{\\mu}\\end{equation*}'
> **********************************************************************
> File "/home/ondra/repos/sympy/sympy/galgebra/latex_ex.py", line 899,
> in sympy.galgebra.latex_ex.LaTeX
> Failed example:
> latex([2/x, y])
> Expected:
> '$\begin{bmatrix}\frac{2}{x}, & y\end{bmatrix}$'
> Got:
> '$\\begin{bmatrix}\\frac{2}{x}, & y\\end{bmatrix}$'
>
> ============ tests finished: 207 passed, 1 failed in 11.05 seconds
> =============
> DO *NOT* COMMIT!
>
>
>
> Ondrej
>
> >
>
>
OK all tests now pass patch attached. Documentation not yet included.
Documentation archive is 2.8MB (not tarred and zipped) is this OK to put
in distribution.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sympy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/sympy?hl=en
-~----------~----~----~----~------~----~------~--~---
>From 3d5a353d760048c116029645eb1c98caf1776b0a Mon Sep 17 00:00:00 2001
From: Alan Bromborsky <bro...@ga.(none)>
Date: Tue, 30 Dec 2008 17:06:07 -0500
Subject: [PATCH] Removed trailing white space and implicit imports
---
sympy/galgebra/GAsympy.py | 50 ++++++++++++------------
sympy/galgebra/examples/Dirac.py | 42 ++++++++++++++++++++
sympy/galgebra/examples/Maxwell.py | 61 +++++++++++++++++++++++++++++
sympy/galgebra/examples/coords.py | 44 +++++++++++++++++++++
sympy/galgebra/examples/testsymbolicGA.py | 7 +--
sympy/galgebra/latex_ex.py | 50 ++++-------------------
6 files changed, 184 insertions(+), 70 deletions(-)
create mode 100755 sympy/galgebra/examples/Dirac.py
create mode 100755 sympy/galgebra/examples/Maxwell.py
create mode 100755 sympy/galgebra/examples/coords.py
diff --git a/sympy/galgebra/GAsympy.py b/sympy/galgebra/GAsympy.py
index 8b73b90..787a3c2 100644
--- a/sympy/galgebra/GAsympy.py
+++ b/sympy/galgebra/GAsympy.py
@@ -434,7 +434,7 @@ def build_base(base_index,base_vectors,reverse=False):
if reverse:
base = base.rev()
return(base)
-
+
class MV(object):
is_setup = False
@@ -725,7 +725,7 @@ class MV(object):
else:
mv.mv[igrade] = numpy.array([coef[0]],dtype=numpy.object)
return(mv)
-
+
@staticmethod
def set_str_format(str_mode=0):
MV.str_mode = str_mode
@@ -826,7 +826,7 @@ class MV(object):
for x in xlst:
xtmp.append(x)
metric.append(xtmp)
-
+
MV.define_metric(metric)
MV.multiplication_table()
MV.blade_table()
@@ -913,12 +913,12 @@ class MV(object):
determines how far in the list to calculate (imput 0 to do the entire list) while debugging.
"""
global MAIN_PROGRAM
-
+
#Form root names for basis, reciprocal basis, normalized basis, and normalized reciprocal basis
if base_name == '':
base_name = MV.basisroot+'prm'
-
+
LaTeX_base = sympy.galgebra.latex_ex.LaTeXPrinter.extended_symbol(base_name)
bm = '\\bm{'+LaTeX_base+'}'
bmhat = '\\hat{'+bm+'}'
@@ -960,18 +960,18 @@ class MV(object):
i += 1
#Calculate normalizee basis vectors and basis vector magnitudes
-
+
if debug:
- print 'Coordinate Generating Vector'
+ print 'Coordinate Generating Vector'
print x
print 'Basis Vectors'
for base in bases:
print base
else:
-
+
#Input basis vectors as N vector fields
-
+
bases = x
for (base,name) in zip(bases,base_name_lst):
@@ -987,9 +987,9 @@ class MV(object):
if debug_level == 1:
return
- #Calculate normalized basis vectors and magnitudes of
+ #Calculate normalized basis vectors and magnitudes of
#unormalized basis vectors
-
+
(nbases,mags) = normalize(bases,nbase_name_lst)
if debug:
@@ -1047,9 +1047,9 @@ class MV(object):
return
#Calculate components of inverse vectors
-
+
Acoef = []
-
+
for ibasis in MV.nrg:
evec = numpy.array(MV.n*[ZERO],dtype=numpy.object)
for jbasis in MV.nrg:
@@ -1101,14 +1101,14 @@ class MV(object):
base.simplify()
base.trigsimp()
rbase = build_base(index,rnbases,True)
- rbase.simplify()
+ rbase.simplify()
rbase.trigsimp()
grade_bases.append(base)
rgrade_bases.append(rbase)
igrade += 1
MV_bases.append(grade_bases)
MV_rbases.append(rgrade_bases)
-
+
#Calculate connection multivectors for geometric derivative
MV_connect = [[ZERO]]
@@ -1124,7 +1124,7 @@ class MV(object):
psum.trigsimp()
sum += psum
itheta += 1
- sum.simplify()
+ sum.simplify()
sum.trigsimp()
grade_connect.append(sum)
ibase += 1
@@ -1196,7 +1196,7 @@ class MV(object):
X = MV()
X.mv[MV.n-1] = Cm1
X.simplify()
- X.trigsimp()
+ X.trigsimp()
grade_connect.append(X)
ibase += 1
@@ -1244,7 +1244,7 @@ class MV(object):
print 'Representation of Original Basis Vectors'
for evec in MV.org_basis:
print evec
-
+
print 'Renormalized Reciprocal Vectors '+\
'$\\bfrac{'+bmhat+'^{k}}{\\abs{\\bm{'+LaTeX_base+'}_{k}}}$'
@@ -1387,7 +1387,7 @@ class MV(object):
w = w12+w21
w.name = name
return(w*HALF)
-
+
@staticmethod
def blade_table():
"""
@@ -1529,7 +1529,7 @@ class MV(object):
product.add_in_place(pg1pg2.project(igrade))
return(product)
return(MV())
-
+
@staticmethod
def addition(mv1,mv2):
"""
@@ -1709,7 +1709,7 @@ class MV(object):
self.mv[0]= numpy.array([sympy.Function(coef)(*MV.coords)],dtype=numpy.object)
else:
for base in range(MV.nbasis[grade]):
- coef = sympy.galgebra.latex_ex.LaTeXPrinter.str_basic(self.mv[grade][base])
+ coef = sympy.galgebra.latex_ex.LaTeXPrinter.str_basic(self.mv[grade][base])
self.mv[grade][base] = sympy.Function(coef)(*MV.coords)
@staticmethod
@@ -2126,7 +2126,7 @@ class MV(object):
sympy.collect(self.mv[igrade][ibase],faclst)
return
"""
-
+
def flatten(self):
flst = []
for igrade in MV.n1rg:
@@ -2153,7 +2153,7 @@ class MV(object):
def sub_mv(self,mv1,mv2):
mv1_flat = mv1.flatten()
mv2_flat = mv2.flatten()
- self.sub_scalar(mv1_flat,mv2_flat)
+ self.sub_scalar(mv1_flat,mv2_flat)
return
def sub_scalar(self,expr1,expr2):
@@ -2167,8 +2167,8 @@ class MV(object):
for ibase in range(MV.nbasis[igrade]):
if expr1 != ZERO:
self.mv[igrade][ibase] = self.mv[igrade][ibase].subs(expr1,expr2)
- return
-
+ return
+
def simplify(self):
"""
Applies sympy subs function
diff --git a/sympy/galgebra/examples/Dirac.py b/sympy/galgebra/examples/Dirac.py
new file mode 100755
index 0000000..310b0a5
--- /dev/null
+++ b/sympy/galgebra/examples/Dirac.py
@@ -0,0 +1,42 @@
+#!/usr/local/bin/python
+#Dirac.py
+
+import sympy.galgebra.GAsympy as GA
+import sympy.galgebra.latex_ex as tex
+import sys
+
+GA.set_main(sys.modules[__name__])
+
+if __name__ == '__main__':
+
+ metric = '1 0 0 0,'+\
+ '0 -1 0 0,'+\
+ '0 0 -1 0,'+\
+ '0 0 0 -1'
+
+ vars = GA.make_symbols('t x y z')
+ GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
+
+ parms = GA.make_symbols('m e')
+ tex.Format('1 1 1 1')
+ I = GA.MV(GA.ONE,'pseudo')
+ nvars = len(vars)
+ psi = GA.MV('psi','spinor',fct=True)
+ psi.convert_to_blades()
+ A = GA.MV('A','vector',fct=True)
+ sig_x = gamma_x*gamma_t
+ sig_y = gamma_y*gamma_t
+ sig_z = gamma_z*gamma_t
+ print '$A$ is 4-vector potential'
+ print A
+ print r'$\bm{\psi}$ is 8-component real spinor (even multi-vector)'
+ print psi
+ dirac_eq = psi.grad()*I*sig_z-e*A*psi-m*psi*gamma_t
+ dirac_eq.simplify()
+ dirac_eq.convert_to_blades()
+ print 'Dirac equation in terms of real geometric algebra/calculus '+\
+ r'$\lp\nabla \bm{\psi} I \sigma_{z}-eA\bm{\psi} = m\bm{\psi}\gamma_{t}\rp$'
+ print 'Spin measured with respect to $z$ axis'
+ tex.Format('mv=3')
+ print r'\nabla \bm{\psi} I \sigma_{z}-eA\bm{\psi}-m\bm{\psi}\gamma_{t} = ',dirac_eq,' = 0'
+ tex.xdvi(filename='Dirac.tex')
\ No newline at end of file
diff --git a/sympy/galgebra/examples/Maxwell.py b/sympy/galgebra/examples/Maxwell.py
new file mode 100755
index 0000000..ade0363
--- /dev/null
+++ b/sympy/galgebra/examples/Maxwell.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import sys
+import sympy.galgebra.GAsympy as GA
+import sympy.galgebra.latex_ex as tex
+
+GA.set_main(sys.modules[__name__])
+
+if __name__ == '__main__':
+
+ metric = '1 0 0 0,'+\
+ '0 -1 0 0,'+\
+ '0 0 -1 0,'+\
+ '0 0 0 -1'
+
+ vars = GA.make_symbols('t x y z')
+ GA.MV.setup('gamma_t gamma_x gamma_y gamma_z',metric,True,vars)
+ tex.LaTeXPrinter.format(1,1,1,1)
+ I = GA.MV(1,'pseudo')
+ I.convert_to_blades()
+ print '$I$ Pseudo-Scalar'
+ print 'I =',I
+ B = GA.MV('B','vector',fct=True)
+ E = GA.MV('E','vector',fct=True)
+ B.set_coef(1,0,0)
+ E.set_coef(1,0,0)
+ B *= gamma_t
+ E *= gamma_t
+ B.convert_to_blades()
+ E.convert_to_blades()
+ J = GA.MV('J','vector',fct=True)
+ print '$B$ Magnetic Field Bi-Vector'
+ print 'B = Bvec gamma_0 =',B
+ print '$E$ Electric Field Bi-Vector'
+ print 'E = Evec gamma_0 =',E
+ F = E+I*B
+ print '$E+IB$ Electo-Magnetic Field Bi-Vector'
+ print 'F = E+IB =',F
+ print '$J$ Four Current'
+ print 'J =',J
+ gradF = F.grad()
+ gradF.convert_to_blades()
+ print 'Geometric Derivative of Electo-Magnetic Field Bi-Vector'
+ tex.MV_format(3)
+ print '\\nabla F =',gradF
+ print 'All Maxwell Equations are'
+ print '\\nabla F = J'
+ print 'Div $E$ and Curl $H$ Equations'
+ print '<\\nabla F>_1 -J =',gradF.project(1)-J,' = 0'
+ print 'Curl $E$ and Div $B$ equations'
+ print '<\\nabla F>_3 =',gradF.project(3),' = 0'
+ tex.xdvi(filename='Maxwell.tex')
+
+
+
+
+
+
+
+
+
diff --git a/sympy/galgebra/examples/coords.py b/sympy/galgebra/examples/coords.py
new file mode 100755
index 0000000..4580386
--- /dev/null
+++ b/sympy/galgebra/examples/coords.py
@@ -0,0 +1,44 @@
+#!/usrlocal/bin/python
+#EandM.py
+
+import sympy.galgebra.GAsympy as GA
+import sympy.galgebra.latex_ex as tex
+import sympy,numpy,sys
+
+GA.set_main(sys.modules[__name__])
+
+if __name__ == '__main__':
+ metric = '1 0 0,'+\
+ '0 1 0,'+\
+ '0 0 1'
+
+ GA.MV.setup('gamma_x gamma_y gamma_z',metric,True)
+ tex.Format('1 1 1 1')
+
+ coords = GA.make_symbols('r theta phi')
+ x = r*(sympy.cos(theta)*gamma_z+sympy.sin(theta)*\
+ (sympy.cos(phi)*gamma_x+sympy.sin(phi)*gamma_y))
+ x.set_name('x')
+
+ GA.MV.rebase(x,coords,'e',True)
+
+ psi = GA.MV('psi','scalar',fct=True)
+
+ dpsi = psi.grad()
+ print 'Gradient of Scalar Function $\\psi$'
+ print '\\nabla\\psi =',dpsi
+
+ A = GA.MV('A','vector',fct=True)
+
+ print 'Div and Curl of Vector Function $A$'
+ print A
+
+ gradA = A.grad()
+ I = GA.MV(GA.ONE,'pseudo')
+ divA = A.grad_int()
+ curlA = -I*A.grad_ext()
+ print '\\nabla \\cdot A =',divA
+ tex.Format('mv=3')
+ print '-I\\lp\\nabla \\W A\\rp =',curlA
+
+ tex.xdvi(filename='coords.tex')
diff --git a/sympy/galgebra/examples/testsymbolicGA.py b/sympy/galgebra/examples/testsymbolicGA.py
index e7aa102..69d7420 100755
--- a/sympy/galgebra/examples/testsymbolicGA.py
+++ b/sympy/galgebra/examples/testsymbolicGA.py
@@ -33,7 +33,7 @@ if __name__ == '__main__':
print -d*(a^b^c)+c*(a^b^d)-b*(a^c^d)+a*(b^c^d)
print (a^b)|(c^d)
-
+
print 'Example: non-euclidian distance calculation'
metric = '0 # #,# 0 #,# # 1'
@@ -90,7 +90,6 @@ if __name__ == '__main__':
print 'Wd[C] =',Wd_C
print 'Wd[S] =',Wd_S
-
lhs = Wd_1+Wd_C*C
rhs = -Wd_S*S
lhs = lhs**2
@@ -102,7 +101,7 @@ if __name__ == '__main__':
print 'W =',W
W = collect(W,[C,C**2],evaluate=False)
print 'W =',W
-
+
a = W[C**2]
b = W[C]
c = W[ONE]
@@ -116,7 +115,7 @@ if __name__ == '__main__':
print 'Descriminant D = b^2-4*a*c =',D
C = (-b/(2*a)).expand()
print 'C = cosh(alpha) = -b/(2*a) =',C
-
+
print '\nExample: Conformal representations of circles, lines, spheres, and planes'
metric = '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'
diff --git a/sympy/galgebra/latex_ex.py b/sympy/galgebra/latex_ex.py
index d443e0e..311d4fe 100644
--- a/sympy/galgebra/latex_ex.py
+++ b/sympy/galgebra/latex_ex.py
@@ -66,7 +66,6 @@ class LaTeXPrinter(Printer):
1 - Use subscript notation with partial symbol to indicate which
variable the differentiation is with respect to. Symbol is of
form \partial_{differentiation variable}
-
"""
#printmethod ='_latex_ex_'
@@ -177,7 +176,7 @@ class LaTeXPrinter(Printer):
LaTeXPrinter.fmt_dict['mv'] = mv
LaTeXPrinter.fmt_dict['str'] = 1
if sympy.galgebra.GAsympy.MV.is_setup:
- LaTeXPrinter.latex_bases()
+ LaTeXPrinter.latex_bases()
LaTeXPrinter.redirect()
return
@@ -198,18 +197,18 @@ class LaTeXPrinter(Printer):
sys.stdout = StringIO.StringIO()
Basic.__str__ = LaTeX
sympy.galgebra.GAsympy.MV.__str__ = LaTeX
- return
+ return
@staticmethod
def restore():
LaTeXPrinter_stdout = sys.stdout
LaTeXPrinter_Basic__str__ = Basic.__str__
LaTeXPrinter_MV__str__ = sympy.galgebra.GAsympy.MV.__str__
-
+
sys.stdout = LaTeXPrinter.stdout
Basic.__str__ = LaTeXPrinter.Basic__str__
sympy.galgebra.GAsympy.MV.__str__ = LaTeXPrinter.MV__str__
-
+
LaTeXPrinter.stdout = LaTeXPrinter_stdout
LaTeXPrinter.Basic__str__ = LaTeXPrinter_Basic__str__
LaTeXPrinter.MV__str__ = LaTeXPrinter_MV__str__
@@ -696,7 +695,7 @@ class LaTeXPrinter(Printer):
return LaTeXPrinter.extended_symbol(name_str)
else:
return(name_str)
- """
+
#convert trailing digits to subscript
m = regrep.match('(^[a-zA-Z]+)([0-9]+)$',name_str)
if m is not None:
@@ -727,7 +726,6 @@ class LaTeXPrinter(Printer):
return "\\" + name_str
else:
return name_str
- """
def _print_Symbol(self, expr):
return LaTeXPrinter.print_Symbol_name(expr.name)
@@ -785,8 +783,8 @@ class LaTeXPrinter(Printer):
tmp = Symbol('XYZW')
base_str = str(base*tmp)
if base_str[0] != '-':
- base_str = '+'+base_str
- base_str = base_str.replace('- ','-')
+ base_str = '+'+base_str
+ base_str = base_str.replace('- ','-')
if base_str[1:5] == 'XYZW':
base_str = base_str.replace('XYZW','')
else:
@@ -875,37 +873,7 @@ class LaTeXPrinter(Printer):
return tex
def LaTeX(expr, inline=True):
- """
- Convert the given expression to LaTeX representation.
-
- You can specify how the generated code will be delimited.
- If the 'inline' keyword is set then inline LaTeX $ $ will
- be used. Otherwise the resulting code will be enclosed in
- 'equation*' environment (remember to import 'amsmath').
-
- >>> from sympy import *
- >>> from sympy.abc import *
-
- >>> latex((2*tau)**Rational(7,2))
- '$8 \\sqrt{2} \\sqrt[7]{\\tau}$'
-
- >>> latex((2*mu)**Rational(7,2), inline=False)
- '\\begin{equation*}8 \\sqrt{2} \\sqrt[7]{\\mu}\\end{equation*}'
-
- Besides all Basic based expressions, you can recursively
- convert Pyhon containers (lists, tuples and dicts) and
- also SymPy matrices:
-
- >>> latex([2/x, y])
- '$\\begin{bmatrix}\\frac{2}{x}, & y\\end{bmatrix}$'
-
- The extended latex printer will also append the output to a
- string (LaTeXPrinter.body) that will be processed by xdvi()
- for immediate display one xdvi() is called.
- """
-
xstr = LaTeXPrinter(inline).doprint(expr)
- #xstr = LaTeXPrinter.append_body(xstr+'\n')
return (xstr)
def print_LaTeX(expr):
@@ -921,7 +889,7 @@ def xdvi(filename='tmplatex.tex',debug=False):
Post processes LaTeX output (see comments below), adds preamble and
postscript, generates tex file, inputs file to latex, displays resulting
dvi file with xdvi.
- """
+ """
if not LaTeXPrinter.LaTeX_flg:
return
body = sys.stdout.getvalue()
@@ -1042,7 +1010,7 @@ def xdvi(filename='tmplatex.tex',debug=False):
latex_file.write(body)
latex_file.close()
if debug: #Display latex excution output for debugging purposes
- os.system('latex '+filename[:-4])
+ os.system('latex '+filename[:-4])
else: #Works for Linux don't know about Windows
os.system('latex '+filename[:-4]+' > /dev/null')
os.system('xdvi '+filename[:-4]+' &')
--
1.5.6.3