Differences

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

Link to this comparison view

documentation:ref:indices [2015/11/21 12:33]
documentation:ref:indices [2015/11/21 12:33] (current)
Line 1: Line 1:
 +====== Indices ======
 +----
 +
 +====Basics====
 +''​Indices''​ represents indices of tensor. ''​Indices''​ is a simple container of single indices. For all types of tensors except [[SimpleTensor]] and [[TensorField]],​ ''​Indices''​ are always sorted in some predefined way (e.g. first upper then lower, first Latin then Greek, in each group indices sorted in lexicographical order  etc.):
 +<sxh groovy; gutter: false>
 +def indices = '​^AB_pqrs^C_A^sp'​.i
 +println indices
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{psABC}_{pqrsA}
 +</​sxh>​
 +
 +The indices of [[SimpleTensor]] and [[TensorField]] are [[SimpleIndices]] --- a subtype of ''​Indices''​ that are not sorted.
 +
 +At the low-level, Redberry stores each single index as 32-bit integer that encodes all information about index: state, type and name (serial number in the alphabet). Within a particular index type, there are $2^{16}$ possible names, which can be inputted using the subscript:
 +<sxh groovy; gutter: false>
 +def indices = '​X_{\\mu_3 a_{122} a_1 b_9}'​.i
 +println indices
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > _{a_{1}b_{9}a_{122}\mu_{3}}
 +</​sxh>​
 +====Features====
 +Here is a list of common ''​Indices''​ properties and methods:
 +<​html>​
 +<​center>​
 +<table style="​width:​500px;"​ cellpadding="​10">​
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.free</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​free indices</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.inverted</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​inverted indices</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.upper</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​contravariant indices</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.lower</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​covariant indices</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.getOfType(type)</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​sub-indices of specified <​i>​type</​i></​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​.size()</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​number of indices</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​[i]</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​i>​i</​i>​-th index</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​[i..j]</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;">​indices from <​i>​i</​i>​-th (inclusive) to <​i>​j</​i>​-th (exclusive)</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​[i,​ j, k]</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​i>​i,​ j, k</​i>​-th indices etc.</​td> ​
 +</tr>
 +<tr>
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​code>​[type,​ i]</​code></​td>​
 +  <td valign="​top"​ style="​padding:​ 15px; border: 1px solid gray;"><​i>​i</​i>​-th index of type <​i>​type</​i></​td> ​
 +</tr>
 +</​table>​
 +</​center>​
 +</​html>​
 +
 +Consider examples. Parse indices from string:
 +<sxh groovy; gutter: true>
 +def indices = '​^an_ab^m_pq^b'​.i
 +println indices
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{abmn}_{abpq}
 +</​sxh>​
 +Get just free indices:
 +<sxh groovy; gutter: true; first-line: 3>
 +println indices.free
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{mn}_{pq}
 +</​sxh>​
 +Invert indices:
 +<sxh groovy; gutter: true; first-line: 4>
 +println indices.inverted
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{abpq}_{abmn}
 +</​sxh>​
 +Get only contra variant indices:
 +<sxh groovy; gutter: true; first-line: 5>
 +println indices.upper
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{abmn}
 +</​sxh>​
 +Get only covariant indices:
 +<sxh groovy; gutter: true; first-line: 6>
 +println indices.lower
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > _{abpq}
 +</​sxh>​
 +
 +Parse indices with multiple types:
 +<sxh groovy; gutter: true>
 +def indices = '​^AB_pqrs^C_A^sp'​.i
 +println indices
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{psABC}_{pqrsA}
 +</​sxh>​
 +Get just Latin upper case:
 +<sxh groovy; gutter: true; first-line: 3>
 +println indices.getOfType(LatinUpper)
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{ABC}_{A}
 +</​sxh>​
 +Get first index:
 +<sxh groovy; gutter: true; first-line: 4>
 +println indices[0].toStringIndex()
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{p}
 +</​sxh>​
 +Get first Latin upper index:
 +<sxh groovy; gutter: true; first-line: 5>
 +println indices[LatinUpper,​ 0].toStringIndex()
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{A}
 +</​sxh>​
 +Get several indices at a time:
 +<sxh groovy; gutter: true; first-line: 6>
 +println indices[1, 3, 4]
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{sBC}
 +</​sxh>​
 +Get range:
 +<sxh groovy; gutter: true; first-line: 7>
 +println indices[1..4]
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{sABC}
 +</​sxh>​
 +
 +As one can see, all methods in the above examples return also sorted indices.
 +====Creating indices====
 +Get indices of tensor:
 +<sxh groovy; gutter: false>
 +println '​t_ba*f^dc'​.t.indices
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^cd_ab
 +</​sxh>​
 +Parse indices from string using ''​.i''​ property:
 +<sxh groovy; gutter: false>
 +println '​_ba^dc'​.i
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^cd_ab
 +</​sxh>​
 +Convert array of single indices into ''​Indices'':​
 +<sxh groovy; gutter: false>
 +println( [0, 1, 2, 3.invert()] as Indices )
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^d_abc
 +</​sxh>​
 +Concatenate several ''​Indices''​ objects:
 +<sxh groovy; gutter: false>
 +println ( '​_abc'​.i + '​^cad'​.i )
 +</​sxh>​
 +<sxh plain; gutter: false>
 +   > ^{acd}_{abc}
 +</​sxh>​
 +
 +====See also====
 +  * Related guides: [[documentation:​guide:​tensors_and_indices]]
 +  * Reference material: [[documentation:​ref:​simpleindices]],​ [[documentation:​ref:​tensor]],​ [[documentation:​ref:​indextype]]
 +  * JavaDocs: [[http://​api.redberry.cc/​redberry/​1.1.9/​java-api/​cc/​redberry/​core/​indices/​Indices.html| Indices]]
 +  * Source code: [[https://​bitbucket.org/​redberry/​redberry/​src/​tip/​core/​src/​main/​java/​cc/​redberry/​core/​indices/​Indices.java|Indices.java]]