Closed vsht closed 4 months ago
Maybe, we could always enclose dot products in parentheses, even when not needed. This may be easier to implement than enclosing or not enclosing dot products in parentheses depending on context.
For reference, operator precedence in Mathematica:
https://reference.wolfram.com/language/tutorial/OperatorInputForms.html
The binary operator .
(Dot
) has a lower precedence than the binary operator ^
(Power
).
A bit confusing. What does it do with 3.2^4 ? (floating point 3.2) Or do you have to write that also as (3.2)^4 ?
On 21 Oct 2023, at 11:19, Takahiro Ueda @.***> wrote:
Maybe, we could always enclose dot products in parentheses, even when not needed. This may be easier to implement than enclosing or not enclosing dot products in parentheses depending on context.
For reference, operator precedence in Mathematica:
https://reference.wolfram.com/language/tutorial/OperatorInputForms.html
The binary operator . (Dot) has a lower precedence than the binary operator ^ (Power).
— Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/460#issuecomment-1773728963, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCETQE3NGNNBA6JXPLWDYAOHS3AVCNFSM6AAAAAA6JBIYZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTG4ZDQOJWGM. You are receiving this because you are subscribed to this thread.
I guess Mathematica treats 3.2
as an "atom". So, 3.2^4
is fine.
Indeed,
3.2^a
gives
Power[3.2`, a]
and
p.q^a
gives
Dot[p, Power[q, a]]
I do not understand why they do it this way. What else can the . operator do? Maybe it was planned to use it for data structs, but then it should also bind tighter.
On 21 Oct 2023, at 13:43, Takahiro Ueda @.***> wrote:
I guess Mathematica treats 3.2 as an "atom". So, 3.2^4 is fine.
Indeed,
3.2^a gives
Power[3.2`, a] and
p.q^a gives
Dot[p, Power[q, a]] — Reply to this email directly, view it on GitHub https://github.com/vermaseren/form/issues/460#issuecomment-1773766053, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJPCEVIJRC7MGUBF222KD3YAOYOHAVCNFSM6AAAAAA6JBIYZ6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZTG43DMMBVGM. You are receiving this because you commented.
The dot operator perfectly works with vectors/tensors in a reasonable way.
For example, the Mathematica code
{1, 2}.{3, 4}^2
gives
41
This is the same as other languages, like Python:
import numpy as np
a = np.array([1, 2])
b = np.array([3, 4])
a@b**2
which also gives 41
, not 121
.
I think an expression $p \cdot q^2$ in math or physics papers would be understood as $p \cdot (q^2)$.
Dear FORM developers,
I guess that all FORM users exporting their results to Mathematica are aware of the issue that happens when naively trying to save expression with scalar products, e.g.
This yields
which Mathematica happens to interpret as
as compared to the correct version
yielding
I know that one could do something like
to circumvent the issue, but perhaps it could be nice if FORM could produce the right expressions right away?
Cheers, Vlad