# Documentation: Error in efficient alternative to diag\_matrix in multi\_normal?

**URL:** <https://discourse.mc-stan.org/t/documentation-error-in-efficient-alternative-to-diag-matrix-in-multi-normal/27818>\
**Category:** General\
**Created:** [June 13, 2022, 1:29pm UTC](https://discourse.mc-stan.org/t/documentation-error-in-efficient-alternative-to-diag-matrix-in-multi-normal/27818 "2022-06-13T13:29:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![tomvar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/tomvar/32/14456_2.png) [@tomvar](https://discourse.mc-stan.org/u/tomvar)\
**Post date:** [June 13, 2022, 1:29pm UTC](https://discourse.mc-stan.org/t/documentation-error-in-efficient-alternative-to-diag-matrix-in-multi-normal/27818/1 "2022-06-13T13:29:38Z")

</div>

In ‘Stan Functions Reference’ manual, version 2.29, section 6.8, it is stated that:

> Although the `diag_matrix` function is available, it is unlikely to ever show up in an efficient Stan program. For example, rather than converting a diagonal to a full matrix for use as a covariance matrix,
> 
> ```no-highlight
> y ~ multi_normal(mu, diag_matrix(square(sigma)));
> 
> ```
> 
> it is much more efficient to just use a univariate normal, which produces the same density,
> 
> ```no-highlight
> y ~ normal(mu, sigma);
> 
> ```

However, the function signature in section 18.1.3 for the normal distribution, only considers `reals` as a possible type for the variance:

> ### 18.1.3 Stan functions
> 
> `real` **`normal_lpdf`** `(reals y | reals mu, reals sigma)`  
> The log of the normal density of y given location mu and scale sigma

Then, how can both functions result in “the same density”, if `multi_normal` allows for a _vector_ of differing variance values for each `y`, while `normal` just accepts a single scalar?

Thanks for your help!

* * *

P.S.: Is there a proper tag for documentation or manual questions? Or a platform to submit errata?

---

<div class="post-metadata">

**Author:** ![WardBrian](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/wardbrian/32/12078_2.png) [@WardBrian](https://discourse.mc-stan.org/u/WardBrian)\
**Post date:** [June 13, 2022, 2:17pm UTC](https://discourse.mc-stan.org/t/documentation-error-in-efficient-alternative-to-diag-matrix-in-multi-normal/27818/2 "2022-06-13T14:17:42Z")

</div>

Hi @tomvar -

This is a good question! The answer lies in the documentation page labelled “Conventions for probability distributions” [13.8 Vectorization | Stan Functions Reference](https://mc-stan.org/docs/2_29/functions-reference/vectorization.html#vectorized-scalar-arguments)

In summary, the term “reals” (as distinct from “real” without the “s”) is used as a shorthand for vectorization, meaning that `sigma` can be a `real`, an `array[] real`, a `vector`, or a `row_vector`.

This shorthand can be confusing, but `normal` actually has 64 unique signatures under these aliases, so listing all of them is also not ideal. We should probably link to the above page more than we do, though!

> [@tomvar](#):
>
> P.S.: Is there a proper tag for documentation or manual questions? Or a platform to submit errata?

If you have a github account, issues can be filed at [Issues · stan-dev/docs · GitHub](https://github.com/stan-dev/docs/issues). If you are unsure if there really is an error or if you simply have a question, I think this is the best place to ask.

---

<div class="post-metadata">

**Author:** ![tomvar](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/tomvar/32/14456_2.png) [@tomvar](https://discourse.mc-stan.org/u/tomvar)\
**Post date:** [June 13, 2022, 2:21pm UTC](https://discourse.mc-stan.org/t/documentation-error-in-efficient-alternative-to-diag-matrix-in-multi-normal/27818/3 "2022-06-13T14:21:36Z")

</div>

Thank you very much for the clear swift reply!
