MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Problem with Mathematica 6


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


  • Prev by Date: RE: simple question
  • Next by Date: Re: MakeExpression problem
  • Previous by thread: Re: Problem with Mathematica 6
  • Next by thread: Re: Problem with Mathematica 6