[ < ] | [ > ] | [ << ] | [ 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:
- it checks the consistency of free indices in sums in the same way
get_free_indices()
does - it tries to give dummy indices that appear in different terms of a sum the same name to allow simplifications like a_i*b_i-a_j*b_j=0
- it (symbolically) calculates all possible dummy index summations/contractions with the predefined tensors (this will be explained in more detail in the next section)
- it detects contractions that vanish for symmetry reasons, for example the contraction of a symmetric and a totally antisymmetric tensor
- as a special case of dummy index summation, it can replace scalar products of two tensors with a user-defined value
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] | [ ? ] |