symbolic Pauli matrix expansions



On  Nov. 26, Ted Woollett wrote:
-------------------------------
So it looks like, again, the tellsimpafter method is
having a problem.

Is there a defrule approach to this final processing?
----------------------------------
Here is a defrule path which works so far and produces
the output:

(%i1) load(pauli1);
(%o1) "c:/work5/pauli1.mac"
(%i2) pauli_simp (comm (sig[1]^^3, sig[2]^^5));
(%o2) 2*%i*sig[3]
(%i3) pauli_simp (comm (sig[2]^^3, sig[1]^^5));
(%o3) -2*%i*sig[3]
(%i4) pauli_simp (comm (sig[2]^^3, sig[3]^^5));
(%o4) 2*%i*sig[1]
(%i5) pauli_simp (comm (sig[3]^^3, sig[2]^^5));
(%o5) -2*%i*sig[1]
(%i6) pauli_simp (comm (sig[3]^^3, sig[1]^^5));
(%o6) 2*%i*sig[2]
(%i7) pauli_simp (comm (sig[1]^^3, sig[3]^^5));
(%o7) -2*%i*sig[2]

------------------
with the code file pauli1.mac (which loads
in your (patched) commutators.mac ):
------------------
/* file pauli1.mac
   symbolic expansion of products of
   pauli matrices */


 load (commutators);

 remove (comm, antisymmetric);

/* declare ([s1, s2, s3, s4], scalar); */

 /* note: nonscalarp (sig[1]) ---> true  */

  declare (eps3,antisymmetric)$

  tellsimpafter (eps3[1,2,3], 1)$

  matchdeclare ([ii,jj,kk],integerp )$

 defrule (rc1, comm (sig[ii], sig[jj]), sum (2*%i*eps3 
[ii,jj,kk]*sig[kk],kk,1,3))$

 defrule (rp1, sig[ii] . sig[jj], sum ( %i*eps3 
[ii,jj,kk]*sig[kk],kk,1,3) )$

 odd1p(x) := (oddp (x) and x > 1)$

 nctimes2p(x) := (nctimesp(x) and length (x) > 2)$

 matchdeclare (aa,nctimes2p)$

 defrule (rn3, aa, rest (aa,-2) . apply1 (rest (aa,length(aa)-2),rp1 ))$

 matchdeclare (aa, nonscalarp,nn,evenp)$

 defrule (rn1, aa^^nn, 1)$

 matchdeclare (aa, nonscalarp, nn, odd1p)$

 defrule (rn2, aa^^nn, aa)$


 matchdeclare (aa,nonscalarp)$

 defrule (rn4,aa, apply1 (aa, rn1, rn2, rn3, rp1))$

 pauli_simp (x) := (comm_simp (x), apply1(%%,rc1), apply1 (%%,rn4))$
-----------------------------------------

Thanks for your defrule examples,

Ted Woollett