
(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 3 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 (+ x x)))
float code(float x) {
return 0.5f * (x + x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * (x + x)
end function
function code(x) return Float32(Float32(0.5) * Float32(x + x)) end
function tmp = code(x) tmp = single(0.5) * (x + x); end
\begin{array}{l}
\\
0.5 \cdot \left(x + x\right)
\end{array}
Initial program 94.5%
Taylor expanded in x around 0
lower-*.f3297.8
Applied rewrites97.8%
Applied rewrites97.8%
(FPCore (x)
:precision binary32
(*
0.5
(log1p
(fma
(* 2.0 (/ (/ -1.0 x) x))
(fma x x x)
(* 2.0 (/ x (- 1.0 (pow x 3.0))))))))
float code(float x) {
return 0.5f * log1pf(fmaf((2.0f * ((-1.0f / x) / x)), fmaf(x, x, x), (2.0f * (x / (1.0f - powf(x, 3.0f))))));
}
function code(x) return Float32(Float32(0.5) * log1p(fma(Float32(Float32(2.0) * Float32(Float32(Float32(-1.0) / x) / x)), fma(x, x, x), Float32(Float32(2.0) * Float32(x / Float32(Float32(1.0) - (x ^ Float32(3.0)))))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{fma}\left(2 \cdot \frac{\frac{-1}{x}}{x}, \mathsf{fma}\left(x, x, x\right), 2 \cdot \frac{x}{1 - {x}^{3}}\right)\right)
\end{array}
Initial program 85.2%
lift-/.f32N/A
lift--.f32N/A
flip3--N/A
associate-/r/N/A
metadata-evalN/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lift-*.f32N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
lower-pow.f32N/A
*-lft-identityN/A
lower-fma.f32N/A
Applied rewrites11.9%
Taylor expanded in x around inf
unpow2N/A
associate-/r*N/A
lower-/.f32N/A
lower-/.f3211.4
Applied rewrites11.7%
Final simplification11.5%
(FPCore (x) :precision binary32 (* 0.0 0.5))
float code(float x) {
return 0.0f * 0.5f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.0e0 * 0.5e0
end function
function code(x) return Float32(Float32(0.0) * Float32(0.5)) end
function tmp = code(x) tmp = single(0.0) * single(0.5); end
\begin{array}{l}
\\
0 \cdot 0.5
\end{array}
Initial program 90.7%
Taylor expanded in x around 0
lower-*.f3297.8
Applied rewrites97.8%
Applied rewrites97.8%
Applied rewrites7.1%
lift-*.f32N/A
*-commutativeN/A
lower-*.f327.4
Applied rewrites11.0%
herbie shell --seed 2024343
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))