MathGroup Archive 2007

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

Search the Archive

Pattern Matching Mathematica 6 versus 5.2?

  • To: mathgroup at
  • Subject: [mg77424] Pattern Matching Mathematica 6 versus 5.2?
  • From: "Michael Weyrauch" <michael.weyrauch at>
  • Date: Fri, 8 Jun 2007 05:34:18 -0400 (EDT)


  I encounter the following different behaviour of the Mathematica pattern matcher
version 6 versus 5.2.

I give to both versions the following rules (which should implement a simple
Grassmann algebra):

Grading[_Symbol] = 0;
Grading[_Integer] = 0;
Grading[_Rational] = 0;
Grading[_Complex] = 0;
Grading[_Real] = 0;
Fermion[a_, b___] := ((Grading[a] = 1); Fermion[b]);

NonCommutativeMultiply[x_, y_ /; EvenQ[Grading[y]]] := x y;
NonCommutativeMultiply[y_ /; EvenQ[Grading[y]], x_] := x y;
NonCommutativeMultiply[x_, x1_ y_ /; EvenQ[Grading[y]]] := y (x ** x1);
NonCommutativeMultiply[x_ y_ /; EvenQ[Grading[y]], x1_] := y (x ** x1);
NonCommutativeMultiply[x_, x_] /; OddQ[Grading[x]] := 0;
NonCommutativeMultiply[y_ /; OddQ[Grading[y]], x_ /; OddQ[Grading[x]]] /; (! OrderedQ[{y, x}]) := -x ** y;

Now in version 6 I get e.g.

In[11]:= Fermion[f1, f2, f3, f4]
Out[11]= Fermion[]

In[13]:= f1 ** f2 ** f1 ** f4
Out[13]= 0

which is as expected, since there a two equal factors.

BUT in version 5.2

In[3]:=Fermion[f1, f2, f3, f4]


which is NOT as it should be.  Mathematica 5.2 fails to simplify this automatically to zero.

I implemented the above rules on the advice of David Bailey, who tried to convince me that the Mathematica pattern matcher makes 
full use of the attributes Flat and OneIdentity, which are given to NonCommuativeMultiply. This means that it should be only 
necessary to deal explicitly with the 2-argument case (as I do above).

>From the results given above , I am not so sure that this holds in version 5.2? Do I misunderstand something? Or is my code buggy? 
Can it be changed that in 5.2 it runs as in 6.0?

Thanks for hints,   Michael

  • Prev by Date: Re: Re: v6: still no multiple undo?
  • Next by Date: Re: Developing Applications using Mathematica
  • Previous by thread: Re: Can anybody help me solving such a system of nonlinear equations?
  • Next by thread: Re: Pattern Matching Mathematica 6 versus 5.2?