
(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 3 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 (+ (* (* (* x x) 0.6666666666666666) x) (* x 2.0))))
float code(float x) {
return 0.5f * ((((x * x) * 0.6666666666666666f) * x) + (x * 2.0f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * ((((x * x) * 0.6666666666666666e0) * x) + (x * 2.0e0))
end function
function code(x) return Float32(Float32(0.5) * Float32(Float32(Float32(Float32(x * x) * Float32(0.6666666666666666)) * x) + Float32(x * Float32(2.0)))) end
function tmp = code(x) tmp = single(0.5) * ((((x * x) * single(0.6666666666666666)) * x) + (x * single(2.0))); end
\begin{array}{l}
\\
0.5 \cdot \left(\left(\left(x \cdot x\right) \cdot 0.6666666666666666\right) \cdot x + x \cdot 2\right)
\end{array}
Initial program 93.0%
lift-/.f32N/A
lift--.f32N/A
flip--N/A
associate-/r/N/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lift-*.f32N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
lower-*.f32N/A
lower-*.f32N/A
Applied rewrites97.0%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lower-neg.f3295.3
Applied rewrites97.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3297.3
Applied rewrites96.5%
Applied rewrites98.7%
Final simplification98.7%
(FPCore (x) :precision binary32 (* 0.5 (* (+ (* (* x x) 0.6666666666666666) 2.0) x)))
float code(float x) {
return 0.5f * ((((x * x) * 0.6666666666666666f) + 2.0f) * x);
}
real(4) function code(x)
real(4), intent (in) :: x
code = 0.5e0 * ((((x * x) * 0.6666666666666666e0) + 2.0e0) * x)
end function
function code(x) return Float32(Float32(0.5) * Float32(Float32(Float32(Float32(x * x) * Float32(0.6666666666666666)) + Float32(2.0)) * x)) end
function tmp = code(x) tmp = single(0.5) * ((((x * x) * single(0.6666666666666666)) + single(2.0)) * x); end
\begin{array}{l}
\\
0.5 \cdot \left(\left(\left(x \cdot x\right) \cdot 0.6666666666666666 + 2\right) \cdot x\right)
\end{array}
Initial program 88.7%
lift-/.f32N/A
lift--.f32N/A
flip--N/A
associate-/r/N/A
+-commutativeN/A
distribute-lft-inN/A
lower-fma.f32N/A
lift-*.f32N/A
associate-/l*N/A
lower-*.f32N/A
lower-/.f32N/A
metadata-evalN/A
lower--.f32N/A
lower-*.f32N/A
lower-*.f32N/A
Applied rewrites97.0%
lift--.f32N/A
sub-negN/A
+-commutativeN/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lower-neg.f3295.3
Applied rewrites97.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3297.3
Applied rewrites97.6%
Applied rewrites98.7%
Final simplification98.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 94.7%
Taylor expanded in x around 0
lower-*.f3297.6
Applied rewrites97.6%
herbie shell --seed 2024308
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))