Implicit Dimensions
Each dimension of an Analytica array is defined by an index. Each dimension of an array is identified by a different index, and when expressions operate over an array, the index can be specified to indicate which dimension is being operated over. We say these indexes are explicit, since these indexes each have a name, giving us a way to identify the dimension of interest in an expression.
In addition to explicit indexes, Analytica arrays may also contain one implicit dimension. An implicit dimension does not correspond to an index, and therefore cannot be identified by name. For this reason, Analytica does not allow more than one implicit index in an array, since this would create an ambiguity.
Implicit dimensions are sometimes also refered to as null-indexes, null-dimensions, or list-dimensions.
Although you cannot identify an implicit dimension by name, in many Analytica functions can be applied across the implicit dimension using variations that omit the index parameter. For example, consider the expression
Max([x,y,z])
The intermediate expression, [x,y,z], evaluates to an array. The brackets introduce an implicit dimension, and if x, y, or z are themselves arrays, the result of [x,y,z] may have multiple dimensions. Because the second index parameter to Max is not specified, the maximum is computed across the implicit dimension.
Multiple Implicit Dimensions Not Allowed
As already mentioned, an Analytica array can have at most one implicit dimension. If you attempt to combine two implicit dimensions, an error will result. For example, when this expression is evaluated
(1..10) * (1..10)
the following error appears:
- Trying to combine two arrays with implicit indexes. An array can contain only one implicit index. One cure might be to define at least one of these as an explicit index.
As the message implies, we can get around this limitation by using Local Indexes as follows:
Index I := 1..10; Index J := 1..10; I * J
Note that Local Indexes are explicit indexes -- they have a name.
Promotion to Self-Index
If an implicit dimension still exists in the result after the full definition of a variable has been evaluated, the implicit dimension gets promoted to be a self index of the result variable. So once the value is stored, the result will no longer have an implicit dimension, since a self index is explicit. From other variables, the dimension can then be refered to by name.
Suppose Variable Scenario is defined as:
"Case " & (1..10)
When this expression is evaluated, a list (considered equivalent to a 1-D array with an implicit index) having elements:
["Case 1","Case 2",....,"Case 10"]
is computed. When this is stored as the value of Scenario, the implicit dimension becomes the index value for Scenario.
When an implicit index gets promoted to a self-index, the index element values may not be available at the time of promotion. This happens with the following example:
Index I := -3..3; I * (-3..3)
The result of this expression is a 2-D array, with the dimension introduced by (-3..3) being implicit. When this 2-D value is stored, the implicit dimension becomes the self-index for the variable, but the index values for that dimension are all blank, with the result appearing as
Notice the blank column labels for the self-index A. Because an implicit dimension is not associated with any Analytica object, the Analytica engine does not keep any index element values around for those values while evaluating is taking place, so that at the time of promotion, these aren't available. Thus, you cannot meaningful use Subscript on this self-index A -- access to specific rows would require the use of Slice. The dimension does, nevertheless, fully array abstract like any other explicit index. If you need the index element values, then use an explicit index.
There are two cases in which Analytica can recover element values when promoting an implicit index to a self-index. First, if the result is one-dimensional, with the implicit index being the only dimension, then those values become the self-index element values. For example:
(2..5)^2
will evaluate to [4,9,16,25], and those squares will become the index values. Because it is 1-D, Analytica assumes the actual array values are the index values. The second case is when an explicit list, with the bracket notation, appears in a definition. For example:
Index I := -3..3; I * [-3,-2,-1,0,1,2,3]
When brackets are used, Analytica uses the original values or expressions appearing inside the brackets as the index values. In this example, the result looks like
Here notice that the original values appear in the column headers.
When Analytica takes index values from explicit list notation (with brackets), it uses the original values or expressions appearing in the brackets as the index element values. Thus, notice the difference between the following two definitions:
(2..5)^2
[2,3,4,5]^2
In the second case, the result array values are different from the self-index values, while in the first case they are the same.
There are several "gotchas" when using bracketed lists. If you include identifiers as elements in the list, the self-index value will contain Handles to objects. These can be referenced in subscript operations, e.g., as A[A=Handle(X)]. If your bracketed list contains expressions, the element values will be parsed expressions, which is a data structure not readily processed from within Analytica expressions. You may find yourself having to use Slice rather than Subscript when expressions (non-literals) are present. However, these expressions may simplify your life when viewing graphs of results, etc. Again, whenever you need more control over the precise labels that appear, use a local index rather than an implicit index.
Enable comment auto-refresher