Skip to content

Commit 78977e6

Browse files
eric-wieserutensil
authored andcommitted
Use sympy scalars in more places (#179)
This reduces the chance of obtaining imprecise floating-point numbers when dividing at the call site. Far from an exhaustive replacement.
1 parent fc4585a commit 78977e6

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

galgebra/deprecated.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import copy
22
from itertools import combinations
3-
from sympy import trigsimp
3+
from sympy import trigsimp, S
44
from . import ga
55
from .mv import Mv
66
from . import utils
@@ -63,7 +63,7 @@ def ReciprocalFrame(basis, mode='norm'):
6363
for igrade in index[-2:]:
6464
grade = []
6565
for iblade in igrade:
66-
blade = Mv(1, 'scalar', ga=GA)
66+
blade = Mv(S(1), 'scalar', ga=GA)
6767
for ibasis in iblade:
6868
blade ^= basis[ibasis]
6969
blade = blade.trigsimp()
@@ -75,7 +75,7 @@ def ReciprocalFrame(basis, mode='norm'):
7575
duals = copy.copy(MFbasis[-2])
7676

7777
duals.reverse()
78-
sgn = 1
78+
sgn = S(1)
7979
rbasis = []
8080
for dual in duals:
8181
recpv = (sgn * dual * E).trigsimp()

galgebra/ga.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ def reduce_basis_loop(g, blst):
10231023

10241024
@staticmethod
10251025
def blade_reduce(lst):
1026-
sgn = 1
1026+
sgn = S(1)
10271027
for i in range(1, len(lst)):
10281028
save = lst[i]
10291029
j = i
@@ -1033,7 +1033,7 @@ def blade_reduce(lst):
10331033
j -= 1
10341034
lst[j] = save
10351035
if lst[j] == lst[j - 1]:
1036-
return 0, None
1036+
return S(0), None
10371037
return sgn, lst
10381038

10391039
def wedge_product_basis_blades(self, blade12): # blade12 = blade1*blade2
@@ -1045,12 +1045,12 @@ def wedge_product_basis_blades(self, blade12): # blade12 = blade1*blade2
10451045
index12 = list(index1 + index2)
10461046

10471047
if len(index12) > self.n:
1048-
return 0
1048+
return S(0)
10491049
(sgn, wedge12) = Ga.blade_reduce(index12)
10501050
if sgn != 0:
10511051
return(sgn * self.indexes_to_blades_dict[tuple(wedge12)])
10521052
else:
1053-
return 0
1053+
return S(0)
10541054

10551055
#****** Dot (|) product, reft (<) and right (>) contractions ******#
10561056

@@ -1089,8 +1089,8 @@ def dot_product_basis_blades(self, blade12, mode):
10891089
return zero
10901090

10911091
n = len(index)
1092-
sgn = 1
1093-
result = 1
1092+
sgn = S(1)
1093+
result = S(1)
10941094
ordered = False
10951095
while n > grade:
10961096
ordered = True
@@ -1102,7 +1102,7 @@ def dot_product_basis_blades(self, blade12, mode):
11021102
if index1 == index2:
11031103
n -= 2
11041104
if n < grade:
1105-
return 0
1105+
return zero
11061106
result *= self.g[index1, index1]
11071107
index = index[:i1] + index[i2 + 1:]
11081108
elif index1 > index2:
@@ -1116,7 +1116,7 @@ def dot_product_basis_blades(self, blade12, mode):
11161116
if ordered:
11171117
break
11181118
if n > grade:
1119-
return 0
1119+
return zero
11201120
else:
11211121
if index == []:
11221122
return sgn * result

0 commit comments

Comments
 (0)