Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Accuracy of atanh on complex arguments

Abierto
#119 22 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Área
backend

Línea de trabajo

Start with the complex atanh implementation in math/private/base/base-functions.rkt around line 104, then compare it with the Chez implementation in src/ChezScheme/s/5_3.ss around lines 761 and 412. Evaluate the cited tiny, ordinary, huge, and near-1 complex cases, and establish whether the improvement should use a math/base algorithm or the Chez primitive.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

While adding complex numbers to WebRacket I have found a potential problem
in the math/base implementation of atanh. When called with complex
arguments, the accuracy isn't as good as Chez Scheme.

For the complex case the implementation of atanh in math/base uses:

(* 0.5 (- (log (+ 1.0 x)) (log (- 1.0 x))))

This is mathematically correct, but not numerically stable.

The problem is how to improve the situation?

Option 1) improve the implementation in math/base.
Option 2) figure out how to call the Chez Scheme primitive atanh.

The section below was produced by Codex when I asked it examine the
accuracy of atanh on complex numbers.

Note: There might be similar problems with asinh and and acosh.

/Jens Axel

Codex:

For math/base, complex accuracy is not uniformly good. It uses the direct formula at [base-functions.rkt (line 104)](/Users/soegaard/Dropbox/GitHub/racket/racket/share/pkgs/math-lib/math/private/base/base-functions.rkt:104):

(* 0.5 (- (log (+ 1.0 x)) (log (- 1.0 x))))

That is mathematically right, but numerically fragile.

Measured against a 4096-bit bigfloat reference:

Region | math/base max-component error -- | -- ordinary random [-10,10]^2 | median 5 ulp, p95 27 ulp, worst 23515 ulp tiny complex inputs | often loses the real part entirely near 1+iε | very good, usually 0-1 ulp huge complex inputs | often loses the small real part entirely

Examples:

z = 1e-20+1e-20i
ref       1e-20+1e-20i
math/base 0.0+1e-20i

z = 1e100+0.0i
ref 1e-100+1.5707963267948966i
math/base 0.0+1.5707963267948966i

The Chez source-level cflatanh at 5_3.ss (line 761) is much more accuracy-oriented: it uses Kahan-style formulas and, when log1p is available through fllog1+ (line 412), it preserves those tiny real parts. In my model of that path, ordinary/tiny cases were typically 0-1 ulp.

But Chez has its own weak spot near z = 1+iε: it adds rho ≈ 2.98e-154 to |imag|, so for ε << rho it clamps the behavior:

z = 1.0+1e-300i
ref 345.73433753938684+0.7853981633974483i
math/base 345.7343375393868 +0.7853981633974483i
Chez model 177.09910463306602+0.7853981633974483i

So: math/base is okay for many ordinary complex values, excellent near 1+iε, but poor when the result has a very small nonzero real component. Chez’s complex algorithm is generally better for cancellation/overflow, except around the guarded branch point near 1.

Lenguaje dominante
Racket
Estrellas
40
Forks
32
Merge medio
2 h 39 min
PR fusionados (30 d)
2

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de racket/math

Todos los issues de racket/math

Issues similares

Más issues de Backend & API Design

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.