Accuracy of atanh on complex arguments
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 entirelyExamples:
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.7853981633974483iSo: 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
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de racket/math
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Wishlist: flzero?Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 45/100
-
Shallow / Optional typesAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
Todos los issues de racket/math
Issues similares
-
Maven path-index: "Ambiguous or noncanonical artifact path" error does not report the offending pathAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
pulp/pulp_maven#524 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 76/100
ethereum/execution-apis#935 ·
Los mantenedores suelen responder en 1 día
-
rc_runtime_activate_richpresence leaves a half-initialised entry when the buffer allocation failsAbierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
RetroAchievements/rcheevos#558 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Qiskit/qiskit-ibm-runtime#3461 ·
Los mantenedores suelen responder en 1 día
-
module: unknown type: bug/reported
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
OpenXiangShan/XiangShan#6688 ·
Los mantenedores suelen responder en 1 día