Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



Re: Implicit Times
Posted:
Nov 14, 2012 1:50 AM


On 11/11/2012 20:56, Dave Snead wrote: > Thanks, but the issue is not defining the operator. > The issue is Mathematica's implicit assumption of a Times (*) when there's a > space between variables. > The NonCommutativeMultiply (**) already exists. > > So when I input > x y//FullForm > I want Mathematica to return > NonCommutativeMultiply[x,y] > instead of > Times[x,y] > > Of course I want the explicit Times (*) to > still work the same as before, > x*y//FullForm > yielding > Times[x,y] > > Dave Snead >
I think you can probably get what you want, if you start with an expression in the form of a string:
In[4]:= str = " (b a) c*d"
Out[4]= " (b a) c*d"
In[8]:= str1 = StringReplace[str, "*" > "\[SmallCircle]"]
Out[8]= " (b a) c\[SmallCircle]d"
In[12]:= expr = ToExpression[str1, StandardForm, Hold] /. Times > CircleTimes /. SmallCircle > Times // ReleaseHold
Out[12]= (b\[CircleTimes]a)\[CircleTimes](c d)
In[14]:= % // FullForm
CircleTimes[CircleTimes[b, a], Times[c, d]]
The above uses the standard Mathematica parser using a couple of tricks, but more generally, if you start with a string, you can parse it as you see fit with a little effort.
David Bailey http://www.dbaileyconsultancy.co.uk



