Repository navigation
Correct the tail statements of the normal cdfs and Phi_approx - #990
Merged
Merged
Conversation
bob-carpenter
approved these changes
Oct 23, 2026
bob-carpenter
left a comment
Member
There was a problem hiding this comment.
Thanks, Aki---this is super helpful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #352.
Summary
The functions reference says in six places that
Phi_approx,log(Phi_approx(...))andlog1m(Phi_approx(...))are more robust in the tails thannormal_cdf,normal_lcdf,normal_lccdfand theirstd_normal_versions. It also says that the log functions underflow or overflow below -37.5 and above 8.25. Both statements are wrong. This PR replaces them and adds a tail warning toPhi_approx.Evidence
Relative error against mpmath (60 digits) on Stan Math
developof 2026-10-22:normal_lcdfnormal_lccdfPhi,normal_cdflog(Phi_approx(z))log(Phi_approx(z))log(Phi_approx(z))log(Phi_approx(z))-inf(the true value is finite)log(Phi_approx(z))With stan-dev/math#3406 the first three rows are at most 4e-16.
Phi_approxisinv_logit(0.07056 x^3 + 1.5976 x), and its log behaves like0.07056 x^3in the lower tail instead of-x^2/2. For example,Phi_approx(-10)is 2.6e-38 andPhi(-10)is 7.6e-24.The statements on the log functions have been out of date since stan-dev/math#1411 (2019) for
normal_lcdfand since stan-dev/math#3363 (2026) fornormal_lccdf.