0
$\begingroup$

How can I rewrite the following expression

$expr1= (A\cdot B)(C\cdot D)(E\cdot F) + (A^\prime\cdot B^\prime)(C^\prime\cdot D^\prime)(E^\prime\cdot F^\prime) +\cdots $

in terms of the components as

$expr2= A_iB_i\;C_jD_j\;E_\ell F_\ell + A^\prime_iB^\prime_i\;C^\prime_jD^\prime_j\;E^\prime_\ell F^\prime_\ell +\cdots $

where $A,A^\prime\cdots F, F^\prime$ are 3D vectors. I start with the following rule

rule = {incr = 1; var = CharacterRange["i", "q"];
Dot[a_, b_] :> (Subscript[a, var[[#]]]*Subscript[b, var[[#]]] &)[
 incr++]}

but at some point I ran out of indices. How to modify the rule such that it starts with the index $i$ in each some as in $expr2$?

$\endgroup$
2
  • $\begingroup$ Large space algebraists use subscripted subscripts: rule = {incr = 1; Dot[a_, b_] :> (Subscript[a, Subscript[i,#] ] * Subscript[b, Subscript[i,#] ]&)[ incr++]} $\endgroup$
    – Roland F
    Oct 18, 2023 at 11:04
  • $\begingroup$ You can use a rule like e.g.: a1 . b1 c1 . d1 e1 . f1 + a2 . b2 c2 . d2 e2 . f2 /. HoldPattern[a_ . b_ c_ . d_ e_ . f_ ] :> ( Subscript[a, i] Subscript[b, i] Subscript[c, j] Subscript[d, j] Subscript[e, k] Subscript[f, k]) but take care to put a space after each "_". Otherwise you will get some unwanted interpretations. $\endgroup$ Oct 18, 2023 at 19:00

1 Answer 1

0
$\begingroup$

I think the following will just give what I want:

For[
term = 1; finalexpr = 0, 
term <= Length@(expr1/.Plus -> List),       
incr = 1,
rule = # /. Dot[a_, b_] :>   (Superscript[a, Subscript[i, #]]*
      Superscript[b, Subscript[i, #]] &)[incr++] &;
dottodummy = rule /@(expr1/.Plus -> List)[[term]];
finalexpr += dottodummy;
term++;
];

finalexpr

Now to test it let's define the input

$(\text{A1}.\text{B1}) (\text{C1}.\text{D1}) (\text{E1}.\text{F1})+(\text{A2}.\text{B2}) (\text{C2}.\text{D2} )(\text{E2}.\text{F2})+(\text{A3}.\text{B3}) (\text{C3}.\text{D3}) (\text{E3}.\text{F3})$

as

expr1 = Dot[A1, B1] Dot[C1, D1] Dot[E1, F1] + Dot[A2, B2] Dot[C2, D2] Dot[E2, F2] + Dot[A3, B3] Dot[C3, D3] Dot[E3, F3]

then running the code gives

finalexpr    
Superscript[A1,Subscript[i, 1]] Superscript[B1,Subscript[i, 1]] Superscript[C1,Subscript[i, 2]] Superscript[D1,Subscript[i, 2]] Superscript[E1,Subscript[i, 3]] Superscript[F1,Subscript[i, 3]] + 
Superscript[A2,Subscript[i, 1]] Superscript[B2,Subscript[i, 1]] Superscript[C2,Subscript[i, 2]] Superscript[D2,Subscript[i, 2]] Superscript[E2,Subscript[i, 3]] Superscript[F2,Subscript[i, 3]] + 
Superscript[A3,Subscript[i, 1]] Superscript[B3,Subscript[i, 1]] Superscript[C3,Subscript[i, 2]] Superscript[D3,Subscript[i, 2]] Superscript[E3,Subscript[i, 3]] Superscript[F3,Subscript[i, 3]]

in plain text as

$\text{A1}^{i_1} \text{B1}^{i_1} \text{C1}^{i_2} \text{D1}^{i_2} \text{E1}^{i_3} \text{F1}^{i_3}+\text{A2}^{i_1} \text{B2}^{i_1} \text{C2}^{i_2} \text{D2}^{i_2} \text{E2}^{i_3} \text{F2}^{i_3}+\text{A3}^{i_1} \text{B3}^{i_1} \text{C3}^{i_2} \text{D3}^{i_2} \text{E3}^{i_3} \text{F3}^{i_3}$

$\endgroup$
1
  • $\begingroup$ You could improve your answer by applying your solution to the expression given in the question.. $\endgroup$
    – bbgodfrey
    Oct 28, 2023 at 21:28

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.