# Implementing Bilinear Products

Consider a real, vector space $V$ with basis $B=\{v_1,v_2,\dots\}$, and let $\star:V\times V\to\mathbb R$ be a bilinear product on $V$.

I would like to implement this product in Mathematica by specifying the action of $\star$ on pairs of basis elements, and by somehow "telling" Mathematica that the product is bilinear. More concretely, I will be specifying elements $v,w$ of $V$ as linear combinations of elements of $B$ \begin{align} v = \sum_i a_iv_i, \qquad w = \sum_i b_iv_i, \end{align} and I would like to tell Mathematica how to deal with products of any two basis elements; \begin{align} v_i\star v_j = \sum_k c_{ijk}v_k \end{align} by telling it how to generate the constants $c_{ijk}$, and then telling it that $\star$ is bilinear so that it can perform the following manipulation: \begin{align} v\star w &= \left(\sum_ia_iv_i\right)\star\left(\sum_j b_jv_j\right) = \sum_{i,j}a_ib_j (v_i\star v_j) = \sum_{ij}a_ib_j\sum_k c_{ijk}v_k\\ &= \sum_{i,j,k}a_ib_jc_{ijk}v_k \end{align} Ideally, I would like to be able to write something like this

Star[5v+7v,14v]


and have Mathematica output something like

2v+5v+7v+11v


depending, of course, on the constants $c_{ijk}$ specified beforehand.

I don't really have a sharp idea of how to approach this, any guidance would be greatly appreciated.

Something along these lines perhaps?

coefs[pol_, base_] := Last@CoefficientArrays[pol, base]

Star[lhs_, rhs_] :=
coefs[lhs, starBase].Transpose /@ starTen.coefs[rhs, starBase].starBase


So you could define

starBase = v~Array~4;
starTen = Array[c, {4, 4, 4}];


and now

Star[5 v + 7 v, 14 v]

(* 14 (5 c[3, 1, 1] + 7 c[4, 1, 1]) v +
14 (5 c[3, 1, 2] + 7 c[4, 1, 2]) v +
14 (5 c[3, 1, 3] + 7 c[4, 1, 3]) v +
14 (5 c[3, 1, 4] + 7 c[4, 1, 4]) v *)


EDIT

ClearAll[Star];
Star[k_?constantQ x_?vectorQ, y_] := k Star[x, y];
Star[x_, k_?constantQ y_?vectorQ] := k Star[x, y];
Star[x1_ + x2_, y_] := Star[x1, y] + Star[x2, y];
Star[x_, y1_ + y2_] := Star[x, y1] + Star[x, y2];

vectorQ = MatchQ[#, Alternatives @@ vectors] &;
constantQ = ! vectorQ@# &;

vectors = {_v};
Star[v[i_], v[j_]] := Sum[c[i, j, \[FormalK]] v[\[FormalK]], {\[FormalK], 0, Infinity}]

• +1: I think this might work. I need work a bit to adapt this precisely to the setting I'm working in (there is, for example, the complication that I'm working with an infinite-dimensional vector space). Thanks for the suggestions. – joshphysics Oct 31 '13 at 7:58
• @joshphysics, see if the edit helps – Rojo Oct 31 '13 at 13:10
• It should be noted that Star is a built in symbol without any definition attached. Conveniently, it has a binary operator form, \[Star]. – rcollyer Oct 31 '13 at 13:29
• @Rojo Thanks for the ideas in the Edit. I'm a relative noob so I'm gonna need to sit with the code and the documentation center for a bit to understand it, but in the time being, did you mean for there to be a v[\[FormalK]] in the last sum? – joshphysics Nov 1 '13 at 22:15
• @joshphysics yes. Formal variables are just variables that you can't assign a value to by default. It is not necesary here but I found it appropriate anyway. Look it up in the site for more info – Rojo Nov 1 '13 at 22:49