
(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 12 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%
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
/-lowering-/.f32N/A
--lowering--.f3299.7%
Applied egg-rr99.7%
Final simplification99.7%
(FPCore (x)
:precision binary32
(let* ((t_0
(*
(* x (* x (* x x)))
(+ 0.1111111111111111 (* (* x x) 0.13333333333333333)))))
(*
x
(/
(- 1.0 (* t_0 t_0))
(*
(-
1.0
(*
x
(*
x
(+
0.3333333333333333
(* (* x x) (+ 0.2 (* (* x x) 0.14285714285714285)))))))
(+ 1.0 t_0))))))
float code(float x) {
float t_0 = (x * (x * (x * x))) * (0.1111111111111111f + ((x * x) * 0.13333333333333333f));
return x * ((1.0f - (t_0 * t_0)) / ((1.0f - (x * (x * (0.3333333333333333f + ((x * x) * (0.2f + ((x * x) * 0.14285714285714285f))))))) * (1.0f + t_0)));
}
real(4) function code(x)
real(4), intent (in) :: x
real(4) :: t_0
t_0 = (x * (x * (x * x))) * (0.1111111111111111e0 + ((x * x) * 0.13333333333333333e0))
code = x * ((1.0e0 - (t_0 * t_0)) / ((1.0e0 - (x * (x * (0.3333333333333333e0 + ((x * x) * (0.2e0 + ((x * x) * 0.14285714285714285e0))))))) * (1.0e0 + t_0)))
end function
function code(x) t_0 = Float32(Float32(x * Float32(x * Float32(x * x))) * Float32(Float32(0.1111111111111111) + Float32(Float32(x * x) * Float32(0.13333333333333333)))) return Float32(x * Float32(Float32(Float32(1.0) - Float32(t_0 * t_0)) / Float32(Float32(Float32(1.0) - Float32(x * Float32(x * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285)))))))) * Float32(Float32(1.0) + t_0)))) end
function tmp = code(x) t_0 = (x * (x * (x * x))) * (single(0.1111111111111111) + ((x * x) * single(0.13333333333333333))); tmp = x * ((single(1.0) - (t_0 * t_0)) / ((single(1.0) - (x * (x * (single(0.3333333333333333) + ((x * x) * (single(0.2) + ((x * x) * single(0.14285714285714285)))))))) * (single(1.0) + t_0))); end
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.1111111111111111 + \left(x \cdot x\right) \cdot 0.13333333333333333\right)\\
x \cdot \frac{1 - t\_0 \cdot t\_0}{\left(1 - x \cdot \left(x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)\right) \cdot \left(1 + t\_0\right)}
\end{array}
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
flip-+N/A
div-invN/A
*-lowering-*.f32N/A
Applied egg-rr99.3%
Taylor expanded in x around 0
*-lowering-*.f32N/A
metadata-evalN/A
pow-sqrN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.4%
Simplified99.4%
un-div-invN/A
flip--N/A
associate-/l/N/A
/-lowering-/.f32N/A
Applied egg-rr99.4%
(FPCore (x)
:precision binary32
(*
x
(/
(-
1.0
(*
(* x (* x (* x x)))
(+ 0.1111111111111111 (* (* x x) 0.13333333333333333))))
(-
1.0
(*
x
(*
x
(+
0.3333333333333333
(* (* x x) (+ 0.2 (* (* x x) 0.14285714285714285))))))))))
float code(float x) {
return x * ((1.0f - ((x * (x * (x * x))) * (0.1111111111111111f + ((x * x) * 0.13333333333333333f)))) / (1.0f - (x * (x * (0.3333333333333333f + ((x * x) * (0.2f + ((x * x) * 0.14285714285714285f))))))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * ((1.0e0 - ((x * (x * (x * x))) * (0.1111111111111111e0 + ((x * x) * 0.13333333333333333e0)))) / (1.0e0 - (x * (x * (0.3333333333333333e0 + ((x * x) * (0.2e0 + ((x * x) * 0.14285714285714285e0))))))))
end function
function code(x) return Float32(x * Float32(Float32(Float32(1.0) - Float32(Float32(x * Float32(x * Float32(x * x))) * Float32(Float32(0.1111111111111111) + Float32(Float32(x * x) * Float32(0.13333333333333333))))) / Float32(Float32(1.0) - Float32(x * Float32(x * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285)))))))))) end
function tmp = code(x) tmp = x * ((single(1.0) - ((x * (x * (x * x))) * (single(0.1111111111111111) + ((x * x) * single(0.13333333333333333))))) / (single(1.0) - (x * (x * (single(0.3333333333333333) + ((x * x) * (single(0.2) + ((x * x) * single(0.14285714285714285))))))))); end
\begin{array}{l}
\\
x \cdot \frac{1 - \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right) \cdot \left(0.1111111111111111 + \left(x \cdot x\right) \cdot 0.13333333333333333\right)}{1 - x \cdot \left(x \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)}
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
flip-+N/A
div-invN/A
*-lowering-*.f32N/A
Applied egg-rr99.3%
Taylor expanded in x around 0
*-lowering-*.f32N/A
metadata-evalN/A
pow-sqrN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.4%
Simplified99.4%
*-commutativeN/A
*-lowering-*.f32N/A
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x)
:precision binary32
(+
x
(*
(* x (* x x))
(+
0.3333333333333333
(* (* x x) (+ 0.2 (* (* x x) 0.14285714285714285)))))))
float code(float x) {
return x + ((x * (x * x)) * (0.3333333333333333f + ((x * x) * (0.2f + ((x * x) * 0.14285714285714285f)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + ((x * (x * x)) * (0.3333333333333333e0 + ((x * x) * (0.2e0 + ((x * x) * 0.14285714285714285e0)))))
end function
function code(x) return Float32(x + Float32(Float32(x * Float32(x * x)) * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285))))))) end
function tmp = code(x) tmp = x + ((x * (x * x)) * (single(0.3333333333333333) + ((x * x) * (single(0.2) + ((x * x) * single(0.14285714285714285)))))); end
\begin{array}{l}
\\
x + \left(x \cdot \left(x \cdot x\right)\right) \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
+-commutativeN/A
distribute-rgt-inN/A
associate-+l+N/A
+-lowering-+.f32N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
Applied egg-rr99.3%
+-commutativeN/A
distribute-lft-inN/A
associate-*l*N/A
+-lowering-+.f32N/A
Applied egg-rr99.4%
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x)
:precision binary32
(+
x
(*
x
(*
(* x x)
(+
0.3333333333333333
(* (* x x) (+ 0.2 (* (* x x) 0.14285714285714285))))))))
float code(float x) {
return x + (x * ((x * x) * (0.3333333333333333f + ((x * x) * (0.2f + ((x * x) * 0.14285714285714285f))))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + (x * ((x * x) * (0.3333333333333333e0 + ((x * x) * (0.2e0 + ((x * x) * 0.14285714285714285e0))))))
end function
function code(x) return Float32(x + Float32(x * Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285)))))))) end
function tmp = code(x) tmp = x + (x * ((x * x) * (single(0.3333333333333333) + ((x * x) * (single(0.2) + ((x * x) * single(0.14285714285714285))))))); end
\begin{array}{l}
\\
x + x \cdot \left(\left(x \cdot x\right) \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
+-lowering-+.f32N/A
Applied egg-rr99.4%
Final simplification99.4%
(FPCore (x)
:precision binary32
(*
x
(+
1.0
(*
(* x x)
(+
0.3333333333333333
(* x (* x (+ 0.2 (* (* x x) 0.14285714285714285)))))))))
float code(float x) {
return x * (1.0f + ((x * x) * (0.3333333333333333f + (x * (x * (0.2f + ((x * x) * 0.14285714285714285f)))))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * (0.3333333333333333e0 + (x * (x * (0.2e0 + ((x * x) * 0.14285714285714285e0)))))))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(x * Float32(x * Float32(Float32(0.2) + Float32(Float32(x * x) * Float32(0.14285714285714285))))))))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * (single(0.3333333333333333) + (x * (x * (single(0.2) + ((x * x) * single(0.14285714285714285)))))))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(0.3333333333333333 + x \cdot \left(x \cdot \left(0.2 + \left(x \cdot x\right) \cdot 0.14285714285714285\right)\right)\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
unpow2N/A
associate-*l*N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.3%
Simplified99.3%
(FPCore (x) :precision binary32 (+ x (* x (* (* x x) (+ 0.3333333333333333 (* x (* x 0.2)))))))
float code(float x) {
return x + (x * ((x * x) * (0.3333333333333333f + (x * (x * 0.2f)))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + (x * ((x * x) * (0.3333333333333333e0 + (x * (x * 0.2e0)))))
end function
function code(x) return Float32(x + Float32(x * Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(x * Float32(x * Float32(0.2))))))) end
function tmp = code(x) tmp = x + (x * ((x * x) * (single(0.3333333333333333) + (x * (x * single(0.2)))))); end
\begin{array}{l}
\\
x + x \cdot \left(\left(x \cdot x\right) \cdot \left(0.3333333333333333 + x \cdot \left(x \cdot 0.2\right)\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.0%
Simplified99.0%
+-commutativeN/A
distribute-rgt-inN/A
*-lft-identityN/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
associate-*l*N/A
*-lowering-*.f32N/A
*-lowering-*.f3299.1%
Applied egg-rr99.1%
Final simplification99.1%
(FPCore (x) :precision binary32 (* x (+ 1.0 (* (* x x) (+ 0.3333333333333333 (* (* x x) 0.2))))))
float code(float x) {
return x * (1.0f + ((x * x) * (0.3333333333333333f + ((x * x) * 0.2f))));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * (0.3333333333333333e0 + ((x * x) * 0.2e0))))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(Float32(0.3333333333333333) + Float32(Float32(x * x) * Float32(0.2)))))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * (single(0.3333333333333333) + ((x * x) * single(0.2))))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot \left(0.3333333333333333 + \left(x \cdot x\right) \cdot 0.2\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-commutativeN/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3299.0%
Simplified99.0%
(FPCore (x) :precision binary32 (+ x (* (* x x) (* x 0.3333333333333333))))
float code(float x) {
return x + ((x * x) * (x * 0.3333333333333333f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x + ((x * x) * (x * 0.3333333333333333e0))
end function
function code(x) return Float32(x + Float32(Float32(x * x) * Float32(x * Float32(0.3333333333333333)))) end
function tmp = code(x) tmp = x + ((x * x) * (x * single(0.3333333333333333))); end
\begin{array}{l}
\\
x + \left(x \cdot x\right) \cdot \left(x \cdot 0.3333333333333333\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3298.5%
Simplified98.5%
+-commutativeN/A
distribute-lft-inN/A
*-rgt-identityN/A
+-lowering-+.f32N/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-lowering-*.f32N/A
*-lowering-*.f32N/A
*-commutativeN/A
*-lowering-*.f3298.5%
Applied egg-rr98.5%
Final simplification98.5%
(FPCore (x) :precision binary32 (* x (+ 1.0 (* (* x x) 0.3333333333333333))))
float code(float x) {
return x * (1.0f + ((x * x) * 0.3333333333333333f));
}
real(4) function code(x)
real(4), intent (in) :: x
code = x * (1.0e0 + ((x * x) * 0.3333333333333333e0))
end function
function code(x) return Float32(x * Float32(Float32(1.0) + Float32(Float32(x * x) * Float32(0.3333333333333333)))) end
function tmp = code(x) tmp = x * (single(1.0) + ((x * x) * single(0.3333333333333333))); end
\begin{array}{l}
\\
x \cdot \left(1 + \left(x \cdot x\right) \cdot 0.3333333333333333\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f32N/A
+-lowering-+.f32N/A
*-lowering-*.f32N/A
unpow2N/A
*-lowering-*.f3298.5%
Simplified98.5%
Final simplification98.5%
(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 2024160
(FPCore (x)
:name "Rust f32::atanh"
:precision binary32
(* 0.5 (log1p (/ (* 2.0 x) (- 1.0 x)))))