
(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 (/ (* 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.7%
Final simplification99.7%
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ 1.0 (+ (/ 0.5 x) -0.5)))))
float code(float x) {
return 0.5f * log1pf((1.0f / ((0.5f / x) + -0.5f)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(1.0) / Float32(Float32(Float32(0.5) / x) + Float32(-0.5))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{1}{\frac{0.5}{x} + -0.5}\right)
\end{array}
Initial program 99.7%
add-log-exp21.6%
*-un-lft-identity21.6%
log-prod21.6%
metadata-eval21.6%
add-log-exp99.7%
*-commutative99.7%
associate-/l*99.6%
Applied egg-rr99.6%
+-lft-identity99.6%
associate-*r/99.7%
*-commutative99.7%
*-lft-identity99.7%
associate-*l/99.6%
associate-/r/99.1%
div-sub99.1%
sub-neg99.1%
associate-/r*99.1%
metadata-eval99.1%
*-commutative99.1%
associate-/r*99.1%
*-inverses99.1%
metadata-eval99.1%
metadata-eval99.1%
Simplified99.1%
Final simplification99.1%
(FPCore (x) :precision binary32 (* 0.5 (* 2.0 x)))
float code(float x) {
return 0.5f * (2.0f * x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * (2.0e0 * x)
end function
function code(x) return Float32(Float32(0.5) * Float32(Float32(2.0) * x)) end
function tmp = code(x) tmp = single(0.5) * (single(2.0) * x); end
\begin{array}{l}
\\
0.5 \cdot \left(2 \cdot x\right)
\end{array}
Initial program 99.7%
add-cube-cbrt97.5%
pow397.5%
*-commutative97.5%
associate-/l*97.4%
Applied egg-rr97.4%
Taylor expanded in x around 0 97.2%
*-commutative97.2%
Simplified97.2%
Final simplification97.2%
herbie shell --seed 2024079
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))