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.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]
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. ...