select all x in L



Hi,

> currently we (me and my students) are studying a book on elementary probability theory
> (with use CAS DERIVE as assistent) and are porting some of the code to (wx)Maxima 5.12.
> Some of the basic concepts we will define ab ovo, before we will switch to Mario
> Riotorto's massive application package 'descriptive.mac' in order to draw histograms etc.
> 

I plan to rewrite histograms and boxplots as parts of the draw package. 


> One early problem is to define the 'frequency of a in list v_'.
> The Derive code is:
>                      H(a, v_) := DIM(SELECT(x = a, x, v_))
> 
> I defined the helper function 
> (%i1)  select(a,L) := block([LL:[]], for x in L do if x=a then LL:cons(x,LL),LL)$
> (%i2)  select(2,[3,2,4,2]);
> (%i3)  H(a,L):= length(select(a,L));
> (%i4)  H(2,[3,2,4,2,5]);
> (%o4)  2
> which seems ok.
> 
> Q1: is there a predefined function 'select' (with another name?) in Maxima
>     I have overlooked?
> Q2: I would like to have a 'more functional and general' version of select.
>     Does a member of the Maxima community has some hints?

I don't know if function 'discrete_freq' fits your needs:

(%i10) load (descriptive)$
(%i11) discrete_freq([3,2,4,2,5]);
(%o11)                   [[2, 3, 4, 5], [2, 1, 1, 1]]

the first list are the values of the sample and the second their
corresponding frequencies. If you prefere the result in pairs:

(%i12) transpose(apply(matrix,%));
                                   [ 2  2 ]
                                   [      ]
                                   [ 3  1 ]
(%o12)                             [      ]
                                   [ 4  1 ]
                                   [      ]
                                   [ 5  1 ]
(%i13) args(%);
(%o13)                 [[2, 2], [3, 1], [4, 1], [5, 1]]




-- 
Mario Rodriguez Riotorto
www.biomates.net