
(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 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))))))))
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 (pow PI -0.5))
(+
(+ (* 0.2 (pow x 4.0)) (* 0.047619047619047616 (pow x 6.0)))
(fma 0.6666666666666666 (* x x) 2.0)))))
double code(double x) {
return fabs(((x * pow(((double) M_PI), -0.5)) * (((0.2 * pow(x, 4.0)) + (0.047619047619047616 * pow(x, 6.0))) + fma(0.6666666666666666, (x * x), 2.0))));
}
function code(x) return abs(Float64(Float64(x * (pi ^ -0.5)) * Float64(Float64(Float64(0.2 * (x ^ 4.0)) + Float64(0.047619047619047616 * (x ^ 6.0))) + fma(0.6666666666666666, Float64(x * x), 2.0)))) end
code[x_] := N[Abs[N[(N[(x * N[Power[Pi, -0.5], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\left(x \cdot {\pi}^{-0.5}\right) \cdot \left(\left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right) + \mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right)\right)\right|
\end{array}
Initial program 99.8%
Simplified99.4%
div-inv99.9%
inv-pow99.9%
sqrt-pow299.9%
metadata-eval99.9%
Applied egg-rr99.9%
unpow199.9%
sqr-pow32.2%
fabs-sqr32.2%
sqr-pow99.9%
unpow199.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (* 0.6666666666666666 (pow x 2.0))))
(if (<= (fabs x) 0.02)
(* x (/ (fma 0.2 (pow x 4.0) (+ 2.0 t_0)) (sqrt PI)))
(fabs
(*
(* x (pow PI -0.5))
(+
(+ (* 0.2 (pow x 4.0)) (* 0.047619047619047616 (pow x 6.0)))
t_0))))))
double code(double x) {
double t_0 = 0.6666666666666666 * pow(x, 2.0);
double tmp;
if (fabs(x) <= 0.02) {
tmp = x * (fma(0.2, pow(x, 4.0), (2.0 + t_0)) / sqrt(((double) M_PI)));
} else {
tmp = fabs(((x * pow(((double) M_PI), -0.5)) * (((0.2 * pow(x, 4.0)) + (0.047619047619047616 * pow(x, 6.0))) + t_0)));
}
return tmp;
}
function code(x) t_0 = Float64(0.6666666666666666 * (x ^ 2.0)) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64(x * Float64(fma(0.2, (x ^ 4.0), Float64(2.0 + t_0)) / sqrt(pi))); else tmp = abs(Float64(Float64(x * (pi ^ -0.5)) * Float64(Float64(Float64(0.2 * (x ^ 4.0)) + Float64(0.047619047619047616 * (x ^ 6.0))) + t_0))); end return tmp end
code[x_] := Block[{t$95$0 = N[(0.6666666666666666 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(x * N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision] + N[(2.0 + t$95$0), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[(N[(x * N[Power[Pi, -0.5], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.6666666666666666 \cdot {x}^{2}\\
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;x \cdot \frac{\mathsf{fma}\left(0.2, {x}^{4}, 2 + t\_0\right)}{\sqrt{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\left|\left(x \cdot {\pi}^{-0.5}\right) \cdot \left(\left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right) + t\_0\right)\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 99.1%
Taylor expanded in x around 0 99.1%
fabs-neg99.1%
fma-def99.1%
associate-*r/99.1%
*-rgt-identity99.1%
fabs-div99.1%
distribute-frac-neg99.1%
fabs-neg99.1%
associate-/l*99.1%
associate-*r/99.7%
rem-square-sqrt48.5%
Simplified50.7%
fma-udef50.7%
Applied egg-rr50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.9%
div-inv99.9%
inv-pow99.9%
sqrt-pow299.9%
metadata-eval99.9%
Applied egg-rr99.9%
unpow199.9%
sqr-pow0.0%
fabs-sqr0.0%
sqr-pow99.9%
unpow199.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
Taylor expanded in x around inf 99.9%
Final simplification67.2%
(FPCore (x)
:precision binary64
(fabs
(*
(+
(+ (* 0.2 (pow x 4.0)) (* 0.047619047619047616 (pow x 6.0)))
(fma 0.6666666666666666 (* x x) 2.0))
(/ x (sqrt PI)))))
double code(double x) {
return fabs(((((0.2 * pow(x, 4.0)) + (0.047619047619047616 * pow(x, 6.0))) + fma(0.6666666666666666, (x * x), 2.0)) * (x / sqrt(((double) M_PI)))));
}
function code(x) return abs(Float64(Float64(Float64(Float64(0.2 * (x ^ 4.0)) + Float64(0.047619047619047616 * (x ^ 6.0))) + fma(0.6666666666666666, Float64(x * x), 2.0)) * Float64(x / sqrt(pi)))) end
code[x_] := N[Abs[N[(N[(N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 6.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision] * N[(x / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\left(\left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right) + \mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right)\right) \cdot \frac{x}{\sqrt{\pi}}\right|
\end{array}
Initial program 99.8%
Simplified99.4%
div-inv99.9%
inv-pow99.9%
sqrt-pow299.9%
metadata-eval99.9%
Applied egg-rr99.9%
unpow199.9%
sqr-pow32.2%
fabs-sqr32.2%
sqr-pow99.9%
unpow199.9%
Simplified99.9%
fma-udef99.9%
Applied egg-rr99.9%
metadata-eval99.9%
sqrt-pow199.9%
inv-pow99.9%
expm1-log1p-u66.3%
expm1-udef5.0%
sqrt-div5.0%
metadata-eval5.0%
un-div-inv5.0%
Applied egg-rr5.0%
expm1-def65.9%
expm1-log1p99.4%
Simplified99.4%
Final simplification99.4%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.02)
(*
x
(/
(fma 0.2 (pow x 4.0) (+ 2.0 (* 0.6666666666666666 (pow x 2.0))))
(sqrt PI)))
(fabs
(/
(+ (* 0.2 (pow x 5.0)) (* 0.047619047619047616 (pow x 7.0)))
(sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.02) {
tmp = x * (fma(0.2, pow(x, 4.0), (2.0 + (0.6666666666666666 * pow(x, 2.0)))) / sqrt(((double) M_PI)));
} else {
tmp = fabs((((0.2 * pow(x, 5.0)) + (0.047619047619047616 * pow(x, 7.0))) / sqrt(((double) M_PI))));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64(x * Float64(fma(0.2, (x ^ 4.0), Float64(2.0 + Float64(0.6666666666666666 * (x ^ 2.0)))) / sqrt(pi))); else tmp = abs(Float64(Float64(Float64(0.2 * (x ^ 5.0)) + Float64(0.047619047619047616 * (x ^ 7.0))) / sqrt(pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(x * N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision] + N[(2.0 + N[(0.6666666666666666 * N[Power[x, 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[(N[(N[(0.2 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;x \cdot \frac{\mathsf{fma}\left(0.2, {x}^{4}, 2 + 0.6666666666666666 \cdot {x}^{2}\right)}{\sqrt{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{0.2 \cdot {x}^{5} + 0.047619047619047616 \cdot {x}^{7}}{\sqrt{\pi}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 99.1%
Taylor expanded in x around 0 99.1%
fabs-neg99.1%
fma-def99.1%
associate-*r/99.1%
*-rgt-identity99.1%
fabs-div99.1%
distribute-frac-neg99.1%
fabs-neg99.1%
associate-/l*99.1%
associate-*r/99.7%
rem-square-sqrt48.5%
Simplified50.7%
fma-udef50.7%
Applied egg-rr50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.8%
Taylor expanded in x around inf 99.7%
Simplified99.7%
expm1-log1p-u0.0%
expm1-udef0.0%
*-commutative0.0%
sqrt-div0.0%
metadata-eval0.0%
un-div-inv0.0%
+-commutative0.0%
fma-def0.0%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p99.8%
Simplified99.8%
fma-udef99.8%
Applied egg-rr99.8%
Final simplification67.2%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.02)
(* (pow PI -0.5) (/ x (fma (pow x 2.0) -0.16666666666666666 0.5)))
(fabs
(/
(+ (* 0.2 (pow x 5.0)) (* 0.047619047619047616 (pow x 7.0)))
(sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.02) {
tmp = pow(((double) M_PI), -0.5) * (x / fma(pow(x, 2.0), -0.16666666666666666, 0.5));
} else {
tmp = fabs((((0.2 * pow(x, 5.0)) + (0.047619047619047616 * pow(x, 7.0))) / sqrt(((double) M_PI))));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64((pi ^ -0.5) * Float64(x / fma((x ^ 2.0), -0.16666666666666666, 0.5))); else tmp = abs(Float64(Float64(Float64(0.2 * (x ^ 5.0)) + Float64(0.047619047619047616 * (x ^ 7.0))) / sqrt(pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(x / N[(N[Power[x, 2.0], $MachinePrecision] * -0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Abs[N[(N[(N[(0.2 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;{\pi}^{-0.5} \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.16666666666666666, 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{0.2 \cdot {x}^{5} + 0.047619047619047616 \cdot {x}^{7}}{\sqrt{\pi}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 98.8%
+-commutative98.8%
associate-*r*98.8%
distribute-rgt-out98.8%
*-commutative98.8%
Simplified98.8%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt50.4%
*-un-lft-identity50.4%
add-sqr-sqrt50.5%
fabs-sqr50.5%
add-sqr-sqrt50.4%
times-frac50.7%
pow1/250.7%
pow-flip50.7%
metadata-eval50.7%
+-commutative50.7%
fma-def50.7%
Applied egg-rr50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.8%
Taylor expanded in x around inf 99.7%
Simplified99.7%
expm1-log1p-u0.0%
expm1-udef0.0%
*-commutative0.0%
sqrt-div0.0%
metadata-eval0.0%
un-div-inv0.0%
+-commutative0.0%
fma-def0.0%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p99.8%
Simplified99.8%
fma-udef99.8%
Applied egg-rr99.8%
Final simplification67.2%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.02)
(* (pow PI -0.5) (/ x (fma (pow x 2.0) -0.16666666666666666 0.5)))
(*
(+ (* 0.2 (pow x 5.0)) (* 0.047619047619047616 (pow x 7.0)))
(sqrt (/ 1.0 PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.02) {
tmp = pow(((double) M_PI), -0.5) * (x / fma(pow(x, 2.0), -0.16666666666666666, 0.5));
} else {
tmp = ((0.2 * pow(x, 5.0)) + (0.047619047619047616 * pow(x, 7.0))) * sqrt((1.0 / ((double) M_PI)));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64((pi ^ -0.5) * Float64(x / fma((x ^ 2.0), -0.16666666666666666, 0.5))); else tmp = Float64(Float64(Float64(0.2 * (x ^ 5.0)) + Float64(0.047619047619047616 * (x ^ 7.0))) * sqrt(Float64(1.0 / pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(x / N[(N[Power[x, 2.0], $MachinePrecision] * -0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(N[(0.2 * N[Power[x, 5.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 7.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;{\pi}^{-0.5} \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.16666666666666666, 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;\left(0.2 \cdot {x}^{5} + 0.047619047619047616 \cdot {x}^{7}\right) \cdot \sqrt{\frac{1}{\pi}}\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 98.8%
+-commutative98.8%
associate-*r*98.8%
distribute-rgt-out98.8%
*-commutative98.8%
Simplified98.8%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt50.4%
*-un-lft-identity50.4%
add-sqr-sqrt50.5%
fabs-sqr50.5%
add-sqr-sqrt50.4%
times-frac50.7%
pow1/250.7%
pow-flip50.7%
metadata-eval50.7%
+-commutative50.7%
fma-def50.7%
Applied egg-rr50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.9%
Taylor expanded in x around 0 99.9%
Simplified0.1%
Taylor expanded in x around inf 0.1%
+-commutative0.1%
associate-*r*0.1%
associate-*r*0.1%
*-commutative0.1%
distribute-rgt-out0.1%
*-commutative0.1%
Simplified0.1%
Final simplification33.7%
(FPCore (x) :precision binary64 (if (<= (fabs x) 0.02) (* (pow PI -0.5) (/ x (fma (pow x 2.0) -0.16666666666666666 0.5))) (* 0.047619047619047616 (/ (pow x 7.0) (sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.02) {
tmp = pow(((double) M_PI), -0.5) * (x / fma(pow(x, 2.0), -0.16666666666666666, 0.5));
} else {
tmp = 0.047619047619047616 * (pow(x, 7.0) / sqrt(((double) M_PI)));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64((pi ^ -0.5) * Float64(x / fma((x ^ 2.0), -0.16666666666666666, 0.5))); else tmp = Float64(0.047619047619047616 * Float64((x ^ 7.0) / sqrt(pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(x / N[(N[Power[x, 2.0], $MachinePrecision] * -0.16666666666666666 + 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(0.047619047619047616 * N[(N[Power[x, 7.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;{\pi}^{-0.5} \cdot \frac{x}{\mathsf{fma}\left({x}^{2}, -0.16666666666666666, 0.5\right)}\\
\mathbf{else}:\\
\;\;\;\;0.047619047619047616 \cdot \frac{{x}^{7}}{\sqrt{\pi}}\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 98.8%
+-commutative98.8%
associate-*r*98.8%
distribute-rgt-out98.8%
*-commutative98.8%
Simplified98.8%
add-sqr-sqrt48.3%
fabs-sqr48.3%
add-sqr-sqrt50.4%
*-un-lft-identity50.4%
add-sqr-sqrt50.5%
fabs-sqr50.5%
add-sqr-sqrt50.4%
times-frac50.7%
pow1/250.7%
pow-flip50.7%
metadata-eval50.7%
+-commutative50.7%
fma-def50.7%
Applied egg-rr50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.9%
Taylor expanded in x around inf 98.8%
associate-*l/98.8%
*-lft-identity98.8%
Simplified98.8%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p0.1%
*-commutative0.1%
metadata-eval0.1%
times-frac0.1%
associate-*r/0.1%
*-commutative0.1%
associate-/r*0.1%
metadata-eval0.1%
Simplified0.1%
expm1-log1p-u0.1%
expm1-udef0.1%
sqrt-div0.1%
sqrt-pow10.1%
metadata-eval0.1%
Applied egg-rr0.1%
expm1-def0.1%
expm1-log1p0.1%
associate-/r/0.1%
*-commutative0.1%
Simplified0.1%
associate-*r*0.1%
pow10.1%
pow-prod-up0.1%
metadata-eval0.1%
clear-num0.1%
un-div-inv0.1%
div-inv0.1%
metadata-eval0.1%
Applied egg-rr0.1%
*-lft-identity0.1%
*-commutative0.1%
times-frac0.1%
metadata-eval0.1%
Simplified0.1%
Final simplification33.7%
(FPCore (x) :precision binary64 (if (<= (fabs x) 0.02) (* (sqrt (/ 1.0 PI)) (* x 2.0)) (* 0.047619047619047616 (/ (pow x 7.0) (sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.02) {
tmp = sqrt((1.0 / ((double) M_PI))) * (x * 2.0);
} else {
tmp = 0.047619047619047616 * (pow(x, 7.0) / sqrt(((double) M_PI)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 0.02) {
tmp = Math.sqrt((1.0 / Math.PI)) * (x * 2.0);
} else {
tmp = 0.047619047619047616 * (Math.pow(x, 7.0) / Math.sqrt(Math.PI));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 0.02: tmp = math.sqrt((1.0 / math.pi)) * (x * 2.0) else: tmp = 0.047619047619047616 * (math.pow(x, 7.0) / math.sqrt(math.pi)) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 0.02) tmp = Float64(sqrt(Float64(1.0 / pi)) * Float64(x * 2.0)); else tmp = Float64(0.047619047619047616 * Float64((x ^ 7.0) / sqrt(pi))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 0.02) tmp = sqrt((1.0 / pi)) * (x * 2.0); else tmp = 0.047619047619047616 * ((x ^ 7.0) / sqrt(pi)); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.02], N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(x * 2.0), $MachinePrecision]), $MachinePrecision], N[(0.047619047619047616 * N[(N[Power[x, 7.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.02:\\
\;\;\;\;\sqrt{\frac{1}{\pi}} \cdot \left(x \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;0.047619047619047616 \cdot \frac{{x}^{7}}{\sqrt{\pi}}\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.0200000000000000004Initial program 99.8%
Simplified99.2%
Taylor expanded in x around 0 99.2%
Simplified50.4%
Taylor expanded in x around 0 50.7%
associate-*r*50.7%
*-commutative50.7%
Simplified50.7%
if 0.0200000000000000004 < (fabs.f64 x) Initial program 99.8%
Simplified99.9%
Taylor expanded in x around inf 98.8%
associate-*l/98.8%
*-lft-identity98.8%
Simplified98.8%
expm1-log1p-u97.6%
expm1-udef97.6%
Applied egg-rr0.0%
expm1-def0.0%
expm1-log1p0.1%
*-commutative0.1%
metadata-eval0.1%
times-frac0.1%
associate-*r/0.1%
*-commutative0.1%
associate-/r*0.1%
metadata-eval0.1%
Simplified0.1%
expm1-log1p-u0.1%
expm1-udef0.1%
sqrt-div0.1%
sqrt-pow10.1%
metadata-eval0.1%
Applied egg-rr0.1%
expm1-def0.1%
expm1-log1p0.1%
associate-/r/0.1%
*-commutative0.1%
Simplified0.1%
associate-*r*0.1%
pow10.1%
pow-prod-up0.1%
metadata-eval0.1%
clear-num0.1%
un-div-inv0.1%
div-inv0.1%
metadata-eval0.1%
Applied egg-rr0.1%
*-lft-identity0.1%
*-commutative0.1%
times-frac0.1%
metadata-eval0.1%
Simplified0.1%
Final simplification33.7%
(FPCore (x) :precision binary64 (if (<= x 1.85) (* (sqrt (/ 1.0 PI)) (* x 2.0)) (sqrt (* (pow x 14.0) (/ 0.0022675736961451248 PI)))))
double code(double x) {
double tmp;
if (x <= 1.85) {
tmp = sqrt((1.0 / ((double) M_PI))) * (x * 2.0);
} else {
tmp = sqrt((pow(x, 14.0) * (0.0022675736961451248 / ((double) M_PI))));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (x <= 1.85) {
tmp = Math.sqrt((1.0 / Math.PI)) * (x * 2.0);
} else {
tmp = Math.sqrt((Math.pow(x, 14.0) * (0.0022675736961451248 / Math.PI)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.85: tmp = math.sqrt((1.0 / math.pi)) * (x * 2.0) else: tmp = math.sqrt((math.pow(x, 14.0) * (0.0022675736961451248 / math.pi))) return tmp
function code(x) tmp = 0.0 if (x <= 1.85) tmp = Float64(sqrt(Float64(1.0 / pi)) * Float64(x * 2.0)); else tmp = sqrt(Float64((x ^ 14.0) * Float64(0.0022675736961451248 / pi))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.85) tmp = sqrt((1.0 / pi)) * (x * 2.0); else tmp = sqrt(((x ^ 14.0) * (0.0022675736961451248 / pi))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.85], N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(x * 2.0), $MachinePrecision]), $MachinePrecision], N[Sqrt[N[(N[Power[x, 14.0], $MachinePrecision] * N[(0.0022675736961451248 / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.85:\\
\;\;\;\;\sqrt{\frac{1}{\pi}} \cdot \left(x \cdot 2\right)\\
\mathbf{else}:\\
\;\;\;\;\sqrt{{x}^{14} \cdot \frac{0.0022675736961451248}{\pi}}\\
\end{array}
\end{array}
if x < 1.8500000000000001Initial program 99.8%
Simplified99.4%
Taylor expanded in x around 0 99.4%
Simplified33.5%
Taylor expanded in x around 0 33.8%
associate-*r*33.8%
*-commutative33.8%
Simplified33.8%
if 1.8500000000000001 < x Initial program 99.8%
Simplified99.4%
Taylor expanded in x around inf 37.0%
associate-*l/37.0%
*-lft-identity37.0%
Simplified37.0%
expm1-log1p-u36.5%
expm1-udef36.4%
Applied egg-rr3.6%
expm1-def3.6%
expm1-log1p3.6%
*-commutative3.6%
metadata-eval3.6%
times-frac3.6%
associate-*r/3.6%
*-commutative3.6%
associate-/r*3.6%
metadata-eval3.6%
Simplified3.6%
expm1-log1p-u3.6%
expm1-udef3.6%
sqrt-div3.6%
sqrt-pow13.6%
metadata-eval3.6%
Applied egg-rr3.6%
expm1-def3.6%
expm1-log1p3.6%
associate-/r/3.6%
*-commutative3.6%
Simplified3.6%
*-commutative3.6%
associate-/r/3.6%
add-sqr-sqrt3.4%
sqrt-unprod35.2%
associate-/r/35.2%
*-commutative35.2%
associate-/r/35.2%
*-commutative35.2%
associate-*r*35.2%
pow135.2%
pow-prod-up35.2%
metadata-eval35.2%
Applied egg-rr35.2%
Final simplification33.8%
(FPCore (x) :precision binary64 (* (sqrt (/ 1.0 PI)) (* x 2.0)))
double code(double x) {
return sqrt((1.0 / ((double) M_PI))) * (x * 2.0);
}
public static double code(double x) {
return Math.sqrt((1.0 / Math.PI)) * (x * 2.0);
}
def code(x): return math.sqrt((1.0 / math.pi)) * (x * 2.0)
function code(x) return Float64(sqrt(Float64(1.0 / pi)) * Float64(x * 2.0)) end
function tmp = code(x) tmp = sqrt((1.0 / pi)) * (x * 2.0); end
code[x_] := N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(x * 2.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sqrt{\frac{1}{\pi}} \cdot \left(x \cdot 2\right)
\end{array}
Initial program 99.8%
Simplified99.4%
Taylor expanded in x around 0 99.4%
Simplified33.5%
Taylor expanded in x around 0 33.8%
associate-*r*33.8%
*-commutative33.8%
Simplified33.8%
Final simplification33.8%
(FPCore (x) :precision binary64 (expm1 0.0))
double code(double x) {
return expm1(0.0);
}
public static double code(double x) {
return Math.expm1(0.0);
}
def code(x): return math.expm1(0.0)
function code(x) return expm1(0.0) end
code[x_] := N[(Exp[0.0] - 1), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{expm1}\left(0\right)
\end{array}
Initial program 99.8%
Simplified99.4%
Taylor expanded in x around inf 37.0%
associate-*l/37.0%
*-lft-identity37.0%
Simplified37.0%
expm1-log1p-u36.5%
expm1-udef36.4%
Applied egg-rr3.6%
expm1-def3.6%
expm1-log1p3.6%
*-commutative3.6%
metadata-eval3.6%
times-frac3.6%
associate-*r/3.6%
*-commutative3.6%
associate-/r*3.6%
metadata-eval3.6%
Simplified3.6%
expm1-log1p-u3.6%
sqrt-div3.6%
sqrt-pow13.6%
metadata-eval3.6%
Applied egg-rr3.6%
Taylor expanded in x around 0 4.2%
Final simplification4.2%
herbie shell --seed 2024026
(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)))))))