
(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}
Herbie found 12 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
(*
(/ 1.0 (sqrt PI))
(fma
0.047619047619047616
(pow (fabs x) 7.0)
(fma
0.2
(pow (fabs x) 5.0)
(fma 0.6666666666666666 (pow (fabs x) 3.0) (* 2.0 (fabs x))))))))
double code(double x) {
return fabs(((1.0 / sqrt(((double) M_PI))) * fma(0.047619047619047616, pow(fabs(x), 7.0), fma(0.2, pow(fabs(x), 5.0), fma(0.6666666666666666, pow(fabs(x), 3.0), (2.0 * fabs(x)))))));
}
function code(x) return abs(Float64(Float64(1.0 / sqrt(pi)) * fma(0.047619047619047616, (abs(x) ^ 7.0), fma(0.2, (abs(x) ^ 5.0), fma(0.6666666666666666, (abs(x) ^ 3.0), Float64(2.0 * abs(x))))))) end
code[x_] := N[Abs[N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(0.047619047619047616 * N[Power[N[Abs[x], $MachinePrecision], 7.0], $MachinePrecision] + N[(0.2 * N[Power[N[Abs[x], $MachinePrecision], 5.0], $MachinePrecision] + N[(0.6666666666666666 * N[Power[N[Abs[x], $MachinePrecision], 3.0], $MachinePrecision] + N[(2.0 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{1}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.047619047619047616, {\left(\left|x\right|\right)}^{7}, \mathsf{fma}\left(0.2, {\left(\left|x\right|\right)}^{5}, \mathsf{fma}\left(0.6666666666666666, {\left(\left|x\right|\right)}^{3}, 2 \cdot \left|x\right|\right)\right)\right)\right|
\end{array}
Initial program 99.8%
Taylor expanded in x around 0
Applied rewrites99.8%
(FPCore (x)
:precision binary64
(*
(/ 1.0 (sqrt PI))
(fabs
(*
(fma (* x x) (fma (* x x) (fma (/ x 21.0) x (/ 1.0 5.0)) (/ 2.0 3.0)) 2.0)
(fabs x)))))
double code(double x) {
return (1.0 / sqrt(((double) M_PI))) * fabs((fma((x * x), fma((x * x), fma((x / 21.0), x, (1.0 / 5.0)), (2.0 / 3.0)), 2.0) * fabs(x)));
}
function code(x) return Float64(Float64(1.0 / sqrt(pi)) * abs(Float64(fma(Float64(x * x), fma(Float64(x * x), fma(Float64(x / 21.0), x, Float64(1.0 / 5.0)), Float64(2.0 / 3.0)), 2.0) * abs(x)))) end
code[x_] := N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(N[(x / 21.0), $MachinePrecision] * x + N[(1.0 / 5.0), $MachinePrecision]), $MachinePrecision] + N[(2.0 / 3.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\pi}} \cdot \left|\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\frac{x}{21}, x, \frac{1}{5}\right), \frac{2}{3}\right), 2\right) \cdot \left|x\right|\right|
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.8%
(FPCore (x)
:precision binary64
(/
(*
(fabs
(fma
(*
(fma (* x x) (fma (* 0.047619047619047616 x) x (/ 1.0 5.0)) (/ 2.0 3.0))
x)
x
2.0))
(fabs x))
(sqrt PI)))
double code(double x) {
return (fabs(fma((fma((x * x), fma((0.047619047619047616 * x), x, (1.0 / 5.0)), (2.0 / 3.0)) * x), x, 2.0)) * fabs(x)) / sqrt(((double) M_PI));
}
function code(x) return Float64(Float64(abs(fma(Float64(fma(Float64(x * x), fma(Float64(0.047619047619047616 * x), x, Float64(1.0 / 5.0)), Float64(2.0 / 3.0)) * x), x, 2.0)) * abs(x)) / sqrt(pi)) end
code[x_] := N[(N[(N[Abs[N[(N[(N[(N[(x * x), $MachinePrecision] * N[(N[(0.047619047619047616 * x), $MachinePrecision] * x + N[(1.0 / 5.0), $MachinePrecision]), $MachinePrecision] + N[(2.0 / 3.0), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x + 2.0), $MachinePrecision]], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(0.047619047619047616 \cdot x, x, \frac{1}{5}\right), \frac{2}{3}\right) \cdot x, x, 2\right)\right| \cdot \left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.4%
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites99.4%
(FPCore (x)
:precision binary64
(/
(fabs
(*
(fma (* x x) (fma (* x x) (fma (/ x 21.0) x (/ 1.0 5.0)) (/ 2.0 3.0)) 2.0)
x))
(sqrt PI)))
double code(double x) {
return fabs((fma((x * x), fma((x * x), fma((x / 21.0), x, (1.0 / 5.0)), (2.0 / 3.0)), 2.0) * x)) / sqrt(((double) M_PI));
}
function code(x) return Float64(abs(Float64(fma(Float64(x * x), fma(Float64(x * x), fma(Float64(x / 21.0), x, Float64(1.0 / 5.0)), Float64(2.0 / 3.0)), 2.0) * x)) / sqrt(pi)) end
code[x_] := N[(N[Abs[N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * N[(N[(x / 21.0), $MachinePrecision] * x + N[(1.0 / 5.0), $MachinePrecision]), $MachinePrecision] + N[(2.0 / 3.0), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(\frac{x}{21}, x, \frac{1}{5}\right), \frac{2}{3}\right), 2\right) \cdot x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.8%
Applied rewrites99.4%
(FPCore (x) :precision binary64 (* (/ 1.0 (sqrt PI)) (fabs (* (fma (* x x) (* 0.047619047619047616 (pow x 4.0)) 2.0) (fabs x)))))
double code(double x) {
return (1.0 / sqrt(((double) M_PI))) * fabs((fma((x * x), (0.047619047619047616 * pow(x, 4.0)), 2.0) * fabs(x)));
}
function code(x) return Float64(Float64(1.0 / sqrt(pi)) * abs(Float64(fma(Float64(x * x), Float64(0.047619047619047616 * (x ^ 4.0)), 2.0) * abs(x)))) end
code[x_] := N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[N[(N[(N[(x * x), $MachinePrecision] * N[(0.047619047619047616 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{\pi}} \cdot \left|\mathsf{fma}\left(x \cdot x, 0.047619047619047616 \cdot {x}^{4}, 2\right) \cdot \left|x\right|\right|
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.8%
Taylor expanded in x around inf
Applied rewrites98.8%
(FPCore (x) :precision binary64 (if (<= x 1.85) (* (sqrt (/ 1.0 PI)) (fabs (* (fabs x) 2.0))) (/ (fabs (* 0.047619047619047616 (* (pow x 6.0) (fabs x)))) (sqrt PI))))
double code(double x) {
double tmp;
if (x <= 1.85) {
tmp = sqrt((1.0 / ((double) M_PI))) * fabs((fabs(x) * 2.0));
} else {
tmp = fabs((0.047619047619047616 * (pow(x, 6.0) * fabs(x)))) / sqrt(((double) M_PI));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.85) {
tmp = Math.sqrt((1.0 / Math.PI)) * Math.abs((Math.abs(x) * 2.0));
} else {
tmp = Math.abs((0.047619047619047616 * (Math.pow(x, 6.0) * Math.abs(x)))) / Math.sqrt(Math.PI);
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.85: tmp = math.sqrt((1.0 / math.pi)) * math.fabs((math.fabs(x) * 2.0)) else: tmp = math.fabs((0.047619047619047616 * (math.pow(x, 6.0) * math.fabs(x)))) / math.sqrt(math.pi) return tmp
function code(x) tmp = 0.0 if (x <= 1.85) tmp = Float64(sqrt(Float64(1.0 / pi)) * abs(Float64(abs(x) * 2.0))); else tmp = Float64(abs(Float64(0.047619047619047616 * Float64((x ^ 6.0) * abs(x)))) / sqrt(pi)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.85) tmp = sqrt((1.0 / pi)) * abs((abs(x) * 2.0)); else tmp = abs((0.047619047619047616 * ((x ^ 6.0) * abs(x)))) / sqrt(pi); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.85], N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[Abs[N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Abs[N[(0.047619047619047616 * N[(N[Power[x, 6.0], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.85:\\
\;\;\;\;\sqrt{\frac{1}{\pi}} \cdot \left|\left|x\right| \cdot 2\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|0.047619047619047616 \cdot \left({x}^{6} \cdot \left|x\right|\right)\right|}{\sqrt{\pi}}\\
\end{array}
\end{array}
if x < 1.8500000000000001Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites68.8%
if 1.8500000000000001 < x Initial program 99.8%
Applied rewrites99.4%
Taylor expanded in x around inf
Applied rewrites35.7%
(FPCore (x) :precision binary64 (/ (* (fabs (fma (* x x) (* 0.047619047619047616 (pow x 4.0)) 2.0)) (fabs x)) (sqrt PI)))
double code(double x) {
return (fabs(fma((x * x), (0.047619047619047616 * pow(x, 4.0)), 2.0)) * fabs(x)) / sqrt(((double) M_PI));
}
function code(x) return Float64(Float64(abs(fma(Float64(x * x), Float64(0.047619047619047616 * (x ^ 4.0)), 2.0)) * abs(x)) / sqrt(pi)) end
code[x_] := N[(N[(N[Abs[N[(N[(x * x), $MachinePrecision] * N[(0.047619047619047616 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(x \cdot x, 0.047619047619047616 \cdot {x}^{4}, 2\right)\right| \cdot \left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.4%
Taylor expanded in x around inf
Applied rewrites98.3%
(FPCore (x) :precision binary64 (/ (* (fabs (fma (* 0.047619047619047616 (pow x 5.0)) x 2.0)) (fabs x)) (sqrt PI)))
double code(double x) {
return (fabs(fma((0.047619047619047616 * pow(x, 5.0)), x, 2.0)) * fabs(x)) / sqrt(((double) M_PI));
}
function code(x) return Float64(Float64(abs(fma(Float64(0.047619047619047616 * (x ^ 5.0)), x, 2.0)) * abs(x)) / sqrt(pi)) end
code[x_] := N[(N[(N[Abs[N[(N[(0.047619047619047616 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] * x + 2.0), $MachinePrecision]], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\mathsf{fma}\left(0.047619047619047616 \cdot {x}^{5}, x, 2\right)\right| \cdot \left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Applied rewrites99.4%
Applied rewrites99.4%
Taylor expanded in x around inf
Applied rewrites98.3%
(FPCore (x) :precision binary64 (/ (fabs (* (fabs x) (fma (* 0.6666666666666666 x) x 2.0))) (sqrt PI)))
double code(double x) {
return fabs((fabs(x) * fma((0.6666666666666666 * x), x, 2.0))) / sqrt(((double) M_PI));
}
function code(x) return Float64(abs(Float64(abs(x) * fma(Float64(0.6666666666666666 * x), x, 2.0))) / sqrt(pi)) end
code[x_] := N[(N[Abs[N[(N[Abs[x], $MachinePrecision] * N[(N[(0.6666666666666666 * x), $MachinePrecision] * x + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\left|x\right| \cdot \mathsf{fma}\left(0.6666666666666666 \cdot x, x, 2\right)\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites88.9%
Applied rewrites88.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (* (* (fabs x) (fabs x)) (fabs x)))
(t_1 (* (* t_0 (fabs x)) (fabs x))))
(if (<=
(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))))))
5e-10)
(* (sqrt (/ 1.0 PI)) (fabs (* (fabs x) 2.0)))
(/ (fabs (* (sqrt (* x x)) 2.0)) (sqrt PI)))))
double code(double x) {
double t_0 = (fabs(x) * fabs(x)) * fabs(x);
double t_1 = (t_0 * fabs(x)) * fabs(x);
double tmp;
if (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)))))) <= 5e-10) {
tmp = sqrt((1.0 / ((double) M_PI))) * fabs((fabs(x) * 2.0));
} else {
tmp = fabs((sqrt((x * x)) * 2.0)) / sqrt(((double) M_PI));
}
return tmp;
}
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);
double tmp;
if (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)))))) <= 5e-10) {
tmp = Math.sqrt((1.0 / Math.PI)) * Math.abs((Math.abs(x) * 2.0));
} else {
tmp = Math.abs((Math.sqrt((x * x)) * 2.0)) / Math.sqrt(Math.PI);
}
return tmp;
}
def code(x): t_0 = (math.fabs(x) * math.fabs(x)) * math.fabs(x) t_1 = (t_0 * math.fabs(x)) * math.fabs(x) tmp = 0 if 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)))))) <= 5e-10: tmp = math.sqrt((1.0 / math.pi)) * math.fabs((math.fabs(x) * 2.0)) else: tmp = math.fabs((math.sqrt((x * x)) * 2.0)) / math.sqrt(math.pi) return tmp
function code(x) t_0 = Float64(Float64(abs(x) * abs(x)) * abs(x)) t_1 = Float64(Float64(t_0 * abs(x)) * abs(x)) tmp = 0.0 if (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)))))) <= 5e-10) tmp = Float64(sqrt(Float64(1.0 / pi)) * abs(Float64(abs(x) * 2.0))); else tmp = Float64(abs(Float64(sqrt(Float64(x * x)) * 2.0)) / sqrt(pi)); end return tmp end
function tmp_2 = code(x) t_0 = (abs(x) * abs(x)) * abs(x); t_1 = (t_0 * abs(x)) * abs(x); tmp = 0.0; if (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)))))) <= 5e-10) tmp = sqrt((1.0 / pi)) * abs((abs(x) * 2.0)); else tmp = abs((sqrt((x * x)) * 2.0)) / sqrt(pi); end tmp_2 = tmp; 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]}, If[LessEqual[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], 5e-10], N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[Abs[N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], N[(N[Abs[N[(N[Sqrt[N[(x * x), $MachinePrecision]], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $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|\\
\mathbf{if}\;\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| \leq 5 \cdot 10^{-10}:\\
\;\;\;\;\sqrt{\frac{1}{\pi}} \cdot \left|\left|x\right| \cdot 2\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|\sqrt{x \cdot x} \cdot 2\right|}{\sqrt{\pi}}\\
\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)))))) < 5.00000000000000031e-10Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites68.8%
if 5.00000000000000031e-10 < (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.4%
Taylor expanded in x around 0
Applied rewrites68.3%
Applied rewrites53.5%
(FPCore (x) :precision binary64 (* (sqrt (/ 1.0 PI)) (fabs (* (fabs x) 2.0))))
double code(double x) {
return sqrt((1.0 / ((double) M_PI))) * fabs((fabs(x) * 2.0));
}
public static double code(double x) {
return Math.sqrt((1.0 / Math.PI)) * Math.abs((Math.abs(x) * 2.0));
}
def code(x): return math.sqrt((1.0 / math.pi)) * math.fabs((math.fabs(x) * 2.0))
function code(x) return Float64(sqrt(Float64(1.0 / pi)) * abs(Float64(abs(x) * 2.0))) end
function tmp = code(x) tmp = sqrt((1.0 / pi)) * abs((abs(x) * 2.0)); end
code[x_] := N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[Abs[N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{\pi}} \cdot \left|\left|x\right| \cdot 2\right|
\end{array}
Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around 0
Applied rewrites68.8%
(FPCore (x) :precision binary64 (/ (fabs (* (fabs x) 2.0)) (sqrt PI)))
double code(double x) {
return fabs((fabs(x) * 2.0)) / sqrt(((double) M_PI));
}
public static double code(double x) {
return Math.abs((Math.abs(x) * 2.0)) / Math.sqrt(Math.PI);
}
def code(x): return math.fabs((math.fabs(x) * 2.0)) / math.sqrt(math.pi)
function code(x) return Float64(abs(Float64(abs(x) * 2.0)) / sqrt(pi)) end
function tmp = code(x) tmp = abs((abs(x) * 2.0)) / sqrt(pi); end
code[x_] := N[(N[Abs[N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\left|x\right| \cdot 2\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.8%
Applied rewrites99.4%
Taylor expanded in x around 0
Applied rewrites68.3%
herbie shell --seed 2025153
(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)))))))