Skip to content

Search for a root of a small or a large number at the size of one - #2067

Merged
Rafael-SOWNet merged 4 commits into
masterfrom
a-root-of-a-small-number-is-searched-at-the-size-of-one
Oct 22, 2026
Merged

Rafael-SOWNet merged 4 commits into
masterfrom
a-root-of-a-small-number-is-searched-at-the-size-of-one

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Fixes #2065.

  • The defect. FindGoodRoot looks for an exact root. It rounded each candidate with the zero range set to 1e-6, and it accepted a rational candidate whose power was within 1e-6 of the base, both absolutely. Two wrong answers followed:
    • A root below 1e-6 became the integer 0, and 0 ^ q is within 1e-6 of any base below it. So sqrt(2/10^20), (3/10^30)^(1/3) and sqrt(i/10^20) were 0.
    • When no rational root held, it returned the rounded candidate as the real root. So the root of 10^12 + 1/2 was 10^6, and (2 + i/10^8)^(1/2) lost its imaginary part.
  • The change.
    • The base is scaled to the size of one by an exact power of ten, and the root is scaled back. sqrt(1/10^20) is now 1/10^10 exactly.
    • A candidate is rounded only to look for a rational root, and that root is accepted where its power is the base at the working precision.
    • A real root is returned as computed.
    • The real cube root of a negative base is still the one given: (-2/10^21)^(1/3) is -1.26e-7, as (-8)^(1/3) is -2.

ARootOfASmallNumberTest checks values against mpmath, exact roots that stay exact, and the two complex cases. 9 of its 12 cases fail on master. The 3 that pass are sqrt(10^30), (-8)^(1/3) and (27/8)^(2/3), which are unchanged.

(1 + i/10^8)^(1/2) is asserted to twelve digits. Its modulus, 1 + 5e-17, is read as 1 within 1e-16, and that is what #1944's PR changes.

Results:

  • Unit suite: passes (16,723).
  • Build: the library builds for netstandard2.0.
  • BREAKING-CHANGES: the entry gives the values on 2.6.0 and now.

🤖 Generated with Claude Code

https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura

Rafael-SOWNet and others added 2 commits October 22, 2026 14:56
FindGoodRoot looks for an exact root. It rounded each candidate with the
zero range set to 1e-6 and accepted a rational one whose power was within
1e-6 of the base, both absolutely. A root below 1e-6 became the integer 0,
and 0 ^ q is within 1e-6 of a base below it, so sqrt(2/10^20),
(3/10^30)^(1/3) and sqrt(i/10^20) were 0. And the rounded candidate was
what it returned as the real root when no rational one held: the root of
10^12 + 1/2 was 10^6, and (2 + i/10^8)^(1/2) lost its imaginary part.

The base is scaled to the size of one by an exact power of ten and the
root scaled back, so sqrt(1/10^20) is 1/10^10 exactly. A candidate is
rounded only to look for a rational root, which is accepted where its
power is the base at the working precision; a real root is the candidate
as computed. The real cube root of a negative base stays the one given:
(-2/10^21)^(1/3) is -1.26e-7, as (-8)^(1/3) is -2.

Fixes #2065.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
Rafael-SOWNet and others added 2 commits October 22, 2026 15:52
…umber-is-searched-at-the-size-of-one

# Conflicts:
#	BREAKING-CHANGES.md
The real root is the candidate as GetAllRoots computed it at the working
precision, where it was made a second time from its parts for every
candidate: (-27)^(1/3) allocated 8.0% more than master, sqrt(2) 1.4%. Now
both are within 0.1% of master, measured per call.

Part of #2065.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012sonx8iAspMiwRwokT1Ura
@Rafael-SOWNet
Rafael-SOWNet merged commit 2045021 into master Oct 22, 2026
36 of 37 checks passed
@github-project-automation github-project-automation Bot moved this from Todo to Done in AngouriMath Oct 22, 2026
@Rafael-SOWNet
Rafael-SOWNet deleted the a-root-of-a-small-number-is-searched-at-the-size-of-one branch October 29, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

A root of a small exact number evaluates to 0

1 participant