Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am looking for a way to simplify dot products etc.

Here is a minimal example: Lets say I have two vectors a and b:

Array[a,2]
Array[b,2]

Now I evaluate their dot product:

c = a.b

which should give me something like this

a[1]b[1] + a[2]b[2]

What I need is a way to transform this expression back into a dot product. So I am looking for a function that realises that I can write this as a.b (similiar to "Factor" for polynomial expressions), e.g.

Function[c]

should give

a.b

In a more general context, I would like to display scalars as vector/matrix/tensor expressions, meaning mathematica should also realize that

m[1,1] + m[2,2]

is simply

Tr[m]

and display it as such.

Is that possible?

Thank you!

share|improve this question
    
Do you realize that there is no unique inverse for a dot product? There are infinitely many dot products that give the same result. See, for instance, this one: {a1, a2}.{b1 + c/a1, b2 - c/a2} // Simplify. The second vector is a different one for every value of c. Yet the dot product is the same every time. –  Sjoerd C. de Vries Sep 18 '13 at 21:58
    
I realise that. But isn't it possible to define a function that would output a[1]b[1] + a[2]b[2] as a.b if a and b were already defined to be a={a[1],a[2]}, b={b[1],b[2]} because in most cases, that is exactly the "inverse" I am looking for. It would remove a lot of clutter in my equations, since I have vectors with >100 entries... –  user9599 Sep 18 '13 at 22:25
1  
Dear physicslol, welcome to Mathematica.SE! Please don't post comments as answers, as it works against the Q&A and model of the site and can be unhelpful for future visitors. I've turned your answer into a proper comment. –  Verbeia Sep 18 '13 at 22:56
add comment

1 Answer

It's very simple in principle, provided that you're sure you have an expression that is in fact going to simplify into a dot product:

Clear[a,b];
Simplify[
   (a[1] b[1] + a[2] b[2]) /. {a[1] b[1] -> 
    Dot[a, b] - a[2] b[2]}]

a.b

Likewise for the trace:

Simplify[(a[1, 1] + a[2, 2]) /. {a[1, 1] -> Tr[a] - a[2, 2]}]

Tr[a]

So you just pick one of the terms in the sum defining your compact expression, and replace that term with the compact expression minus the missing terms. Then Simplify will afterwards take care of the rest by canceling the individual terms. It' is however important that the compact expression doesn't contain symbols that expand to something longer again under Simplify. So here a and b themselves shouldn't have values assigned to them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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