
(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.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(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.8%
associate-/l*99.1%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
metadata-eval99.1%
sub-neg99.1%
*-inverses99.1%
div-sub99.1%
associate-/r/99.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x) :precision binary32 (* 0.5 (+ x x)))
float code(float x) {
return 0.5f * (x + x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * (x + x)
end function
function code(x) return Float32(Float32(0.5) * Float32(x + x)) end
function tmp = code(x) tmp = single(0.5) * (x + x); end
\begin{array}{l}
\\
0.5 \cdot \left(x + x\right)
\end{array}
Initial program 99.8%
associate-/l*99.1%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
flip-+59.9%
associate-/r/59.6%
metadata-eval59.6%
sub-neg59.6%
inv-pow59.6%
inv-pow59.6%
pow-prod-up59.6%
metadata-eval59.6%
metadata-eval59.6%
sub-neg59.6%
metadata-eval59.6%
Applied egg-rr59.6%
associate-*l/59.8%
+-commutative59.8%
distribute-lft-in59.8%
metadata-eval59.8%
associate-*r/59.8%
metadata-eval59.8%
+-commutative59.8%
Simplified59.8%
Taylor expanded in x around 0 94.9%
Simplified94.9%
Taylor expanded in x around 0 95.4%
Simplified95.4%
Final simplification95.4%
(FPCore (x) :precision binary32 1.5)
float code(float x) {
return 1.5f;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 1.5e0
end function
function code(x) return Float32(1.5) end
function tmp = code(x) tmp = single(1.5); end
\begin{array}{l}
\\
1.5
\end{array}
Initial program 99.8%
associate-/l*99.1%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
metadata-eval99.1%
sub-neg99.1%
*-inverses99.1%
div-sub99.1%
associate-/l*99.8%
log1p-udef23.9%
add-cube-cbrt23.0%
log-prod22.9%
Applied egg-rr22.9%
log-prod22.9%
*-un-lft-identity22.9%
*-un-lft-identity22.9%
distribute-rgt-out22.9%
metadata-eval22.9%
Applied egg-rr22.9%
Taylor expanded in x around inf -0.0%
Simplified8.0%
Final simplification8.0%
herbie shell --seed 2023268
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))