galgebra
galgebra copied to clipboard
Dop.__truediv__ behaves confusingly
Division does not behave like right-multiplication by the inverse:
>>> from sympy import symbols, S
>>> from galgebra.ga import Ga
>>> coords = x, y, z = symbols('x y z', real=True)
>>> ga, ex, ey, ez = Ga.build('e*x|y|z', g=[1, 1, 1], coords=coords)
>>> ga.grad / 2
\boldsymbol{e}_{x}*\frac{1}{2} \frac{\partial}{\partial x} + \boldsymbol{e}_{y}*\frac{1}{2} \frac{\partial}{\partial y} + \boldsymbol{e}_{z}*\frac{1}{2} \frac{\partial}{\partial z}
>>> ga.grad * S.Half
0
Note that for rgrad
everything is fine:
>>> ga.rgrad / 2
\frac{1}{2} \frac{\partial}{\partial x}*\boldsymbol{e}_{x} + \frac{1}{2} \frac{\partial}{\partial y}*\boldsymbol{e}_{y} + \frac{1}{2} \frac{\partial}{\partial z}*\boldsymbol{e}_{z}
>>> ga.rgrad * S.Half
\frac{1}{2} \frac{\partial}{\partial x}*\boldsymbol{e}_{x} + \frac{1}{2} \frac{\partial}{\partial y}*\boldsymbol{e}_{y} + \frac{1}{2} \frac{\partial}{\partial z}*\boldsymbol{e}_{z}
One option would be to make grad / 2
raise an error. Another would just be to document this quirk.
I think the issue lies with multiplication, not division?
Arguably the multiplicative behavior is correct - the gradient of a constant is zero
To be precise, I don't think the equivalence should always hold in the first place.
The division makes it clear that it's a plain multiplication with a scalar, not to apply the operator to a (constant) function.
But the multiplication has ambiguous semantics, it could be both.
So I would say the division is perfectly fine in these cases and what's in question is the multiplication.
Am I missing something?
Bump
I believe this behavior is correct and should be documented to avoid confusion.
The division makes it clear that it's a plain multiplication with a scalar, not to apply the operator to a (constant) function.
The question is, what should the following mean, where for simplicity f
and g
are scalar not multivector functions of x.
(Dop / f(x)) * g(x),
-
diff(1 / f(x), x) * g(x)
- consistent with(Dop * (1 / f(x))) * g(x)
-
1 / f(x) * diff(g(x), x)
- what it is today - An error. Force the author to be explicit about which one they want.
That's exactly I'm saying, it seems obvious to me that if we allow such a spelling , then the first doesn't make sense and the second should be correct and the expected behavior should be documented.
Using *
to apply Dop
to a function is a happy accident, it doesn't have any semantics related to the usual multiplication and thus no such thing as a division.
A more tricky case is Dop / g(x) * g(x)
it's intuitively just Dop
but actually is 1/g(x) Dop g(x)
.
From the case above it's now clear that /
and *
don't follow the usually algebra rules here. So error on /
is also a reasonable option.