focus expression text field at startup -> version 1.2
[LeanCalc.git] / help / indices
1 NAME
2     indices - indices for specified matrix or association element
3
4 SYNOPSIS
5     indices(V, index)
6
7 TYPES
8     V           matrix or association
9     index       integer
10
11     return      list with up to 4 elements
12
13 DESCRIPTION
14     For 0 <= index < size(V), indices(V, index) returns list(i_0, i_1, ...)
15     for which V[i_0, i_1, ...] is the same lvalue as V[[index]].
16
17     For other values of index, a null value is returned.
18
19     This function can be useful for determining those elements for which
20     the indices satisfy some condition.  This is particularly so for
21     associations since these have no simple relation between the
22     double-bracket index and the single-bracket indices, which may be
23     non-integer numbers or strings or other types of value.  The
24     information provided by indices() is often required after the use
25     of search() or rsearch() which, when successful, return the
26     double-bracket index of the item found.
27
28 EXAMPLE
29         > mat M[2,3,1:5]
30
31         > indices(M, 11)
32         list (3 elements, 2 nonzero):
33                 [[0]] = 0
34                 [[1]] = 2
35                 [[2]] = 2
36
37         > A = assoc();
38
39         > A["cat", "dog"] = "fight";
40         > A[2,3,5,7] = "primes";
41         > A["square", 3] = 9
42
43         > indices(A, search(A, "primes"))
44         list (4 elements, 4 nonzero):
45                 [[0]] = 2
46                 [[1]] = 3
47                 [[2]] = 5
48                 [[3]] = 7
49
50 LIMITS
51     abs(index) < 2^31
52
53 LINK LIBRARY
54     LIST* associndices(ASSOC *ap, long index)
55     LIST* matindices(MATRIX *mp, long index)
56
57 SEE ALSO
58     assoc, mat
59