manpagez: man pages & more
info ginac
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.14.5 Simplifying indexed expressions

In addition to the few automatic simplifications that GiNaC performs on indexed expressions (such as re-ordering the indices of symmetric tensors and calculating traces and convolutions of matrices and predefined tensors) there is the method

 
ex ex::simplify_indexed();
ex ex::simplify_indexed(const scalar_products & sp);

that performs some more expensive operations:

The last point is done with the help of the scalar_products class which is used to store scalar products with known values (this is not an arithmetic class, you just pass it to simplify_indexed()):

 
{
    symbol A("A"), B("B"), C("C"), i_sym("i");
    idx i(i_sym, 3);

    scalar_products sp;
    sp.add(A, B, 0); // A and B are orthogonal
    sp.add(A, C, 0); // A and C are orthogonal
    sp.add(A, A, 4); // A^2 = 4 (A has length 2)

    e = indexed(A + B, i) * indexed(A + C, i);
    cout << e << endl;
     // -> (B+A).i*(A+C).i

    cout << e.expand(expand_options::expand_indexed).simplify_indexed(sp)
         << endl;
     // -> 4+C.i*B.i
}

The scalar_products object sp acts as a storage for the scalar products added to it with the .add() method. This method takes three arguments: the two expressions of which the scalar product is taken, and the expression to replace it with.

The example above also illustrates a feature of the expand() method: if passed the expand_indexed option it will distribute indices over sums, so ‘(A+B).i’ becomes ‘A.i+B.i’.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]
© manpagez.com 2000-2024
Individual documents may contain additional copyright information.