next up previous
Next: A term Up: Elementary objects Previous: A Kronecker symbol

A second quantized operator

Toggle Background


A second quantized operator consists of an orbital and a "gender" (creator or annihilator):

Interface: SQOperator.H SQOperator.H

 1 #include <string>
 2 #include <iostream>
 3 
 4 using namespace std;
 5 
 6 
 7 /*!
 8     Implements a second quantized creation \[ \hat a_i^\dagger \]
 9     or annihilation \[ \hat a_i \] operator
10 */
11 class SQOperator {
12 public:
13     //! enumerate operator types
14 enum Gender { Creator, Annihilator };
15 
16     //! short cut constructor from character (upper case: creator, lower case annihilator)
17     SQOperator(char c);
18     
19     //! construct from gender and character (capital does not matter)
20     SQOperator(Gender gender, char orb);
21 
22 
23     //! return gender
24     Gender gender() const;
25     
26     //! return orbital
27     char orb() const;
28 
29 
30     //! check equality
31     bool operator == (SQOperator const & o) const;
32     //! "artificial" ordering relation (for sorting purposes)
33     bool operator < (SQOperator const & o) const;
34 
35 private:
36 Gender  _gender;
37 char    _orb;
38 };
39 
40 ostream & operator << (ostream & o, SQOperator const & op);
Implementation: SQOperator.C SQOperator.C
 1 #include "SQOperator.H"
 2 
 3 
 4 
 5 SQOperator::SQOperator(char c) :
 6     _gender(isupper(c) ? Creator : Annihilator), _orb(tolower(c)) {}
 7 
 8 SQOperator::SQOperator(Gender gender, char orb) :
 9     _gender(gender), _orb(orb) {}
10 
11 SQOperator::Gender SQOperator::gender() const
12 {   return _gender; }
13 
14 char SQOperator::orb() const
15 {   return _orb;    }
16 
17 
18 bool SQOperator::operator == (SQOperator const & o) const
19 {   return _gender==o._gender && _orb==o._orb;  }
20 
21 bool SQOperator::operator < (SQOperator const & o) const
22 {
23     if ( _gender<o._gender )
24         return true;
25     if ( o._gender<_gender )
26         return false;
27     return _orb<o._orb;
28 }
29 
30 
31 ostream & operator << (ostream & o, SQOperator const & op)
32 {
33     if ( op.gender()==SQOperator::Creator )
34         o << static_cast<char>(toupper(op.orb()));
35     else
36         o << static_cast<char>(tolower(op.orb()));
37     return o;
38 }

Let's test it: SQOperator_Test.C SQOperator_Test.C

 1 #include "SQOperator.H"
 2 
 3 int main()
 4 {
 5 SQOperator  op(SQOperator::Creator, 'i');   // test construtor
 6 
 7     cout << op << endl;
 8 
 9 
10 SQOperator  op1('u');   // annihilator orbital "u"
11 SQOperator  op2('A');   // creator orbital "A"
12 
13     cout << op1 << op2 << endl;
14     return 0;
15 }
The output is (download files into a fresh directory, compile and link with g++ *.C, run a.out)
I
uA
Okay. Still trivial. Be patient...



Michael Hanrath 2006-05-02