====== Expand ======
----
====Description====
* ''Expand'' expands out products and positive integer powers.
* ''Expand[transformations]'' expands out products and positive integer powers and applies ''transformations'' at each level of expand procedure.
====Examples====
----
Expand a polynomial expressions:
println Expand >> '(x_n + y_n)*(f_m - r_m)'.t
> x_{n}*f_{m}+f_{m}*y_{n}-r_{m}*y_{n}-x_{n}*r_{m}
println Expand >> '(1 + x)**4'.t
> x**4+1+4*x**3+6*x**2+4*x
----
println Expand >> '(x + y)/z'.t
> x/z+y/z
----
''Expand'' relabels dummies when necessary:
println Expand >> '(A_m^m + 1)**3'.t
> 3*A_{m}^{m}*A_{a}^{a}+A_{m}^{m}*A_{a}^{a}*A_{b}^{b}+1+3*A_{b}^{b}
----
''Expand'' does not go inside functions and denominators; ''ExpandAll'' does:
println Expand >> 'f[(x + y)**2]'.t
> f[(x + y)**2]
println ExpandAll >> 'f[(x + y)**2]'.t
> f[x**2 + 2*x*y + y**2]
----
====Details====
''Expand[transformations]'' will additionally apply ''transformations'' during expand procedure:
println Expand['k_a*k^a = 0'.t] >> '(k_a + t_a)*(k^a + t^a)'.t
> 2*k_a*t^a + t_a*t^a
Passing additional ''transformations'' can significantly improve the performance when expanding huge expressions. For example, when a huge expression involves many metric tensors, one can pass ''EliminateMetrics'' in order to reduce the number of processed terms. Consider a random example:
//create random generator, which generates
// random tensors consisting of metric and A_m
RandomTensor randomTensor = new RandomTensor();
randomTensor.clearNamespace()
randomTensor.addToNamespace('g_mn'.t, 'A_m'.t)
//loop to warm up JVM
for (def i in 1..1000) {
def a, b
//next random tensor
def t = randomTensor.nextTensorTree(4, 3, 8, '_a'.si)
def simplify = EliminateMetrics & 'A_a*A^a = 1'.t & 'd^i_i = 10'.t
//this will typically 10 times faster
timing {
a = Expand[simplify] >> t
}
//then this
timing {
b = (Expand & simplify) >> t
}
assert a == b
println ''
}
The sample output will looks like:
Time: 10 ms.
Time: 1015 ms.
Time: 7 ms.
Time: 6566 ms.
Time: 66 ms.
Time: 983 ms.
...
====See also====
* Related guides: [[documentation:guide:applying_and_manipulating_transformations]], [[documentation:guide:list_of_transformations]]
* Related transformations: [[documentation:ref:expandtensors]], [[documentation:ref:expandall]], [[documentation:ref:expandnumerator]], [[documentation:ref:expanddenominator]]
* JavaDocs: [[http://api.redberry.cc/redberry/1.1.9/java-api/cc/redberry/core/transformations/expand/ExpandTransformation.html|ExpandTransformation]]
* Source code: [[https://bitbucket.org/redberry/redberry/src/tip/core/src/main/java/cc/redberry/core/transformations/expand/ExpandTransformation.java|ExpandTransformation.java]]