Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12339

Re: Implicit Times

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Implicit Times
Date 2012-11-14 06:50 +0000
Message-ID <k7vf0j$s5d$1@smc.vnet.net> (permalink)
References <20121109000050.A731368E1@smc.vnet.net> <20121110070632.836E26951@smc.vnet.net> <k7p3di$c9h$1@smc.vnet.net>
Organization Time-Warner Telecom

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Implicit Times "Dave Snead" <dsnead6@charter.net> - 2012-11-11 20:56 +0000
  Re: Implicit Times David Bailey <dave@removedbailey.co.uk> - 2012-11-14 06:50 +0000

csiph-web