Difference between revisions of "Implicit index"

m
Line 1: Line 1:
 
[[Category: Arrays]]
 
[[Category: Arrays]]
  
An [[Implicit index]] (also known as a ''null-index'') is an [[index]] that does not have a name, e.g. a list (a 1-dimensional array) with its single dimension not explicitly named.
+
An [[Implicit index]] (also known as a ''null-index'') is an [[index]] that does not have a name, e.g. a list (a 1-dimensional array). It arises in rare cases in a Definition that contains a subexpression that generates a list of values.  Normally, when you define an Index variable as a list of values, it becomes an explicit index, for example:
  
Because an implicit index has no name, it is not possible to refer to it in [[expressions]] where index [[parameters]] are expected.  
+
:<code>Index Years := 2016 .. 2020</code>
  
Most built-in Analytica [[functions]] can still be employed to operate over implicit indexes, e.g. the [[Subset]] function with the optional «position» parameter:
+
Or if you define a variable as an expression containing subexpression that generates a list, e.g.
  
:<code>Subset(1997..2008 > 2005, position: true) &rarr; [10, 11, 12] </code> -- returns positions of elements
+
:<code>Variable Year_number := (1 .. 5) + 2015</code>
 +
:<code>Year_number -> [2016, 2017, 2018, 2019, 2020]</code>
 +
 
 +
The variable becomes  a [[Self index]], i.e. it acts as an Index with values 
 +
 
 +
<code>Year_number -> [2016, 2017, 2018, 2019, 2020]</code>
 +
 
 +
<code>Year_number -> [2016, 2017, 2018, 2019, 2020]</code>
 +
 
 +
Because an implicit index has no name, you can't refer to it in [[expressions]] where index [[parameters]] are expected.
 +
 
 +
Most built-in Analytica [[functions]] work fine over implicit indexes, e.g. the [[Subset]] function:
 +
 
 +
:<code>Subset(1997..2008 > 2005) &rarr; <code>[2006, 2007, 2008]</code> </code>
  
 
vs
 
vs
  
 
:<code>Index Years := 1997..2008</code>
 
:<code>Index Years := 1997..2008</code>
:<code>Subset(Years > 2005) &rarr; [2006, 2007, 2008] </code> -- returns index values
+
:<code>Subset(Years > 2005) &rarr; [2006, 2007, 2008] </code>
  
To avoid ambiguity, Analytica does not allow more than one implicit index in an [[array]]. If you try to combine multiple arrays with implicit indexes, it will cause an [[Error Messages/40045|error]].
+
To avoid ambiguity, Analytica does not allow more than one implicit index in an [[array]]. It gives an error if you try to combine multiple arrays with implicit indexes.
  
 
When an implicit index reaches the top level of an expression, it is promoted to a [[Self index]].
 
When an implicit index reaches the top level of an expression, it is promoted to a [[Self index]].

Revision as of 17:09, 26 August 2016


An Implicit index (also known as a null-index) is an index that does not have a name, e.g. a list (a 1-dimensional array). It arises in rare cases in a Definition that contains a subexpression that generates a list of values. Normally, when you define an Index variable as a list of values, it becomes an explicit index, for example:

Index Years := 2016 .. 2020

Or if you define a variable as an expression containing subexpression that generates a list, e.g.

Variable Year_number := (1 .. 5) + 2015
Year_number -> [2016, 2017, 2018, 2019, 2020]

The variable becomes a Self index, i.e. it acts as an Index with values

Year_number -> [2016, 2017, 2018, 2019, 2020]

Year_number -> [2016, 2017, 2018, 2019, 2020]

Because an implicit index has no name, you can't refer to it in expressions where index parameters are expected.

Most built-in Analytica functions work fine over implicit indexes, e.g. the Subset function:

Subset(1997..2008 > 2005) → [2006, 2007, 2008]

vs

Index Years := 1997..2008
Subset(Years > 2005) → [2006, 2007, 2008]

To avoid ambiguity, Analytica does not allow more than one implicit index in an array. It gives an error if you try to combine multiple arrays with implicit indexes.

When an implicit index reaches the top level of an expression, it is promoted to a Self index.

Implicit indexes define implicit dimensions, e.g. (-3..3) or [-3, -2, -1, 0, 1, 2, 3]. Indexes that do have a name, are called explicit indexes and define explicit dimensions, e.g. Index I := 1..10.

See Also

Comments


You are not allowed to post comments.