
(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
(*
(/ -1.0 (sqrt (PI)))
(fma
(pow x 6.0)
(* x 0.047619047619047616)
(fma 0.2 (pow x 5.0) (fma 0.6666666666666666 (pow x 3.0) (* 2.0 x)))))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \mathsf{fma}\left({x}^{6}, x \cdot 0.047619047619047616, \mathsf{fma}\left(0.2, {x}^{5}, \mathsf{fma}\left(0.6666666666666666, {x}^{3}, 2 \cdot x\right)\right)\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (PI))) (t_1 (/ -1.0 t_0)) (t_2 (* (* (* (* x x) x) x) x)))
(if (<=
(fabs
(*
t_1
(-
(-
(+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) (* (* x x) (fabs x))))
(* (/ -1.0 5.0) (fabs t_2)))
(* (/ -1.0 21.0) (* (fabs (* t_2 x)) (fabs x))))))
2e-8)
(fabs (* t_1 (* 2.0 x)))
(/ (fabs (sqrt (* 4.0 (* x x)))) t_0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
t_1 := \frac{-1}{t\_0}\\
t_2 := \left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\\
\mathbf{if}\;\left|t\_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) - \frac{-1}{5} \cdot \left|t\_2\right|\right) - \frac{-1}{21} \cdot \left(\left|t\_2 \cdot x\right| \cdot \left|x\right|\right)\right)\right| \leq 2 \cdot 10^{-8}:\\
\;\;\;\;\left|t\_1 \cdot \left(2 \cdot x\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|\sqrt{4 \cdot \left(x \cdot x\right)}\right|}{t\_0}\\
\end{array}
\end{array}
if (fabs.f64 (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 (PI.f64))) (+.f64 (+.f64 (+.f64 (*.f64 #s(literal 2 binary64) (fabs.f64 x)) (*.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)))) (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 5 binary64)) (*.f64 (*.f64 (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)))) (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 21 binary64)) (*.f64 (*.f64 (*.f64 (*.f64 (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)))))) < 2e-8Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6499.9
Applied rewrites99.9%
if 2e-8 < (fabs.f64 (*.f64 (/.f64 #s(literal 1 binary64) (sqrt.f64 (PI.f64))) (+.f64 (+.f64 (+.f64 (*.f64 #s(literal 2 binary64) (fabs.f64 x)) (*.f64 (/.f64 #s(literal 2 binary64) #s(literal 3 binary64)) (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)))) (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 5 binary64)) (*.f64 (*.f64 (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)))) (*.f64 (/.f64 #s(literal 1 binary64) #s(literal 21 binary64)) (*.f64 (*.f64 (*.f64 (*.f64 (*.f64 (*.f64 (fabs.f64 x) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)) (fabs.f64 x)))))) Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f647.3
Applied rewrites7.3%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
*-lft-identityN/A
rem-sqrt-squareN/A
Applied rewrites7.3%
Applied rewrites49.0%
Final simplification83.4%
(FPCore (x)
:precision binary64
(fabs
(*
(/ -1.0 (sqrt (PI)))
(*
(fma
(fma (- 0.2 (* -0.047619047619047616 (* x x))) (* x x) 0.6666666666666666)
(* x x)
2.0)
x))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(0.2 - -0.047619047619047616 \cdot \left(x \cdot x\right), x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(fabs
(*
(/ -1.0 (sqrt (PI)))
(*
(fma
(fma (fma 0.047619047619047616 (* x x) 0.2) (* x x) 0.6666666666666666)
(* x x)
2.0)
x))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.047619047619047616, x \cdot x, 0.2\right), x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x)
:precision binary64
(fabs
(*
(/ -1.0 (sqrt (PI)))
(*
(fma
(fma (* (* x x) 0.047619047619047616) (* x x) 0.6666666666666666)
(* x x)
2.0)
x))))\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(\left(x \cdot x\right) \cdot 0.047619047619047616, x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites99.5%
Final simplification99.5%
(FPCore (x)
:precision binary64
(/
(fabs
(*
(fma
(fma (fma (* x x) 0.047619047619047616 0.2) (* x x) 0.6666666666666666)
(* x x)
2.0)
x))
(sqrt (PI))))\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x\right|}{\sqrt{\mathsf{PI}\left(\right)}}
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
*-lft-identityN/A
rem-sqrt-squareN/A
Applied rewrites69.4%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.3
Applied rewrites99.3%
(FPCore (x) :precision binary64 (fabs (* (/ -1.0 (sqrt (PI))) (* (fma (fma 0.2 (* x x) 0.6666666666666666) (* x x) 2.0) x))))
\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(0.2, x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6494.9
Applied rewrites94.9%
Final simplification94.9%
(FPCore (x) :precision binary64 (/ (* (fma (fma (* x x) 0.2 0.6666666666666666) (* x x) 2.0) x) (sqrt (PI))))
\begin{array}{l}
\\
\frac{\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, 0.2, 0.6666666666666666\right), x \cdot x, 2\right) \cdot x}{\sqrt{\mathsf{PI}\left(\right)}}
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6494.9
Applied rewrites94.9%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
Applied rewrites94.4%
Applied rewrites34.7%
(FPCore (x) :precision binary64 (fabs (* (/ -1.0 (sqrt (PI))) (* (fma (* x x) 0.6666666666666666 2.0) x))))
\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(\mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right) \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f6490.8
Applied rewrites90.8%
Final simplification90.8%
(FPCore (x) :precision binary64 (fabs (* (/ -1.0 (sqrt (PI))) (* 2.0 x))))
\begin{array}{l}
\\
\left|\frac{-1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot \left(2 \cdot x\right)\right|
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
Final simplification69.9%
(FPCore (x) :precision binary64 (/ (fabs (+ x x)) (sqrt (PI))))
\begin{array}{l}
\\
\frac{\left|x + x\right|}{\sqrt{\mathsf{PI}\left(\right)}}
\end{array}
Initial program 99.8%
Applied rewrites99.9%
Taylor expanded in x around 0
lower-*.f6469.9
Applied rewrites69.9%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
*-lft-identityN/A
rem-sqrt-squareN/A
Applied rewrites69.4%
Applied rewrites69.4%
herbie shell --seed 2024353
(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)))))))