
(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.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ 2.0 (+ (/ 1.0 x) -1.0)))))
float code(float x) {
return 0.5f * log1pf((2.0f / ((1.0f / x) + -1.0f)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(2.0) / Float32(Float32(Float32(1.0) / x) + Float32(-1.0))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2}{\frac{1}{x} + -1}\right)
\end{array}
Initial program 99.8%
associate-/l*99.0%
div-sub99.0%
sub-neg99.0%
*-inverses99.0%
metadata-eval99.0%
Simplified99.0%
Final simplification99.0%
(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.8%
associate-/l*99.0%
div-sub99.0%
sub-neg99.0%
*-inverses99.0%
metadata-eval99.0%
Simplified99.0%
flip-+55.3%
associate-/r/55.2%
metadata-eval55.2%
sub-neg55.2%
inv-pow55.2%
inv-pow55.2%
pow-prod-up55.0%
metadata-eval55.0%
metadata-eval55.0%
sub-neg55.0%
metadata-eval55.0%
Applied egg-rr55.0%
associate-*l/55.2%
+-commutative55.2%
distribute-lft-in55.2%
metadata-eval55.2%
associate-*r/55.2%
metadata-eval55.2%
+-commutative55.2%
Simplified55.2%
Taylor expanded in x around 0 96.3%
distribute-lft-out96.3%
unpow296.3%
distribute-rgt1-in96.2%
Simplified96.2%
Taylor expanded in x around 0 96.7%
*-commutative96.7%
Simplified96.7%
Final simplification96.7%
herbie shell --seed 2024010
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))