pygae / galgebra

Symbolic Geometric Algebra/Calculus package for SymPy :crystal_ball:

Home Page:https://galgebra.rtfd.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

diff and pdiff method of class Mv throws exception when differentiate by a coordinate symbol

mammalwong opened this issue · comments

x is a coordinate symbol (a plain sympy Symbol object) and ex is a Mv instance of a Ga basis symbol. I tried to invoke (x*ex).diff(x) and the method throws exception. From the exception stack frame below, it looks like Mv.diff passed self.obj to Ga.pDiff and pDiff try to resolve .obj again from obj.


AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 (x*ex).diff(x)

1 frames
/usr/local/lib/python3.10/dist-packages/galgebra/mv.py in diff(self, coord)
1070 obj += tmp1 * tmp2
1071 else:
-> 1072 obj = self.Ga.pDiff(self.obj, coord)
1073 return Mv(obj, ga=self.Ga)
1074

/usr/local/lib/python3.10/dist-packages/galgebra/ga.py in pDiff(self, A, coord)
2050 # variable, but including case of non-constant basis vectors
2051
-> 2052 dA = self.mv(expand(diff(A.obj, coord)))
2053
2054 if self.connect_flg and self.dslot == -1 and not A.is_scalar(): # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

pdiff method of Mv class also throws the same exception when invoking (x*ex).pdiff(x).


AttributeError Traceback (most recent call last)
in <cell line: 1>()
----> 1 (x*ex).pdiff(x)

1 frames
/usr/local/lib/python3.10/dist-packages/galgebra/ga.py in pDiff(self, A, coord)
2050 # variable, but including case of non-constant basis vectors
2051
-> 2052 dA = self.mv(expand(diff(A.obj, coord)))
2053
2054 if self.connect_flg and self.dslot == -1 and not A.is_scalar(): # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

@mammalwong Can you also post minimal working example for this issue? Thanks!

In version 0.5.1

x,y,z = coords = S.symbols('x y z', real=True)
ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
ex,ey,ez = ga.mv()
(x*ex).diff(x)

raise exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-9-4979ad157f80>](https://localhost:8080/#) in <cell line: 4>()
      2 ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
      3 ex,ey,ez = ga.mv()
----> 4 (x*ex).diff(x)

1 frames
[/usr/local/lib/python3.10/dist-packages/galgebra/mv.py](https://localhost:8080/#) in diff(self, coord)
   1070                         obj += tmp1 * tmp2
   1071         else:
-> 1072             obj = self.Ga.pDiff(self.obj, coord)
   1073         return Mv(obj, ga=self.Ga)
   1074 

[/usr/local/lib/python3.10/dist-packages/galgebra/ga.py](https://localhost:8080/#) in pDiff(self, A, coord)
   2050         # variable, but including case of non-constant basis vectors
   2051 
-> 2052         dA = self.mv(expand(diff(A.obj, coord)))
   2053 
   2054         if self.connect_flg and self.dslot == -1 and not A.is_scalar():  # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

Another related issue:

x,y,z = coords = S.symbols('x y z', real=True)
ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
ex,ey,ez = ga.mv()
(x*ex).pdiff(x) # notice this is pdiff() not diff() this time

raise exception:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-10-5767979f98eb>](https://localhost:8080/#) in <cell line: 4>()
      2 ga = Ga('e', g=[1,1,1], coords=coords, wedge=False)
      3 ex,ey,ez = ga.mv()
----> 4 (x*ex).pdiff(x)

1 frames
[/usr/local/lib/python3.10/dist-packages/galgebra/mv.py](https://localhost:8080/#) in pdiff(self, var)
   1074 
   1075     def pdiff(self, var) -> 'Mv':
-> 1076         return Mv(self.Ga.pDiff(self.obj, var), ga=self.Ga)
   1077 
   1078     def Grad(self, coords, mode: str = '*', left: bool = True) -> 'Mv':

[/usr/local/lib/python3.10/dist-packages/galgebra/ga.py](https://localhost:8080/#) in pDiff(self, A, coord)
   2050         # variable, but including case of non-constant basis vectors
   2051 
-> 2052         dA = self.mv(expand(diff(A.obj, coord)))
   2053 
   2054         if self.connect_flg and self.dslot == -1 and not A.is_scalar():  # Basis blades are function of coordinates

AttributeError: 'Mul' object has no attribute 'obj'

Thank you, @mammalwong , the fix should be in master now as #510 is now merged.