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

Listing 3.15: Typo in f(double d) function #1310

Open
hollasch opened this issue Oct 27, 2023 · 5 comments
Open

Listing 3.15: Typo in f(double d) function #1310

hollasch opened this issue Oct 27, 2023 · 5 comments

Comments

@hollasch
Copy link
Collaborator

Benny Tsang writes:

(Book 3) Section 3.7, Listing 15, typo in the f(double d) function, the `8.0' should be inside pow(8.0*d, 1./3.).

@hollasch hollasch added this to the v4.0.0 milestone Oct 27, 2023
@hollasch hollasch self-assigned this Oct 27, 2023
@hollasch hollasch assigned rupsis and unassigned hollasch Feb 10, 2024
@hollasch
Copy link
Collaborator Author

I'm not sure I understand this. @trevordblack ?

Interestingly, 8.0 * pow(d, 1.0/3.0) yields the same result as pow(8.0 * d, 1.0/3.0).

@hollasch
Copy link
Collaborator Author

Wait, what the heck is going on here?

$$ x = \text{something} $$

$$ sum = \frac{x^2}{pdf(x)} = \frac{x^2}{3/8 x^2} = 8/3 $$

So, yeah. This "always returns the exact answer." Regardless of the function f. Given all this, why did we bother deriving the function f?

@hollasch
Copy link
Collaborator Author

hollasch commented Mar 24, 2024

For some reason I had a hard time grokking Benny's original inverse assertion, but here's the derivation:

$$ P(x) = f = \frac{x^3}{8} $$

$$ 8f = x^3 $$

$$ (8f)^\frac{1}{3} = x $$

Also note that the original books had the (correct?) equation: x = pow(8*drand48(), 1./3.).

@petershirley
Copy link
Collaborator

I had to go reread this-- I am thinking the motivation in the text isn't super. In the never happens case where you know the integral's solution already you can sample it perfectly. We can do this in this artificial example. I want to sleep on this. Should we even have it? Steve I am confused about today's note-- I think it should be a times? But should we get rid of this example becuase it never happens in real life that exact sampling is possible?

@trevordblack
Copy link
Collaborator

I had a hard time rewritting this.

I don't remember exactly what I was trying to say, but it was something in the realm that
"If your random generator function is a delta function with the correct answer, then you don't need to sample multiple times"

But I never found the time to clean it up

@hollasch hollasch assigned trevordblack and unassigned rupsis Mar 26, 2024
@hollasch hollasch changed the title Listing 3.15 / Typo in f(double d) function Listing 3.15: Typo in f(double d) function Apr 19, 2024
@hollasch hollasch modified the milestones: v4.0.0, Backlog, v4.1.0 Jul 22, 2024
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

4 participants