# Expectation function in Mathematica

**URL:** <https://community.wolfram.com/t/expectation-function-in-mathematica/18557>\
**Category:** Questions\
**Tags:** statistics-and-probability, tuning-and-debugging\
**Created:** [July 16, 2021, 1:22pm UTC](https://community.wolfram.com/t/expectation-function-in-mathematica/18557 "2021-07-16T13:22:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sharanb02](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@sharanb02](https://community.wolfram.com/u/sharanb02)\
**Post date:** [July 16, 2021, 1:22pm UTC](https://community.wolfram.com/t/expectation-function-in-mathematica/18557/1 "2021-07-16T13:22:28Z")

</div>

I was working with some statistics on Mathematica and the Expectation function made me curious. I tried to calculate the expected value of an expression containing multivariate distribution and it gave the result almost instantly.

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/34386150-24c2-4b8b-a363-1d39bc718e53)

On the other hand, trying to find the same by direct integration after applying the Law of iterated expectation took almost an hour.

◔

[Open in Wolfram Cloud ↗](https://www.wolframcloud.com/obj/cd7ab6f0-eb15-4bfe-bdf5-5fd98d640729)

I’m curious to know how Mathematica processes expectations so fast, no matter what distribution they are. Is there any computationally easier analytical method to calculate expectations that Mathematica exploits behind the scenes?
