Sponsored links: Algebra eBooks
 

Related

sublist_indices

Run Example
(%i1)a:[1,2,3,4,3,2,4,2,1];
(%o1)                     [1, 2, 3, 4, 3, 2, 4, 2, 1]
(%i2) sublist_indices(a,lambda([x],x>
=2));
(%o2)                        [2, 3, 4, 5, 6, 7, 8]
(%i3) 
Run Example
a: [1,2,3,4,5,6];
(%o1)                         [1, 2, 3, 4, 5, 6]
(%i2) b: [6,5,4,3,2,1];
(%o2)                         [6, 5, 4, 3, 2, 1]
(%i3) id: sublist_indices(a,evenp);
(%o3)                              [2, 4, 6]
(%i4) 
Run Example
? sublist_indices;

 -- Function: sublist_indices (<L>, <P>)
     Returns the indices of the elements `x' of the list <L> for which
     the predicate `maybe(<P>(x))' returns `true'; this excludes
     `unknown' as well as `false'.  <P> may be the name of a function
     or a lambda expression.  <L> must be a literal list.

     Examples:

          (%i1) sublist_indices ('[a, b, b, c, 1, 2, b, 3, b],
                                 lambda ([x], x='b));
          (%o1)                     [2, 3, 7, 9]
          (%i2) sublist_indices ('[a, b, b, c, 1, 2, b, 3, b], symbolp);
          (%o2)                  [1, 2, 3, 4, 7, 9]
          (%i3) sublist_indices ([1 > 0, 1 < 0, 2 < 1, 2 > 1, 2 > 0],
                                 identity);
          (%o3)                       [1, 4, 5]
          (%i4) assume (x < -1);
          (%o4)                       [x < - 1]
          (%i5) map (maybe, [x > 0, x < 0, x < -2]);
          (%o5)                [false, true, unknown]
          (%i6) sublist_indices ([x > 0, x < 0, x < -2], identity);
          (%o6)                          [2]


(%o1)                                true
(%i2) 

Related Help

Help for Sublist_indices