
(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 15 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
(*
(fma
(fabs x)
(fma (* x x) 0.6666666666666666 2.0)
(*
(fma (* x x) 0.047619047619047616 0.2)
(* (* (* (* x x) x) x) (fabs x))))
(/ 1.0 (sqrt PI)))))
double code(double x) {
return fabs((fma(fabs(x), fma((x * x), 0.6666666666666666, 2.0), (fma((x * x), 0.047619047619047616, 0.2) * ((((x * x) * x) * x) * fabs(x)))) * (1.0 / sqrt(((double) M_PI)))));
}
function code(x) return abs(Float64(fma(abs(x), fma(Float64(x * x), 0.6666666666666666, 2.0), Float64(fma(Float64(x * x), 0.047619047619047616, 0.2) * Float64(Float64(Float64(Float64(x * x) * x) * x) * abs(x)))) * Float64(1.0 / sqrt(pi)))) end
code[x_] := N[Abs[N[(N[(N[Abs[x], $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.6666666666666666 + 2.0), $MachinePrecision] + N[(N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision] * N[(N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\mathsf{fma}\left(\left|x\right|, \mathsf{fma}\left(x \cdot x, 0.6666666666666666, 2\right), \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right) \cdot \left(\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot \left|x\right|\right)\right) \cdot \frac{1}{\sqrt{\pi}}\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(fabs
(*
(*
(fma
x
(fma
(* (fma 0.2 x (* (* 0.047619047619047616 (* x x)) x)) x)
x
(* 0.6666666666666666 x))
2.0)
(fabs x))
(/ 1.0 (sqrt PI)))))
double code(double x) {
return fabs(((fma(x, fma((fma(0.2, x, ((0.047619047619047616 * (x * x)) * x)) * x), x, (0.6666666666666666 * x)), 2.0) * fabs(x)) * (1.0 / sqrt(((double) M_PI)))));
}
function code(x) return abs(Float64(Float64(fma(x, fma(Float64(fma(0.2, x, Float64(Float64(0.047619047619047616 * Float64(x * x)) * x)) * x), x, Float64(0.6666666666666666 * x)), 2.0) * abs(x)) * Float64(1.0 / sqrt(pi)))) end
code[x_] := N[Abs[N[(N[(N[(x * N[(N[(N[(0.2 * x + N[(N[(0.047619047619047616 * N[(x * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x + N[(0.6666666666666666 * x), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\left(\mathsf{fma}\left(x, \mathsf{fma}\left(\mathsf{fma}\left(0.2, x, \left(0.047619047619047616 \cdot \left(x \cdot x\right)\right) \cdot x\right) \cdot x, x, 0.6666666666666666 \cdot x\right), 2\right) \cdot \left|x\right|\right) \cdot \frac{1}{\sqrt{\pi}}\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+r+N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-outN/A
lower-fma.f64N/A
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(*
(*
(fabs
(fma
(* x x)
(fma
x
(fma 0.2 x (* (* 0.047619047619047616 (* x x)) x))
0.6666666666666666)
2.0))
(fabs x))
(/ 1.0 (sqrt PI))))
double code(double x) {
return (fabs(fma((x * x), fma(x, fma(0.2, x, ((0.047619047619047616 * (x * x)) * x)), 0.6666666666666666), 2.0)) * fabs(x)) * (1.0 / sqrt(((double) M_PI)));
}
function code(x) return Float64(Float64(abs(fma(Float64(x * x), fma(x, fma(0.2, x, Float64(Float64(0.047619047619047616 * Float64(x * x)) * x)), 0.6666666666666666), 2.0)) * abs(x)) * Float64(1.0 / sqrt(pi))) end
code[x_] := N[(N[(N[Abs[N[(N[(x * x), $MachinePrecision] * N[(x * N[(0.2 * x + N[(N[(0.047619047619047616 * N[(x * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(\left|\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, \mathsf{fma}\left(0.2, x, \left(0.047619047619047616 \cdot \left(x \cdot x\right)\right) \cdot x\right), 0.6666666666666666\right), 2\right)\right| \cdot \left|x\right|\right) \cdot \frac{1}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Applied rewrites99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.1)
(fabs
(*
(/ (fma (fma (* 0.2 x) x 0.6666666666666666) (* x x) 2.0) (sqrt PI))
(fabs x)))
(fabs
(/
(* (* (* (* (* x x) x) (* x x)) (* 0.047619047619047616 (fabs x))) x)
(sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.1) {
tmp = fabs(((fma(fma((0.2 * x), x, 0.6666666666666666), (x * x), 2.0) / sqrt(((double) M_PI))) * fabs(x)));
} else {
tmp = fabs(((((((x * x) * x) * (x * x)) * (0.047619047619047616 * fabs(x))) * x) / sqrt(((double) M_PI))));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.1) tmp = abs(Float64(Float64(fma(fma(Float64(0.2 * x), x, 0.6666666666666666), Float64(x * x), 2.0) / sqrt(pi)) * abs(x))); else tmp = abs(Float64(Float64(Float64(Float64(Float64(Float64(x * x) * x) * Float64(x * x)) * Float64(0.047619047619047616 * abs(x))) * x) / sqrt(pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.1], N[Abs[N[(N[(N[(N[(N[(0.2 * x), $MachinePrecision] * x + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * N[(x * x), $MachinePrecision]), $MachinePrecision] * N[(0.047619047619047616 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.1:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.2 \cdot x, x, 0.6666666666666666\right), x \cdot x, 2\right)}{\sqrt{\pi}} \cdot \left|x\right|\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot \left(x \cdot x\right)\right) \cdot \left(0.047619047619047616 \cdot \left|x\right|\right)\right) \cdot x}{\sqrt{\pi}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.10000000000000001Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.6%
Applied rewrites99.6%
Applied rewrites99.6%
if 0.10000000000000001 < (fabs.f64 x) Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around inf
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites97.6%
Applied rewrites97.7%
Final simplification99.0%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.1)
(fabs
(*
(/ (fma (fma (* 0.2 x) x 0.6666666666666666) (* x x) 2.0) (sqrt PI))
(fabs x)))
(fabs
(*
(/ (* (* (* (* (* 0.047619047619047616 (* x x)) x) x) x) x) (sqrt PI))
(fabs x)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.1) {
tmp = fabs(((fma(fma((0.2 * x), x, 0.6666666666666666), (x * x), 2.0) / sqrt(((double) M_PI))) * fabs(x)));
} else {
tmp = fabs((((((((0.047619047619047616 * (x * x)) * x) * x) * x) * x) / sqrt(((double) M_PI))) * fabs(x)));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.1) tmp = abs(Float64(Float64(fma(fma(Float64(0.2 * x), x, 0.6666666666666666), Float64(x * x), 2.0) / sqrt(pi)) * abs(x))); else tmp = abs(Float64(Float64(Float64(Float64(Float64(Float64(Float64(0.047619047619047616 * Float64(x * x)) * x) * x) * x) * x) / sqrt(pi)) * abs(x))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.1], N[Abs[N[(N[(N[(N[(N[(0.2 * x), $MachinePrecision] * x + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(N[(N[(N[(N[(0.047619047619047616 * N[(x * x), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.1:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.2 \cdot x, x, 0.6666666666666666\right), x \cdot x, 2\right)}{\sqrt{\pi}} \cdot \left|x\right|\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(\left(\left(\left(0.047619047619047616 \cdot \left(x \cdot x\right)\right) \cdot x\right) \cdot x\right) \cdot x\right) \cdot x}{\sqrt{\pi}} \cdot \left|x\right|\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.10000000000000001Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.6%
Applied rewrites99.6%
Applied rewrites99.6%
if 0.10000000000000001 < (fabs.f64 x) Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around inf
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites97.6%
Applied rewrites97.6%
Final simplification99.0%
(FPCore (x)
:precision binary64
(fabs
(*
(*
(fma
(fma (fma 0.047619047619047616 (* x x) 0.2) (* x x) 0.6666666666666666)
(* x x)
2.0)
(fabs x))
(/ 1.0 (sqrt PI)))))
double code(double x) {
return fabs(((fma(fma(fma(0.047619047619047616, (x * x), 0.2), (x * x), 0.6666666666666666), (x * x), 2.0) * fabs(x)) * (1.0 / sqrt(((double) M_PI)))));
}
function code(x) return abs(Float64(Float64(fma(fma(fma(0.047619047619047616, Float64(x * x), 0.2), Float64(x * x), 0.6666666666666666), Float64(x * x), 2.0) * abs(x)) * Float64(1.0 / sqrt(pi)))) end
code[x_] := N[Abs[N[(N[(N[(N[(N[(0.047619047619047616 * N[(x * x), $MachinePrecision] + 0.2), $MachinePrecision] * N[(x * x), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(0.047619047619047616, x \cdot x, 0.2\right), x \cdot x, 0.6666666666666666\right), x \cdot x, 2\right) \cdot \left|x\right|\right) \cdot \frac{1}{\sqrt{\pi}}\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
+-commutativeN/A
lower-fma.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x)
:precision binary64
(if (<= (fabs x) 0.1)
(fabs
(*
(/ (fma (fma (* 0.2 x) x 0.6666666666666666) (* x x) 2.0) (sqrt PI))
(fabs x)))
(fabs
(/
(* (* (* (* (* (* (* x x) x) x) x) 0.047619047619047616) x) x)
(sqrt PI)))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.1) {
tmp = fabs(((fma(fma((0.2 * x), x, 0.6666666666666666), (x * x), 2.0) / sqrt(((double) M_PI))) * fabs(x)));
} else {
tmp = fabs(((((((((x * x) * x) * x) * x) * 0.047619047619047616) * x) * x) / sqrt(((double) M_PI))));
}
return tmp;
}
function code(x) tmp = 0.0 if (abs(x) <= 0.1) tmp = abs(Float64(Float64(fma(fma(Float64(0.2 * x), x, 0.6666666666666666), Float64(x * x), 2.0) / sqrt(pi)) * abs(x))); else tmp = abs(Float64(Float64(Float64(Float64(Float64(Float64(Float64(Float64(x * x) * x) * x) * x) * 0.047619047619047616) * x) * x) / sqrt(pi))); end return tmp end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.1], N[Abs[N[(N[(N[(N[(N[(0.2 * x), $MachinePrecision] * x + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(N[(N[(N[(N[(N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] * 0.047619047619047616), $MachinePrecision] * x), $MachinePrecision] * x), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.1:\\
\;\;\;\;\left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.2 \cdot x, x, 0.6666666666666666\right), x \cdot x, 2\right)}{\sqrt{\pi}} \cdot \left|x\right|\right|\\
\mathbf{else}:\\
\;\;\;\;\left|\frac{\left(\left(\left(\left(\left(\left(x \cdot x\right) \cdot x\right) \cdot x\right) \cdot x\right) \cdot 0.047619047619047616\right) \cdot x\right) \cdot x}{\sqrt{\pi}}\right|\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.10000000000000001Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites99.6%
Applied rewrites99.6%
Applied rewrites99.6%
if 0.10000000000000001 < (fabs.f64 x) Initial program 99.8%
Applied rewrites99.8%
Taylor expanded in x around inf
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
Applied rewrites97.6%
Applied rewrites97.6%
Applied rewrites97.6%
Final simplification99.0%
(FPCore (x)
:precision binary64
(*
(fabs
(fma
(*
(fma (* x x) (fma (* x x) 0.047619047619047616 0.2) 0.6666666666666666)
x)
x
2.0))
(/ (fabs x) (sqrt PI))))
double code(double x) {
return fabs(fma((fma((x * x), fma((x * x), 0.047619047619047616, 0.2), 0.6666666666666666) * x), x, 2.0)) * (fabs(x) / sqrt(((double) M_PI)));
}
function code(x) return Float64(abs(fma(Float64(fma(Float64(x * x), fma(Float64(x * x), 0.047619047619047616, 0.2), 0.6666666666666666) * x), x, 2.0)) * Float64(abs(x) / sqrt(pi))) end
code[x_] := N[(N[Abs[N[(N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * x), $MachinePrecision] * x + 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), 0.6666666666666666\right) \cdot x, x, 2\right)\right| \cdot \frac{\left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
lift-fma.f64N/A
lift-fma.f64N/A
lift-*.f64N/A
associate-+r+N/A
lift-*.f64N/A
associate-*l*N/A
lift-*.f64N/A
lift-*.f64N/A
associate-*l*N/A
distribute-lft-outN/A
lower-fma.f64N/A
Applied rewrites99.9%
Applied rewrites99.3%
Final simplification99.3%
(FPCore (x)
:precision binary64
(*
(fabs
(fma
(fma (* x x) (fma (* x x) 0.047619047619047616 0.2) 0.6666666666666666)
(* x x)
2.0))
(/ (fabs x) (sqrt PI))))
double code(double x) {
return fabs(fma(fma((x * x), fma((x * x), 0.047619047619047616, 0.2), 0.6666666666666666), (x * x), 2.0)) * (fabs(x) / sqrt(((double) M_PI)));
}
function code(x) return Float64(abs(fma(fma(Float64(x * x), fma(Float64(x * x), 0.047619047619047616, 0.2), 0.6666666666666666), Float64(x * x), 2.0)) * Float64(abs(x) / sqrt(pi))) end
code[x_] := N[(N[Abs[N[(N[(N[(x * x), $MachinePrecision] * N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|\mathsf{fma}\left(\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), 0.6666666666666666\right), x \cdot x, 2\right)\right| \cdot \frac{\left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Applied rewrites99.3%
Applied rewrites99.3%
(FPCore (x)
:precision binary64
(/
(*
(fabs
(fma
(* x x)
(fma x (* 0.047619047619047616 (* (* x x) x)) 0.6666666666666666)
2.0))
(fabs x))
(sqrt PI)))
double code(double x) {
return (fabs(fma((x * x), fma(x, (0.047619047619047616 * ((x * x) * x)), 0.6666666666666666), 2.0)) * fabs(x)) / sqrt(((double) M_PI));
}
function code(x) return Float64(Float64(abs(fma(Float64(x * x), fma(x, Float64(0.047619047619047616 * Float64(Float64(x * x) * x)), 0.6666666666666666), 2.0)) * abs(x)) / sqrt(pi)) end
code[x_] := N[(N[(N[Abs[N[(N[(x * x), $MachinePrecision] * N[(x * N[(0.047619047619047616 * N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] + 0.6666666666666666), $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, \mathsf{fma}\left(x, 0.047619047619047616 \cdot \left(\left(x \cdot x\right) \cdot x\right), 0.6666666666666666\right), 2\right)\right| \cdot \left|x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Applied rewrites99.3%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
unpow3N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f6498.2
Applied rewrites98.2%
Final simplification98.2%
(FPCore (x) :precision binary64 (fabs (* (/ (fma (fma (* 0.2 x) x 0.6666666666666666) (* x x) 2.0) (sqrt PI)) (fabs x))))
double code(double x) {
return fabs(((fma(fma((0.2 * x), x, 0.6666666666666666), (x * x), 2.0) / sqrt(((double) M_PI))) * fabs(x)));
}
function code(x) return abs(Float64(Float64(fma(fma(Float64(0.2 * x), x, 0.6666666666666666), Float64(x * x), 2.0) / sqrt(pi)) * abs(x))) end
code[x_] := N[Abs[N[(N[(N[(N[(N[(0.2 * x), $MachinePrecision] * x + 0.6666666666666666), $MachinePrecision] * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{\mathsf{fma}\left(\mathsf{fma}\left(0.2 \cdot x, x, 0.6666666666666666\right), x \cdot x, 2\right)}{\sqrt{\pi}} \cdot \left|x\right|\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites94.3%
Applied rewrites94.3%
Applied rewrites94.3%
Final simplification94.3%
(FPCore (x) :precision binary64 (if (<= (fabs x) 0.1) (* (/ (fabs 2.0) (sqrt PI)) (fabs x)) (/ (fabs (* (* (* x x) x) 0.6666666666666666)) (sqrt PI))))
double code(double x) {
double tmp;
if (fabs(x) <= 0.1) {
tmp = (fabs(2.0) / sqrt(((double) M_PI))) * fabs(x);
} else {
tmp = fabs((((x * x) * x) * 0.6666666666666666)) / sqrt(((double) M_PI));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 0.1) {
tmp = (Math.abs(2.0) / Math.sqrt(Math.PI)) * Math.abs(x);
} else {
tmp = Math.abs((((x * x) * x) * 0.6666666666666666)) / Math.sqrt(Math.PI);
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 0.1: tmp = (math.fabs(2.0) / math.sqrt(math.pi)) * math.fabs(x) else: tmp = math.fabs((((x * x) * x) * 0.6666666666666666)) / math.sqrt(math.pi) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 0.1) tmp = Float64(Float64(abs(2.0) / sqrt(pi)) * abs(x)); else tmp = Float64(abs(Float64(Float64(Float64(x * x) * x) * 0.6666666666666666)) / sqrt(pi)); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 0.1) tmp = (abs(2.0) / sqrt(pi)) * abs(x); else tmp = abs((((x * x) * x) * 0.6666666666666666)) / sqrt(pi); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 0.1], N[(N[(N[Abs[2.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision], N[(N[Abs[N[(N[(N[(x * x), $MachinePrecision] * x), $MachinePrecision] * 0.6666666666666666), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 0.1:\\
\;\;\;\;\frac{\left|2\right|}{\sqrt{\pi}} \cdot \left|x\right|\\
\mathbf{else}:\\
\;\;\;\;\frac{\left|\left(\left(x \cdot x\right) \cdot x\right) \cdot 0.6666666666666666\right|}{\sqrt{\pi}}\\
\end{array}
\end{array}
if (fabs.f64 x) < 0.10000000000000001Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites98.7%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
Applied rewrites98.0%
lift-/.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
Applied rewrites98.7%
if 0.10000000000000001 < (fabs.f64 x) Initial program 99.8%
Taylor expanded in x around 0
associate-+r+N/A
+-commutativeN/A
+-commutativeN/A
unpow3N/A
associate-*r*N/A
distribute-rgt-outN/A
*-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites99.9%
Taylor expanded in x around inf
Applied rewrites65.1%
Applied rewrites65.1%
Final simplification88.2%
(FPCore (x) :precision binary64 (fabs (* (/ (fma (* 0.6666666666666666 x) x 2.0) (sqrt PI)) (fabs x))))
double code(double x) {
return fabs(((fma((0.6666666666666666 * x), x, 2.0) / sqrt(((double) M_PI))) * fabs(x)));
}
function code(x) return abs(Float64(Float64(fma(Float64(0.6666666666666666 * x), x, 2.0) / sqrt(pi)) * abs(x))) end
code[x_] := N[Abs[N[(N[(N[(N[(0.6666666666666666 * x), $MachinePrecision] * x + 2.0), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{\mathsf{fma}\left(0.6666666666666666 \cdot x, x, 2\right)}{\sqrt{\pi}} \cdot \left|x\right|\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
associate-*r*N/A
distribute-rgt-inN/A
associate-*r*N/A
distribute-rgt-inN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites88.6%
Applied rewrites88.6%
(FPCore (x) :precision binary64 (* (/ (fabs 2.0) (sqrt PI)) (fabs x)))
double code(double x) {
return (fabs(2.0) / sqrt(((double) M_PI))) * fabs(x);
}
public static double code(double x) {
return (Math.abs(2.0) / Math.sqrt(Math.PI)) * Math.abs(x);
}
def code(x): return (math.fabs(2.0) / math.sqrt(math.pi)) * math.fabs(x)
function code(x) return Float64(Float64(abs(2.0) / sqrt(pi)) * abs(x)) end
function tmp = code(x) tmp = (abs(2.0) / sqrt(pi)) * abs(x); end
code[x_] := N[(N[(N[Abs[2.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|2\right|}{\sqrt{\pi}} \cdot \left|x\right|
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
Applied rewrites69.2%
lift-/.f64N/A
lift-*.f64N/A
lift-fabs.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lift-fabs.f64N/A
Applied rewrites69.7%
Final simplification69.7%
(FPCore (x) :precision binary64 (/ (fabs (* 2.0 x)) (sqrt PI)))
double code(double x) {
return fabs((2.0 * x)) / sqrt(((double) M_PI));
}
public static double code(double x) {
return Math.abs((2.0 * x)) / Math.sqrt(Math.PI);
}
def code(x): return math.fabs((2.0 * x)) / math.sqrt(math.pi)
function code(x) return Float64(abs(Float64(2.0 * x)) / sqrt(pi)) end
function tmp = code(x) tmp = abs((2.0 * x)) / sqrt(pi); end
code[x_] := N[(N[Abs[N[(2.0 * x), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|2 \cdot x\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied rewrites99.9%
Taylor expanded in x around 0
Applied rewrites69.7%
lift-fabs.f64N/A
lift-*.f64N/A
lift-/.f64N/A
associate-*l/N/A
fabs-divN/A
Applied rewrites69.2%
lift-*.f64N/A
lift-fabs.f64N/A
lift-fabs.f64N/A
mul-fabsN/A
lower-fabs.f64N/A
lower-*.f6469.2
Applied rewrites69.2%
herbie shell --seed 2024236
(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)))))))