Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Book3] Typo in Listing 13? #1563

Closed
YSakhno opened this issue May 24, 2024 · 4 comments
Closed

[Book3] Typo in Listing 13? #1563

YSakhno opened this issue May 24, 2024 · 4 comments

Comments

@YSakhno
Copy link

YSakhno commented May 24, 2024

Shouldn't function pdf be

double pdf(double x) {
    return 0.5 * x;
}

instead of return 0.5;?

I do not know much, but a function that returns constant value regardless of its input seems weird to me, especially in this context.

@dimitry-ishenko
Copy link
Contributor

dimitry-ishenko commented May 28, 2024

@YSakhno what makes it seem weird to you?

Chapter 3.7 says that we are using constant PDF over the interval [0, 2]. That alone should tell you the function will return constant value not dependent on x.

If you use the data learned in the book, you should also be able to verify it yourself. We know that integral of the PDF over its interval must be equal to 1 (ie, 100% probability), so:

$$ \int_0^2 pdf(x) dx = \int_0^2 0.5 dx = 0.5 \int_0^2 dx = 0.5 \cdot x\big|_0^2 = 0.5 \cdot (2 - 0) = 1$$

QED

@YSakhno
Copy link
Author

YSakhno commented May 29, 2024

OK, I was confused by the function $P(x) = x/2$ immediately prior to the listing, and thought that $P(x)$ was the PDF.

@dimitry-ishenko
Copy link
Contributor

Oh I see what you mean. In this case $P(x)$ refers to the CDF.

There is a bit of inconsistency with function and parameter names in the text. I've raised an issue #1531 in regards to the function parameters. Feel free to drop a note in there to unify function names as well.

There was also a relevant issue #1537 which deals with function names used in the code.

@hollasch
Copy link
Collaborator

I'll close this one out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants