# Where is the \`pdf\` function in Distribution.jl implemented?

**URL:** <https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896>\
**Category:** General Usage\
**Created:** [May 6, 2019, 1:18am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896 "2019-05-06T01:18:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![biona001](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/biona001/32/16497_2.png) [@biona001](https://discourse.julialang.org/u/biona001)\
**Post date:** [May 6, 2019, 1:18am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/1 "2019-05-06T01:18:31Z")

</div>

Hello Julia community,

```julia
julia> pdf(Normal(), 0.3)
0.38138781546052414

```

I want to know how the `pdf` function is implemented, but the [source code](https://github.com/JuliaStats/Distributions.jl/blob/2ac3a83aef47132d97bb6632e8465617cd493c9f/src/univariates.jl#L308-L314) for `Distribution.jl` tells me nothing (in fact it looks like an infinite loop).

Am I missing something? Wouldn’t there at least have to have a 2\pi somewhere?

---

<div class="post-metadata">

**Author:** ![Ralph\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ralph_smith/32/10344_2.png) [@Ralph\_Smith](https://discourse.julialang.org/u/Ralph_Smith)\
**Post date:** [May 6, 2019, 2:10am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/2 "2019-05-06T02:10:25Z")

</div>

```julia
julia-1.1> d = Normal()
julia-1.1> @less pdf(d, 0.3) # shows this is implemented via a macro, so try something else
julia-1.1> @code_lowered pdf(d,0.3)
CodeInfo(
1 ─ %1 = (Base.getproperty)(d, :μ)
│ %2 = (Base.getproperty)(d, :σ)
│ %3 = (Distributions.normpdf)(%1, %2, x)
└── return %3
)

julia-1.1> @less Distributions.normpdf(0.0,1.0,0.3) # this is what you want

```

Page up to see your beloved constant.

---

<div class="post-metadata">

**Author:** ![aharoun](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aharoun/32/6887_2.png) [@aharoun](https://discourse.julialang.org/u/aharoun)\
**Post date:** [May 6, 2019, 2:51am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/4 "2019-05-06T02:51:17Z")

</div>

In case it is not clear: `pdf` and other relevant functions are implemented in [StatsFuns.jl](https://github.com/JuliaStats/StatsFuns.jl).

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 6, 2019, 6:50am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/5 "2019-05-06T06:50:33Z")

</div>

> [@biona001](#):
>
> I want to know how the `pdf` function is implemented

Technically, functions are not implemented, _methods_ are. What you linked are some generic fallback methods for dealing with some general cases (and the first one doesn’t look like a function definition at all, maybe a bug?).

You can also use

```julia
@edit pdf(Normal(), 0.3)

```

to take you to the source code (if your editor is set up properly).

In this case it takes you to a macro defining functions using primitives from StatsFuns, which I agree is rather opaque.

---

<div class="post-metadata">

**Author:** ![koushikkhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/koushikkhan/32/47282_2.png) [@koushikkhan](https://discourse.julialang.org/u/koushikkhan)\
**Post date:** [February 28, 2023, 3:18am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/6 "2023-02-28T03:18:57Z")

</div>

How can we calculate PDF at each point (randomly generated) of a vector? I am trying to do this using the snippet below, but it is giving me PDF values \> 1 which cannot be true for Normal distribution with combination of parameter

```julia
x = rand(Normal(3, 0.05), 10^3)
y = pdf.(Normal(3, 0.05), x)

```

There must be something wrong I am doing, please help me to get this.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [February 28, 2023, 3:34am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/7 "2023-02-28T03:34:54Z")

</div>

> [@koushikkhan](#):
>
> but it is giving me PDF values \> 1 which cannot be true

It can be true 🙂

This is what the pdf of `Normal(3, 0.05)` looks like

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/2/023553389e437ec014bf5adc5213559c4f62fabe.png)

---

<div class="post-metadata">

**Author:** ![koushikkhan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/koushikkhan/32/47282_2.png) [@koushikkhan](https://discourse.julialang.org/u/koushikkhan)\
**Post date:** [February 28, 2023, 4:38am UTC](https://discourse.julialang.org/t/where-is-the-pdf-function-in-distribution-jl-implemented/23896/8 "2023-02-28T04:38:13Z")

</div>

Oh, sorry, my bad, the property of density function is that (1) it must be greater than zero, (2) integrating it under the support (a.k.a total area under the curve) must be 0

Thanks a lot for correcting me. But what about evaluating density over the vector? Am I doing it correctly?
