
(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 (/ (* 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.9%
(FPCore (x) :precision binary32 (fma (+ (* (fma x (* x 0.14285714285714285) 0.2) (* x x)) 0.3333333333333333) (* x (* x x)) x))
float code(float x) {
return fmaf(((fmaf(x, (x * 0.14285714285714285f), 0.2f) * (x * x)) + 0.3333333333333333f), (x * (x * x)), x);
}
function code(x) return fma(Float32(Float32(fma(x, Float32(x * Float32(0.14285714285714285)), Float32(0.2)) * Float32(x * x)) + Float32(0.3333333333333333)), Float32(x * Float32(x * x)), x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot 0.14285714285714285, 0.2\right) \cdot \left(x \cdot x\right) + 0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f32N/A
Applied rewrites99.2%
Applied rewrites99.2%
(FPCore (x) :precision binary32 (fma (fma x (* x (fma x (* x 0.14285714285714285) 0.2)) 0.3333333333333333) (* x (* x x)) x))
float code(float x) {
return fmaf(fmaf(x, (x * fmaf(x, (x * 0.14285714285714285f), 0.2f)), 0.3333333333333333f), (x * (x * x)), x);
}
function code(x) return fma(fma(x, Float32(x * fma(x, Float32(x * Float32(0.14285714285714285)), Float32(0.2))), Float32(0.3333333333333333)), Float32(x * Float32(x * x)), x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.14285714285714285, 0.2\right), 0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f32N/A
Applied rewrites99.2%
(FPCore (x) :precision binary32 (fma (fma (* x x) 0.2 0.3333333333333333) (* x (* x x)) x))
float code(float x) {
return fmaf(fmaf((x * x), 0.2f, 0.3333333333333333f), (x * (x * x)), x);
}
function code(x) return fma(fma(Float32(x * x), Float32(0.2), Float32(0.3333333333333333)), Float32(x * Float32(x * x)), x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.2, 0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.1
Applied rewrites99.1%
(FPCore (x) :precision binary32 (fma 0.3333333333333333 (* x (* x x)) x))
float code(float x) {
return fmaf(0.3333333333333333f, (x * (x * x)), x);
}
function code(x) return fma(Float32(0.3333333333333333), Float32(x * Float32(x * x)), x) end
\begin{array}{l}
\\
\mathsf{fma}\left(0.3333333333333333, x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 99.9%
Taylor expanded in x around 0
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
lower-fma.f32N/A
cube-multN/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3298.7
Applied rewrites98.7%
(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.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f3297.1
Applied rewrites97.1%
Final simplification97.1%
herbie shell --seed 2024237
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))