
(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 (* 0.5 (log1p (/ (* 2.0 (fma x x x)) (fma x (- x) 1.0)))))
float code(float x) {
return 0.5f * log1pf(((2.0f * fmaf(x, x, x)) / fmaf(x, -x, 1.0f)));
}
function code(x) return Float32(Float32(0.5) * log1p(Float32(Float32(Float32(2.0) * fma(x, x, x)) / fma(x, Float32(-x), Float32(1.0))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{log1p}\left(\frac{2 \cdot \mathsf{fma}\left(x, x, x\right)}{\mathsf{fma}\left(x, -x, 1\right)}\right)
\end{array}
Initial program 99.8%
flip--N/A
associate-/r/N/A
associate-*l/N/A
/-lowering-/.f32N/A
associate-*l*N/A
+-commutativeN/A
distribute-rgt-outN/A
*-lowering-*.f32N/A
*-lft-identityN/A
accelerator-lowering-fma.f32N/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f32N/A
neg-lowering-neg.f3299.9
Applied egg-rr99.9%
(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
(let* ((t_0 (fma (* x x) 0.2857142857142857 0.4)))
(*
0.5
(fma
(/
(fma x (* x (* x (* 0.4 (* x t_0)))) -0.4444444444444444)
(fma (* x x) t_0 -0.6666666666666666))
(* x (* x x))
(* 2.0 x)))))
float code(float x) {
float t_0 = fmaf((x * x), 0.2857142857142857f, 0.4f);
return 0.5f * fmaf((fmaf(x, (x * (x * (0.4f * (x * t_0)))), -0.4444444444444444f) / fmaf((x * x), t_0, -0.6666666666666666f)), (x * (x * x)), (2.0f * x));
}
function code(x) t_0 = fma(Float32(x * x), Float32(0.2857142857142857), Float32(0.4)) return Float32(Float32(0.5) * fma(Float32(fma(x, Float32(x * Float32(x * Float32(Float32(0.4) * Float32(x * t_0)))), Float32(-0.4444444444444444)) / fma(Float32(x * x), t_0, Float32(-0.6666666666666666))), Float32(x * Float32(x * x)), Float32(Float32(2.0) * x))) end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(x \cdot x, 0.2857142857142857, 0.4\right)\\
0.5 \cdot \mathsf{fma}\left(\frac{\mathsf{fma}\left(x, x \cdot \left(x \cdot \left(0.4 \cdot \left(x \cdot t\_0\right)\right)\right), -0.4444444444444444\right)}{\mathsf{fma}\left(x \cdot x, t\_0, -0.6666666666666666\right)}, x \cdot \left(x \cdot x\right), 2 \cdot x\right)
\end{array}
\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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
*-lowering-*.f3297.9
Simplified97.9%
flip-+N/A
/-lowering-/.f32N/A
Applied egg-rr97.9%
Taylor expanded in x around 0
Simplified98.2%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
associate-*r*N/A
accelerator-lowering-fma.f32N/A
Applied egg-rr98.3%
Final simplification98.3%
(FPCore (x)
:precision binary32
(*
0.5
(*
x
(fma
(* x x)
(fma
(* x x)
(fma (* x x) (fma (* x x) 0.34285714285714286 0.2857142857142857) 0.4)
0.6666666666666666)
2.0))))
float code(float x) {
return 0.5f * (x * fmaf((x * x), fmaf((x * x), fmaf((x * x), fmaf((x * x), 0.34285714285714286f, 0.2857142857142857f), 0.4f), 0.6666666666666666f), 2.0f));
}
function code(x) return Float32(Float32(0.5) * Float32(x * fma(Float32(x * x), fma(Float32(x * x), fma(Float32(x * x), fma(Float32(x * x), Float32(0.34285714285714286), Float32(0.2857142857142857)), Float32(0.4)), Float32(0.6666666666666666)), Float32(2.0)))) end
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.34285714285714286, 0.2857142857142857\right), 0.4\right), 0.6666666666666666\right), 2\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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
*-lowering-*.f3297.9
Simplified97.9%
flip-+N/A
/-lowering-/.f32N/A
Applied egg-rr97.9%
Taylor expanded in x around 0
unpow2N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f3297.9
Simplified97.9%
Taylor expanded in x around 0
+-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.2
Simplified98.2%
(FPCore (x)
:precision binary32
(*
0.5
(*
x
(fma
(* x x)
(fma
(* x x)
(fma (* x x) (fma (* x x) 0.17142857142857143 0.2857142857142857) 0.4)
0.6666666666666666)
2.0))))
float code(float x) {
return 0.5f * (x * fmaf((x * x), fmaf((x * x), fmaf((x * x), fmaf((x * x), 0.17142857142857143f, 0.2857142857142857f), 0.4f), 0.6666666666666666f), 2.0f));
}
function code(x) return Float32(Float32(0.5) * Float32(x * fma(Float32(x * x), fma(Float32(x * x), fma(Float32(x * x), fma(Float32(x * x), Float32(0.17142857142857143), Float32(0.2857142857142857)), Float32(0.4)), Float32(0.6666666666666666)), Float32(2.0)))) end
\begin{array}{l}
\\
0.5 \cdot \left(x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.17142857142857143, 0.2857142857142857\right), 0.4\right), 0.6666666666666666\right), 2\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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
*-lowering-*.f3297.9
Simplified97.9%
flip-+N/A
/-lowering-/.f32N/A
Applied egg-rr97.9%
Taylor expanded in x around 0
Simplified98.2%
Taylor expanded in x around 0
+-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.1
Simplified98.1%
(FPCore (x)
:precision binary32
(*
0.5
(fma
x
2.0
(*
(* x (* x x))
(fma x (* x (fma (* x x) 0.2857142857142857 0.4)) 0.6666666666666666)))))
float code(float x) {
return 0.5f * fmaf(x, 2.0f, ((x * (x * x)) * fmaf(x, (x * fmaf((x * x), 0.2857142857142857f, 0.4f)), 0.6666666666666666f)));
}
function code(x) return Float32(Float32(0.5) * fma(x, Float32(2.0), Float32(Float32(x * Float32(x * x)) * fma(x, Float32(x * fma(Float32(x * x), Float32(0.2857142857142857), Float32(0.4))), Float32(0.6666666666666666))))) end
\begin{array}{l}
\\
0.5 \cdot \mathsf{fma}\left(x, 2, \left(x \cdot \left(x \cdot x\right)\right) \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x \cdot x, 0.2857142857142857, 0.4\right), 0.6666666666666666\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
unpow2N/A
associate-*r*N/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
*-lowering-*.f3297.9
Simplified97.9%
+-commutativeN/A
distribute-lft-inN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
associate-*l*N/A
pow3N/A
*-lowering-*.f32N/A
Applied egg-rr98.0%
Final simplification98.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(Float32(x * 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 \cdot x, \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
*-commutativeN/A
+-commutativeN/A
distribute-lft1-inN/A
*-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
accelerator-lowering-fma.f32N/A
Simplified98.0%
(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.8%
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
accelerator-lowering-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f32N/A
unpow2N/A
*-lowering-*.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3297.7
Simplified97.7%
(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.8%
Taylor expanded in x around 0
distribute-rgt-inN/A
*-lft-identityN/A
+-commutativeN/A
associate-*l*N/A
unpow2N/A
unpow3N/A
accelerator-lowering-fma.f32N/A
cube-multN/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3297.2
Simplified97.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%
flip--N/A
associate-/r/N/A
associate-*l/N/A
/-lowering-/.f32N/A
associate-*l*N/A
+-commutativeN/A
distribute-rgt-outN/A
*-lowering-*.f32N/A
*-lft-identityN/A
accelerator-lowering-fma.f32N/A
metadata-evalN/A
sub-negN/A
+-commutativeN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f32N/A
neg-lowering-neg.f3299.9
Applied egg-rr99.9%
Taylor expanded in x around 0
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
accelerator-lowering-fma.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3297.2
Simplified97.2%
*-commutativeN/A
distribute-lft1-inN/A
*-lowering-*.f32N/A
associate-*l*N/A
accelerator-lowering-fma.f32N/A
*-lowering-*.f3297.1
Applied egg-rr97.1%
Final simplification97.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
Simplified95.4%
herbie shell --seed 2024199
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))