The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Implicit Times
Replies: 4   Last Post: Nov 14, 2012 1:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
David Bailey

Posts: 714
Registered: 11/7/08
Re: Implicit Times
Posted: Nov 14, 2012 1:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.