Skip to content

Commit 1abbc18

Browse files
authored
Remove the special cases in Ga.blade_derivation (#283)
The special case in the `grade > 2` branch was previously needed because `indexes_to_blades_dict` did not contain the scalar element. Also switches to using `reduce` for a bit of clarity. The other cases were there for optimization purposes. It's not clear whether they were worthwhile. Fixes gh-282
1 parent 8556d88 commit 1abbc18

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

galgebra/ga.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,17 +1828,15 @@ def blade_derivation(self, blade, ib):
18281828

18291829
index = self.indexes_to_blades_dict.inverse[blade]
18301830
grade = len(index)
1831-
if grade == 1:
1832-
db = self.de[ib][index[0]]
1833-
elif grade == 2:
1834-
db = self.wedge(self.de[ib][index[0]], self.basis[index[1]]) + \
1835-
self.wedge(self.basis[index[0]], self.de[ib][index[1]])
1836-
else:
1837-
db = self.wedge(self.de[ib][index[0]], self.indexes_to_blades_dict[index[1:]]) + \
1838-
self.wedge(self.indexes_to_blades_dict[index[:-1]], self.de[ib][index[-1]])
1839-
for i in range(1, grade - 1):
1840-
db += self.wedge(self.wedge(self.indexes_to_blades_dict[index[:i]], self.de[ib][index[i]]),
1841-
self.indexes_to_blades_dict[index[i + 1:]])
1831+
1832+
# differentiate each basis vector separately and sum
1833+
db = S.Zero
1834+
for i in range(grade):
1835+
db += reduce(self.wedge, [
1836+
self.indexes_to_blades_dict[index[:i]],
1837+
self.de[ib][index[i]],
1838+
self.indexes_to_blades_dict[index[i + 1:]]
1839+
])
18421840
self._dbases[key] = db
18431841
return db
18441842

0 commit comments

Comments
 (0)