
(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.7%
Final simplification99.7%
(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.7%
associate-/l*99.2%
Simplified99.2%
Taylor expanded in x around 0 99.2%
Final simplification99.2%
(FPCore (x) :precision binary32 (* 0.5 (+ (* 2.0 x) (* 0.6666666666666666 (* x (* x x))))))
float code(float x) {
return 0.5f * ((2.0f * x) + (0.6666666666666666f * (x * (x * x))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * ((2.0e0 * x) + (0.6666666666666666e0 * (x * (x * x))))
end function
function code(x) return Float32(Float32(0.5) * Float32(Float32(Float32(2.0) * x) + Float32(Float32(0.6666666666666666) * Float32(x * Float32(x * x))))) end
function tmp = code(x) tmp = single(0.5) * ((single(2.0) * x) + (single(0.6666666666666666) * (x * (x * x)))); end
\begin{array}{l}
\\
0.5 \cdot \left(2 \cdot x + 0.6666666666666666 \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)
\end{array}
Initial program 99.7%
associate-/l*99.2%
Simplified99.2%
Taylor expanded in x around 0 97.0%
unpow397.0%
Applied egg-rr97.0%
Final simplification97.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.7%
associate-/l*99.2%
Simplified99.2%
log1p-udef24.8%
associate-/l*24.9%
add-cube-cbrt23.9%
log-prod23.9%
Applied egg-rr23.9%
pow1/323.9%
pow1/323.9%
pow-prod-up24.7%
metadata-eval24.7%
Applied egg-rr24.7%
Taylor expanded in x around 0 95.5%
*-commutative95.5%
Simplified95.5%
Final simplification95.5%
herbie shell --seed 2023240
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))