
(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 (cast (! :precision binary64 (* 0.5 (log1p (* (/ x (- 1.0 x)) 2.0))))))
float code(float x) {
double tmp = 0.5 * log1p(((((double) x) / (1.0 - ((double) x))) * 2.0));
return (float) tmp;
}
function code(x) tmp = Float64(0.5 * log1p(Float64(Float64(Float64(x) / Float64(1.0 - Float64(x))) * 2.0))) return Float32(tmp) end
\begin{array}{l}
\\
\langle \left( 0.5 \cdot \mathsf{log1p}\left(\frac{x}{1 - x} \cdot 2\right) \right)_{\text{binary64}} \rangle_{\text{binary32}}
\end{array}
Initial program 100.0%
Final simplification100.0%
(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.7%
Simplified99.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(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.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* 0.5 (* x (- -2.0))))
float code(float x) {
return 0.5f * (x * -(-2.0f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * (x * -(-2.0e0))
end function
function code(x) return Float32(Float32(0.5) * Float32(x * Float32(-Float32(-2.0)))) end
function tmp = code(x) tmp = single(0.5) * (x * -single(-2.0)); end
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \left(--2\right)\right)
\end{array}
Initial program 99.8%
associate-*l/99.7%
Simplified99.7%
Applied egg-rr23.9%
Taylor expanded in x around 0 96.6%
Final simplification96.6%
herbie shell --seed 2023297
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))