FAILURE MAP
← Case archive

FA-16481 / Floating-point arithmetic / Open access

Complex logarithm uses one-argument arctangent · case 01

Complex logarithm uses one-argument arctangent.

Verified by executionVariant 1 · 9 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Complex logarithm uses one-argument arctangent. The faulty expression is imag=math.atan(y/x).

VERIFIED REPAIR

Apply the contract at this fault site using imag=math.atan2(y,x).

Unsuccessful approach: The attempted local correction imag=math.atan(y/x) if x else math.pi/2 still violates the explicit regression fixtures.

Case contract

Principal logarithm of nonzero finite complex x+iy, using hypot and atan2; zero returns a pole marker. Inputs keep hypot finite. Finite results are rendered to eleven significant decimal digits; modeled domain violations and arithmetic errors are explicit strings.

Why this case matters

An offline floating representation model isolates a reproducible arithmetic fault.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x,y):
    try:
        if x==0 and y==0: return 'pole'
        a=abs(x); b=abs(y)
        hi=max(a,b); lo=min(a,b)
        ratio=lo/hi
        real=math.log(hi)+0.5*math.log1p(ratio*ratio)
        imag=math.atan(y/x)
        return [render(real),render(imag)]
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('unequal components', solve(3.0,4.0), [render(math.log(5)),render(math.atan2(4,3))])
check('huge', solve(N*1e200,1e200), [render(math.log(math.hypot(N*1e200,1e200))),render(math.atan2(1,N))])
check('tiny', solve(N*1e-200,-1e-200), [render(math.log(math.hypot(N*1e-200,1e-200))),render(math.atan2(-1,N))])
check('negative real above', solve(-float(N),0.0), [render(math.log(N)),render(math.pi)])
check('negative real below', solve(-float(N),-0.0), [render(math.log(N)),render(-math.pi)])
check('imaginary axis', solve(0.0,float(N)), [render(math.log(N)),render(math.pi/2)])
check('real axis', solve(float(N),0.0), [render(math.log(N)),"0"])
check('origin', solve(0.0,0.0), "pole")
check('quadrant three', solve(-float(N),-float(N)), [render(math.log(math.hypot(N,N))),render(-3*math.pi/4)])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
unequal components['1.6094379124', '0.927295218']['1.6094379124', '0.927295218']Passed
huge['460.86359219', '0.7853981634']['460.86359219', '0.7853981634']Passed
tiny['-460.17044501', '-0.7853981634']['-460.17044501', '-0.7853981634']Passed
negative real above['0', '-0']['0', '3.1415926536']Failed
negative real below['0', '0']['0', '-3.1415926536']Failed
imaginary axisarithmetic-error['0', '1.5707963268']Failed
real axis['0', '0']['0', '0']Passed
originpolepolePassed
quadrant three['0.34657359028', '0.7853981634']['0.34657359028', '-2.3561944902']Failed

