# How to define replacement rule for Minkowski inner product

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?

• Incorrect: {x_ :> x_^2}. Correct: {x_ :> x^2}. Sep 26, 2022 at 13:45

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]}]
]

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]

• Your Fold[#1-#2&,a b] is an amusing trick, but probably difficult to understand for people that are new to Mathematica. Sep 26, 2022 at 14:19
• @user293787 I remember a time when it was not even on my radar.
– Syed
Sep 26, 2022 at 14:24
• why does the Fold[#1 - #2 &, a b] term have the same function as (t1 . Mi . t2) ? Sep 26, 2022 at 16:50
• 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.
– Syed
Sep 26, 2022 at 16:58