
(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 4 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 (* (+ (* x 2.0) (* (* 0.6666666666666666 (* x x)) x)) 0.5))
float code(float x) {
return ((x * 2.0f) + ((0.6666666666666666f * (x * x)) * x)) * 0.5f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = ((x * 2.0e0) + ((0.6666666666666666e0 * (x * x)) * x)) * 0.5e0
end function
function code(x) return Float32(Float32(Float32(x * Float32(2.0)) + Float32(Float32(Float32(0.6666666666666666) * Float32(x * x)) * x)) * Float32(0.5)) end
function tmp = code(x) tmp = ((x * single(2.0)) + ((single(0.6666666666666666) * (x * x)) * x)) * single(0.5); end
\begin{array}{l}
\\
\left(x \cdot 2 + \left(0.6666666666666666 \cdot \left(x \cdot x\right)\right) \cdot x\right) \cdot 0.5
\end{array}
Initial program 93.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3296.7
Applied rewrites96.7%
Applied rewrites96.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3296.3
Applied rewrites95.6%
Applied rewrites98.2%
Final simplification98.2%
(FPCore (x) :precision binary32 (* (* (+ (* 0.6666666666666666 (* x x)) 2.0) x) 0.5))
float code(float x) {
return (((0.6666666666666666f * (x * x)) + 2.0f) * x) * 0.5f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = (((0.6666666666666666e0 * (x * x)) + 2.0e0) * x) * 0.5e0
end function
function code(x) return Float32(Float32(Float32(Float32(Float32(0.6666666666666666) * Float32(x * x)) + Float32(2.0)) * x) * Float32(0.5)) end
function tmp = code(x) tmp = (((single(0.6666666666666666) * (x * x)) + single(2.0)) * x) * single(0.5); end
\begin{array}{l}
\\
\left(\left(0.6666666666666666 \cdot \left(x \cdot x\right) + 2\right) \cdot x\right) \cdot 0.5
\end{array}
Initial program 88.2%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3296.7
Applied rewrites96.7%
Applied rewrites96.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3296.3
Applied rewrites95.6%
Applied rewrites98.1%
Final simplification98.1%
(FPCore (x) :precision binary32 (* (* x 2.0) 0.5))
float code(float x) {
return (x * 2.0f) * 0.5f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = (x * 2.0e0) * 0.5e0
end function
function code(x) return Float32(Float32(x * Float32(2.0)) * Float32(0.5)) end
function tmp = code(x) tmp = (x * single(2.0)) * single(0.5); end
\begin{array}{l}
\\
\left(x \cdot 2\right) \cdot 0.5
\end{array}
Initial program 93.6%
Taylor expanded in x around 0
lower-*.f3296.7
Applied rewrites96.7%
Final simplification96.7%
(FPCore (x) :precision binary32 (- x))
float code(float x) {
return -x;
}
real(4) function code(x)
real(4), intent (in) :: x
code = -x
end function
function code(x) return Float32(-x) end
function tmp = code(x) tmp = -x; end
\begin{array}{l}
\\
-x
\end{array}
Initial program 89.3%
Applied rewrites8.9%
Taylor expanded in x around 0
mul-1-negN/A
lower-neg.f328.0
Applied rewrites8.0%
herbie shell --seed 2024295
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))