====== 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.
* A list of common useful transformations can be found at [[documentation:guide:list_of_transformations]] page.
* 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 [[documentation:guide:programming_with_redberry#functions|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====
* Related guides: [[documentation:guide:applying_and_manipulating_transformations]], [[documentation:guide:list_of_transformations]]
* Related reference material: [[documentation:ref:tensor]]
* JavaDocs: [[http://api.redberry.cc/redberry/1.1.9/java-api/cc/redberry/core/transformations/Transformation.html|Transformation]]
* Source code: [[https://bitbucket.org/redberry/redberry/src/tip/core/src/main/java/cc/redberry/core/transformations/Transformation.java|Transformation.java]]