
(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 (log1p (- (/ x (fabs (+ -1.0 x))) (* (- x 1.0) x)))))
float code(float x) {
return 0.5f * log1pf(((x / fabsf((-1.0f + x))) - ((x - 1.0f) * x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(x / abs(Float32(Float32(-1.0) + x))) - Float32(Float32(x - Float32(1.0)) * x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x}{\left|-1 + x\right|} - \left(x - 1\right) \cdot x\right)
\end{array}
Initial program 88.5%
Applied rewrites95.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
lower--.f3294.5
Applied rewrites89.6%
Applied rewrites96.9%
Final simplification96.9%
(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 87.7%
Taylor expanded in x around 0
lower-*.f3296.7
Applied rewrites96.7%
Applied rewrites96.7%
(FPCore (x) :precision binary32 0.0)
float code(float x) {
return 0.0f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.0e0
end function
function code(x) return Float32(0.0) end
function tmp = code(x) tmp = single(0.0); end
\begin{array}{l}
\\
0
\end{array}
Initial program 85.3%
Applied rewrites11.0%
Taylor expanded in x around 0
Applied rewrites11.0%
herbie shell --seed 2024337
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))