galgebra icon indicating copy to clipboard operation
galgebra copied to clipboard

Dop.__truediv__ behaves confusingly

Open eric-wieser opened this issue 4 years ago • 7 comments

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.

eric-wieser avatar Dec 18 '19 10:12 eric-wieser

I think the issue lies with multiplication, not division?

utensil avatar Dec 19 '19 11:12 utensil

Arguably the multiplicative behavior is correct - the gradient of a constant is zero

eric-wieser avatar Dec 19 '19 11:12 eric-wieser

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?

utensil avatar Dec 19 '19 12:12 utensil

Bump

utensil avatar Jun 02 '20 12:06 utensil

I believe this behavior is correct and should be documented to avoid confusion.

utensil avatar Jun 02 '20 12:06 utensil

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.

eric-wieser avatar Jun 02 '20 12:06 eric-wieser

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.

utensil avatar Jun 04 '20 06:06 utensil