Transformation


Basics

  • Transformation represents a transformation of expression; it is a super type for all transformations (e.g. Expand or EliminateMetrics).
  • Transformation can be applied to expression using >> operator.
  • Transformations can be combined using & operator; e.g. Expand & EliminateMetrics will first expand out products of sums and then eliminate metric tensors.
  • Applying Transformation using >> operator is equivalent to direct invocation of method .transform(exp).
  • The Identity transformation does nothing (expr == Identity >> expr)

Examples

Expand is a Transformation that expands out product of sums:

println Expand >> '(a+b)*(c+d)'.t
   > a*c + a*d + b*c + b*d


Expression lhs = rhs is both Tensor and Transformation:

println 'f_a[x_a] = x_a'.t >> 'g^b[z_a] = f^b[z^i]'.t
   > g^b[z_a] = z^b


Combine transformations using &:

def tr = Expand & EliminateMetrics
println tr >> '(g_ab*g_cd + g_ac*g_bd)*g^bc'.t
   > 2*g_{da}


One can define a custom transformation using closures:

def customTr = { expr -> 2*expr } as Transformation
println customTr >> 'z + t'.t
   > 2*(z + t)
Define transformation that inverts indices:
def tr = { expr ->
    //invert indices
    (expr.indices % expr.indices.inverted) >> expr
} as Transformation
println tr >> 'f_ab^cd'.t
   > f^ab_cd

See also