Re: Re: Problem with Mathematica 6
- To: mathgroup at smc.vnet.net
- Subject: [mg77124] Re: [mg77087] Re: [mg77065] Problem with Mathematica 6
- From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
- Date: Mon, 4 Jun 2007 03:52:17 -0400 (EDT)
- References: <200706020819.EAA29947@smc.vnet.net> <200706031009.GAA02755@smc.vnet.net>
On 3 Jun 2007, at 19:09, Carl Woll wrote:
> The problem is that NonCommutativeMultiply is Flat and OneIdentity,
> so I
> think
>
> NonCommutativeMultiply[a,b]
>
> is being interpreted as
> NonCommutativeMultiply[NonCommutativeMultiply[a],b] which gets
> converted
> to NonCommutativeMultiply[Times[a],b] and then
> NonCommutativeMultiply[a,b] and so you get an iteration error. To
> avoid
> this Flat issue, use HoldPattern:
>
> Unprotect[NonCommutativeMultiply];
> HoldPattern[NonCommutativeMultiply][a___] /; (Length[GetGradeds[a]] <=
> 1) := Times[a];
> Protect[NonCommutativeMultiply];
>
> Now, it works:
>
> In[347]:= a ** b
> Out[347]= a**b
>
> Carl Woll
> Wolfram Research
>
I don't think it is quite as simple as that.
In[1]:= ClearAttributes[NonCommutativeMultiply, OneIdentity]
In[2]:= Attributes[NonCommutativeMultiply]
Out[2]= {Flat, Protected}
In[3]:= Grading[_] = 0;
Fermion[a__] := ((Grading[#1] = 1) &) /@ {a};
Fermion[a, b];
GetGradeds[a___] := GetGradeds[a] = Select[{a}, Grading[#1] != 0 &];
In[7]:= Unprotect[NonCommutativeMultiply];
NonCommutativeMultiply[a___] /; (Length[GetGradeds[a]] <= 1) := Times
[a];
Protect[NonCommutativeMultiply];
In[10]:= a ** b
and you get exactly the same problem. Also, see my post in this
thread that shows that clearly there has been a change in the way
pattern works. Namely, running
a ** b /. NonCommutativeMultiply[x___] /; (Print[{x}];
Length[{x}] <= 1) :> f[x]
gives different output in Mathematica 5.2 and 6.0. To me it seems
clear that the behaviour in 6 is an imporovement, but the OneIdentity
attribute alone does not seem to be responsible for it.
Andrzej Kozlowski
- References:
- Problem with Mathematica 6
- From: "Michael Weyrauch" <michael.weyrauch@gmx.de>
- Re: Problem with Mathematica 6
- From: Carl Woll <carlw@wolfram.com>
- Problem with Mathematica 6