
(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 11 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 (* (log1p (/ (* x 2.0) (- 1.0 x))) 0.5))
float code(float x) {
return log1pf(((x * 2.0f) / (1.0f - x))) * 0.5f;
}
function code(x) return Float32(log1p(Float32(Float32(x * Float32(2.0)) / Float32(Float32(1.0) - x))) * Float32(0.5)) end
\begin{array}{l}
\\
\mathsf{log1p}\left(\frac{x \cdot 2}{1 - x}\right) \cdot 0.5
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x) :precision binary32 (* (log1p (* (/ -2.0 (- x 1.0)) x)) 0.5))
float code(float x) {
return log1pf(((-2.0f / (x - 1.0f)) * x)) * 0.5f;
}
function code(x) return Float32(log1p(Float32(Float32(Float32(-2.0) / Float32(x - Float32(1.0))) * x)) * Float32(0.5)) end
\begin{array}{l}
\\
\mathsf{log1p}\left(\frac{-2}{x - 1} \cdot x\right) \cdot 0.5
\end{array}
Initial program 99.8%
lift-/.f32N/A
lift-*.f32N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-*.f32N/A
frac-2negN/A
lower-/.f32N/A
metadata-evalN/A
neg-sub0N/A
lift--.f32N/A
sub-negN/A
+-commutativeN/A
associate--r+N/A
neg-sub0N/A
remove-double-negN/A
lower--.f3299.7
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x)
:precision binary32
(*
(/
x
(fma
(fma (fma (* x x) 0.14285714285714285 0.2) (* x x) 0.3333333333333333)
(* x x)
-1.0))
(fma
(* (* (* (fma (* x x) 0.13333333333333333 0.1111111111111111) x) x) x)
x
-1.0)))
float code(float x) {
return (x / fmaf(fmaf(fmaf((x * x), 0.14285714285714285f, 0.2f), (x * x), 0.3333333333333333f), (x * x), -1.0f)) * fmaf((((fmaf((x * x), 0.13333333333333333f, 0.1111111111111111f) * x) * x) * x), x, -1.0f);
}
function code(x) return Float32(Float32(x / fma(fma(fma(Float32(x * x), Float32(0.14285714285714285), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333)), Float32(x * x), Float32(-1.0))) * fma(Float32(Float32(Float32(fma(Float32(x * x), Float32(0.13333333333333333), Float32(0.1111111111111111)) * x) * x) * x), x, Float32(-1.0))) end
\begin{array}{l}
\\
\frac{x}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.14285714285714285, 0.2\right), x \cdot x, 0.3333333333333333\right), x \cdot x, -1\right)} \cdot \mathsf{fma}\left(\left(\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, 0.1111111111111111\right) \cdot x\right) \cdot x\right) \cdot x, x, -1\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.5
Applied rewrites99.5%
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites99.7%
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x)
:precision binary32
(*
(/
(fma
(* (* (* (fma (* x x) 0.13333333333333333 0.1111111111111111) x) x) x)
x
-1.0)
(fma
(fma (fma (* x x) 0.14285714285714285 0.2) (* x x) 0.3333333333333333)
(* x x)
-1.0))
x))
float code(float x) {
return (fmaf((((fmaf((x * x), 0.13333333333333333f, 0.1111111111111111f) * x) * x) * x), x, -1.0f) / fmaf(fmaf(fmaf((x * x), 0.14285714285714285f, 0.2f), (x * x), 0.3333333333333333f), (x * x), -1.0f)) * x;
}
function code(x) return Float32(Float32(fma(Float32(Float32(Float32(fma(Float32(x * x), Float32(0.13333333333333333), Float32(0.1111111111111111)) * x) * x) * x), x, Float32(-1.0)) / fma(fma(fma(Float32(x * x), Float32(0.14285714285714285), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333)), Float32(x * x), Float32(-1.0))) * x) end
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\left(\left(\mathsf{fma}\left(x \cdot x, 0.13333333333333333, 0.1111111111111111\right) \cdot x\right) \cdot x\right) \cdot x, x, -1\right)}{\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.14285714285714285, 0.2\right), x \cdot x, 0.3333333333333333\right), x \cdot x, -1\right)} \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.5
Applied rewrites99.5%
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites99.7%
Applied rewrites99.6%
Final simplification99.6%
(FPCore (x) :precision binary32 (fma (* (* (fma (fma 0.14285714285714285 (* x x) 0.2) (* x x) 0.3333333333333333) x) x) x x))
float code(float x) {
return fmaf(((fmaf(fmaf(0.14285714285714285f, (x * x), 0.2f), (x * x), 0.3333333333333333f) * x) * x), x, x);
}
function code(x) return fma(Float32(Float32(fma(fma(Float32(0.14285714285714285), Float32(x * x), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333)) * x) * x), x, x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(0.14285714285714285, x \cdot x, 0.2\right), x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x, x, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.5
Applied rewrites99.5%
Applied rewrites99.6%
(FPCore (x) :precision binary32 (* (fma (fma (fma 0.14285714285714285 (* x x) 0.2) (* x x) 0.3333333333333333) (* x x) 1.0) x))
float code(float x) {
return fmaf(fmaf(fmaf(0.14285714285714285f, (x * x), 0.2f), (x * x), 0.3333333333333333f), (x * x), 1.0f) * x;
}
function code(x) return Float32(fma(fma(fma(Float32(0.14285714285714285), Float32(x * x), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333)), Float32(x * x), Float32(1.0)) * x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.14285714285714285, x \cdot x, 0.2\right), x \cdot x, 0.3333333333333333\right), x \cdot x, 1\right) \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.5
Applied rewrites99.5%
(FPCore (x) :precision binary32 (fma (* (* (fma 0.2 (* x x) 0.3333333333333333) x) x) x x))
float code(float x) {
return fmaf(((fmaf(0.2f, (x * x), 0.3333333333333333f) * x) * x), x, x);
}
function code(x) return fma(Float32(Float32(fma(Float32(0.2), Float32(x * x), Float32(0.3333333333333333)) * x) * x), x, x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\mathsf{fma}\left(0.2, x \cdot x, 0.3333333333333333\right) \cdot x\right) \cdot x, x, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.1
Applied rewrites99.1%
Applied rewrites99.2%
(FPCore (x) :precision binary32 (* (fma (fma 0.2 (* x x) 0.3333333333333333) (* x x) 1.0) x))
float code(float x) {
return fmaf(fmaf(0.2f, (x * x), 0.3333333333333333f), (x * x), 1.0f) * x;
}
function code(x) return Float32(fma(fma(Float32(0.2), Float32(x * x), Float32(0.3333333333333333)), Float32(x * x), Float32(1.0)) * x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(0.2, x \cdot x, 0.3333333333333333\right), x \cdot x, 1\right) \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.1
Applied rewrites99.1%
(FPCore (x) :precision binary32 (fma (* (* x x) 0.3333333333333333) x x))
float code(float x) {
return fmaf(((x * x) * 0.3333333333333333f), x, x);
}
function code(x) return fma(Float32(Float32(x * x) * Float32(0.3333333333333333)), x, x) end
\begin{array}{l}
\\
\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.3333333333333333, x, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3298.4
Applied rewrites98.4%
Applied rewrites98.5%
Final simplification98.5%
(FPCore (x) :precision binary32 (* (fma (* x x) 0.3333333333333333 1.0) x))
float code(float x) {
return fmaf((x * x), 0.3333333333333333f, 1.0f) * x;
}
function code(x) return Float32(fma(Float32(x * x), Float32(0.3333333333333333), Float32(1.0)) * x) end
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot x, 0.3333333333333333, 1\right) \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f3298.4
Applied rewrites98.4%
(FPCore (x) :precision binary32 (* 1.0 x))
float code(float x) {
return 1.0f * x;
}
real(4) function code(x)
real(4), intent (in) :: x
code = 1.0e0 * x
end function
function code(x) return Float32(Float32(1.0) * x) end
function tmp = code(x) tmp = single(1.0) * x; end
\begin{array}{l}
\\
1 \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f32N/A
unpow2N/A
lower-*.f3299.5
Applied rewrites99.5%
Taylor expanded in x around 0
Applied rewrites96.5%
herbie shell --seed 2024235
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))