MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: DiscreteUniformDistribution PDF isn't piecewise?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107657] Re: DiscreteUniformDistribution PDF isn't piecewise?
  • From: gekko <pfalloon at gmail.com>
  • Date: Mon, 22 Feb 2010 03:08:11 -0500 (EST)
  • References: <hlqu3v$go8$1@smc.vnet.net>

On Feb 21, 8:24 pm, "richard.wesley.todd"
<richard.wesley.t... at gmail.com> wrote:
> A PDF for a discrete uniform distribution, say for a die roll...
>
> In[101]:= PDF[DiscreteUniformDistribution[{1, 6}]]
>
> Out[101]= 1/6 &
>
> ... gives 1/6 for all inputs, _not_ just between 1 and 6.   Shouldn't
> it be defined piecewise?  This is from Mathematica 7.0.1.0 on
> Windows.   The CDF is correct.

This may have been considered a design decision: i.e. for symbolic
input (or equivalently, the "pure function" form that you show), the
function could have been designed to return the result that would be
expected for all meaningful inputs -- in this case, integers in the
range 1 to 6.

A slightly tenuous analogy would be the way other functions return
generic results which fail to give the correct result for certain
specific argument values. e.g. FunctionExpand:

In[33]:= f[z_] = SphericalBesselJ[1,z] // FunctionExpand
Out[33]= -(Cos[z]/z)+Sin[z]/z^2
In[34]:= f[0]
During evaluation of In[34]:= Power::infy: Infinite expression 1/0
encountered. >>
During evaluation of In[34]:= Power::infy: Infinite expression 1/0^2
encountered. >>
During evaluation of In[34]:= \[Infinity]::indet: Indeterminate
expression 0 ComplexInfinity encountered. >>
Out[34]= Indeterminate
In[35]:= SphericalBesselJ[1,0]
Out[35]= 0

However, even supposing this were a deliberate decision, it appears to
be somewhat inconsistent with the equivalent definition for CDF, which
uses Piecewise.

So, I would be inclined to agree with you that there is an issue there
to be resolved. Have you fwded this on to WRI?

It's also interesting to note that, when given numeric arguments, the
PDF function only returns non-zero values if the input is an Integer,
thus:

dist = DiscreteUniformDistribution[{1,6}];
In[40]:= PDF[dist, #] & /@ Range[-10,10]
Out[40]= {0,0,0,0,0,0,0,0,0,0,0,1/6,1/6,1/6,1/6,1/6,1/6,0,0,0,0}
In[41]:= PDF[dist, #] & /@ N[Range[-10,10]]
Out[41]= {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

This looks like another potential gotcha, but in this case my feeling
is that it is the "right" behaviour. It would be nice to see this
added to the list of "Possible Issues" in the documentation.

Cheers, P.


  • Prev by Date: Re: Handheld mathematica
  • Next by Date: Re: Loops in Manipulate
  • Previous by thread: Re: DiscreteUniformDistribution PDF isn't piecewise?
  • Next by thread: Re: DiscreteUniformDistribution PDF isn't piecewise?