
(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 5 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 (fma x x x)) (- 1.0 (* x x))))))
float code(float x) {
return 0.5f * log1pf(((2.0f * fmaf(x, x, x)) / (1.0f - (x * x))));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * fma(x, x, x)) / Float32(Float32(1.0) - Float32(x * x))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot \mathsf{fma}\left(x, x, x\right)}{1 - x \cdot x}\right)
\end{array}
Initial program 99.7%
associate-/l*99.3%
Simplified99.3%
associate-/l*99.7%
flip--99.8%
associate-/r/99.8%
add-log-exp23.5%
*-commutative23.5%
exp-lft-sqr22.7%
log-prod22.7%
add-log-exp36.5%
add-log-exp99.8%
metadata-eval99.8%
Applied egg-rr99.8%
associate-*l/99.8%
count-299.8%
associate-*l*99.8%
+-commutative99.8%
distribute-rgt-in99.9%
unpow299.9%
*-lft-identity99.9%
unpow299.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x) :precision binary32 (* 0.5 (log1p (* (/ (+ x x) (- 1.0 (* x x))) (+ x 1.0)))))
float code(float x) {
return 0.5f * log1pf((((x + x) / (1.0f - (x * x))) * (x + 1.0f)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(x + x) / Float32(Float32(1.0) - Float32(x * x))) * Float32(x + Float32(1.0))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{x + x}{1 - x \cdot x} \cdot \left(x + 1\right)\right)
\end{array}
Initial program 99.7%
associate-/l*99.3%
Simplified99.3%
associate-/l*99.7%
flip--99.8%
associate-/r/99.8%
add-log-exp23.5%
*-commutative23.5%
exp-lft-sqr22.7%
log-prod22.7%
add-log-exp36.5%
add-log-exp99.8%
metadata-eval99.8%
Applied egg-rr99.8%
Final simplification99.8%
(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.3%
Simplified99.3%
Taylor expanded in x around 0 99.3%
Final simplification99.3%
(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 (+ 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.7%
associate-/l*99.3%
Simplified99.3%
log1p-udef23.4%
associate-/l*23.5%
+-commutative23.5%
associate-*l/23.4%
*-commutative23.4%
fma-def23.5%
Applied egg-rr23.5%
Taylor expanded in x around 0 19.6%
Taylor expanded in x around 0 97.1%
count-297.1%
Simplified97.1%
Final simplification97.1%
herbie shell --seed 2023172
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))