
(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))))))))
double code(double x) {
double t_0 = (fabs(x) * fabs(x)) * fabs(x);
double t_1 = (t_0 * fabs(x)) * fabs(x);
return fabs(((1.0 / sqrt(((double) M_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))))));
}
public static double code(double x) {
double t_0 = (Math.abs(x) * Math.abs(x)) * Math.abs(x);
double t_1 = (t_0 * Math.abs(x)) * Math.abs(x);
return Math.abs(((1.0 / Math.sqrt(Math.PI)) * ((((2.0 * Math.abs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * Math.abs(x)) * Math.abs(x))))));
}
def code(x): t_0 = (math.fabs(x) * math.fabs(x)) * math.fabs(x) t_1 = (t_0 * math.fabs(x)) * math.fabs(x) return math.fabs(((1.0 / math.sqrt(math.pi)) * ((((2.0 * math.fabs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * math.fabs(x)) * math.fabs(x))))))
function code(x) t_0 = Float64(Float64(abs(x) * abs(x)) * abs(x)) t_1 = Float64(Float64(t_0 * abs(x)) * abs(x)) return abs(Float64(Float64(1.0 / sqrt(pi)) * Float64(Float64(Float64(Float64(2.0 * abs(x)) + Float64(Float64(2.0 / 3.0) * t_0)) + Float64(Float64(1.0 / 5.0) * t_1)) + Float64(Float64(1.0 / 21.0) * Float64(Float64(t_1 * abs(x)) * abs(x)))))) end
function tmp = code(x) t_0 = (abs(x) * abs(x)) * abs(x); t_1 = (t_0 * abs(x)) * abs(x); tmp = abs(((1.0 / sqrt(pi)) * ((((2.0 * abs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * abs(x)) * abs(x)))))); end
code[x_] := Block[{t$95$0 = N[(N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(2.0 * N[Abs[x], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 5.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 21.0), $MachinePrecision] * N[(N[(t$95$1 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\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{\pi}} \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 5 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))))))))
double code(double x) {
double t_0 = (fabs(x) * fabs(x)) * fabs(x);
double t_1 = (t_0 * fabs(x)) * fabs(x);
return fabs(((1.0 / sqrt(((double) M_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))))));
}
public static double code(double x) {
double t_0 = (Math.abs(x) * Math.abs(x)) * Math.abs(x);
double t_1 = (t_0 * Math.abs(x)) * Math.abs(x);
return Math.abs(((1.0 / Math.sqrt(Math.PI)) * ((((2.0 * Math.abs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * Math.abs(x)) * Math.abs(x))))));
}
def code(x): t_0 = (math.fabs(x) * math.fabs(x)) * math.fabs(x) t_1 = (t_0 * math.fabs(x)) * math.fabs(x) return math.fabs(((1.0 / math.sqrt(math.pi)) * ((((2.0 * math.fabs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * math.fabs(x)) * math.fabs(x))))))
function code(x) t_0 = Float64(Float64(abs(x) * abs(x)) * abs(x)) t_1 = Float64(Float64(t_0 * abs(x)) * abs(x)) return abs(Float64(Float64(1.0 / sqrt(pi)) * Float64(Float64(Float64(Float64(2.0 * abs(x)) + Float64(Float64(2.0 / 3.0) * t_0)) + Float64(Float64(1.0 / 5.0) * t_1)) + Float64(Float64(1.0 / 21.0) * Float64(Float64(t_1 * abs(x)) * abs(x)))))) end
function tmp = code(x) t_0 = (abs(x) * abs(x)) * abs(x); t_1 = (t_0 * abs(x)) * abs(x); tmp = abs(((1.0 / sqrt(pi)) * ((((2.0 * abs(x)) + ((2.0 / 3.0) * t_0)) + ((1.0 / 5.0) * t_1)) + ((1.0 / 21.0) * ((t_1 * abs(x)) * abs(x)))))); end
code[x_] := Block[{t$95$0 = N[(N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[Abs[N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(N[(2.0 * N[Abs[x], $MachinePrecision]), $MachinePrecision] + N[(N[(2.0 / 3.0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 5.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 21.0), $MachinePrecision] * N[(N[(t$95$1 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\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{\pi}} \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 x)
(fabs
(*
(sqrt (/ 1.0 PI))
(+
2.0
(+
(* 0.047619047619047616 (pow x 6.0))
(+ (* 0.2 (pow x 4.0)) (* 0.6666666666666666 (* x x)))))))))
double code(double x) {
return fabs(x) * fabs((sqrt((1.0 / ((double) M_PI))) * (2.0 + ((0.047619047619047616 * pow(x, 6.0)) + ((0.2 * pow(x, 4.0)) + (0.6666666666666666 * (x * x)))))));
}
public static double code(double x) {
return Math.abs(x) * Math.abs((Math.sqrt((1.0 / Math.PI)) * (2.0 + ((0.047619047619047616 * Math.pow(x, 6.0)) + ((0.2 * Math.pow(x, 4.0)) + (0.6666666666666666 * (x * x)))))));
}
def code(x): return math.fabs(x) * math.fabs((math.sqrt((1.0 / math.pi)) * (2.0 + ((0.047619047619047616 * math.pow(x, 6.0)) + ((0.2 * math.pow(x, 4.0)) + (0.6666666666666666 * (x * x)))))))
function code(x) return Float64(abs(x) * abs(Float64(sqrt(Float64(1.0 / pi)) * Float64(2.0 + Float64(Float64(0.047619047619047616 * (x ^ 6.0)) + Float64(Float64(0.2 * (x ^ 4.0)) + Float64(0.6666666666666666 * Float64(x * x)))))))) end
function tmp = code(x) tmp = abs(x) * abs((sqrt((1.0 / pi)) * (2.0 + ((0.047619047619047616 * (x ^ 6.0)) + ((0.2 * (x ^ 4.0)) + (0.6666666666666666 * (x * x))))))); end
code[x_] := N[(N[Abs[x], $MachinePrecision] * N[Abs[N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(2.0 + N[(N[(0.047619047619047616 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.6666666666666666 * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|x\right| \cdot \left|\sqrt{\frac{1}{\pi}} \cdot \left(2 + \left(0.047619047619047616 \cdot {x}^{6} + \left(0.2 \cdot {x}^{4} + 0.6666666666666666 \cdot \left(x \cdot x\right)\right)\right)\right)\right|
\end{array}
Initial program 99.8%
Simplified99.9%
Taylor expanded in x around 0 99.9%
pow299.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 1e+25)
(*
x
(/
(fma 0.2 (pow x 4.0) (fma (pow x 2.0) 0.6666666666666666 2.0))
(sqrt PI)))
(fabs (* 0.2 (sqrt (/ (pow x 10.0) PI))))))
double code(double x) {
double tmp;
if (fabs(x) <= 1e+25) {
tmp = x * (fma(0.2, pow(x, 4.0), fma(pow(x, 2.0), 0.6666666666666666, 2.0)) / sqrt(((double) M_PI)));
} else {
tmp = fabs((0.2 * sqrt((pow(x, 10.0) / ((double) M_PI)))));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 1e+25) tmp = Float64(x * Float64(fma(0.2, (x ^ 4.0), fma((x ^ 2.0), 0.6666666666666666, 2.0)) / sqrt(pi))); else tmp = abs(Float64(0.2 * sqrt(Float64((x ^ 10.0) / pi)))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 1e+25], N[(x * N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision] + N[(N[Power[x, 2.0], $MachinePrecision] * 0.6666666666666666 + 2.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[(0.2 * N[Sqrt[N[(N[Power[x, 10.0], $MachinePrecision] / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 10^{+25}:\\
\;\;\;\;x \cdot \frac{\mathsf{fma}\left(0.2, {x}^{4}, \mathsf{fma}\left({x}^{2}, 0.6666666666666666, 2\right)\right)}{\sqrt{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\left|0.2 \cdot \sqrt{\frac{{x}^{10}}{\pi}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 1.00000000000000009e25Initial program 99.8%
Simplified99.8%
Taylor expanded in x around 0 94.8%
pow194.8%
add-sqr-sqrt48.0%
fabs-sqr48.0%
add-sqr-sqrt50.0%
add-sqr-sqrt49.2%
fabs-sqr49.2%
add-sqr-sqrt50.0%
fma-define50.0%
pow250.0%
Applied egg-rr50.0%
unpow150.0%
fma-define50.0%
*-commutative50.0%
fma-define50.0%
Simplified50.0%
if 1.00000000000000009e25 < (fabs.f64 x) Initial program 100.0%
Simplified100.0%
Taylor expanded in x around inf 92.9%
associate-*r*92.9%
*-commutative92.9%
*-commutative92.9%
unpow292.9%
associate-*r*92.9%
unpow392.9%
fabs-mul92.9%
unpow292.9%
fabs-mul92.9%
unpow292.9%
unpow392.9%
unpow192.9%
sqr-pow72.2%
fabs-sqr72.2%
sqr-pow92.9%
unpow192.9%
pow-plus92.9%
metadata-eval92.9%
pow-plus92.9%
metadata-eval92.9%
Simplified92.9%
pow192.9%
inv-pow92.9%
sqrt-pow192.9%
metadata-eval92.9%
Applied egg-rr92.9%
unpow192.9%
*-commutative92.9%
associate-*l*92.9%
Simplified92.9%
associate-*r*92.9%
expm1-log1p-u0.0%
metadata-eval0.0%
pow-flip0.0%
pow1/20.0%
un-div-inv0.0%
expm1-log1p-u92.9%
Applied egg-rr92.9%
associate-/l*92.9%
Simplified92.9%
add-sqr-sqrt0.0%
sqrt-unprod97.7%
frac-times97.7%
pow-prod-up97.7%
metadata-eval97.7%
add-sqr-sqrt97.7%
Applied egg-rr97.7%
Final simplification64.7%
(FPCore (x)
:precision binary64
(*
(fabs x)
(fabs
(/
(+
(* 0.047619047619047616 (pow x 6.0))
(fma 0.6666666666666666 (* x x) 2.0))
(sqrt PI)))))
double code(double x) {
return fabs(x) * fabs((((0.047619047619047616 * pow(x, 6.0)) + fma(0.6666666666666666, (x * x), 2.0)) / sqrt(((double) M_PI))));
}
function code(x) return Float64(abs(x) * abs(Float64(Float64(Float64(0.047619047619047616 * (x ^ 6.0)) + fma(0.6666666666666666, Float64(x * x), 2.0)) / sqrt(pi)))) end
code[x_] := N[(N[Abs[x], $MachinePrecision] * N[Abs[N[(N[(N[(0.047619047619047616 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision] + N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|x\right| \cdot \left|\frac{0.047619047619047616 \cdot {x}^{6} + \mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right)}{\sqrt{\pi}}\right|
\end{array}
Initial program 99.8%
Simplified99.9%
Taylor expanded in x around inf 98.6%
Final simplification98.6%
(FPCore (x) :precision binary64 (* (sqrt (/ 1.0 PI)) (+ (* 0.2 (pow x 5.0)) (* x 2.0))))
double code(double x) {
return sqrt((1.0 / ((double) M_PI))) * ((0.2 * pow(x, 5.0)) + (x * 2.0));
}
public static double code(double x) {
return Math.sqrt((1.0 / Math.PI)) * ((0.2 * Math.pow(x, 5.0)) + (x * 2.0));
}
def code(x): return math.sqrt((1.0 / math.pi)) * ((0.2 * math.pow(x, 5.0)) + (x * 2.0))
function code(x) return Float64(sqrt(Float64(1.0 / pi)) * Float64(Float64(0.2 * (x ^ 5.0)) + Float64(x * 2.0))) end
function tmp = code(x) tmp = sqrt((1.0 / pi)) * ((0.2 * (x ^ 5.0)) + (x * 2.0)); end
code[x_] := N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(N[(0.2 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(x * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{\pi}} \cdot \left(0.2 \cdot {x}^{5} + x \cdot 2\right)
\end{array}
Initial program 99.8%
Simplified99.9%
Taylor expanded in x around 0 93.9%
Taylor expanded in x around 0 93.1%
log1p-expm1-u94.6%
log1p-undefine35.9%
add-sqr-sqrt2.3%
fabs-sqr2.3%
add-sqr-sqrt3.9%
add-sqr-sqrt3.9%
fabs-sqr3.9%
add-sqr-sqrt3.9%
fma-define3.9%
Applied egg-rr3.9%
Taylor expanded in x around 0 34.4%
associate-*r*34.4%
associate-*r*34.4%
distribute-rgt-out34.4%
*-commutative34.4%
Simplified34.4%
Final simplification34.4%
(FPCore (x) :precision binary64 (* 2.0 (* x (sqrt (/ 1.0 PI)))))
double code(double x) {
return 2.0 * (x * sqrt((1.0 / ((double) M_PI))));
}
public static double code(double x) {
return 2.0 * (x * Math.sqrt((1.0 / Math.PI)));
}
def code(x): return 2.0 * (x * math.sqrt((1.0 / math.pi)))
function code(x) return Float64(2.0 * Float64(x * sqrt(Float64(1.0 / pi)))) end
function tmp = code(x) tmp = 2.0 * (x * sqrt((1.0 / pi))); end
code[x_] := N[(2.0 * N[(x * N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot \left(x \cdot \sqrt{\frac{1}{\pi}}\right)
\end{array}
Initial program 99.8%
Simplified99.9%
Taylor expanded in x around 0 93.9%
Taylor expanded in x around 0 93.1%
log1p-expm1-u94.6%
log1p-undefine35.9%
add-sqr-sqrt2.3%
fabs-sqr2.3%
add-sqr-sqrt3.9%
add-sqr-sqrt3.9%
fabs-sqr3.9%
add-sqr-sqrt3.9%
fma-define3.9%
Applied egg-rr3.9%
Taylor expanded in x around 0 34.5%
*-commutative34.5%
Simplified34.5%
Final simplification34.5%
herbie shell --seed 2024044
(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)))))))