
(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
(*
(/ 1.0 (sqrt PI))
(fma
(* (fabs x) (* x (* x (* x x))))
(fma (* x 0.047619047619047616) x 0.2)
(* (fabs x) (fma 0.6666666666666666 (* x x) 2.0))))))
double code(double x) {
return fabs(((1.0 / sqrt(((double) M_PI))) * fma((fabs(x) * (x * (x * (x * x)))), fma((x * 0.047619047619047616), x, 0.2), (fabs(x) * fma(0.6666666666666666, (x * x), 2.0)))));
}
function code(x) return abs(Float64(Float64(1.0 / sqrt(pi)) * fma(Float64(abs(x) * Float64(x * Float64(x * Float64(x * x)))), fma(Float64(x * 0.047619047619047616), x, 0.2), Float64(abs(x) * fma(0.6666666666666666, Float64(x * x), 2.0))))) end
code[x_] := N[Abs[N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[(N[Abs[x], $MachinePrecision] * N[(x * N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(N[(x * 0.047619047619047616), $MachinePrecision] * x + 0.2), $MachinePrecision] + N[(N[Abs[x], $MachinePrecision] * N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{1}{\sqrt{\pi}} \cdot \mathsf{fma}\left(\left|x\right| \cdot \left(x \cdot \left(x \cdot \left(x \cdot x\right)\right)\right), \mathsf{fma}\left(x \cdot 0.047619047619047616, x, 0.2\right), \left|x\right| \cdot \mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right)\right)\right|
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied egg-rr99.9%
(FPCore (x)
:precision binary64
(let* ((t_0 (* x (* x x))) (t_1 (* x t_0)) (t_2 (* (fabs x) (fabs t_1))))
(if (<=
(+
(+
(+ (* (fabs x) 2.0) (* (/ 2.0 3.0) (fabs t_0)))
(* (/ 1.0 5.0) t_2))
(* (/ 1.0 21.0) (* (fabs x) (* (fabs x) t_2))))
0.002)
(fabs
(* (fabs x) (* (sqrt (/ 1.0 PI)) (fma x (* x 0.6666666666666666) 2.0))))
(fabs (* 0.2 (* t_1 (/ (fabs x) (sqrt PI))))))))
double code(double x) {
double t_0 = x * (x * x);
double t_1 = x * t_0;
double t_2 = fabs(x) * fabs(t_1);
double tmp;
if (((((fabs(x) * 2.0) + ((2.0 / 3.0) * fabs(t_0))) + ((1.0 / 5.0) * t_2)) + ((1.0 / 21.0) * (fabs(x) * (fabs(x) * t_2)))) <= 0.002) {
tmp = fabs((fabs(x) * (sqrt((1.0 / ((double) M_PI))) * fma(x, (x * 0.6666666666666666), 2.0))));
} else {
tmp = fabs((0.2 * (t_1 * (fabs(x) / sqrt(((double) M_PI))))));
}
return tmp;
}
function code(x) t_0 = Float64(x * Float64(x * x)) t_1 = Float64(x * t_0) t_2 = Float64(abs(x) * abs(t_1)) tmp = 0.0 if (Float64(Float64(Float64(Float64(abs(x) * 2.0) + Float64(Float64(2.0 / 3.0) * abs(t_0))) + Float64(Float64(1.0 / 5.0) * t_2)) + Float64(Float64(1.0 / 21.0) * Float64(abs(x) * Float64(abs(x) * t_2)))) <= 0.002) tmp = abs(Float64(abs(x) * Float64(sqrt(Float64(1.0 / pi)) * fma(x, Float64(x * 0.6666666666666666), 2.0)))); else tmp = abs(Float64(0.2 * Float64(t_1 * Float64(abs(x) / sqrt(pi))))); end return tmp end
code[x_] := Block[{t$95$0 = N[(x * N[(x * x), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[Abs[x], $MachinePrecision] * N[Abs[t$95$1], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(N[(N[(N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision] + N[(N[(2.0 / 3.0), $MachinePrecision] * N[Abs[t$95$0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 5.0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(1.0 / 21.0), $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.002], N[Abs[N[(N[Abs[x], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(x * N[(x * 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], N[Abs[N[(0.2 * N[(t$95$1 * N[(N[Abs[x], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(x \cdot x\right)\\
t_1 := x \cdot t\_0\\
t_2 := \left|x\right| \cdot \left|t\_1\right|\\
\mathbf{if}\;\left(\left(\left|x\right| \cdot 2 + \frac{2}{3} \cdot \left|t\_0\right|\right) + \frac{1}{5} \cdot t\_2\right) + \frac{1}{21} \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot t\_2\right)\right) \leq 0.002:\\
\;\;\;\;\left|\left|x\right| \cdot \left(\sqrt{\frac{1}{\pi}} \cdot \mathsf{fma}\left(x, x \cdot 0.6666666666666666, 2\right)\right)\right|\\
\mathbf{else}:\\
\;\;\;\;\left|0.2 \cdot \left(t\_1 \cdot \frac{\left|x\right|}{\sqrt{\pi}}\right)\right|\\
\end{array}
\end{array}
if (+.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)))) < 2e-3Initial program 99.9%
Applied egg-rr99.9%
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around 0
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
Simplified99.8%
if 2e-3 < (+.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.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fabs.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Simplified89.6%
Taylor expanded in x around inf
lower-*.f64N/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
*-commutativeN/A
lower-*.f64N/A
metadata-evalN/A
pow-sqrN/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lower-PI.f6489.6
Simplified89.6%
lift-fabs.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-*.f64N/A
lift-PI.f64N/A
frac-2negN/A
metadata-evalN/A
metadata-evalN/A
frac-2negN/A
lift-/.f64N/A
lift-sqrt.f64N/A
*-commutativeN/A
associate-*r*N/A
Applied egg-rr89.6%
Final simplification96.0%
(FPCore (x)
:precision binary64
(*
(fabs
(*
x
(fma
(* x x)
(fma x (* x (fma (* x x) 0.047619047619047616 0.2)) 0.6666666666666666)
2.0)))
(sqrt (/ 1.0 PI))))
double code(double x) {
return fabs((x * fma((x * x), fma(x, (x * fma((x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0))) * sqrt((1.0 / ((double) M_PI)));
}
function code(x) return Float64(abs(Float64(x * fma(Float64(x * x), fma(x, Float64(x * fma(Float64(x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0))) * sqrt(Float64(1.0 / pi))) end
code[x_] := N[(N[Abs[N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision]), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), 0.6666666666666666\right), 2\right)\right| \cdot \sqrt{\frac{1}{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
pow-sqrN/A
metadata-evalN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Simplified99.9%
Applied egg-rr99.9%
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(*
(fabs x)
(/
(fabs
(fma
(* x x)
(fma x (* x (fma (* x x) 0.047619047619047616 0.2)) 0.6666666666666666)
2.0))
(sqrt PI))))
double code(double x) {
return fabs(x) * (fabs(fma((x * x), fma(x, (x * fma((x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0)) / sqrt(((double) M_PI)));
}
function code(x) return Float64(abs(x) * Float64(abs(fma(Float64(x * x), fma(x, Float64(x * fma(Float64(x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0)) / sqrt(pi))) end
code[x_] := N[(N[Abs[x], $MachinePrecision] * N[(N[Abs[N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision]), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|x\right| \cdot \frac{\left|\mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), 0.6666666666666666\right), 2\right)\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
pow-sqrN/A
metadata-evalN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Simplified99.9%
Applied egg-rr99.9%
lift-fabs.f64N/A
/-rgt-identity99.9
Applied egg-rr99.9%
Final simplification99.9%
(FPCore (x)
:precision binary64
(/
(fabs
(*
x
(fma
(* x x)
(fma x (* x (fma (* x x) 0.047619047619047616 0.2)) 0.6666666666666666)
2.0)))
(sqrt PI)))
double code(double x) {
return fabs((x * fma((x * x), fma(x, (x * fma((x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0))) / sqrt(((double) M_PI));
}
function code(x) return Float64(abs(Float64(x * fma(Float64(x * x), fma(x, Float64(x * fma(Float64(x * x), 0.047619047619047616, 0.2)), 0.6666666666666666), 2.0))) / sqrt(pi)) end
code[x_] := N[(N[Abs[N[(x * N[(N[(x * x), $MachinePrecision] * N[(x * N[(x * N[(N[(x * x), $MachinePrecision] * 0.047619047619047616 + 0.2), $MachinePrecision]), $MachinePrecision] + 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|x \cdot \mathsf{fma}\left(x \cdot x, \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x \cdot x, 0.047619047619047616, 0.2\right), 0.6666666666666666\right), 2\right)\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
pow-sqrN/A
metadata-evalN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Simplified99.9%
Applied egg-rr99.9%
Applied egg-rr99.5%
Final simplification99.5%
(FPCore (x) :precision binary64 (fabs (* (/ 1.0 (sqrt PI)) (* (fabs x) (fma x (* x (fma x (* x 0.2) 0.6666666666666666)) 2.0)))))
double code(double x) {
return fabs(((1.0 / sqrt(((double) M_PI))) * (fabs(x) * fma(x, (x * fma(x, (x * 0.2), 0.6666666666666666)), 2.0))));
}
function code(x) return abs(Float64(Float64(1.0 / sqrt(pi)) * Float64(abs(x) * fma(x, Float64(x * fma(x, Float64(x * 0.2), 0.6666666666666666)), 2.0)))) end
code[x_] := N[Abs[N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.2), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\frac{1}{\sqrt{\pi}} \cdot \left(\left|x\right| \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.2, 0.6666666666666666\right), 2\right)\right)\right|
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
+-commutativeN/A
+-commutativeN/A
+-commutativeN/A
distribute-rgt-inN/A
associate-*l*N/A
pow-sqrN/A
metadata-evalN/A
distribute-lft-outN/A
unpow2N/A
associate-*l*N/A
unpow2N/A
associate-*l*N/A
distribute-lft-outN/A
Simplified99.9%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6496.0
Simplified96.0%
(FPCore (x) :precision binary64 (/ (fabs (* (fabs x) (fma x (* x (fma x (* x 0.2) 0.6666666666666666)) 2.0))) (sqrt PI)))
double code(double x) {
return fabs((fabs(x) * fma(x, (x * fma(x, (x * 0.2), 0.6666666666666666)), 2.0))) / sqrt(((double) M_PI));
}
function code(x) return Float64(abs(Float64(abs(x) * fma(x, Float64(x * fma(x, Float64(x * 0.2), 0.6666666666666666)), 2.0))) / sqrt(pi)) end
code[x_] := N[(N[Abs[N[(N[Abs[x], $MachinePrecision] * N[(x * N[(x * N[(x * N[(x * 0.2), $MachinePrecision] + 0.6666666666666666), $MachinePrecision]), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\left|x\right| \cdot \mathsf{fma}\left(x, x \cdot \mathsf{fma}\left(x, x \cdot 0.2, 0.6666666666666666\right), 2\right)\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fabs.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Simplified96.0%
Applied egg-rr95.6%
Taylor expanded in x around 0
Simplified95.6%
(FPCore (x) :precision binary64 (if (<= (fabs x) 4e-27) (* (fabs x) (/ 2.0 (sqrt PI))) (* (* x x) (/ 2.0 (fabs (* (sqrt PI) x))))))
double code(double x) {
double tmp;
if (fabs(x) <= 4e-27) {
tmp = fabs(x) * (2.0 / sqrt(((double) M_PI)));
} else {
tmp = (x * x) * (2.0 / fabs((sqrt(((double) M_PI)) * x)));
}
return tmp;
}
public static double code(double x) {
double tmp;
if (Math.abs(x) <= 4e-27) {
tmp = Math.abs(x) * (2.0 / Math.sqrt(Math.PI));
} else {
tmp = (x * x) * (2.0 / Math.abs((Math.sqrt(Math.PI) * x)));
}
return tmp;
}
def code(x): tmp = 0 if math.fabs(x) <= 4e-27: tmp = math.fabs(x) * (2.0 / math.sqrt(math.pi)) else: tmp = (x * x) * (2.0 / math.fabs((math.sqrt(math.pi) * x))) return tmp
function code(x) tmp = 0.0 if (abs(x) <= 4e-27) tmp = Float64(abs(x) * Float64(2.0 / sqrt(pi))); else tmp = Float64(Float64(x * x) * Float64(2.0 / abs(Float64(sqrt(pi) * x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (abs(x) <= 4e-27) tmp = abs(x) * (2.0 / sqrt(pi)); else tmp = (x * x) * (2.0 / abs((sqrt(pi) * x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[Abs[x], $MachinePrecision], 4e-27], N[(N[Abs[x], $MachinePrecision] * N[(2.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * x), $MachinePrecision] * N[(2.0 / N[Abs[N[(N[Sqrt[Pi], $MachinePrecision] * x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\left|x\right| \leq 4 \cdot 10^{-27}:\\
\;\;\;\;\left|x\right| \cdot \frac{2}{\sqrt{\pi}}\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot x\right) \cdot \frac{2}{\left|\sqrt{\pi} \cdot x\right|}\\
\end{array}
\end{array}
if (fabs.f64 x) < 4.0000000000000002e-27Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
Simplified99.9%
Applied egg-rr99.2%
lift-fabs.f64N/A
lift-PI.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
times-fracN/A
/-rgt-identityN/A
lower-*.f64N/A
lower-/.f6499.9
Applied egg-rr99.9%
if 4.0000000000000002e-27 < (fabs.f64 x) Initial program 99.9%
Applied egg-rr33.5%
Taylor expanded in x around 0
*-commutativeN/A
associate-*l/N/A
associate-/l*N/A
*-rgt-identityN/A
associate-*r/N/A
associate-*r*N/A
*-commutativeN/A
*-commutativeN/A
*-commutativeN/A
associate-*l*N/A
lower-*.f64N/A
Simplified63.7%
Applied egg-rr62.8%
Final simplification84.4%
(FPCore (x) :precision binary64 (fabs (* (fabs x) (* (sqrt (/ 1.0 PI)) (fma x (* x 0.6666666666666666) 2.0)))))
double code(double x) {
return fabs((fabs(x) * (sqrt((1.0 / ((double) M_PI))) * fma(x, (x * 0.6666666666666666), 2.0))));
}
function code(x) return abs(Float64(abs(x) * Float64(sqrt(Float64(1.0 / pi)) * fma(x, Float64(x * 0.6666666666666666), 2.0)))) end
code[x_] := N[Abs[N[(N[Abs[x], $MachinePrecision] * N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] * N[(x * N[(x * 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]
\begin{array}{l}
\\
\left|\left|x\right| \cdot \left(\sqrt{\frac{1}{\pi}} \cdot \mathsf{fma}\left(x, x \cdot 0.6666666666666666, 2\right)\right)\right|
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
associate-*l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-*.f6499.9
Applied egg-rr99.9%
Taylor expanded in x around 0
associate-*l*N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
associate-*r*N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
lower-*.f64N/A
Simplified90.4%
(FPCore (x) :precision binary64 (/ (fabs (* (fabs x) (fma x (* x 0.6666666666666666) 2.0))) (sqrt PI)))
double code(double x) {
return fabs((fabs(x) * fma(x, (x * 0.6666666666666666), 2.0))) / sqrt(((double) M_PI));
}
function code(x) return Float64(abs(Float64(abs(x) * fma(x, Float64(x * 0.6666666666666666), 2.0))) / sqrt(pi)) end
code[x_] := N[(N[Abs[N[(N[Abs[x], $MachinePrecision] * N[(x * N[(x * 0.6666666666666666), $MachinePrecision] + 2.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left|\left|x\right| \cdot \mathsf{fma}\left(x, x \cdot 0.6666666666666666, 2\right)\right|}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
lower-fma.f64N/A
lower-fabs.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
unpow2N/A
lower-*.f64N/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
distribute-lft-inN/A
+-commutativeN/A
lower-*.f64N/A
lower-fabs.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
Simplified96.0%
Applied egg-rr95.6%
Taylor expanded in x around 0
+-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f64N/A
lower-fabs.f64N/A
+-commutativeN/A
unpow2N/A
associate-*r*N/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f6489.9
Simplified89.9%
(FPCore (x) :precision binary64 (* (fabs x) (/ 2.0 (sqrt PI))))
double code(double x) {
return fabs(x) * (2.0 / sqrt(((double) M_PI)));
}
public static double code(double x) {
return Math.abs(x) * (2.0 / Math.sqrt(Math.PI));
}
def code(x): return math.fabs(x) * (2.0 / math.sqrt(math.pi))
function code(x) return Float64(abs(x) * Float64(2.0 / sqrt(pi))) end
function tmp = code(x) tmp = abs(x) * (2.0 / sqrt(pi)); end
code[x_] := N[(N[Abs[x], $MachinePrecision] * N[(2.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left|x\right| \cdot \frac{2}{\sqrt{\pi}}
\end{array}
Initial program 99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0
Simplified64.4%
Applied egg-rr64.0%
lift-fabs.f64N/A
lift-PI.f64N/A
lift-sqrt.f64N/A
metadata-evalN/A
times-fracN/A
*-commutativeN/A
times-fracN/A
/-rgt-identityN/A
lower-*.f64N/A
lower-/.f6464.4
Applied egg-rr64.4%
Final simplification64.4%
herbie shell --seed 2024208
(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)))))))