(FPCore (r a t) :precision binary64 (* (* (/ (/ (/ 1.0 4.0) (PI)) (pow r 2.0)) a) (- (erf (/ r t)) (* (* (/ 2.0 (sqrt (PI))) (exp (/ (- (pow r 2.0)) (pow t 2.0)))) r))))
\begin{array}{l} \\ \left(\frac{\frac{\frac{1}{4}}{\mathsf{PI}\left(\right)}}{{r}^{2}} \cdot a\right) \cdot \left(\mathsf{erf}\left(\left(\frac{r}{t}\right)\right) - \left(\frac{2}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\frac{-{r}^{2}}{{t}^{2}}}\right) \cdot r\right) \end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
Alternative | Accuracy | Speedup |
---|
(FPCore (r a t) :precision binary64 (* (* (/ (/ (/ 1.0 4.0) (PI)) (pow r 2.0)) a) (- (erf (/ r t)) (* (* (/ 2.0 (sqrt (PI))) (exp (/ (- (pow r 2.0)) (pow t 2.0)))) r))))
\begin{array}{l} \\ \left(\frac{\frac{\frac{1}{4}}{\mathsf{PI}\left(\right)}}{{r}^{2}} \cdot a\right) \cdot \left(\mathsf{erf}\left(\left(\frac{r}{t}\right)\right) - \left(\frac{2}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\frac{-{r}^{2}}{{t}^{2}}}\right) \cdot r\right) \end{array}
(FPCore (r a t) :precision binary64 (/ (* (fma (/ r (exp (pow (/ t r) -2.0))) (/ -2.0 (sqrt (PI))) (erf (/ r t))) (/ (* 0.25 a) r)) (* (PI) r)))
\begin{array}{l} \\ \frac{\mathsf{fma}\left(\frac{r}{e^{{\left(\frac{t}{r}\right)}^{-2}}}, \frac{-2}{\sqrt{\mathsf{PI}\left(\right)}}, \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)\right) \cdot \frac{0.25 \cdot a}{r}}{\mathsf{PI}\left(\right) \cdot r} \end{array}
Initial program 99.1%
lift-*.f64
N/A
lift-/.f64
N/A
lift-/.f64
N/A
associate-/l/
N/A
associate-*l/
N/A
lower-/.f64
N/A
*-commutative
N/A
lower-*.f64
N/A
lift-/.f64
N/A
metadata-eval
N/A
lower-*.f64
99.2
lift-pow.f64
N/A
unpow2
N/A
lower-*.f64
99.2
Applied rewrites99.2%
Applied rewrites99.3%
(FPCore (r a t) :precision binary64 (let* ((t_1 (erf (/ r t)))) (if (<= r 0.0028) (* (/ (* a 0.25) (* (* r r) (PI))) (fma (* (sqrt (pow (PI) -1.0)) (fma (/ 2.0 t) (/ (* r r) t) -2.0)) r t_1)) (/ (/ (* (* 0.25 a) t_1) r) (* (PI) r)))))
\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)\\ \mathbf{if}\;r \leq 0.0028:\\ \;\;\;\;\frac{a \cdot 0.25}{\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)} \cdot \mathsf{fma}\left(\sqrt{{\mathsf{PI}\left(\right)}^{-1}} \cdot \mathsf{fma}\left(\frac{2}{t}, \frac{r \cdot r}{t}, -2\right), r, t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(0.25 \cdot a\right) \cdot t\_1}{r}}{\mathsf{PI}\left(\right) \cdot r}\\ \end{array} \end{array}
if r < 0.00279999999999999997
Initial program 99.0%
lift-*.f64
N/A
lift-/.f64
N/A
lift-/.f64
N/A
associate-/l/
N/A
associate-*l/
N/A
lower-/.f64
N/A
*-commutative
N/A
lower-*.f64
N/A
lift-/.f64
N/A
metadata-eval
N/A
lower-*.f64
99.0
lift-pow.f64
N/A
unpow2
N/A
lower-*.f64
99.0
Applied rewrites99.0%
Taylor expanded in r around 0
+-commutative
N/A
*-commutative
N/A
lower-fma.f64
N/A
Applied rewrites76.7%
if 0.00279999999999999997 < r
Initial program 99.2%
Applied rewrites99.4%
Taylor expanded in r around 0
associate-*r*
N/A
lower-*.f64
N/A
lower-*.f64
N/A
lower-erf.f64
N/A
lower-/.f64
93.4
Applied rewrites93.4%
Final simplification87.5%
(FPCore (r a t) :precision binary64 (* (/ (* a 0.25) (* (* r r) (PI))) (- (erf (/ r t)) (* (* (/ 2.0 (sqrt (PI))) (exp (/ (* (- r) r) (* t t)))) r))))
\begin{array}{l} \\ \frac{a \cdot 0.25}{\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)} \cdot \left(\mathsf{erf}\left(\left(\frac{r}{t}\right)\right) - \left(\frac{2}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\frac{\left(-r\right) \cdot r}{t \cdot t}}\right) \cdot r\right) \end{array}
Initial program 99.1%
lift-*.f64
N/A
lift-/.f64
N/A
lift-/.f64
N/A
associate-/l/
N/A
associate-*l/
N/A
lower-/.f64
N/A
*-commutative
N/A
lower-*.f64
N/A
lift-/.f64
N/A
metadata-eval
N/A
lower-*.f64
99.2
lift-pow.f64
N/A
unpow2
N/A
lower-*.f64
99.2
Applied rewrites99.2%
lift-neg.f64
N/A
lift-pow.f64
N/A
pow2
N/A
distribute-lft-neg-in
N/A
lower-*.f64
N/A
lower-neg.f64
99.2
lift-pow.f64
N/A
unpow2
N/A
lower-*.f64
99.2
Applied rewrites99.2%
(FPCore (r a t) :precision binary64 (let* ((t_1 (erf (/ r t))) (t_2 (* (PI) r))) (if (<= r 3.8e-5) (* (/ (fma (* -2.0 r) (sqrt (pow (PI) -1.0)) t_1) t_2) (/ (* 0.25 a) r)) (/ (/ (* (* 0.25 a) t_1) r) t_2))))
\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)\\ t_2 := \mathsf{PI}\left(\right) \cdot r\\ \mathbf{if}\;r \leq 3.8 \cdot 10^{-5}:\\ \;\;\;\;\frac{\mathsf{fma}\left(-2 \cdot r, \sqrt{{\mathsf{PI}\left(\right)}^{-1}}, t\_1\right)}{t\_2} \cdot \frac{0.25 \cdot a}{r}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(0.25 \cdot a\right) \cdot t\_1}{r}}{t\_2}\\ \end{array} \end{array}
if r < 3.8000000000000002e-5
Initial program 99.0%
Applied rewrites98.8%
Taylor expanded in t around inf
associate-*r/
N/A
*-commutative
N/A
metadata-eval
N/A
cancel-sign-sub-inv
N/A
*-commutative
N/A
associate-*l*
N/A
*-commutative
N/A
*-commutative
N/A
unpow2
N/A
associate-*r*
N/A
*-commutative
N/A
Applied rewrites76.0%
if 3.8000000000000002e-5 < r
Initial program 99.2%
Applied rewrites99.3%
Taylor expanded in r around 0
associate-*r*
N/A
lower-*.f64
N/A
lower-*.f64
N/A
lower-erf.f64
N/A
lower-/.f64
86.5
Applied rewrites86.5%
Final simplification84.0%
(FPCore (r a t) :precision binary64 (let* ((t_1 (erf (/ r t)))) (if (<= r 3.8e-5) (* (/ (* a 0.25) (* (* r r) (PI))) (fma (* -2.0 r) (sqrt (pow (PI) -1.0)) t_1)) (/ (/ (* (* 0.25 a) t_1) r) (* (PI) r)))))
\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)\\ \mathbf{if}\;r \leq 3.8 \cdot 10^{-5}:\\ \;\;\;\;\frac{a \cdot 0.25}{\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)} \cdot \mathsf{fma}\left(-2 \cdot r, \sqrt{{\mathsf{PI}\left(\right)}^{-1}}, t\_1\right)\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(0.25 \cdot a\right) \cdot t\_1}{r}}{\mathsf{PI}\left(\right) \cdot r}\\ \end{array} \end{array}
if r < 3.8000000000000002e-5
Initial program 99.0%
lift-*.f64
N/A
lift-/.f64
N/A
lift-/.f64
N/A
associate-/l/
N/A
associate-*l/
N/A
lower-/.f64
N/A
*-commutative
N/A
lower-*.f64
N/A
lift-/.f64
N/A
metadata-eval
N/A
lower-*.f64
98.9
lift-pow.f64
N/A
unpow2
N/A
lower-*.f64
98.9
Applied rewrites98.9%
Taylor expanded in r around 0
+-commutative
N/A
associate-*r*
N/A
lower-fma.f64
N/A
lower-*.f64
N/A
lower-sqrt.f64
N/A
lower-/.f64
N/A
lower-PI.f64
N/A
lower-erf.f64
N/A
lower-/.f64
76.0
Applied rewrites76.0%
if 3.8000000000000002e-5 < r
Initial program 99.2%
Applied rewrites99.3%
Taylor expanded in r around 0
associate-*r*
N/A
lower-*.f64
N/A
lower-*.f64
N/A
lower-erf.f64
N/A
lower-/.f64
86.5
Applied rewrites86.5%
Final simplification84.0%
(FPCore (r a t) :precision binary64 (let* ((t_1 (erf (/ r t))) (t_2 (* (PI) r))) (if (<= r 0.003) (/ (/ (* (* a 0.25) (fma (/ -2.0 (sqrt (PI))) (/ r (fma (/ r t) (/ r t) 1.0)) t_1)) r) t_2) (/ (/ (* (* 0.25 a) t_1) r) t_2))))
\begin{array}{l} \\ \begin{array}{l} t_1 := \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)\\ t_2 := \mathsf{PI}\left(\right) \cdot r\\ \mathbf{if}\;r \leq 0.003:\\ \;\;\;\;\frac{\frac{\left(a \cdot 0.25\right) \cdot \mathsf{fma}\left(\frac{-2}{\sqrt{\mathsf{PI}\left(\right)}}, \frac{r}{\mathsf{fma}\left(\frac{r}{t}, \frac{r}{t}, 1\right)}, t\_1\right)}{r}}{t\_2}\\ \mathbf{else}:\\ \;\;\;\;\frac{\frac{\left(0.25 \cdot a\right) \cdot t\_1}{r}}{t\_2}\\ \end{array} \end{array}
if r < 0.0030000000000000001
Initial program 99.0%
Applied rewrites98.9%
Taylor expanded in r around 0
+-commutative
N/A
unpow2
N/A
unpow2
N/A
times-frac
N/A
lower-fma.f64
N/A
lower-/.f64
N/A
lower-/.f64
79.4
Applied rewrites79.4%
if 0.0030000000000000001 < r
Initial program 99.2%
Applied rewrites99.4%
Taylor expanded in r around 0
associate-*r*
N/A
lower-*.f64
N/A
lower-*.f64
N/A
lower-erf.f64
N/A
lower-/.f64
93.4
Applied rewrites93.4%
(FPCore (r a t) :precision binary64 (/ (/ (* (* 0.25 a) (erf (/ r t))) r) (* (PI) r)))
\begin{array}{l} \\ \frac{\frac{\left(0.25 \cdot a\right) \cdot \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)}{r}}{\mathsf{PI}\left(\right) \cdot r} \end{array}
Initial program 99.1%
Applied rewrites99.2%
Taylor expanded in r around 0
associate-*r*
N/A
lower-*.f64
N/A
lower-*.f64
N/A
lower-erf.f64
N/A
lower-/.f64
74.2
Applied rewrites74.2%
(FPCore (r a t) :precision binary64 (/ (* a (erf (/ r t))) (* (* r (* (PI) 4.0)) r)))
\begin{array}{l} \\ \frac{a \cdot \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)}{\left(r \cdot \left(\mathsf{PI}\left(\right) \cdot 4\right)\right) \cdot r} \end{array}
Initial program 99.1%
Taylor expanded in r around 0
associate-*r/
N/A
*-commutative
N/A
unpow2
N/A
associate-*r*
N/A
*-commutative
N/A
times-frac
N/A
lower-*.f64
N/A
*-commutative
N/A
associate-/r*
N/A
lower-/.f64
N/A
lower-/.f64
N/A
lower-PI.f64
N/A
associate-*l/
N/A
lower-*.f64
N/A
lower-/.f64
N/A
lower-erf.f64
N/A
lower-/.f64
74.1
Applied rewrites74.1%
Applied rewrites74.2%
Final simplification74.2%
(FPCore (r a t) :precision binary64 (/ (* (* 0.25 a) (erf (/ r t))) (* (* r r) (PI))))
\begin{array}{l} \\ \frac{\left(0.25 \cdot a\right) \cdot \mathsf{erf}\left(\left(\frac{r}{t}\right)\right)}{\left(r \cdot r\right) \cdot \mathsf{PI}\left(\right)} \end{array}
Initial program 99.1%
Taylor expanded in r around 0
associate-*r/
N/A
*-commutative
N/A
unpow2
N/A
associate-*r*
N/A
*-commutative
N/A
times-frac
N/A
lower-*.f64
N/A
*-commutative
N/A
associate-/r*
N/A
lower-/.f64
N/A
lower-/.f64
N/A
lower-PI.f64
N/A
associate-*l/
N/A
lower-*.f64
N/A
lower-/.f64
N/A
lower-erf.f64
N/A
lower-/.f64
74.1
Applied rewrites74.1%
Applied rewrites74.2%
herbie shell --seed 1
(FPCore (r a t)
:name "1 / 4 / PI / r^2 * a * (erf(r / t) - 2 / sqrt(PI) * exp(- r^2 / t^2) * r)"
:precision binary64
:pre (and (and (and (<= 1e-10 r) (<= r 10000000000.0)) (and (<= 0.0 a) (<= a 1.0))) (and (<= 1e-6 t) (<= t 1.0)))
(* (* (/ (/ (/ 1.0 4.0) (PI)) (pow r 2.0)) a) (- (erf (/ r t)) (* (* (/ 2.0 (sqrt (PI))) (exp (/ (- (pow r 2.0)) (pow t 2.0)))) r))))