[GiNaC-list] question about quantum operator algebra

Chris Dams Chris.Dams at mi.infn.it
Wed May 9 16:07:52 CEST 2007


Dear Can-Hua, 

> >    {  ... constructing the result of rewriting is done here ...
> 
> Sorry, but I have no idea what goes here. Could you show me somewhere
> to find examples? Thank you.

Your function could look like the following

ex rewrite_operators(const ex &x)
{  if (is_a<ncmul>(x))
   {  if (x.has(one))
      {  exvector v;
         v.reserve(x.nops());
         for (int i=0; i<x.nops(); ++i)
            if (x.op(i) != one)
               v.push_back(x.op(i));
         if (v.empty())
            v.push_back(one);
         return rewrite_operators(ncmul(v));
      }
      for (int i=0; i<x.nops()-1; ++i)
         if (x.op(i) == adag && x.op(i+1) == a)
         {  exvector v;
            v.reserve(x.nops());
            for (int j=0; j<i; ++j)
               v.push_back(x.op(j));
            v.push_back(one+a*adag);
            for (int j=i+2; j<x.nops(); ++j)
               v.push_back(x.op(j));
            return rewrite_operators(expand(ncmul(v)));
         }
      return x;
   }
   else
     return expand(x.map(rewrite_operators));
}

Note that it is necesary to also declare an element "one" for your algebra
because one cannot add numbers and noncommutative objects.

Best wishes,
Chris



More information about the GiNaC-list mailing list