Differences

This shows you the differences between two versions of the page.

Link to this comparison view

documentation:ref:product [2015/11/21 12:33]
documentation:ref:product [2015/11/21 12:33] (current)
Line 1: Line 1:
 +====== Product ======
 +----
 +
 +=====Basics=====
 +''​Product''​ represents a product of terms. Like any other expression, it inherits all properties of [[Tensor]]. ''​Product''​ adopts the following convention on its indices: the indices of product are sorted concatenated indices of its multipliers:​
 +<sxh groovy; gutter: false>
 +def t = '​f_ba*t^c_c*h^a'​.t
 +println t.indice
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{ac}_{abc}
 +</​sxh>​
 +
 +''​Product''​ sorts its arguments and collapses equal scalar terms into powers. ​
 +
 +
 +''​Product''​ is one of the most sophisticated entities in Redberry: contractions of indices brings additional structure of mathematical //graph// which is reflected in ''​Product''​ by introducing several methods to access graph structure of product.
 +
 +The data structure used to represent product contains three main blocks: numerical factor, subproduct of scalar factors (with ''​indices.size() == 0''​),​ and tensorial content (with ''​indices.size() != 0''​). Each block can be obtained via special additional methods introduced in product.
 +=====Additional features=====
 +There are several features in addition to those defined in [[Tensor]] that are inherent only in [[Product]]:​
 +
 +<​html>​
 +<table style="​width:​600px;"​ cellpadding="​10">​
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.select(positions)</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a product of elements at specified positions</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.remove(positions)</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a product with removed elements at specified positions</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.factor</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a numerical factor of product</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.indexlessSubProduct</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a subproduct of indexless terms, i.e. product of those terms which <​code>​indices.size() == 0</​code></​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.dataSubProduct</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a subproduct of indexed terms, i.e. product of those terms which <​code>​indices.size() != 0</​code></​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;"><​code>​.content</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px;​margin-top:​ 35px;​border:​ 1px solid gray;">​returns a data structure that allows to access <​i>​graph structure</​i>​ of product</​td> ​
 +</tr>
 +</​table>​
 +</​html>​
 +
 +Consider examples:
 +<sxh groovy; gutter: true>
 +def p = '​2*a*b*f_ba*t^c_c*h^a'​.t
 +println p.select(2, 3, 5)
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > a*t^{c}_{c}*h^{a}
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 3>
 +println p.remove(2, 3, 5)
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > 2*b*f_{ba}
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 4>
 +println p.factor
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > 2
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 5>
 +println p.indexlessSubProduct
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > 2*b*a
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 6>
 +println p.dataSubProduct
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > t^{c}_{c}*f_{ba}*h^{a}
 +</​sxh>​
 +=====Advanced features: product content and graph structure =====
 +The presence of indices bring a //graph structure// of Product: each multiplier represents a graph vertex, while contractions between indices are edges. One can check whether two graph isomorphic, i.e. that two tensors are equal to within free and dummy indices relabelling using [[documentation:​guide:​mappings_of_indices]].
 +
 +There is a special property ''​.content'',​ which allows to access graph structure of ''​Product'';​ the object returned by ''​.content''​ called ''​ProductContent''​. It holds tensorial part of product and additional low-level data structures used in Redberry to represent tensorial graphs. Besides, ''​ProductContent''​ provides several useful methods like ''​.scalars''​ and ''​.nonScalar''​ which return array of scalar sub-products and non-scalar part of tensor respectively. Consider examples:
 +<sxh groovy; gutter: true>
 +def p = '​2*a*f_a*t^ba*g_b*t^i_i*t^mn*f_nmk'​.t
 +println p.size()
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > 8
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 3>
 +def content = p.content
 +println content.size()
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > 6
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 5>
 +println content[0..content.size()]
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > [f_a, t^ba, g_b, t^i_i, t^mn, f_nmk]
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 6>
 +println content.scalars
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > [t^{i}_{i}, t^{ba}*g_{b}*f_{a}]
 +</​sxh>​
 +<sxh groovy; gutter: true;​first-line:​ 7>
 +println content.nonScalar
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > t^{mn}*f_{nmk}
 +</​sxh>​
 +
 +In order to access low-level structure that encodes ''​Product''​ graph there is ''​.structureOfContractions''​ property in ''​ProductContent''​. This structure allows to check connected components of graph and check for each particular tensor ​ with which tensors it is contracted. ​ Without going into low-level details, let's illustrate this features by the examples:
 +<sxh groovy; gutter: true>
 +def p = '​3*c*f_i*g_b*t^i_i*t^pq*f_qpk*t^bie'​.t
 +def content = p.content
 +//get graph representation
 +def graph = content.structureOfContractions
 +//array of connected components
 +println graph.components
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > [0, 1, 0, 1, 2, 0]
 +</​sxh>​
 +The array of //​components//​ indicates whether two tensors belongs to the same  connected component of graph: two tensors at //i//-th and //j//-th positions belongs to the same component if 
 +''​components[i] == components[j]'',​ and ''​components[i]''​ is the number of corresponding component.
 +<sxh groovy; gutter: true;​first-line:​ 7>
 +//get position of tensor t^bie
 +def i = content.findIndexOf { it.equals('​t^bie'​.t) }
 +//​contractions of tensor t^bie
 +def contractions = graph.getContractedWith(i)
 +for (def c in contractions) {
 +    if (c.tensor == -1)//free index
 +        println "Free indices:"​ + content[i].indices[c.indicesFrom]
 +    else {
 +        println "With tensor: " + content[c.tensor]
 +        println "This indices:"​ + content[i].indices[c.indicesFrom]
 +        println "With indices:"​ + content[c.tensor].indices[c.indicesTo]
 +    }
 +}
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > Free indices:​^{e}
 +   > With tensor: g_{b}
 +   > This indices:​^{b}
 +   > With indices:​_{b}
 +   > With tensor: f_{i}
 +   > This indices:​^{i}
 +   > With indices:​_{i}
 +</​sxh>​
 +=====See also=====
 +  * Related guides: [[documentation:​guide:​tensors_and_indices]],​ [[documentation:​guide:​tree_traversal]],​ [[documentation:​guide:​mappings_of_indices]]
 +  * Reference: [[documentation:​ref:​tensor]],​ [[documentation:​ref:​sum]],​ [[documentation:​ref:​indices]],​ [[documentation:​ref:​simpletensor]],​ [[documentation:​ref:​tensorfield]]
 +  * JavaDocs: [[http://​api.redberry.cc/​redberry/​1.1.9/​java-api/​cc/​redberry/​core/​tensor/​Product.html| Product]]
 +  * Source code: [[https://​bitbucket.org/​redberry/​redberry/​src/​tip/​core/​src/​main/​java/​cc/​redberry/​core/​tensor/​Product.java|Product.java]]