
(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 10 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.8%
(FPCore (x) :precision binary32 (* 0.5 (log1p (* x (/ 2.0 (- 1.0 x))))))
float code(float x) {
return 0.5f * log1pf((x * (2.0f / (1.0f - x))));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(x * Float32(Float32(2.0) / Float32(Float32(1.0) - x))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(x \cdot \frac{2}{1 - x}\right)
\end{array}
Initial program 99.8%
frac-2negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
associate-/l*N/A
*-lowering-*.f32N/A
neg-lowering-neg.f32N/A
/-lowering-/.f32N/A
neg-sub0N/A
associate--r-N/A
metadata-evalN/A
+-commutativeN/A
+-lowering-+.f3299.8
Applied egg-rr99.8%
distribute-lft-neg-outN/A
distribute-rgt-neg-inN/A
frac-2negN/A
distribute-frac-neg2N/A
remove-double-negN/A
*-lowering-*.f32N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
/-lowering-/.f32N/A
+-commutativeN/A
distribute-neg-inN/A
metadata-evalN/A
unsub-negN/A
--lowering--.f3299.8
Applied egg-rr99.8%
(FPCore (x)
:precision binary32
(+
x
(*
x
(*
(* x x)
(fma (fma x (* x 0.14285714285714285) 0.2) (* x x) 0.3333333333333333)))))
float code(float x) {
return x + (x * ((x * x) * fmaf(fmaf(x, (x * 0.14285714285714285f), 0.2f), (x * x), 0.3333333333333333f)));
}
function code(x) return Float32(x + Float32(x * Float32(Float32(x * x) * fma(fma(x, Float32(x * Float32(0.14285714285714285)), Float32(0.2)), Float32(x * x), Float32(0.3333333333333333))))) end
\begin{array}{l}
\\
x + x \cdot \left(\left(x \cdot x\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(x, x \cdot 0.14285714285714285, 0.2\right), x \cdot x, 0.3333333333333333\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f3298.9
Simplified98.9%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-lft-identityN/A
accelerator-lowering-fma.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f3299.0
Applied egg-rr99.0%
+-lowering-+.f32N/A
associate-*r*N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f3299.0
Applied egg-rr99.0%
Final simplification99.0%
(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.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f3298.9
Simplified98.9%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
*-lft-identityN/A
accelerator-lowering-fma.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f3299.0
Applied egg-rr99.0%
(FPCore (x) :precision binary32 (* x (fma (* x x) (fma (* x x) (fma (* x x) 0.14285714285714285 0.2) 0.3333333333333333) 1.0)))
float code(float x) {
return x * fmaf((x * x), fmaf((x * x), fmaf((x * x), 0.14285714285714285f, 0.2f), 0.3333333333333333f), 1.0f);
}
function code(x) return Float32(x * fma(Float32(x * x), fma(Float32(x * x), fma(Float32(x * x), Float32(0.14285714285714285), Float32(0.2)), Float32(0.3333333333333333)), Float32(1.0))) end
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.14285714285714285, 0.2\right), 0.3333333333333333\right), 1\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f3298.9
Simplified98.9%
(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(x, Float32(x * 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 0.2, 0.3333333333333333\right), x \cdot \left(x \cdot x\right), x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f3298.6
Simplified98.6%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
unpow3N/A
*-lft-identityN/A
accelerator-lowering-fma.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f32N/A
cube-multN/A
*-lowering-*.f32N/A
*-lowering-*.f3298.7
Applied egg-rr98.7%
(FPCore (x) :precision binary32 (* x (fma (* x x) (fma (* x x) 0.2 0.3333333333333333) 1.0)))
float code(float x) {
return x * fmaf((x * x), fmaf((x * x), 0.2f, 0.3333333333333333f), 1.0f);
}
function code(x) return Float32(x * fma(Float32(x * x), fma(Float32(x * x), Float32(0.2), Float32(0.3333333333333333)), Float32(1.0))) end
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.2, 0.3333333333333333\right), 1\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f3298.6
Simplified98.6%
(FPCore (x) :precision binary32 (fma (* x (* x x)) 0.3333333333333333 x))
float code(float x) {
return fmaf((x * (x * x)), 0.3333333333333333f, x);
}
function code(x) return fma(Float32(x * Float32(x * x)), Float32(0.3333333333333333), x) end
\begin{array}{l}
\\
\mathsf{fma}\left(x \cdot \left(x \cdot x\right), 0.3333333333333333, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f3298.1
Simplified98.1%
distribute-lft-inN/A
associate-*r*N/A
associate-*r*N/A
cube-multN/A
*-rgt-identityN/A
accelerator-lowering-fma.f32N/A
cube-multN/A
*-lowering-*.f32N/A
*-lowering-*.f3298.2
Applied egg-rr98.2%
(FPCore (x) :precision binary32 (* x (fma x (* x 0.3333333333333333) 1.0)))
float code(float x) {
return x * fmaf(x, (x * 0.3333333333333333f), 1.0f);
}
function code(x) return Float32(x * fma(x, Float32(x * Float32(0.3333333333333333)), Float32(1.0))) end
\begin{array}{l}
\\
x \cdot \mathsf{fma}\left(x, x \cdot 0.3333333333333333, 1\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-commutativeN/A
*-commutativeN/A
unpow2N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f3298.1
Simplified98.1%
(FPCore (x) :precision binary32 x)
float code(float x) {
return x;
}
real(4) function code(x)
real(4), intent (in) :: x
code = x
end function
function code(x) return x end
function tmp = code(x) tmp = x; end
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Simplified96.6%
herbie shell --seed 2024198
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))