Skip to content

The principal root of a negative real carries a 1e-102 real part, and its square then lies a hair below the negative axis, where ln takes the wrong branch #1378

Closed

Description

@Rafael-SOWNet

Measured on master (2b4a5256), with DowncastingEnabled off, as a numerical verification evaluates:

(-0.473)^(1/2)          -> -6.1e-102 + 0.68775i        (the real part should be 0)
(-4)^(1/2)              -> -1.8e-101 + 2i
((-0.473)^(1/2))^2      -> -0.473 - 8.4e-102 i         (should be -0.473 exactly)
ln(((-0.473)^(1/2))^2)  -> -0.7487 - 3.14159 i         (ln(-0.473) is -0.7487 + 3.14159 i)

Two causes, both in Number.Pow:

  1. A negative real to a half power goes through the polar form, rho^p (cos(p theta) + i sin(p theta)) with theta = pi from Arctan2, and cos(pi/2) at a hundred digits is 6e-102, not zero. The principal root of a negative real is the root of the modulus times i, exactly, and the same for every power that is a whole number of halves ((-4)^(3/2) is -8i; (-8)^(1/3) is not affected — a third is not a multiple of a right angle, and this library's real-root convention for it stays).
  2. With the downcasting off, the literal 2 arrives as the decimal 2, not the Integer, so z^2 takes the polar form too instead of the exact multiplication z * z — which is what turns (0 + 0.68775i)^2 into -0.473 - 8.4e-102 i: a hair below the negative axis, where ln reads -i pi for the +i pi the number has.

Together they made a right antiderivative read as wrong: u ln(u^2) for u = sqrt(-1 + a x) is sqrt(-1 + a x) ln(((-1 + a x)^(1/2))^2) written back, whose numerical derivative at -1 + a x < 0 disagreed with the integrand by exactly the 2 pi i of the branch — the corpus harness reported the answer wrong at 3 of 6 points while its symbolic derivative is the integrand.

Fix in the PR that found it: a negative real base to a real power that is a whole number of halves is the modulus to that power times i^k, exactly; and a real power that is a whole number is read as the integer it is, so the exact multiplication is used.

Activity

  1. added this to the 2.6.0 milestone on Sep 18, 2026
  2. added theissue type on Sep 22, 2026
  3. Rafael-SOWNet commented on Sep 28, 2026

    @Rafael-SOWNet
    MemberAuthor

    On master (40b7e587) both causes are gone, with the downcasting off:

    (-0.473)^(1/2)           0 + 0.68774995456…i     (was -6.1e-102 + 0.68775i)
    (-4)^(3/2)               -8i exactly
    ((-0.473)^(1/2))^2       -0.473, imaginary part zero
    ln(((-0.473)^(1/2))^2)   -0.74866 + 3.14159i     (+i pi, the principal branch)
    

    and with it on, the root and the logarithm come out the same. A half power of a negative real is i times the root of the modulus now, a decimal power with nothing after the point is taken as the whole power it is (#1379), and a zero imaginary part is on the real axis whatever its sign (#1433). Closing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions