Sometimes it can be very useful to know the indices of entries (of an Array) which obey some conditions. The following procedure (which works for any Array) makes this possible:
`index/makeIndex` := proc(indices::list,array::Array,value::list)
	# Retrieving from the Array
	if nargs = 2 then return array[op(indices)]: end if:
	# Storing in the Array
	if nargs = 3 then array[op(indices)] := indices = op(value): end if:
end proc:
An example: For Array A find the set S of indices of entries being positive integers, using as an intermediate step the Array B with entries of the form "indices = value":
isPosInt := x -> if type(rhs(x),posint) then lhs(x) end if:
A := Array([[-1,2,-3],[4,-5,6]]);
B := Array(makeIndex,A);
S := convert(map(isPosInt,B),set);

Please Wait...