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


and have Mathematica output something like


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[3] + 7 v[4], 14 v[1]] 

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


What about

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}]
  • $\begingroup$ +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. $\endgroup$ – joshphysics Oct 31 '13 at 7:58
  • $\begingroup$ @joshphysics, see if the edit helps $\endgroup$ – Rojo Oct 31 '13 at 13:10
  • 2
    $\begingroup$ It should be noted that Star is a built in symbol without any definition attached. Conveniently, it has a binary operator form, \[Star]. $\endgroup$ – rcollyer Oct 31 '13 at 13:29
  • $\begingroup$ @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? $\endgroup$ – joshphysics Nov 1 '13 at 22:15
  • $\begingroup$ @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 $\endgroup$ – Rojo Nov 1 '13 at 22:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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