
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x)))
(t_1 (* (* t_0 t_0) t_0))
(t_2 (* (* t_1 t_0) t_0)))
(*
(* (/ 1.0 (sqrt (PI))) (exp (* (fabs x) (fabs x))))
(+
(+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
(* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x)))
(t_1 (* (* t_0 t_0) t_0))
(t_2 (* (* t_1 t_0) t_0)))
(*
(* (/ 1.0 (sqrt (PI))) (exp (* (fabs x) (fabs x))))
(+
(+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
(* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\mathsf{PI}\left(\right)}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x))))
(*
(-
(-
(/ (- (/ 0.5 (* x x)) -1.0) (fabs x))
(* (* (* (* (/ -1.0 (* x x)) t_0) t_0) t_0) (/ 3.0 4.0)))
(* (* (* (* (/ -1.0 (* (* x x) (* x x))) t_0) t_0) t_0) (/ 15.0 8.0)))
(exp (fma x x (- (log (sqrt (PI)))))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\left(\left(\frac{\frac{0.5}{x \cdot x} - -1}{\left|x\right|} - \left(\left(\left(\frac{-1}{x \cdot x} \cdot t\_0\right) \cdot t\_0\right) \cdot t\_0\right) \cdot \frac{3}{4}\right) - \left(\left(\left(\frac{-1}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)} \cdot t\_0\right) \cdot t\_0\right) \cdot t\_0\right) \cdot \frac{15}{8}\right) \cdot e^{\mathsf{fma}\left(x, x, -\log \left(\sqrt{\mathsf{PI}\left(\right)}\right)\right)}
\end{array}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
unpow3N/A
unpow2N/A
associate-/r*N/A
associate-*r/N/A
*-lft-identityN/A
associate-*l/N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*l/N/A
*-commutativeN/A
*-rgt-identityN/A
lower-/.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
pow-plusN/A
metadata-evalN/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow2N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
metadata-evalN/A
pow-prod-upN/A
pow-prod-downN/A
inv-powN/A
metadata-evalN/A
frac-timesN/A
Applied rewrites100.0%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
prod-expN/A
lower-exp.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-to-expN/A
rem-log-expN/A
lower-*.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
metadata-evalN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x))))
(*
(+
(* (/ (pow (fabs x) -5.0) (* x x)) (/ 15.0 8.0))
(-
(/ (- (/ 0.5 (* x x)) -1.0) (fabs x))
(* (* (/ -1.0 (fabs x)) (* (/ t_0 (* x x)) t_0)) (/ 3.0 4.0))))
(* (exp (* (fabs x) (fabs x))) (/ 1.0 (sqrt (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\left(\frac{{\left(\left|x\right|\right)}^{-5}}{x \cdot x} \cdot \frac{15}{8} + \left(\frac{\frac{0.5}{x \cdot x} - -1}{\left|x\right|} - \left(\frac{-1}{\left|x\right|} \cdot \left(\frac{t\_0}{x \cdot x} \cdot t\_0\right)\right) \cdot \frac{3}{4}\right)\right) \cdot \left(e^{\left|x\right| \cdot \left|x\right|} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right)
\end{array}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
unpow3N/A
unpow2N/A
associate-/r*N/A
associate-*r/N/A
*-lft-identityN/A
associate-*l/N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*l/N/A
*-commutativeN/A
*-rgt-identityN/A
lower-/.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-/.f64N/A
frac-timesN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-/.f64N/A
frac-timesN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
*-rgt-identityN/A
frac-2negN/A
mul-1-negN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-/.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x)
:precision binary64
(let* ((t_0 (/ 1.0 (fabs x))))
(*
(-
(-
(/ (- (/ 0.5 (* x x)) -1.0) (fabs x))
(* (* (/ -1.0 (fabs x)) (* (/ t_0 (* x x)) t_0)) (/ 3.0 4.0)))
(* (* (* (* (/ -1.0 (* (* x x) (* x x))) t_0) t_0) t_0) (/ 15.0 8.0)))
(* (exp (* (fabs x) (fabs x))) (/ 1.0 (sqrt (PI)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
\left(\left(\frac{\frac{0.5}{x \cdot x} - -1}{\left|x\right|} - \left(\frac{-1}{\left|x\right|} \cdot \left(\frac{t\_0}{x \cdot x} \cdot t\_0\right)\right) \cdot \frac{3}{4}\right) - \left(\left(\left(\frac{-1}{\left(x \cdot x\right) \cdot \left(x \cdot x\right)} \cdot t\_0\right) \cdot t\_0\right) \cdot t\_0\right) \cdot \frac{15}{8}\right) \cdot \left(e^{\left|x\right| \cdot \left|x\right|} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right)
\end{array}
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
+-commutativeN/A
unpow3N/A
unpow2N/A
associate-/r*N/A
associate-*r/N/A
*-lft-identityN/A
associate-*l/N/A
*-rgt-identityN/A
distribute-lft-inN/A
associate-*l/N/A
*-commutativeN/A
*-rgt-identityN/A
lower-/.f64N/A
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
pow3N/A
pow-plusN/A
metadata-evalN/A
lift-/.f64N/A
inv-powN/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
pow-powN/A
pow2N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
metadata-evalN/A
pow-prod-upN/A
pow-prod-downN/A
inv-powN/A
metadata-evalN/A
frac-timesN/A
Applied rewrites100.0%
lift-*.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
lift-/.f64N/A
frac-timesN/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
*-rgt-identityN/A
frac-2negN/A
mul-1-negN/A
lift-*.f64N/A
distribute-lft-neg-outN/A
lower-/.f64N/A
lift-/.f64N/A
un-div-invN/A
lower-/.f64N/A
lower-*.f64N/A
lower-neg.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (x) :precision binary64 (* (+ (* 0.75 (pow (fabs x) -5.0)) (/ (- (/ 0.5 (* x x)) -1.0) (fabs x))) (* (exp (* (fabs x) (fabs x))) (/ 1.0 (sqrt (PI))))))
\begin{array}{l}
\\
\left(0.75 \cdot {\left(\left|x\right|\right)}^{-5} + \frac{\frac{0.5}{x \cdot x} - -1}{\left|x\right|}\right) \cdot \left(e^{\left|x\right| \cdot \left|x\right|} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
frac-timesN/A
*-rgt-identityN/A
frac-2negN/A
distribute-lft-neg-inN/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around inf
*-lft-identityN/A
lft-mult-inverseN/A
associate-*r*N/A
distribute-rgt-inN/A
distribute-lft-inN/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites99.7%
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (* (- (/ 0.75 (pow (fabs x) 5.0)) (/ -1.0 (fabs x))) (* (exp (* (fabs x) (fabs x))) (/ 1.0 (sqrt (PI))))))
\begin{array}{l}
\\
\left(\frac{0.75}{{\left(\left|x\right|\right)}^{5}} - \frac{-1}{\left|x\right|}\right) \cdot \left(e^{\left|x\right| \cdot \left|x\right|} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
frac-timesN/A
*-rgt-identityN/A
frac-2negN/A
distribute-lft-neg-inN/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around inf
*-lft-identityN/A
lft-mult-inverseN/A
associate-*r*N/A
distribute-rgt-inN/A
distribute-lft-inN/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites99.7%
Final simplification99.7%
(FPCore (x) :precision binary64 (* (/ 0.5 (pow (fabs x) 3.0)) (* (exp (* (fabs x) (fabs x))) (/ 1.0 (sqrt (PI))))))
\begin{array}{l}
\\
\frac{0.5}{{\left(\left|x\right|\right)}^{3}} \cdot \left(e^{\left|x\right| \cdot \left|x\right|} \cdot \frac{1}{\sqrt{\mathsf{PI}\left(\right)}}\right)
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
frac-timesN/A
*-rgt-identityN/A
frac-2negN/A
distribute-lft-neg-inN/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around inf
*-lft-identityN/A
lft-mult-inverseN/A
associate-*r*N/A
distribute-rgt-inN/A
distribute-lft-inN/A
+-commutativeN/A
lower-+.f64N/A
Applied rewrites99.7%
Applied rewrites99.7%
Taylor expanded in x around 0
Applied rewrites33.7%
Final simplification33.7%
(FPCore (x) :precision binary64 (* (/ (/ 1.875 (pow x 6.0)) (fabs x)) (exp (* x x))))
double code(double x) {
return ((1.875 / pow(x, 6.0)) / fabs(x)) * exp((x * x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = ((1.875d0 / (x ** 6.0d0)) / abs(x)) * exp((x * x))
end function
public static double code(double x) {
return ((1.875 / Math.pow(x, 6.0)) / Math.abs(x)) * Math.exp((x * x));
}
def code(x): return ((1.875 / math.pow(x, 6.0)) / math.fabs(x)) * math.exp((x * x))
function code(x) return Float64(Float64(Float64(1.875 / (x ^ 6.0)) / abs(x)) * exp(Float64(x * x))) end
function tmp = code(x) tmp = ((1.875 / (x ^ 6.0)) / abs(x)) * exp((x * x)); end
code[x_] := N[(N[(N[(1.875 / N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] / N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(x * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\frac{1.875}{{x}^{6}}}{\left|x\right|} \cdot e^{x \cdot x}
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
frac-timesN/A
*-rgt-identityN/A
frac-2negN/A
distribute-lft-neg-inN/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
associate-/r*N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
unpow2N/A
sqr-absN/A
associate-*r*N/A
pow-plusN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
lower-pow.f64N/A
lower-fabs.f6416.5
Applied rewrites16.5%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
prod-expN/A
lower-exp.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-to-expN/A
rem-log-expN/A
lower-*.f64N/A
Applied rewrites16.5%
Taylor expanded in x around inf
unpow2N/A
lower-*.f6416.5
Applied rewrites16.5%
Final simplification16.5%
(FPCore (x) :precision binary64 (* (sqrt (/ 1.0 (PI))) (/ 1.875 (pow (fabs x) 7.0))))
\begin{array}{l}
\\
\sqrt{\frac{1}{\mathsf{PI}\left(\right)}} \cdot \frac{1.875}{{\left(\left|x\right|\right)}^{7}}
\end{array}
Initial program 100.0%
lift-*.f64N/A
lift-/.f64N/A
lift-*.f64N/A
lift-/.f64N/A
un-div-invN/A
frac-timesN/A
*-rgt-identityN/A
frac-2negN/A
distribute-lft-neg-inN/A
lower-/.f64N/A
Applied rewrites100.0%
Taylor expanded in x around 0
associate-/r*N/A
unpow3N/A
unpow2N/A
associate-/r*N/A
lower-/.f64N/A
associate-/l/N/A
lower-/.f64N/A
*-commutativeN/A
unpow2N/A
sqr-absN/A
associate-*r*N/A
pow-plusN/A
metadata-evalN/A
pow-plusN/A
metadata-evalN/A
lower-pow.f64N/A
lower-fabs.f6416.5
Applied rewrites16.5%
lift-*.f64N/A
*-commutativeN/A
lift-exp.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
sqr-absN/A
lift-*.f64N/A
lift-/.f64N/A
inv-powN/A
pow-to-expN/A
prod-expN/A
lower-exp.f64N/A
lift-*.f64N/A
lower-fma.f64N/A
lift-sqrt.f64N/A
pow1/2N/A
metadata-evalN/A
pow-to-expN/A
rem-log-expN/A
lower-*.f64N/A
Applied rewrites16.5%
Taylor expanded in x around 0
associate-*r*N/A
lower-*.f64N/A
Applied rewrites1.8%
Final simplification1.8%
herbie shell --seed 2024276
(FPCore (x)
:name "Jmat.Real.erfi, branch x greater than or equal to 5"
:precision binary64
:pre (>= x 0.5)
(* (* (/ 1.0 (sqrt (PI))) (exp (* (fabs x) (fabs x)))) (+ (+ (+ (/ 1.0 (fabs x)) (* (/ 1.0 2.0) (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 3.0 4.0) (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 15.0 8.0) (* (* (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))))