
(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 6 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 2.0) (- 1.0 (pow x 2.0))) (+ x 1.0)))))
float code(float x) {
return 0.5f * log1pf((((x * 2.0f) / (1.0f - powf(x, 2.0f))) * (x + 1.0f)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(x * Float32(2.0)) / Float32(Float32(1.0) - (x ^ Float32(2.0)))) * Float32(x + Float32(1.0))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x \cdot 2}{1 - {x}^{2}} \cdot \left(x + 1\right)\right)
\end{array}
Initial program 99.7%
flip--99.7%
associate-/r/99.8%
*-commutative99.8%
metadata-eval99.8%
pow299.8%
+-commutative99.8%
Applied egg-rr99.8%
(FPCore (x) :precision binary32 (* 0.5 (log1p (* (+ x 1.0) (/ (* x -2.0) (fma x x -1.0))))))
float code(float x) {
return 0.5f * log1pf(((x + 1.0f) * ((x * -2.0f) / fmaf(x, x, -1.0f))));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(x + Float32(1.0)) * Float32(Float32(x * Float32(-2.0)) / fma(x, x, Float32(-1.0)))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\left(x + 1\right) \cdot \frac{x \cdot -2}{\mathsf{fma}\left(x, x, -1\right)}\right)
\end{array}
Initial program 99.7%
flip--99.7%
associate-/r/99.8%
*-commutative99.8%
metadata-eval99.8%
pow299.8%
+-commutative99.8%
Applied egg-rr99.8%
associate-/l*99.7%
Applied egg-rr99.7%
associate-*r/99.8%
associate-*l/99.8%
*-commutative99.8%
metadata-eval99.8%
times-frac99.8%
*-commutative99.8%
neg-mul-199.8%
sub-neg99.8%
+-commutative99.8%
distribute-neg-in99.8%
remove-double-neg99.8%
unpow299.8%
metadata-eval99.8%
fma-undefine99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* 0.5 (log1p (/ (* x 2.0) (- 1.0 x)))))
float code(float x) {
return 0.5f * log1pf(((x * 2.0f) / (1.0f - x)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(x * Float32(2.0)) / Float32(Float32(1.0) - x)))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x \cdot 2}{1 - x}\right)
\end{array}
Initial program 99.7%
Final simplification99.7%
(FPCore (x) :precision binary32 (* 0.5 (log1p (* x (/ 2.0 (- 1.0 x))))))
float code(float x) {
return 0.5f * log1pf((x * (2.0f / (1.0f - x))));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(x * Float32(Float32(2.0) / Float32(Float32(1.0) - x))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(x \cdot \frac{2}{1 - x}\right)
\end{array}
Initial program 99.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
(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.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 97.8%
distribute-rgt-in97.9%
*-lft-identity97.9%
associate-*l*97.9%
unpow297.9%
unpow397.9%
Simplified97.9%
(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.7%
*-commutative99.7%
associate-/l*99.7%
Simplified99.7%
Taylor expanded in x around 0 96.0%
herbie shell --seed 2024137
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))