Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Problem with Mathematica 6

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77087] Re: [mg77065] Problem with Mathematica 6
  • From: Carl Woll <carlw at wolfram.com>
  • Date: Sun, 3 Jun 2007 06:09:04 -0400 (EDT)
  • References: <200706020819.EAA29947@smc.vnet.net>

Michael Weyrauch wrote:

>Hello,
>
>  the following code fragment runs under Mathematica 5.2 but
>produces an infinite recursion error in Mathematica 6.0 in certain cases:
>
>First I define a number of commands and slightly change the
>built-in command "NonCommutativeMultiply":
>Grading[_] = 0;
>Fermion[a__] := ((Grading[#1] = 1) & ) /@ {a};
>Fermion[a, b];
>GetGradeds[a___] := GetGradeds[a] = Select[{a}, Grading[#1] != 0 & ];
>
>Unprotect[NonCommutativeMultiply];
>NonCommutativeMultiply[a___] /; (Length[GetGradeds[a]] <= 1) := Times[a];
>Protect[NonCommutativeMultiply];
>
>If you now e.g. evaluate
>
>In[22]:= k ** l
>Out[22]= k*l
>
>or
>
>In[23]:= a ** l
>Out[23]= a*l
>
>BUT in Mathematica 6.0:
>
>In[24]:= a ** b
>
>$IterationLimit::"itlim" : "Iteration limit of 4096 exceeded. \
>\!\(\*ButtonBox["\[RightSkeleton]",
>BaseStyle->"Link",
>ButtonData:>"paclet:ref/message/$IterationLimit/itlim",
>ButtonFrame->None,
>ButtonNote->"$IterationLimit::itlim"]\)"
>Out[24]= Hold[(Times[a]) ** b]
>
>However in Mathematica 5.2 one gets
>
>In[10]:= a ** b
>Out[10]=a**b
>
>which is what I expect and I want to have.
>
>I.e., whenever I NonCommutativeMultiply two variables which are explicitly declared as fermions by the command Fermion[], I get an 
>infinite recursion error in Mathematica 6.
>
>This behaviour of Mathematica 6.0 is rather confusing to me, since I believe that I just use very basic and elementary assignments 
>in my code. Why shouldn't it work  under Mathematica 6.0 if it works under 5.2? It appears that the 6.0 kernel behaves differently than the 
>5.2 kernel in such basic situations. Very unpleasant!
>
>(For anyone who wonders about the purpose of  this (strange) code: It is a small fragment of a package  that implements the handling 
>of Grassmann variables. I just extracted that bit in order to show the Mathematica 6.0 problem.)
>
>Furthermore, beyond an explanation of this unexpected behaviour of Mathematica 6, I would like to find a workaround in Mathematica 6 such that I get 
>the same result as in Mathematica 5.2.
>
>Thanks for any suggestions.
>
>Michael Weyrauch
>
>
>  
>
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


  • Prev by Date: Re: Using Part
  • Next by Date: Re: Using Part
  • Previous by thread: Problem with Mathematica 6
  • Next by thread: Re: Re: Problem with Mathematica 6