Skip to content

ENH: add one_minus_square - #1051

Open
NeilGirdhar wants to merge 2 commits into
data-apis:mainfrom
NeilGirdhar:one-minus-square
Open

NeilGirdhar wants to merge 2 commits into
data-apis:mainfrom
NeilGirdhar:one-minus-square

Conversation

@NeilGirdhar

Copy link
Copy Markdown
Contributor

Compute 1 - x**2 as (1 + x) * (1 - x), which avoids catastrophic cancellation when |x| is close to 1. On JAX >= 0.11.2, delegate to jax.lax.one_minus_square, whose derivative is defined as -2x and so stays accurate near zero.

Reference issue

Closes #1050

AI Generation Disclosure

Yes, Claude. I reviewed the change. Please let me know if that's okay.

@lucascolley lucascolley added this to the 0.12.1 milestone Oct 25, 2026
NeilGirdhar and others added 2 commits November 18, 2026 11:47
Compute `1 - x**2` as `(1 + x) * (1 - x)`, which avoids catastrophic
cancellation when `|x|` is close to 1. On JAX >= 0.11.2, delegate to
`jax.lax.one_minus_square`, whose derivative is defined as `-2x` and so
stays accurate near zero.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The lint environment has no JAX, so pyright sees jax.lax as unknown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@NeilGirdhar

NeilGirdhar commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor Author

@lucascolley Should I add polynomial in this pull request as a related function, or a separate pull request? polynomial is a generalization of this exact concept to arbitrary polynomials.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add one_minus_square

2 participants