We shall start once again with the end... We want our library to provide some objects that may be used according to the following code fragment
1 int main() 2 { 3 Product<SQOperator> p; // declare a product of second quantized operators 4 5 // set up a product of second quantized operators 6 p *= SQOperator('i'); // lower case letter shall be an annihilator 7 p *= SQOperator('j'); 8 p *= SQOperator('A'); // upper case letter shall be an creator 9 p *= SQOperator('B'); 10 11 Term term(p); // make up a term of it 12 13 cout << term << endl; // print the term 14 cout << term.normalOrder() << endl; // print the term in normal order 15 cout << term.normalOrder_fullyContractedOnly() << endl; // as before but fully contracted terms only 16 }yielding the following output:
i*j*A*B A*B*i*j + d(ai)*B*j - d(ai)*d(bj) - d(aj)*B*i + d(aj)*d(bi) - d(bi)*A*j + d(bj)*A*i -d(ai)*d(bj) + d(aj)*d(bi)
Of course one may make things more comfortable in the code fragment (e. g. define
member function * and + operators) but we shall keep things simple.
How to make the above example work?
The crucial step in any object oriented program is the object design. You should spend some time on this and try to deeply understand your problem.
However, in this case we are dealing with theoretical physics
and the mathematicians have already solved the problem of object design for us.
This is nothing special to this example. The underlying mathematical structure is
usually an excellent starting point for object oriented design and you should use it.
What are the mathematical objects present in our above example?
Take your time and think about it...