1

I'm new to Mathematica, and I'm trying to learn the ropes. I'm trying to write a little boson algebra engine, with basic useful functions such as non-commutative algebra, normal-ordering and vacuum expectation values.

So, for starters I define the following OpProd[] function,

OpProd[a_ + b_, c_] := OpProd[a, c] + OpProd[b, c];
OpProd[a_, b_ + c_] := OpProd[a, b] + OpProd[a, c];
OpProd[c_, a_] := c a /; NumericQ[c] == True;
OpProd[left__, a_, b_] = OpProd[left, OpProd[a, b]];

which simply defines the basic properties of the algebra, and seems to work fine.

My problem is that I'd like to have an alias for OpProd[], so that whenever I write a^ b^ c^, or any string like that, Mathematica would use OpProd[] to implement the product.

(*Shorthand notation for operator products*)
Unprotect[Times];

\!\(\*OverscriptBox[\(a__\), \(^\)]\) 
\!\(\*OverscriptBox[\(b__\), \(^\)]\) := OpProd[a, b];
Protect[Times];

This unfortunately does not seem to work, outputting just

In[10]:= 
\!\(\*OverscriptBox[\(a\), \(^\)]\) 
\!\(\*OverscriptBox[\(b\), \(^\)]\) 
\!\(\*OverscriptBox[\(c\), \(^\)]\) 
\!\(\*OverscriptBox[\(d\), \(^\)]\) 
\!\(\*OverscriptBox[\(e\), \(^\)]\) // Simplify

Out[10]= OpProd[a, b] OpProd[c, d] 
\!\(\*OverscriptBox[\(e\), \(^\)]\)

Any help would be appreciated!

lbello
  • 11
  • 2

0 Answers0