
(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 10 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 (let* ((t_0 (/ (* 2.0 x) (fma x (- x) 1.0)))) (* 0.5 (log1p (fma t_0 1.0 (* x t_0))))))
float code(float x) {
float t_0 = (2.0f * x) / fmaf(x, -x, 1.0f);
return 0.5f * log1pf(fmaf(t_0, 1.0f, (x * t_0)));
}
function code(x) t_0 = Float32(Float32(Float32(2.0) * x) / fma(x, Float32(-x), Float32(1.0))) return Float32(Float32(0.5) * log1p(fma(t_0, Float32(1.0), Float32(x * t_0)))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot x}{\mathsf{fma}\left(x, -x, 1\right)}\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(t\_0, 1, x \cdot t\_0\right)\right)
\end{array}
\end{array}
Initial program 99.8%
lift-/.f32N/A
lift--.f32N/A
flip--N/A
associate-/r/N/A
distribute-lft-inN/A
lower-fma.f32N/A
lower-/.f32N/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
lower-fma.f32N/A
lower-neg.f32N/A
lower-*.f32N/A
Applied rewrites99.9%
Final simplification99.9%
(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%
herbie shell --seed 2024229
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))