This shows you the differences between two versions of the page.
documentation:ref:expand [2015/11/21 11:03] poslavskysv [See also] |
documentation:ref:expand [2015/11/21 12:33] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== 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: | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> '(x_n + y_n)*(f_m - r_m)'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > x_{n}*f_{m}+f_{m}*y_{n}-r_{m}*y_{n}-x_{n}*r_{m} | ||
- | </sxh> | ||
- | |||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> '(1 + x)**4'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > x**4+1+4*x**3+6*x**2+4*x | ||
- | </sxh> | ||
- | |||
- | ---- | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> '(x + y)/z'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > x/z+y/z | ||
- | </sxh> | ||
- | |||
- | ---- | ||
- | ''Expand'' relabels dummies when necessary: | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> '(A_m^m + 1)**3'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > 3*A_{m}^{m}*A_{a}^{a}+A_{m}^{m}*A_{a}^{a}*A_{b}^{b}+1+3*A_{b}^{b} | ||
- | </sxh> | ||
- | |||
- | |||
- | ---- | ||
- | |||
- | |||
- | ''Expand'' does not go inside functions and denominators; ''ExpandAll'' does: | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand >> 'f[(x + y)**2]'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > f[(x + y)**2] | ||
- | </sxh> | ||
- | <sxh groovy; gutter: false> | ||
- | println ExpandAll >> 'f[(x + y)**2]'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > f[x**2 + 2*x*y + y**2] | ||
- | </sxh> | ||
- | |||
- | ---- | ||
- | ====Details==== | ||
- | ''Expand[transformations]'' will additionally apply ''transformations'' during expand procedure: | ||
- | <sxh groovy; gutter: false> | ||
- | println Expand['k_a*k^a = 0'.t] >> '(k_a + t_a)*(k^a + t^a)'.t | ||
- | </sxh> | ||
- | <sxh plain; gutter: false> | ||
- | > 2*k_a*t^a + t_a*t^a | ||
- | </sxh> | ||
- | |||
- | 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: | ||
- | <sxh groovy; gutter: true> | ||
- | //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 '' | ||
- | } | ||
- | </sxh> | ||
- | The sample output will looks like: | ||
- | <sxh plain; gutter: false> | ||
- | Time: 10 ms. | ||
- | Time: 1015 ms. | ||
- | |||
- | Time: 7 ms. | ||
- | Time: 6566 ms. | ||
- | |||
- | Time: 66 ms. | ||
- | Time: 983 ms. | ||
- | ... | ||
- | </sxh> | ||
- | |||
- | ====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.8/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]] |