Invalid Syntax With Particular Expression
Closed this issue · 1 comments
sudgy commented
- kingdon version: 0.1.0
- Python version: 3.11
- Operating System: ArchLinux
When executing this code:
#!/bin/python
from kingdon import Algebra
alg = Algebra(3, 0, 1)
globals().update(alg.blades)
print((e12 * (0*e2 + e0).dual()) | e1.dual())
This error happens:
Traceback (most recent call last):
File "/home/sudgy/programs/python/./test.py", line 7, in <module>
print((e12 * (0*e2 + e0).dual()) | e1.dual())
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/multivector.py", line 374, in ip
return self.algebra.ip(self, other)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/operator_dict.py", line 63, in __call__
return self._call_binary(*mvs)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/operator_dict.py", line 94, in _call_binary
keys_out, func, numba_func = self[mv1.keys(), mv2.keys()]
~~~~^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/operator_dict.py", line 43, in __getitem__
keys_out, func = do_codegen(self.codegen, *mvs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/codegen.py", line 494, in do_codegen
lambdify(args, exprs, funcname=funcname, cse=mvs[0].algebra.cse)
File "/home/sudgy/.local/lib/python3.11/site-packages/kingdon/codegen.py", line 576, in lambdify
c = compile(funcstr, filename, 'exec')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<codegen_ip_0_0001_000000_0010_0_x_0_0000_000000_0010_0>", line 4
return (, +a3*b023,)
^
SyntaxError: invalid syntax
tBuLi commented
Thanks for reporting this! I have now fixed this issue. It was caused by the fact that codegen for all products is the same, only distinguished by three optional functions as arguments to codegen_product
. The default settings where such that elements which have a "sign" of 0 are automatically dropped, like in the geometric product. However, for e.g. the inner product this filter function was replaced by another. The logic here was incorrect however: we should always drop terms with a sign of zero, and only then apply the extra filter function, for all products. So I fixed it with #26.