This shows you the differences between two versions of the page.
documentation:ref:transformation [2015/09/22 19:15] poslavskysv [Basics] |
documentation:ref:transformation [2015/11/21 12:33] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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: | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> '(a+b)*(c+d)'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > a*c + a*d + b*c + b*d | ||
- | </sxh> | ||
- | ---- | ||
- | Expression ''lhs = rhs'' is both [[Tensor]] and ''Transformation'': | ||
- | <sxh groovy; gutter: false> | ||
- | println 'f_a[x_a] = x_a'.t >> 'g^b[z_a] = f^b[z^i]'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > g^b[z_a] = z^b | ||
- | </sxh> | ||
- | ---- | ||
- | Combine transformations using ''&'': | ||
- | <sxh groovy; gutter: false> | ||
- | def tr = Expand & EliminateMetrics | ||
- | println tr >> '(g_ab*g_cd + g_ac*g_bd)*g^bc'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > 2*g_{da} | ||
- | </sxh> | ||
- | ---- | ||
- | One can define a custom transformation using [[documentation:guide:programming_with_redberry#functions|closures]]: | ||
- | <sxh groovy; gutter: false> | ||
- | def customTr = { expr -> 2*expr } as Transformation | ||
- | println customTr >> 'z + t'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > 2*(z + t) | ||
- | </sxh> | ||
- | Define transformation that inverts indices: | ||
- | <sxh groovy; gutter: false> | ||
- | def tr = { expr -> | ||
- | //invert indices | ||
- | (expr.indices % expr.indices.inverted) >> expr | ||
- | } as Transformation | ||
- | println tr >> 'f_ab^cd'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > f^ab_cd | ||
- | </sxh> | ||
- | |||
- | ====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.8/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]] |