# Symbolic linear algebra

I would like to know how I can ask Mathematica to expand (and simplify) such an expression :

$$(\alpha A + \beta B)^\top (\alpha A + \beta B)$$

where $\alpha,\beta$ are two real numbers and $A,B$ are vectors in $\mathbb{R}^{n}$. $A^\top$ denotes the transpose of $A$. I assume I must tell Mathematica that $A$ and $B$ are vectors. Here is what I have tried :

$Assumptions = (A | B) [Element] Vectors[n];$Assumptions = (a | b) [Element] Reals;
TensorExpand[ Transpose[a*A + b*B].(a*A + b*B) ]


and the output is :

a A.Transpose[a A + b B, {2, 1}] + b B.Transpose[a A + b B, {2, 1}]


Which is not what I expected since I would like the output to be :

$$\alpha^{2} A^\top A + 2 \alpha \beta A^\top B + \beta^{2} B^\top B$$

• You can do no harm by trying. Oct 28, 2013 at 20:06
• I would if I had Mathematica on the computer I'm currently using but I don't. I can't try it right now but I will later. Oct 28, 2013 at 20:13
• This is closely related: How can I get Mathematica to recognize equality of symbolic matrix expressions?. In fact, following the answer you should resolve your prolem, i.e. use TensorReduce instead of FullSimplify. Oct 28, 2013 at 20:24
• I have tried : $Assumptions = (A | B) [Element] Matrices[{n, 1}]; TensorExpand[ Transpose[A + B].(A + B) ] But the output I get is not Transpose[A].A + 2Transpose[A].B + Transpose[B].B What did I do wrong ? Oct 28, 2013 at 21:06 • You can use Vectors[n]. In your original question you have ( a*A + b*B)]*( a*A + b*B), instead of * use . i.e. Dot or you can use TensorProduct. Oct 28, 2013 at 21:45 ## 1 Answer Since you're working with vectors, just let Mathematica know that these are vectors. Some other systems (MATLAB and its relatives in particular) have the limitation that they can only work with matrices, forcing you to distinguish between row vector and column vectors and keep transposing. This is not necessary nor convenient in Mathematica. In:=$Assumptions = a ∈ Vectors[n, Reals] && b ∈ Vectors[n, Reals]
Out= a ∈ Vectors[n, Reals] && b ∈ Vectors[n, Reals]

In:= (α a + β b).(α a + β b) // TensorExpand
Out= α^2 a.a + 2 α β a.b + β^2 b.b

• Thank you for your answer! It seems to work just fine in your example. However, would it still work if I had Transpose[] to your example ? Oct 31, 2013 at 17:19
• @jibounet Well, does it make any sense to transpose a vector? Oct 31, 2013 at 17:20
• I think it does. A real vector $X$ belongs to $\mathrm{Mat}_{n,1}(\mathbb{R})$. We can define its transpose to be the matrix of the linear form $L_{X} \, : \, Y \in \mathbb{R}^{n} \, \longmapsto \, \left\langle X,Y \right\rangle$, which is an element of $\mathrm{Mat}_{1,n}(\mathbb{R})$. Oct 31, 2013 at 17:30
• @jibounet For Mathematica a "vector" is a 1-dimensional tensor. What people call a "row vector" is a really a matrix, i.e. a 2-dimensional tensor. It's more difficult to reason about those and figure out such things that $AB^T=BA^T$ only if both A and B are 1 by $n$ matrices, but not otherwise. In Mathematica it does not make sense to transpose a vector because it's a one-dimensional structure. Oct 31, 2013 at 17:31
• Alright. I understand. Oct 31, 2013 at 17:38