
(FPCore (x) :precision binary32 (atanh x))
float code(float x) {
return atanhf(x);
}
function code(x) return atanh(x) end
function tmp = code(x) tmp = atanh(x); end
\begin{array}{l}
\\
\tanh^{-1} x
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
\end{array}
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * x) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * x) / Float32(Float32(1.0) - x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot x}{1 - x}\right)
\end{array}
Initial program 99.8%
(FPCore (x) :precision binary32 (fma (pow x 3.0) (fma (fma 0.14285714285714285 (* x x) 0.2) (* x x) 0.3333333333333333) x))
float code(float x) {
return fmaf(powf(x, 3.0f), fmaf(fmaf(0.14285714285714285f, (x * x), 0.2f), (x * x), 0.3333333333333333f), x);
}
function code(x) return fma((x ^ Float32(3.0)), fma(fma(Float32(0.14285714285714285), Float32(x * x), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333)), x) end
\begin{array}{l}
\\
\mathsf{fma}\left({x}^{3}, \mathsf{fma}\left(\mathsf{fma}\left(0.14285714285714285, x \cdot x, 0.2\right), x \cdot x, 0.3333333333333333\right), x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
associate-*r*N/A
unpow2N/A
cube-multN/A
*-rgt-identityN/A
lower-fma.f32N/A
Applied rewrites99.3%
herbie shell --seed 2025057
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))