pdf_continuous_uniform



On 9/1/08, Alexey Beshenov <al at beshenov.ru> wrote:

>  It seems that the following line at the pdf_continuous_uniform definition
>  (/contrib/distrib/distrib.mac):
>
>   if member(sign(x-a), ['nz,'neg,'zero]) or member(sign(x-b), ['pos,'pz,'zero])
>
>  should be replaced by
>
>   if member(sign(x-a), ['nz,'neg,'zero]) or member(sign(b-x), ['pos,'pz,'zero])

I'm pretty sure that that function and others in the distrib package
can be substantially simplified. The problem is that the result should
be different according to values of parameters such as a and b,
which is handled OK by the existing code, but it can be written
in a clearer way. For example:

pdf_continuous_uniform(x,a,b):=if maybe(b < a) = true then
error("Illegal argument")
                        elseif maybe(a < b) = true
                        then (if maybe(a < x and x < b) = true then 1/(b-a)
                                  elseif maybe(x <= a or b <= x) = true then 0
                                  else funmake('pdf_continuous_uniform,[x,a,b]))
                        else funmake('pdf_continuous_uniform,[x,a,b])$

If I'm not mistaken, the definition above has the same behavior as the
existing one.
I claim that calling "maybe" is clearer than the existing constructs:

pdf_continuous_uniform(x,a,b):=block([cp:control1(b-a)],if cp = -1
then error("Illegal parameter"),
                       if cp = 0 or sign(x-a) = 'pnz or sign(x-b) = 'pnz
                           then
return(funmake('pdf_continuous_uniform,[x,a,b])),
                       if member(sign(x-a),['nz,'neg,'zero]) or
member(sign(x-b),['pos,'pz,'zero])
                           then 0
                           else (if sign(x-a) = 'pos and sign(x-b) =
'pos then 1/(b-a)
                                     else
funmake('pdf_continuous_uniform,[x,a,b])))$

control1(a):=if member(sign(a),['nz,'neg,'zero]) then -1 else (if
sign(a) = 'pos then 1 else 0)$

I've left aside the question of whether a noun or verb expression should
be returned, and also whether a conditional expression should be returned.
(As it is written above, pdf_continuous_uniform never returns a conditional
expression.)

Since the existing code works OK, it's not a pressing issue, but I think
statistical computation is an important application for Maxima, so I'd like
to revise the distrib code at some point.

best

Robert Dodier