1
$\begingroup$

following question,

I have an expression that consists of several Minkowski inner products between 2 four vectors written as in Mathematika:

Dotp[{qm[0], qm[1], qm[2], qm[3]},{qn[0], qn[1], qn[2], qn[3]}],

Which I want to evaluate explicitly.

The Minkowski inner product I defined as:

Mi = {{1, 0, 0, 0}, {0, -1, 0, 0}, {0, 0, -1, 0}, {0, 0, 0, -1}};

doM = {qm[0], qm[1], qm[2], qm[3]}.Mi.{qn[0], qn[1], qn[2], qn[3]};

doM=qm[0] qn[0] - qm[1] qn[1] - qm[2] qn[2] - qm[3] qn[3];

To evaluate the Minkowski inner products in the Expressions explicitly. For this I wanted to define a replacement rule that acts on

Dotp[{qm[0], qm[1], qm[2], qm[3]},{qn[0], qn[1], qn[2], qn[3]}]

,and gives me

qm[0] qn[0] - qm[1] qn[1] - qm[2] qn[2] - qm[3] qn[3].

My current approach to define a rule:

rule1 = {Dotp[{x1_[0], x1_[1], x1_[2], x1_[3]}, {x2_[0], x2_[1], x2_[2], x2_[3]}] :-> {x1_[0], x1_[1], x1_[2], x1_[3]}.Mi.{x2_[0], x2_[1], x2_[2], x2_[3]}};

But then I get the error message:

RuleDelayed::rhs: Pattern x1_ appears on the right-hand side of rule Dotp[{x1_[0],x1_[1],x1_[2],q1_[3]},{x2_[0],x2_[1] ,x2_[2],x2_[3]}]:>{x1_[0],x1_[1],x1_[2],x1_[3]}.Mi.{x2_[0],x2_[1],x2_ [2],x2_[3]}.

My question is, how do I define rule s.t

Dotp[{qm[0], qm[1], qm[2], qm[3]},{qn[0], qn[1], qn [2], qn[3]}:-> qm[0] qn[0] - qm[1] qn[1] - qm[2] qn[2] - qm[3] qn[3] ?

Is a rule even the right approach?

Thanks in advance

$\endgroup$
1
  • 3
    $\begingroup$ Incorrect: {x_ :> x_^2}. Correct: {x_ :> x^2}. $\endgroup$
    – user293787
    Commented Sep 26, 2022 at 13:45

2 Answers 2

7
$\begingroup$
Mi = DiagonalMatrix[{1,-1,-1,-1}]

Dotp[{qm[0], qm[1], qm[2], qm[3]}, {qn[0], qn[1], qn[2], qn[3]}] /.  Dotp[t1_List, t2_List] :> (t1.Mi.t2)

Or

Block[
   {
      Dotp= Function[{t1, t2},(t1.Mi.t2)]
   },
   Dotp[{qm[0], qm[1], qm[2], qm[3]}, {qn[0], qn[1], qn[2], qn[3]}]
]
$\endgroup$
4
$\begingroup$
Dotp[{qm[0], qm[1], qm[2], qm[3]}, {qn[0], qn[1], qn[2], qn[3]}] /. 
 Dotp[a_List, b_List] :> Fold[#1 - #2 &, a b]

qm[0] qn[0] - qm[1] qn[1] - qm[2] qn[2] - qm[3] qn[3]

$\endgroup$
4
  • 2
    $\begingroup$ Your Fold[#1-#2&,a b] is an amusing trick, but probably difficult to understand for people that are new to Mathematica. $\endgroup$
    – user293787
    Commented Sep 26, 2022 at 14:19
  • 1
    $\begingroup$ @user293787 I remember a time when it was not even on my radar. $\endgroup$
    – Syed
    Commented Sep 26, 2022 at 14:24
  • $\begingroup$ why does the Fold[#1 - #2 &, a b] term have the same function as (t1 . Mi . t2) ? $\endgroup$
    – Faktor 2
    Commented Sep 26, 2022 at 16:50
  • 2
    $\begingroup$ Focus on the first term #1 and the second term #2 of the element-wise product a b. Do a #1-#2&, you get: qm[0] qn[0] - qm[1] qn[1]. Now this becomes the first term. The second term is the next one in the list. When it folds, you get qm[0] qn[0] - qm[1] qn[1] - qm[2] qn[2]; and so it goes until the end of the list. You can study more examples from the docs. Change Fold to FoldList to see the steps. $\endgroup$
    – Syed
    Commented Sep 26, 2022 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.