tools for long lists or sums



while working on ch. 8, in a section on
fast fourier transforms, I frequently generate
long lists.  Mathematica has some tools to
see a "short view" of a list, but I haven't
seen an obvious one in the core Maxima set.

Some users may find the tools short(..)
and browse(..) useful. They have the
behavior:

(%i1) display2d:false$
(%i2) load(qfft);
 type qfft_syntax(); to see qfft,qift,dft,dift syntax 
------------------------------------------
   type chop_syntax(); to see fchop and fchop1 use 
(%o2) "c:/work3/qfft.mac"
(%i3) mylist : makelist( a[j] , j, 1, 20 )$

(%i4) mysum : sum( b[j], j, 1, 20 )$

(%i5) short( mylist );
 there are  20  elements  
  [ a[1] , a[2] <<, 16 elements,>> a[19] , a[20] ] 
(%o5) done

(%i6) short( mysum );
 there are  20  terms  
   b[20] + b[19] <<+ 16 terms +>> b[2] + b[1] 
(%o6) done

(%i7) browse( mylist );
 there are  20  elements or terms   
(%o7) [ a[9], a[10], a[11], a[12] ]

(%i8) browse( mylist, 1, 3);
 there are  20  elements or terms   
(%o8) [ a[1], a[2], a[3] ]

(%i9) browse(mysum);
 there are  20  elements or terms   
(%o9) b[12] + b[11] + b[10] + b[9]

(%i10) browse( mysum, 18, 20 );
 there are  20  elements or terms   
(%o10) b[3] + b[2] + b[1]
----------------------------------
code used follows:
----------------------------------
/* _lshort% shows beginning and end of a list  */

_lshort%(alist) :=
  block( [nl ],
   nl : length( alist),
   if nl > 4 then
     print("  [", alist[1], ",", alist[2], "<<,", 
        nl-4, "elements,>>", alist[ nl - 1], ",", alist[ nl ], "]" )
   else print( alist ),
   return("  ") )$
   
/* use _sshort% if expr is not a list  */   
   
_sshort%( mysum ) := 
   block( [ ns ],
     ns : length( mysum ),
     if ns > 4 then (
      print("  ", rest(mysum,-(ns-2)), "<<+", 
          ns-4, "terms +>>", rest( mysum, ns-2 ) ) )
    else print( mysum ),
    return(" ") )$
              
/* short calls _lshort% if arg is list
     otherwise calls _sshort%   */

short(expr) :=
  block( [],
    if listp(expr) then _lshort%(expr)
    else _sshort%(expr) )$
    
/* use browse for either a list or a sum of
   expressions  */
    
browse( [v] ) :=
  block( [alist, nl, nl2, n1, n2 ],
    alist : v[1],
    nl : length( alist ),
    print(" there are ", nl, " elements or terms"),
    print(" "),
    if length(v) = 1 and nl <= 5 then return(alist),
    if length(v) = 1 and nl > 5 then (
         if evenp(nl) then nl2 : nl/2 else nl2 : (nl - 1)/2,
             rest( rest(alist, nl2 - 2), -nl + nl2 + 2 ) )       
     else (
       n1 : v[2],
       if n1 >= nl then n1 : nl - 3,
       n2 : v[3],
       if n2 > nl then n2 : nl,
       rest ( rest( alist, n1-1), -nl + n2 ) ) )$  

----------------------------------------------------
Ted Woollett