
(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 (* 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.9%
(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.9%
add-log-exp18.9%
*-un-lft-identity18.9%
log-prod18.9%
metadata-eval18.9%
add-log-exp99.9%
associate-/l*99.9%
Applied egg-rr99.9%
+-lft-identity99.9%
associate-*r/99.9%
*-lft-identity99.9%
associate-*l/99.8%
associate-/r/99.4%
div-sub99.4%
sub-neg99.4%
associate-/r*99.4%
metadata-eval99.4%
*-commutative99.4%
associate-/r*99.4%
*-inverses99.4%
metadata-eval99.4%
metadata-eval99.4%
Simplified99.4%
(FPCore (x) :precision binary32 (+ x (* 0.3333333333333333 (pow x 3.0))))
float code(float x) {
return x + (0.3333333333333333f * powf(x, 3.0f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + (0.3333333333333333e0 * (x ** 3.0e0))
end function
function code(x) return Float32(x + Float32(Float32(0.3333333333333333) * (x ^ Float32(3.0)))) end
function tmp = code(x) tmp = x + (single(0.3333333333333333) * (x ^ single(3.0))); end
\begin{array}{l}
\\
x + 0.3333333333333333 \cdot {x}^{3}
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 98.8%
distribute-rgt-in98.8%
*-lft-identity98.8%
associate-*l*98.8%
unpow298.8%
unpow398.8%
Simplified98.8%
(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 x end
function tmp = code(x) tmp = x; end
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around 0 98.0%
herbie shell --seed 2024177
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))