How can I automate this tensor computation?Why doesn't Mathematica make an obvious simplification?Simplify matrix algebraReduce the output from tuples by including symmetry?How to put the tensor product of two operators onto two variables?Symbolic Tensor AlgebraExpression containing $ttI$ is real — how can I show this is so in my notebook?Working with tensor algebraPython's einsum equivalent in Mathematica?Del as a Differential Operator: (Matrix times Del) cross vectorExplicitly construct tensor quantities with given symmetries

Do the books ever say oliphaunts aren’t elephants?

Exploiting the delay when a festival ticket is scanned

Would people understand me speaking German all over Europe?

How should I quote American English speakers in a British English essay?

Blank spaces in a font

Why does the Eurostar not show youth pricing?

Who said "one can be a powerful king with a very small sceptre"?

Why are we moving in circles with a tandem kayak?

Composing fill in the blanks

Is there a word to describe someone who is, or the state of being, content with hanging around others without interacting with them?

Omnidirectional LED, is it possible?

Why does Canada require bilingualism in a lot of federal government posts?

Is it safe if the neutral lead is exposed and disconnected?

Alternatives to minimizing loss in regression

What clothes would flying-people wear?

Argand formula and more for quaternions?

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

GNU sort stable sort when sort does not know sort order

What is the German equivalent of the proverb 水清ければ魚棲まず (if the water is clear, fish won't live there)?

Is The Venice Syndrome documentary cover photo real?

Was Donald Trump at ground zero helping out on 9-11?

Is SecureRandom.ints() secure?

How does ssh-copy-id get the public key when only the private key is loaded?

Scam? Checks via Email



How can I automate this tensor computation?


Why doesn't Mathematica make an obvious simplification?Simplify matrix algebraReduce the output from tuples by including symmetry?How to put the tensor product of two operators onto two variables?Symbolic Tensor AlgebraExpression containing $ttI$ is real — how can I show this is so in my notebook?Working with tensor algebraPython's einsum equivalent in Mathematica?Del as a Differential Operator: (Matrix times Del) cross vectorExplicitly construct tensor quantities with given symmetries






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








8












$begingroup$


I am doing this work by hand, but it takes a lot of time and I make several calculation errors, so I was thinking to make Mathematica to calculate this for me, but I am stuck at the very beginning.



I am working with tensors like this:



$XXV_ijk = dfrac16(X_iX_jV_k+X_iX_kV_j+X_jX_iV_k+X_kX_jV_i+X_jX_kV_i+X_kX_iV_j)$
$-dfrac15(delta_ij, (Xcdot X) V_k+delta_ik (Xcdot V) X_j+delta_jk (Xcdot V) X_i)$



where $X_i$ and $V_i$ are the components of the 3-vectors $vecX$ and $vecV$. I have to multiply these tensors, for example



$XXV times XXV = dfrac225V^2+dfrac825 (Xcdot V)^2$



I think I can obtain the first part with Tuples and Total(?) but I don't know how to obtain the part with the Kroeneker deltas; if I can write these tensors correctly I think I can multiply these tensors with . and Transpose.



As @yarchik has pointd out, I have to add that my tensors have unit length










share|improve this question











$endgroup$













  • $begingroup$
    Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
    $endgroup$
    – Roman
    Jul 19 at 14:52










  • $begingroup$
    @Roman yes it is a typo
    $endgroup$
    – mattiav27
    Jul 19 at 15:13










  • $begingroup$
    I think your second term still needs a power correction. The answer should be proportional to $V^2$.
    $endgroup$
    – yarchik
    Jul 19 at 15:40










  • $begingroup$
    @yarchik you are right, but this is a typo not a calculation error...
    $endgroup$
    – mattiav27
    Jul 19 at 15:44










  • $begingroup$
    Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
    $endgroup$
    – Shadowray
    Jul 20 at 0:15


















8












$begingroup$


I am doing this work by hand, but it takes a lot of time and I make several calculation errors, so I was thinking to make Mathematica to calculate this for me, but I am stuck at the very beginning.



I am working with tensors like this:



$XXV_ijk = dfrac16(X_iX_jV_k+X_iX_kV_j+X_jX_iV_k+X_kX_jV_i+X_jX_kV_i+X_kX_iV_j)$
$-dfrac15(delta_ij, (Xcdot X) V_k+delta_ik (Xcdot V) X_j+delta_jk (Xcdot V) X_i)$



where $X_i$ and $V_i$ are the components of the 3-vectors $vecX$ and $vecV$. I have to multiply these tensors, for example



$XXV times XXV = dfrac225V^2+dfrac825 (Xcdot V)^2$



I think I can obtain the first part with Tuples and Total(?) but I don't know how to obtain the part with the Kroeneker deltas; if I can write these tensors correctly I think I can multiply these tensors with . and Transpose.



As @yarchik has pointd out, I have to add that my tensors have unit length










share|improve this question











$endgroup$













  • $begingroup$
    Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
    $endgroup$
    – Roman
    Jul 19 at 14:52










  • $begingroup$
    @Roman yes it is a typo
    $endgroup$
    – mattiav27
    Jul 19 at 15:13










  • $begingroup$
    I think your second term still needs a power correction. The answer should be proportional to $V^2$.
    $endgroup$
    – yarchik
    Jul 19 at 15:40










  • $begingroup$
    @yarchik you are right, but this is a typo not a calculation error...
    $endgroup$
    – mattiav27
    Jul 19 at 15:44










  • $begingroup$
    Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
    $endgroup$
    – Shadowray
    Jul 20 at 0:15














8












8








8


1



$begingroup$


I am doing this work by hand, but it takes a lot of time and I make several calculation errors, so I was thinking to make Mathematica to calculate this for me, but I am stuck at the very beginning.



I am working with tensors like this:



$XXV_ijk = dfrac16(X_iX_jV_k+X_iX_kV_j+X_jX_iV_k+X_kX_jV_i+X_jX_kV_i+X_kX_iV_j)$
$-dfrac15(delta_ij, (Xcdot X) V_k+delta_ik (Xcdot V) X_j+delta_jk (Xcdot V) X_i)$



where $X_i$ and $V_i$ are the components of the 3-vectors $vecX$ and $vecV$. I have to multiply these tensors, for example



$XXV times XXV = dfrac225V^2+dfrac825 (Xcdot V)^2$



I think I can obtain the first part with Tuples and Total(?) but I don't know how to obtain the part with the Kroeneker deltas; if I can write these tensors correctly I think I can multiply these tensors with . and Transpose.



As @yarchik has pointd out, I have to add that my tensors have unit length










share|improve this question











$endgroup$




I am doing this work by hand, but it takes a lot of time and I make several calculation errors, so I was thinking to make Mathematica to calculate this for me, but I am stuck at the very beginning.



I am working with tensors like this:



$XXV_ijk = dfrac16(X_iX_jV_k+X_iX_kV_j+X_jX_iV_k+X_kX_jV_i+X_jX_kV_i+X_kX_iV_j)$
$-dfrac15(delta_ij, (Xcdot X) V_k+delta_ik (Xcdot V) X_j+delta_jk (Xcdot V) X_i)$



where $X_i$ and $V_i$ are the components of the 3-vectors $vecX$ and $vecV$. I have to multiply these tensors, for example



$XXV times XXV = dfrac225V^2+dfrac825 (Xcdot V)^2$



I think I can obtain the first part with Tuples and Total(?) but I don't know how to obtain the part with the Kroeneker deltas; if I can write these tensors correctly I think I can multiply these tensors with . and Transpose.



As @yarchik has pointd out, I have to add that my tensors have unit length







simplifying-expressions tensors code-request






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 19 at 17:49









Carl Woll

88.4k3 gold badges117 silver badges227 bronze badges




88.4k3 gold badges117 silver badges227 bronze badges










asked Jul 19 at 13:14









mattiav27mattiav27

2,3262 gold badges15 silver badges33 bronze badges




2,3262 gold badges15 silver badges33 bronze badges














  • $begingroup$
    Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
    $endgroup$
    – Roman
    Jul 19 at 14:52










  • $begingroup$
    @Roman yes it is a typo
    $endgroup$
    – mattiav27
    Jul 19 at 15:13










  • $begingroup$
    I think your second term still needs a power correction. The answer should be proportional to $V^2$.
    $endgroup$
    – yarchik
    Jul 19 at 15:40










  • $begingroup$
    @yarchik you are right, but this is a typo not a calculation error...
    $endgroup$
    – mattiav27
    Jul 19 at 15:44










  • $begingroup$
    Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
    $endgroup$
    – Shadowray
    Jul 20 at 0:15

















  • $begingroup$
    Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
    $endgroup$
    – Roman
    Jul 19 at 14:52










  • $begingroup$
    @Roman yes it is a typo
    $endgroup$
    – mattiav27
    Jul 19 at 15:13










  • $begingroup$
    I think your second term still needs a power correction. The answer should be proportional to $V^2$.
    $endgroup$
    – yarchik
    Jul 19 at 15:40










  • $begingroup$
    @yarchik you are right, but this is a typo not a calculation error...
    $endgroup$
    – mattiav27
    Jul 19 at 15:44










  • $begingroup$
    Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
    $endgroup$
    – Shadowray
    Jul 20 at 0:15
















$begingroup$
Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
$endgroup$
– Roman
Jul 19 at 14:52




$begingroup$
Is there a typo in your last term on the first line, $X_kX_iV_k$? There should be a $j$-index somewhere.
$endgroup$
– Roman
Jul 19 at 14:52












$begingroup$
@Roman yes it is a typo
$endgroup$
– mattiav27
Jul 19 at 15:13




$begingroup$
@Roman yes it is a typo
$endgroup$
– mattiav27
Jul 19 at 15:13












$begingroup$
I think your second term still needs a power correction. The answer should be proportional to $V^2$.
$endgroup$
– yarchik
Jul 19 at 15:40




$begingroup$
I think your second term still needs a power correction. The answer should be proportional to $V^2$.
$endgroup$
– yarchik
Jul 19 at 15:40












$begingroup$
@yarchik you are right, but this is a typo not a calculation error...
$endgroup$
– mattiav27
Jul 19 at 15:44




$begingroup$
@yarchik you are right, but this is a typo not a calculation error...
$endgroup$
– mattiav27
Jul 19 at 15:44












$begingroup$
Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
$endgroup$
– Shadowray
Jul 20 at 0:15





$begingroup$
Note that in your example the the correct result should be $frac825 V^2 + frac225 (Xcdot V)^2$. See all four answers below.
$endgroup$
– Shadowray
Jul 20 at 0:15











4 Answers
4






active

oldest

votes


















7












$begingroup$

You can write it directly as you see it



xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
+x[j]x[i]v[k]+x[k]x[j]v[i]
+x[j]x[k]v[i]+x[k]x[i]v[j] )
-1/5( KroneckerDelta[i,j]Sum[x[l]x[l],l,3]v[k]
+KroneckerDelta[i,k]Sum[x[l]v[l],l,3]x[j]
+KroneckerDelta[j,k]Sum[x[l]v[l],l,3]x[i] )

FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],i,3,j,3,k,3],
Assumptions->Sum[x[i]^2,i,3]==1
&&Sum[x[i]v[i],i,3]==xv
&&Sum[v[i]v[i],i,3]==vv]

Out[1]= 2/25 (4 vv + xv^2)


where I assumed that your vector x is normalized






share|improve this answer











$endgroup$






















    6












    $begingroup$

    You can cast this as a symbolic tensor question, and make use of my TensorSimplify package. Install the paclet with:



    PacletInstall[
    "TensorSimplify",
    "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
    ]


    Once installed, load the package with:



    <<TensorSimplify`


    Now, define your tensor using TensorProduct:



    XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) - 
    1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
    X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],1,3,2] +
    X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
    );


    Note the use of Inactive[IdentityMatrix][3] instead of IdentityMatrix[3]. Then:



    TensorSimplify[
    TensorContract[TensorProduct[XXV, XXV], 1, 4, 2, 5, 3, 6],
    Assumptions -> (X|V) ∈ Vectors[3]
    ]



    2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2




    Using X.X == 1 reproduces your result.






    share|improve this answer









    $endgroup$






















      5












      $begingroup$

      This is how I'd do it; maybe it's useful for you.



      Define $vecX$ and $vecV$ as vectors:



      X = Array[x, 3];
      V = Array[v, 3];


      useful $3times3times3$ tensors for assembling:



      a = Outer[Times, X, X, V];
      b = (X.X) Outer[Times, IdentityMatrix[3], V];
      c = (X.V) Outer[Times, IdentityMatrix[3], X];


      assemble $XXV$:



      XXV = (a + Transpose[a, 3, 1, 2] + Transpose[a, 2, 3, 1])/3 -
      (b + Transpose[c, 3, 1, 2] + Transpose[c, 2, 3, 1])/5;


      check a formula:



      Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
      (* True *)





      share|improve this answer









      $endgroup$














      • $begingroup$
        Nice that you verified my answer. I already started to doubt.
        $endgroup$
        – yarchik
        Jul 19 at 15:20










      • $begingroup$
        @yarchik this is one of my calculation errors... I have corrected the formula in my post
        $endgroup$
        – mattiav27
        Jul 19 at 15:35






      • 1




        $begingroup$
        @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
        $endgroup$
        – Roman
        Jul 19 at 15:57


















      2












      $begingroup$

      You can implement Einstein's summation convention using, for example, temporary variables as summation indices.



      ClearAll[delta, CenterDot, dummyIndexQ, tensorSimplify];

      SetAttributes[delta, Orderless];
      SetAttributes[CenterDot, Orderless];

      dummyIndexQ[x_Symbol] := MemberQ[Attributes[x], Temporary];

      tensorSimplificationRules =
      delta[a_?dummyIndexQ, a_] :> 3,
      delta[a_?dummyIndexQ, b_]^2 :> delta[b, b],
      delta[a_, b_?dummyIndexQ] delta[b_, c_] :> delta[a, c],
      delta[i_?dummyIndexQ, j_]t_[i_] :> t[j],
      (t_[i_?dummyIndexQ])^2 :> (t[CenterDot]t),
      t1_[x_?dummyIndexQ] t2_[x_] :> t1[CenterDot]t2
      ;

      tensorSimplify[expr_] := FixedPoint[(Expand[#]//.tensorSimplificationRules)&, expr];


      Let's define $XXV_ijk$:



      xxv[i_, j_, k_] := (1/3 * (v[k] x[i] x[j] + v[j] x[i] x[k] + v[i] x[j] x[k]) - 1/5 * (delta[i,j] (x[CenterDot]x) v[k] + delta[i,k] (x[CenterDot]v) x[j] + delta[j,k] (x[CenterDot]v) x[i]))


      Result for your example $XXV_abc XXV_abc$:



      expr = Module[a,b,c, xxv[a,b,c] xxv[a,b,c]];
      tensorSimplify[expr]



      2/25 (v$cdot$x)^2 (x$cdot$x) + 8/25 (v$cdot$v) (x$cdot$x)^2




      Result for more complicated input $XXV_abc XXV_bcd XXV_def XXV_efa$:



      expr2 = Module[a,b,c,d,e,f, xxv[a,b,c] xxv[b,c,d] xxv[d,e,f] xxv[e,f,a]];
      tensorSimplify[expr2]



      $frac524 (xcdot x)^2 (vcdot x)^450625+frac1454 vcdot v (xcdot x)^3 (vcdot
      x)^250625+frac1586 (vcdot v)^2 (xcdot x)^450625$




      Note that all summation indices must be listed inside the first argument of Module.






      share|improve this answer









      $endgroup$

















        Your Answer








        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "387"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader:
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        ,
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













        draft saved

        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202373%2fhow-can-i-automate-this-tensor-computation%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        7












        $begingroup$

        You can write it directly as you see it



        xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
        +x[j]x[i]v[k]+x[k]x[j]v[i]
        +x[j]x[k]v[i]+x[k]x[i]v[j] )
        -1/5( KroneckerDelta[i,j]Sum[x[l]x[l],l,3]v[k]
        +KroneckerDelta[i,k]Sum[x[l]v[l],l,3]x[j]
        +KroneckerDelta[j,k]Sum[x[l]v[l],l,3]x[i] )

        FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],i,3,j,3,k,3],
        Assumptions->Sum[x[i]^2,i,3]==1
        &&Sum[x[i]v[i],i,3]==xv
        &&Sum[v[i]v[i],i,3]==vv]

        Out[1]= 2/25 (4 vv + xv^2)


        where I assumed that your vector x is normalized






        share|improve this answer











        $endgroup$



















          7












          $begingroup$

          You can write it directly as you see it



          xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
          +x[j]x[i]v[k]+x[k]x[j]v[i]
          +x[j]x[k]v[i]+x[k]x[i]v[j] )
          -1/5( KroneckerDelta[i,j]Sum[x[l]x[l],l,3]v[k]
          +KroneckerDelta[i,k]Sum[x[l]v[l],l,3]x[j]
          +KroneckerDelta[j,k]Sum[x[l]v[l],l,3]x[i] )

          FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],i,3,j,3,k,3],
          Assumptions->Sum[x[i]^2,i,3]==1
          &&Sum[x[i]v[i],i,3]==xv
          &&Sum[v[i]v[i],i,3]==vv]

          Out[1]= 2/25 (4 vv + xv^2)


          where I assumed that your vector x is normalized






          share|improve this answer











          $endgroup$

















            7












            7








            7





            $begingroup$

            You can write it directly as you see it



            xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
            +x[j]x[i]v[k]+x[k]x[j]v[i]
            +x[j]x[k]v[i]+x[k]x[i]v[j] )
            -1/5( KroneckerDelta[i,j]Sum[x[l]x[l],l,3]v[k]
            +KroneckerDelta[i,k]Sum[x[l]v[l],l,3]x[j]
            +KroneckerDelta[j,k]Sum[x[l]v[l],l,3]x[i] )

            FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],i,3,j,3,k,3],
            Assumptions->Sum[x[i]^2,i,3]==1
            &&Sum[x[i]v[i],i,3]==xv
            &&Sum[v[i]v[i],i,3]==vv]

            Out[1]= 2/25 (4 vv + xv^2)


            where I assumed that your vector x is normalized






            share|improve this answer











            $endgroup$



            You can write it directly as you see it



            xxv[i_,j_,k_]:= 1/6( x[i]x[j]v[k]+x[i]x[k]v[j]
            +x[j]x[i]v[k]+x[k]x[j]v[i]
            +x[j]x[k]v[i]+x[k]x[i]v[j] )
            -1/5( KroneckerDelta[i,j]Sum[x[l]x[l],l,3]v[k]
            +KroneckerDelta[i,k]Sum[x[l]v[l],l,3]x[j]
            +KroneckerDelta[j,k]Sum[x[l]v[l],l,3]x[i] )

            FullSimplify[ Sum[xxv[i,j,k] xxv[i,j,k],i,3,j,3,k,3],
            Assumptions->Sum[x[i]^2,i,3]==1
            &&Sum[x[i]v[i],i,3]==xv
            &&Sum[v[i]v[i],i,3]==vv]

            Out[1]= 2/25 (4 vv + xv^2)


            where I assumed that your vector x is normalized







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jul 19 at 14:28

























            answered Jul 19 at 14:21









            yarchikyarchik

            4,63610 silver badges34 bronze badges




            4,63610 silver badges34 bronze badges


























                6












                $begingroup$

                You can cast this as a symbolic tensor question, and make use of my TensorSimplify package. Install the paclet with:



                PacletInstall[
                "TensorSimplify",
                "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
                ]


                Once installed, load the package with:



                <<TensorSimplify`


                Now, define your tensor using TensorProduct:



                XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) - 
                1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
                X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],1,3,2] +
                X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
                );


                Note the use of Inactive[IdentityMatrix][3] instead of IdentityMatrix[3]. Then:



                TensorSimplify[
                TensorContract[TensorProduct[XXV, XXV], 1, 4, 2, 5, 3, 6],
                Assumptions -> (X|V) ∈ Vectors[3]
                ]



                2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2




                Using X.X == 1 reproduces your result.






                share|improve this answer









                $endgroup$



















                  6












                  $begingroup$

                  You can cast this as a symbolic tensor question, and make use of my TensorSimplify package. Install the paclet with:



                  PacletInstall[
                  "TensorSimplify",
                  "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
                  ]


                  Once installed, load the package with:



                  <<TensorSimplify`


                  Now, define your tensor using TensorProduct:



                  XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) - 
                  1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
                  X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],1,3,2] +
                  X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
                  );


                  Note the use of Inactive[IdentityMatrix][3] instead of IdentityMatrix[3]. Then:



                  TensorSimplify[
                  TensorContract[TensorProduct[XXV, XXV], 1, 4, 2, 5, 3, 6],
                  Assumptions -> (X|V) ∈ Vectors[3]
                  ]



                  2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2




                  Using X.X == 1 reproduces your result.






                  share|improve this answer









                  $endgroup$

















                    6












                    6








                    6





                    $begingroup$

                    You can cast this as a symbolic tensor question, and make use of my TensorSimplify package. Install the paclet with:



                    PacletInstall[
                    "TensorSimplify",
                    "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
                    ]


                    Once installed, load the package with:



                    <<TensorSimplify`


                    Now, define your tensor using TensorProduct:



                    XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) - 
                    1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
                    X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],1,3,2] +
                    X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
                    );


                    Note the use of Inactive[IdentityMatrix][3] instead of IdentityMatrix[3]. Then:



                    TensorSimplify[
                    TensorContract[TensorProduct[XXV, XXV], 1, 4, 2, 5, 3, 6],
                    Assumptions -> (X|V) ∈ Vectors[3]
                    ]



                    2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2




                    Using X.X == 1 reproduces your result.






                    share|improve this answer









                    $endgroup$



                    You can cast this as a symbolic tensor question, and make use of my TensorSimplify package. Install the paclet with:



                    PacletInstall[
                    "TensorSimplify",
                    "Site" -> "http://raw.githubusercontent.com/carlwoll/TensorSimplify/master"
                    ]


                    Once installed, load the package with:



                    <<TensorSimplify`


                    Now, define your tensor using TensorProduct:



                    XXV = 1/3 (TensorProduct[X,X,V] + TensorProduct[X,V,X] + TensorProduct[V,X,X]) - 
                    1/5 (X.X TensorProduct[Inactive[IdentityMatrix][3], V] +
                    X.V TensorTranspose[TensorProduct[Inactive[IdentityMatrix][3],X],1,3,2] +
                    X.V TensorProduct[X,Inactive[IdentityMatrix][3]]
                    );


                    Note the use of Inactive[IdentityMatrix][3] instead of IdentityMatrix[3]. Then:



                    TensorSimplify[
                    TensorContract[TensorProduct[XXV, XXV], 1, 4, 2, 5, 3, 6],
                    Assumptions -> (X|V) ∈ Vectors[3]
                    ]



                    2/25 (V.X)^2 X.X + 8/25 V.V (X.X)^2




                    Using X.X == 1 reproduces your result.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jul 19 at 17:46









                    Carl WollCarl Woll

                    88.4k3 gold badges117 silver badges227 bronze badges




                    88.4k3 gold badges117 silver badges227 bronze badges
























                        5












                        $begingroup$

                        This is how I'd do it; maybe it's useful for you.



                        Define $vecX$ and $vecV$ as vectors:



                        X = Array[x, 3];
                        V = Array[v, 3];


                        useful $3times3times3$ tensors for assembling:



                        a = Outer[Times, X, X, V];
                        b = (X.X) Outer[Times, IdentityMatrix[3], V];
                        c = (X.V) Outer[Times, IdentityMatrix[3], X];


                        assemble $XXV$:



                        XXV = (a + Transpose[a, 3, 1, 2] + Transpose[a, 2, 3, 1])/3 -
                        (b + Transpose[c, 3, 1, 2] + Transpose[c, 2, 3, 1])/5;


                        check a formula:



                        Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
                        (* True *)





                        share|improve this answer









                        $endgroup$














                        • $begingroup$
                          Nice that you verified my answer. I already started to doubt.
                          $endgroup$
                          – yarchik
                          Jul 19 at 15:20










                        • $begingroup$
                          @yarchik this is one of my calculation errors... I have corrected the formula in my post
                          $endgroup$
                          – mattiav27
                          Jul 19 at 15:35






                        • 1




                          $begingroup$
                          @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                          $endgroup$
                          – Roman
                          Jul 19 at 15:57















                        5












                        $begingroup$

                        This is how I'd do it; maybe it's useful for you.



                        Define $vecX$ and $vecV$ as vectors:



                        X = Array[x, 3];
                        V = Array[v, 3];


                        useful $3times3times3$ tensors for assembling:



                        a = Outer[Times, X, X, V];
                        b = (X.X) Outer[Times, IdentityMatrix[3], V];
                        c = (X.V) Outer[Times, IdentityMatrix[3], X];


                        assemble $XXV$:



                        XXV = (a + Transpose[a, 3, 1, 2] + Transpose[a, 2, 3, 1])/3 -
                        (b + Transpose[c, 3, 1, 2] + Transpose[c, 2, 3, 1])/5;


                        check a formula:



                        Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
                        (* True *)





                        share|improve this answer









                        $endgroup$














                        • $begingroup$
                          Nice that you verified my answer. I already started to doubt.
                          $endgroup$
                          – yarchik
                          Jul 19 at 15:20










                        • $begingroup$
                          @yarchik this is one of my calculation errors... I have corrected the formula in my post
                          $endgroup$
                          – mattiav27
                          Jul 19 at 15:35






                        • 1




                          $begingroup$
                          @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                          $endgroup$
                          – Roman
                          Jul 19 at 15:57













                        5












                        5








                        5





                        $begingroup$

                        This is how I'd do it; maybe it's useful for you.



                        Define $vecX$ and $vecV$ as vectors:



                        X = Array[x, 3];
                        V = Array[v, 3];


                        useful $3times3times3$ tensors for assembling:



                        a = Outer[Times, X, X, V];
                        b = (X.X) Outer[Times, IdentityMatrix[3], V];
                        c = (X.V) Outer[Times, IdentityMatrix[3], X];


                        assemble $XXV$:



                        XXV = (a + Transpose[a, 3, 1, 2] + Transpose[a, 2, 3, 1])/3 -
                        (b + Transpose[c, 3, 1, 2] + Transpose[c, 2, 3, 1])/5;


                        check a formula:



                        Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
                        (* True *)





                        share|improve this answer









                        $endgroup$



                        This is how I'd do it; maybe it's useful for you.



                        Define $vecX$ and $vecV$ as vectors:



                        X = Array[x, 3];
                        V = Array[v, 3];


                        useful $3times3times3$ tensors for assembling:



                        a = Outer[Times, X, X, V];
                        b = (X.X) Outer[Times, IdentityMatrix[3], V];
                        c = (X.V) Outer[Times, IdentityMatrix[3], X];


                        assemble $XXV$:



                        XXV = (a + Transpose[a, 3, 1, 2] + Transpose[a, 2, 3, 1])/3 -
                        (b + Transpose[c, 3, 1, 2] + Transpose[c, 2, 3, 1])/5;


                        check a formula:



                        Total[XXV*XXV, 3] == 2/25 (X.X) ((X.V)^2 + 4 (X.X) (V.V)) // FullSimplify
                        (* True *)






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Jul 19 at 15:00









                        RomanRoman

                        14.9k1 gold badge20 silver badges51 bronze badges




                        14.9k1 gold badge20 silver badges51 bronze badges














                        • $begingroup$
                          Nice that you verified my answer. I already started to doubt.
                          $endgroup$
                          – yarchik
                          Jul 19 at 15:20










                        • $begingroup$
                          @yarchik this is one of my calculation errors... I have corrected the formula in my post
                          $endgroup$
                          – mattiav27
                          Jul 19 at 15:35






                        • 1




                          $begingroup$
                          @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                          $endgroup$
                          – Roman
                          Jul 19 at 15:57
















                        • $begingroup$
                          Nice that you verified my answer. I already started to doubt.
                          $endgroup$
                          – yarchik
                          Jul 19 at 15:20










                        • $begingroup$
                          @yarchik this is one of my calculation errors... I have corrected the formula in my post
                          $endgroup$
                          – mattiav27
                          Jul 19 at 15:35






                        • 1




                          $begingroup$
                          @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                          $endgroup$
                          – Roman
                          Jul 19 at 15:57















                        $begingroup$
                        Nice that you verified my answer. I already started to doubt.
                        $endgroup$
                        – yarchik
                        Jul 19 at 15:20




                        $begingroup$
                        Nice that you verified my answer. I already started to doubt.
                        $endgroup$
                        – yarchik
                        Jul 19 at 15:20












                        $begingroup$
                        @yarchik this is one of my calculation errors... I have corrected the formula in my post
                        $endgroup$
                        – mattiav27
                        Jul 19 at 15:35




                        $begingroup$
                        @yarchik this is one of my calculation errors... I have corrected the formula in my post
                        $endgroup$
                        – mattiav27
                        Jul 19 at 15:35




                        1




                        1




                        $begingroup$
                        @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                        $endgroup$
                        – Roman
                        Jul 19 at 15:57




                        $begingroup$
                        @mattiav27 it's still wrong, the second term should be 8/25 and you need to specify that you're assuming that $vecX$ has unit length.
                        $endgroup$
                        – Roman
                        Jul 19 at 15:57











                        2












                        $begingroup$

                        You can implement Einstein's summation convention using, for example, temporary variables as summation indices.



                        ClearAll[delta, CenterDot, dummyIndexQ, tensorSimplify];

                        SetAttributes[delta, Orderless];
                        SetAttributes[CenterDot, Orderless];

                        dummyIndexQ[x_Symbol] := MemberQ[Attributes[x], Temporary];

                        tensorSimplificationRules =
                        delta[a_?dummyIndexQ, a_] :> 3,
                        delta[a_?dummyIndexQ, b_]^2 :> delta[b, b],
                        delta[a_, b_?dummyIndexQ] delta[b_, c_] :> delta[a, c],
                        delta[i_?dummyIndexQ, j_]t_[i_] :> t[j],
                        (t_[i_?dummyIndexQ])^2 :> (t[CenterDot]t),
                        t1_[x_?dummyIndexQ] t2_[x_] :> t1[CenterDot]t2
                        ;

                        tensorSimplify[expr_] := FixedPoint[(Expand[#]//.tensorSimplificationRules)&, expr];


                        Let's define $XXV_ijk$:



                        xxv[i_, j_, k_] := (1/3 * (v[k] x[i] x[j] + v[j] x[i] x[k] + v[i] x[j] x[k]) - 1/5 * (delta[i,j] (x[CenterDot]x) v[k] + delta[i,k] (x[CenterDot]v) x[j] + delta[j,k] (x[CenterDot]v) x[i]))


                        Result for your example $XXV_abc XXV_abc$:



                        expr = Module[a,b,c, xxv[a,b,c] xxv[a,b,c]];
                        tensorSimplify[expr]



                        2/25 (v$cdot$x)^2 (x$cdot$x) + 8/25 (v$cdot$v) (x$cdot$x)^2




                        Result for more complicated input $XXV_abc XXV_bcd XXV_def XXV_efa$:



                        expr2 = Module[a,b,c,d,e,f, xxv[a,b,c] xxv[b,c,d] xxv[d,e,f] xxv[e,f,a]];
                        tensorSimplify[expr2]



                        $frac524 (xcdot x)^2 (vcdot x)^450625+frac1454 vcdot v (xcdot x)^3 (vcdot
                        x)^250625+frac1586 (vcdot v)^2 (xcdot x)^450625$




                        Note that all summation indices must be listed inside the first argument of Module.






                        share|improve this answer









                        $endgroup$



















                          2












                          $begingroup$

                          You can implement Einstein's summation convention using, for example, temporary variables as summation indices.



                          ClearAll[delta, CenterDot, dummyIndexQ, tensorSimplify];

                          SetAttributes[delta, Orderless];
                          SetAttributes[CenterDot, Orderless];

                          dummyIndexQ[x_Symbol] := MemberQ[Attributes[x], Temporary];

                          tensorSimplificationRules =
                          delta[a_?dummyIndexQ, a_] :> 3,
                          delta[a_?dummyIndexQ, b_]^2 :> delta[b, b],
                          delta[a_, b_?dummyIndexQ] delta[b_, c_] :> delta[a, c],
                          delta[i_?dummyIndexQ, j_]t_[i_] :> t[j],
                          (t_[i_?dummyIndexQ])^2 :> (t[CenterDot]t),
                          t1_[x_?dummyIndexQ] t2_[x_] :> t1[CenterDot]t2
                          ;

                          tensorSimplify[expr_] := FixedPoint[(Expand[#]//.tensorSimplificationRules)&, expr];


                          Let's define $XXV_ijk$:



                          xxv[i_, j_, k_] := (1/3 * (v[k] x[i] x[j] + v[j] x[i] x[k] + v[i] x[j] x[k]) - 1/5 * (delta[i,j] (x[CenterDot]x) v[k] + delta[i,k] (x[CenterDot]v) x[j] + delta[j,k] (x[CenterDot]v) x[i]))


                          Result for your example $XXV_abc XXV_abc$:



                          expr = Module[a,b,c, xxv[a,b,c] xxv[a,b,c]];
                          tensorSimplify[expr]



                          2/25 (v$cdot$x)^2 (x$cdot$x) + 8/25 (v$cdot$v) (x$cdot$x)^2




                          Result for more complicated input $XXV_abc XXV_bcd XXV_def XXV_efa$:



                          expr2 = Module[a,b,c,d,e,f, xxv[a,b,c] xxv[b,c,d] xxv[d,e,f] xxv[e,f,a]];
                          tensorSimplify[expr2]



                          $frac524 (xcdot x)^2 (vcdot x)^450625+frac1454 vcdot v (xcdot x)^3 (vcdot
                          x)^250625+frac1586 (vcdot v)^2 (xcdot x)^450625$




                          Note that all summation indices must be listed inside the first argument of Module.






                          share|improve this answer









                          $endgroup$

















                            2












                            2








                            2





                            $begingroup$

                            You can implement Einstein's summation convention using, for example, temporary variables as summation indices.



                            ClearAll[delta, CenterDot, dummyIndexQ, tensorSimplify];

                            SetAttributes[delta, Orderless];
                            SetAttributes[CenterDot, Orderless];

                            dummyIndexQ[x_Symbol] := MemberQ[Attributes[x], Temporary];

                            tensorSimplificationRules =
                            delta[a_?dummyIndexQ, a_] :> 3,
                            delta[a_?dummyIndexQ, b_]^2 :> delta[b, b],
                            delta[a_, b_?dummyIndexQ] delta[b_, c_] :> delta[a, c],
                            delta[i_?dummyIndexQ, j_]t_[i_] :> t[j],
                            (t_[i_?dummyIndexQ])^2 :> (t[CenterDot]t),
                            t1_[x_?dummyIndexQ] t2_[x_] :> t1[CenterDot]t2
                            ;

                            tensorSimplify[expr_] := FixedPoint[(Expand[#]//.tensorSimplificationRules)&, expr];


                            Let's define $XXV_ijk$:



                            xxv[i_, j_, k_] := (1/3 * (v[k] x[i] x[j] + v[j] x[i] x[k] + v[i] x[j] x[k]) - 1/5 * (delta[i,j] (x[CenterDot]x) v[k] + delta[i,k] (x[CenterDot]v) x[j] + delta[j,k] (x[CenterDot]v) x[i]))


                            Result for your example $XXV_abc XXV_abc$:



                            expr = Module[a,b,c, xxv[a,b,c] xxv[a,b,c]];
                            tensorSimplify[expr]



                            2/25 (v$cdot$x)^2 (x$cdot$x) + 8/25 (v$cdot$v) (x$cdot$x)^2




                            Result for more complicated input $XXV_abc XXV_bcd XXV_def XXV_efa$:



                            expr2 = Module[a,b,c,d,e,f, xxv[a,b,c] xxv[b,c,d] xxv[d,e,f] xxv[e,f,a]];
                            tensorSimplify[expr2]



                            $frac524 (xcdot x)^2 (vcdot x)^450625+frac1454 vcdot v (xcdot x)^3 (vcdot
                            x)^250625+frac1586 (vcdot v)^2 (xcdot x)^450625$




                            Note that all summation indices must be listed inside the first argument of Module.






                            share|improve this answer









                            $endgroup$



                            You can implement Einstein's summation convention using, for example, temporary variables as summation indices.



                            ClearAll[delta, CenterDot, dummyIndexQ, tensorSimplify];

                            SetAttributes[delta, Orderless];
                            SetAttributes[CenterDot, Orderless];

                            dummyIndexQ[x_Symbol] := MemberQ[Attributes[x], Temporary];

                            tensorSimplificationRules =
                            delta[a_?dummyIndexQ, a_] :> 3,
                            delta[a_?dummyIndexQ, b_]^2 :> delta[b, b],
                            delta[a_, b_?dummyIndexQ] delta[b_, c_] :> delta[a, c],
                            delta[i_?dummyIndexQ, j_]t_[i_] :> t[j],
                            (t_[i_?dummyIndexQ])^2 :> (t[CenterDot]t),
                            t1_[x_?dummyIndexQ] t2_[x_] :> t1[CenterDot]t2
                            ;

                            tensorSimplify[expr_] := FixedPoint[(Expand[#]//.tensorSimplificationRules)&, expr];


                            Let's define $XXV_ijk$:



                            xxv[i_, j_, k_] := (1/3 * (v[k] x[i] x[j] + v[j] x[i] x[k] + v[i] x[j] x[k]) - 1/5 * (delta[i,j] (x[CenterDot]x) v[k] + delta[i,k] (x[CenterDot]v) x[j] + delta[j,k] (x[CenterDot]v) x[i]))


                            Result for your example $XXV_abc XXV_abc$:



                            expr = Module[a,b,c, xxv[a,b,c] xxv[a,b,c]];
                            tensorSimplify[expr]



                            2/25 (v$cdot$x)^2 (x$cdot$x) + 8/25 (v$cdot$v) (x$cdot$x)^2




                            Result for more complicated input $XXV_abc XXV_bcd XXV_def XXV_efa$:



                            expr2 = Module[a,b,c,d,e,f, xxv[a,b,c] xxv[b,c,d] xxv[d,e,f] xxv[e,f,a]];
                            tensorSimplify[expr2]



                            $frac524 (xcdot x)^2 (vcdot x)^450625+frac1454 vcdot v (xcdot x)^3 (vcdot
                            x)^250625+frac1586 (vcdot v)^2 (xcdot x)^450625$




                            Note that all summation indices must be listed inside the first argument of Module.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jul 19 at 23:48









                            ShadowrayShadowray

                            5,8871 gold badge9 silver badges34 bronze badges




                            5,8871 gold badge9 silver badges34 bronze badges






























                                draft saved

                                draft discarded
















































                                Thanks for contributing an answer to Mathematica Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid


                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.

                                Use MathJax to format equations. MathJax reference.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f202373%2fhow-can-i-automate-this-tensor-computation%23new-answer', 'question_page');

                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                                Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                                Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?