SHA-256 / 85e49cef906695f7c2f666ac7aec5f6094009fd8f37be8a13841e73f2a0dfb8e

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x,y):
    try:
        if x==0 and y==0: return 'pole'
        a=abs(x); b=abs(y)
        hi=max(a,b); lo=min(a,b)
        ratio=lo/hi
        real=math.log(hi)+0.5*math.log1p(ratio*ratio)
        imag=math.atan(y/x) if x else math.pi/2
        return [render(real),render(imag)]
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('unequal components', solve(3.0,4.0), [render(math.log(5)),render(math.atan2(4,3))])
check('huge', solve(N*1e200,1e200), [render(math.log(math.hypot(N*1e200,1e200))),render(math.atan2(1,N))])
check('tiny', solve(N*1e-200,-1e-200), [render(math.log(math.hypot(N*1e-200,1e-200))),render(math.atan2(-1,N))])
check('negative real above', solve(-float(N),0.0), [render(math.log(N)),render(math.pi)])
check('negative real below', solve(-float(N),-0.0), [render(math.log(N)),render(-math.pi)])
check('imaginary axis', solve(0.0,float(N)), [render(math.log(N)),render(math.pi/2)])
check('real axis', solve(float(N),0.0), [render(math.log(N)),"0"])
check('origin', solve(0.0,0.0), "pole")
check('quadrant three', solve(-float(N),-float(N)), [render(math.log(math.hypot(N,N))),render(-3*math.pi/4)])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
unequal components['1.6094379124', '0.927295218']['1.6094379124', '0.927295218']Passed
huge['460.86359219', '0.7853981634']['460.86359219', '0.7853981634']Passed
tiny['-460.17044501', '-0.7853981634']['-460.17044501', '-0.7853981634']Passed
negative real above['0', '-0']['0', '3.1415926536']Failed
negative real below['0', '0']['0', '-3.1415926536']Failed
imaginary axis['0', '1.5707963268']['0', '1.5707963268']Passed
real axis['0', '0']['0', '0']Passed
originpolepolePassed
quadrant three['0.34657359028', '0.7853981634']['0.34657359028', '-2.3561944902']Failed

SHA-256 / abd011744ef51c9b8d9437299b30db397c60441c39af1eb843b13364367fac63

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
import struct
def render(x):
    if math.isnan(x): return 'nan'
    if math.isinf(x): return '-infinity' if x<0 else '+infinity'
    return format(x,'.11g')

N = 1
observations = []
def solve(x,y):
    try:
        if x==0 and y==0: return 'pole'
        a=abs(x); b=abs(y)
        hi=max(a,b); lo=min(a,b)
        ratio=lo/hi
        real=math.log(hi)+0.5*math.log1p(ratio*ratio)
        imag=math.atan2(y,x)
        return [render(real),render(imag)]
    except (ValueError, OverflowError, ZeroDivisionError, TypeError):
        return "arithmetic-error"
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
check('unequal components', solve(3.0,4.0), [render(math.log(5)),render(math.atan2(4,3))])
check('huge', solve(N*1e200,1e200), [render(math.log(math.hypot(N*1e200,1e200))),render(math.atan2(1,N))])
check('tiny', solve(N*1e-200,-1e-200), [render(math.log(math.hypot(N*1e-200,1e-200))),render(math.atan2(-1,N))])
check('negative real above', solve(-float(N),0.0), [render(math.log(N)),render(math.pi)])
check('negative real below', solve(-float(N),-0.0), [render(math.log(N)),render(-math.pi)])
check('imaginary axis', solve(0.0,float(N)), [render(math.log(N)),render(math.pi/2)])
check('real axis', solve(float(N),0.0), [render(math.log(N)),"0"])
check('origin', solve(0.0,0.0), "pole")
check('quadrant three', solve(-float(N),-float(N)), [render(math.log(math.hypot(N,N))),render(-3*math.pi/4)])
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
unequal components['1.6094379124', '0.927295218']['1.6094379124', '0.927295218']Passed
huge['460.86359219', '0.7853981634']['460.86359219', '0.7853981634']Passed
tiny['-460.17044501', '-0.7853981634']['-460.17044501', '-0.7853981634']Passed
negative real above['0', '3.1415926536']['0', '3.1415926536']Passed
negative real below['0', '-3.1415926536']['0', '-3.1415926536']Passed
imaginary axis['0', '1.5707963268']['0', '1.5707963268']Passed
real axis['0', '0']['0', '0']Passed
originpolepolePassed
quadrant three['0.34657359028', '-2.3561944902']['0.34657359028', '-2.3561944902']Passed

SHA-256 / 90d110e005a3f3aab59f9617726bd5a7fe057ca8740394bba91ace8bbd714e39

Verification & scope

Controlled binary64 or explicitly stipulated miniature format; no hardware exception flags or platform floating environment are modeled. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:39:36.696691+00:00.

Case digest / e972b7dfd075a6d3f3e9d747816d91b1a35b8ee2a78fd2ae8220aae398f18389