# Constant Distribution

As far as I know, Mathematica lacks a definition for a probability distribution representing a constant random variable.

Is this assertion correct?

Is there a problem in making such a distribution well-defined in Mathematica (assuming we treat it as a continuous rather than a discrete distribution)?

In principle, we could add definitions for this distribution, e.g.

CDF[ConstantDistribution[μ_]] ^:= UnitStep[# - μ] &


How would I find what definitions are needed to make it a "first class" member of the set of distributions supported by Mathematica? So that, for example, it could be used in functions such as TransformedDistribution?

In general, there are ways to work around the lack of such a distribution, but just as it is sometimes useful to have a function such as Identity (e.g. to pass to a function that transforms an input) it can be useful to have the "trivial" distribution.

• Is this too limited: constantD = UniformDistribution[{4.3, 4.3}]; RandomVariate[constantD, 10] ? This results in {4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3, 4.3}. But the PDF and CDF functions don't work with this. – JimB May 15 at 21:51
• @JimB I think defining it in terms of pre-defined distributions would be a simple way forward. But as you show, your example doesn't work fully and neither does setting the SD = 0 in a Normal distribution. – mikado May 15 at 21:58

A relatively simple trick can achieve this

ConstantDistribution[m_] = TransformedDistribution[m, {x \[Distributed] NormalDistribution[0, 1]}];


This behaves as desired for some key functions

{Mean, Variance, CDF[#, t] &, CharacteristicFunction[#, t] &}[ConstantDistribution[m]] // Through // InputForm
(* {m, 0, Piecewise[{{1, m - t <= 0}}, 0], E^(I*m*t)} *)

• Wow! Even Expectation works with this approach. – JimB May 17 at 18:12

In[35]:= dist = ProbabilityDistribution[1, {x, a, a, 1}];

In[36]:= DistributionParameterQ[dist]

Out[36]= True

In[39]:= {Mean[dist], Variance[dist], CDF[dist, x], Expectation[s^2 + 1, s [Distributed] dist]} // InputForm

Out[39]//InputForm= {a, 0, Piecewise[{{1, a <= x}}, 0], 1 + a^2}

• Interesting - technically you have defined a discrete distribution that only takes the value a, whereas my answer defined a continuous distribution. Mathematica makes a distinction between the two types, at least in PDF – mikado Jun 18 at 21:03
• The integral of a finite function from a to a is zero... This really should not work, but I guess the framework is just too robust ;) In[62]:= td = TransformedDistribution[3, {x [Distributed] NormalDistribution[0, 1]}]; In[63]:= DistributionDomain[td] Out[63]= Interval[{3, 3}] In[64]:= DistributionParameterQ[td] Out[64]= True In[69]:= PDF[td, x] // InputForm Out[69]//InputForm= Piecewise[{{0, x != 3}}, Indeterminate] – Gosia Jun 18 at 21:14