
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* (fabs x) (fabs x)) (fabs x)))
(t_1 (* (* t_0 (fabs x)) (fabs x))))
(fabs
(*
(/ 1.0 (sqrt (PI)))
(+
(+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0)) (* (/ 1.0 5.0) t_1))
(* (/ 1.0 21.0) (* (* t_1 (fabs x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) + \frac{1}{5} \cdot t\_1\right) + \frac{1}{21} \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* (fabs x) (fabs x)) (fabs x)))
(t_1 (* (* t_0 (fabs x)) (fabs x))))
(fabs
(*
(/ 1.0 (sqrt (PI)))
(+
(+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0)) (* (/ 1.0 5.0) t_1))
(* (/ 1.0 21.0) (* (* t_1 (fabs x)) (fabs x))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) + \frac{1}{5} \cdot t\_1\right) + \frac{1}{21} \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(fabs
(*
(pow (sqrt (PI)) -1.0)
(+
(+
(+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* x x) (fabs x))))
(* (pow 5.0 -1.0) (fabs (* (* (* (* x x) x) x) x))))
(* (pow 21.0 -1.0) (* (pow x 6.0) (fabs x)))))))\begin{array}{l}
\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(x \cdot x\right) \cdot \left|x\right|\right)\right) + {5}^{-1} \cdot \left|\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right|\right) + {21}^{-1} \cdot \left({x}^{6} \cdot \left|x\right|\right)\right)\right|
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
lift-*.f64N/A
pow2N/A
pow-powN/A
lower-pow.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-eval99.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x)
:precision binary64
(fabs
(*
(pow (sqrt (PI)) -1.0)
(+
(+
(* (fma (* 0.6666666666666666 x) x 2.0) x)
(* 0.2 (* (* (* x x) (* x x)) (fabs x))))
(* (pow 21.0 -1.0) (* (pow x 6.0) (fabs x)))))))\begin{array}{l}
\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \left(\left(\mathsf{fma}\left(0.6666666666666666 \cdot x, x, 2\right) \cdot x + 0.2 \cdot \left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left|x\right|\right)\right) + {21}^{-1} \cdot \left({x}^{6} \cdot \left|x\right|\right)\right)\right|
\end{array}
Initial program 99.8%
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
lift-*.f64N/A
pow2N/A
pow-powN/A
lower-pow.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
metadata-eval99.8
Applied rewrites99.8%
lift-+.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
metadata-evalN/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*r*N/A
distribute-rgt-outN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
pow2N/A
sqrt-pow1N/A
metadata-evalN/A
unpow1N/A
+-commutativeN/A
lift-fma.f64N/A
*-commutativeN/A
Applied rewrites75.7%
lift-/.f64N/A
metadata-eval75.7
Applied rewrites75.7%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lower-*.f64N/A
lift-*.f64N/A
lift-*.f6475.7
Applied rewrites75.7%
Final simplification75.7%
(FPCore (x)
:precision binary64
(fabs
(*
(pow (sqrt (PI)) -1.0)
(+
(+
(+ (* 2.0 (fabs x)) (* (* x x) (* x 0.6666666666666666)))
(* 0.2 (* (* (* x x) (* x x)) (fabs x))))
(*
(pow 21.0 -1.0)
(* (* (fabs (* (* (* (* x x) x) x) x)) (fabs x)) (fabs x)))))))\begin{array}{l}
\\
\left|{\left(\sqrt{\mathsf{PI}\left(\right)}\right)}^{-1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \left(x \cdot x\right) \cdot \left(x \cdot 0.6666666666666666\right)\right) + 0.2 \cdot \left(\left(\left(x \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left|x\right|\right)\right) + {21}^{-1} \cdot \left(\left(\left|\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f6499.8
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt75.4
lift-/.f64N/A
metadata-eval75.4
Applied rewrites75.4%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
lift-/.f64N/A
metadata-eval75.4
Applied rewrites75.4%
Final simplification75.4%
(FPCore (x) :precision binary64 (fabs (* (+ (fma (pow x 7.0) 0.047619047619047616 x) x) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\left(\mathsf{fma}\left({x}^{7}, 0.047619047619047616, x\right) + x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.8%
lift-*.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrtN/A
lower-*.f6499.8
lift-fabs.f64N/A
rem-sqrt-square-revN/A
sqrt-prodN/A
rem-square-sqrt75.4
lift-/.f64N/A
metadata-eval75.4
Applied rewrites75.4%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
associate-*l*N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-abs-revN/A
lift-*.f64N/A
lower-*.f6475.4
Applied rewrites75.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-fma.f64N/A
lower-pow.f64N/A
lower-fabs.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6498.1
Applied rewrites98.1%
Applied rewrites98.1%
Final simplification98.1%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 1.0)
(fabs
(*
(fma (* (* x x) 0.6666666666666666) x (* 2.0 x))
(sqrt (pow (PI) -1.0))))
(fabs (/ (* (pow x 7.0) 0.047619047619047616) (sqrt (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\left|\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.6666666666666666, x, 2 \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{{x}^{7} \cdot 0.047619047619047616}{\sqrt{\mathsf{PI}\left(\right)}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 1Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
rem-square-sqrtN/A
Applied rewrites98.9%
Applied rewrites98.9%
if 1 < (fabs.f64 x) Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6497.4
Applied rewrites97.4%
Applied rewrites97.5%
Applied rewrites97.5%
Final simplification98.5%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 1.0)
(fabs
(*
(fma (* (* x x) 0.6666666666666666) x (* 2.0 x))
(sqrt (pow (PI) -1.0))))
(fabs (* (pow x 7.0) (/ 0.047619047619047616 (sqrt (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\left|\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.6666666666666666, x, 2 \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|\\
\mathbf{else}:\\
\;\;\;\;\left|{x}^{7} \cdot \frac{0.047619047619047616}{\sqrt{\mathsf{PI}\left(\right)}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 1Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
rem-square-sqrtN/A
Applied rewrites98.9%
Applied rewrites98.9%
if 1 < (fabs.f64 x) Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around inf
associate-*r*N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6497.4
Applied rewrites97.4%
Applied rewrites97.4%
Final simplification98.4%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (pow (PI) -1.0))))
(if (<= (fabs x) 1.0)
(fabs (* (+ x x) t_0))
(fabs (* (* (* (* x x) 0.6666666666666666) x) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\\
\mathbf{if}\;\left|x\right| \leq 1:\\
\;\;\;\;\left|\left(x + x\right) \cdot t\_0\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\left(\left(\left(x \cdot x\right) \cdot 0.6666666666666666\right) \cdot x\right) \cdot t\_0\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 1Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6498.5
Applied rewrites98.5%
Applied rewrites98.5%
if 1 < (fabs.f64 x) Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
rem-square-sqrtN/A
Applied rewrites71.6%
Taylor expanded in x around inf
Applied rewrites71.6%
Final simplification89.5%
(FPCore (x) :precision binary64 (fabs (* (fma (* (* x x) 0.6666666666666666) x (* 2.0 x)) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.6666666666666666, x, 2 \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
rem-square-sqrtN/A
Applied rewrites89.9%
Applied rewrites89.9%
Final simplification89.9%
(FPCore (x) :precision binary64 (fabs (* (* (fma (* x x) 0.6666666666666666 2.0) x) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\left(\mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right) \cdot x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
rem-square-sqrtN/A
Applied rewrites89.9%
Final simplification89.9%
(FPCore (x) :precision binary64 (fabs (* (+ x x) (sqrt (pow (PI) -1.0)))))
\begin{array}{l}
\\
\left|\left(x + x\right) \cdot \sqrt{{\mathsf{PI}\left(\right)}^{-1}}\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6467.7
Applied rewrites67.7%
Applied rewrites67.7%
Final simplification67.7%
(FPCore (x) :precision binary64 (fabs 0.0))
double code(double x) {
return fabs(0.0);
}
real(8) function code(x)
real(8), intent (in) :: x
code = abs(0.0d0)
end function
public static double code(double x) {
return Math.abs(0.0);
}
def code(x): return math.fabs(0.0)
function code(x) return abs(0.0) end
function tmp = code(x) tmp = abs(0.0); end
code[x_] := N[Abs[0.0], $MachinePrecision]
\begin{array}{l}
\\
\left|0\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
rem-square-sqrtN/A
lower-sqrt.f64N/A
rem-square-sqrtN/A
lower-/.f64N/A
lower-PI.f6467.7
Applied rewrites67.7%
Applied rewrites67.7%
Applied rewrites0.0%
Final simplification4.3%
herbie shell --seed 2024331
(FPCore (x)
:name "Jmat.Real.erfi, branch x less than or equal to 0.5"
:precision binary64
:pre (<= x 0.5)
(fabs (* (/ 1.0 (sqrt (PI))) (+ (+ (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* (fabs x) (fabs x)) (fabs x)))) (* (/ 1.0 5.0) (* (* (* (* (fabs x) (fabs x)) (fabs x)) (fabs x)) (fabs x)))) (* (/ 1.0 21.0) (* (* (* (* (* (* (fabs x) (fabs x)) (fabs x)) (fabs x)) (fabs x)) (fabs x)) (fabs x)))))))