Skip to content

fix: evaluate the left tail without cancellation in stats/base/dists/cauchy/cdf - #15967

Open
Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/cauchy-cdf-left-tail
Open

Abhist17 wants to merge 1 commit into
stdlib-js:developfrom
Abhist17:fix/cauchy-cdf-left-tail

Conversation

@Abhist17

@Abhist17 Abhist17 commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Description

What is the purpose of this pull request?

This pull request:

  • evaluates the left tail of stats/base/dists/cauchy/cdf without cancellation (JS, factory and C).

0.5 + atan(z)/pi cancels below the median, so the CDF loses digits steadily and reaches 0 from about x = x0 - 1e16*gamma:

var cdf = require( '@stdlib/stats/base/dists/cauchy/cdf' );

cdf( -1.0e8, 0.0, 1.0 );
// develop: 3.1830988400649574e-9   (8 correct digits)
// this PR: 3.183098861837907e-9

cdf( -1.0e16, 0.0, 1.0 );
// develop: 0
// this PR: 3.183098861837907e-17

Below z = -1 it uses the identity 0.5 + atan(z)/pi = atan2( gamma, x0-x )/pi, which has no subtraction. Above that the sum doesn't cancel. I first applied the identity everywhere left of the median, but near the median it's less accurate than the sum (atan2 is close to pi/2 there and picks up the rounding of 1/pi), so it's gated at z = -1.

Fixtures. They came from Distributions.jl's Float64 cdf, which uses the same formula. Against the regenerated 2048-bit BigFloat reference, develop is up to 12,729 ULP off on the existing fixtures and this PR is within 3. Point by point, this PR is closer to the exact value on 1,867 of the 2,000 negative_median and positive_median points, and further on 37, by at most an ULP. gen now evaluates in BigFloat (as in #15772 and #15966); all three fixtures were regenerated, plus a new left_tail.json. Tolerances are unchanged, and the new blocks use 2 ULP. test.cdf.js / test.factory.js / test.native.js pass 4,014 / 4,018 / 4,014.

Same fix as #15966 for cauchy/logcdf.

Related Issues

Does this pull request have any related issues?

None. Related to #15966 (cauchy/logcdf).

Questions

Any questions for reviewers of this pull request?

…/cauchy/cdf`

`0.5 + atan(z)/pi` cancels below the median: `cdf( -1e16, 0, 1 )` returned 0
(about 3.18e-17) and `cdf( -1e8, 0, 1 )` had 8 correct digits. Below `z = -1`
use the equivalent `atan2( gamma, x0-x )/pi`; nearer the median the sum
doesn't cancel and stays as it was.

Fixtures are now evaluated in 2048-bit BigFloat (the Float64 references
were up to 12,729 ULP off), with a new far-left-tail fixture.
@Abhist17
Abhist17 requested a review from a team October 7, 2026 21:33
@stdlib-bot stdlib-bot added Statistics Issue or pull request related to statistical functionality. Needs Review A pull request which needs code review. labels Oct 7, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

1 similar comment
@stdlib-bot

Copy link
Copy Markdown
Contributor

Hello! Thank you for your contribution to stdlib.

We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:

  1. Please read our contributing guidelines.

  2. Update your pull request description to include this checked box:

    - [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)

This acknowledgment confirms that you've read the guidelines, which include:

  • The developer's certificate of origin
  • Your agreement to license your contributions under the project's terms

We can't review or accept contributions without this acknowledgment.

Thank you for your understanding and cooperation. We look forward to reviewing your contribution!

@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/cauchy/cdf $\\color{green}295/295$
$\\color{green}+100.00\\%$
$\\color{green}23/23$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}295/295$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Review A pull request which needs code review. Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants