Jmat.Real.erfi, branch x less than or equal to 0.5

Percentage Accurate: 99.8% → 99.8%
Time: 5.3s
Alternatives: 3
Speedup: N/A×

Specification

?
\[x \leq 0.5\]
\[\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
 (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:

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 3 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.8% accurate, 1.0× speedup?

\[\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
 (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}

Alternative 1: 99.8% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := {\left(x \cdot x\right)}^{2.5}\\ \left|\mathsf{fma}\left({\pi}^{-0.5} \cdot \left(\left(t\_0 \cdot x\right) \cdot x\right), 0.047619047619047616, \mathsf{fma}\left(t\_0, 0.2, \mathsf{fma}\left({\left(x \cdot x\right)}^{1.5}, 0.6666666666666666, \left|x\right| \cdot 2\right)\right) \cdot {\pi}^{-0.5}\right)\right| \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (pow (* x x) 2.5)))
   (fabs
    (fma
     (* (pow PI -0.5) (* (* t_0 x) x))
     0.047619047619047616
     (*
      (fma t_0 0.2 (fma (pow (* x x) 1.5) 0.6666666666666666 (* (fabs x) 2.0)))
      (pow PI -0.5))))))
double code(double x) {
	double t_0 = pow((x * x), 2.5);
	return fabs(fma((pow(((double) M_PI), -0.5) * ((t_0 * x) * x)), 0.047619047619047616, (fma(t_0, 0.2, fma(pow((x * x), 1.5), 0.6666666666666666, (fabs(x) * 2.0))) * pow(((double) M_PI), -0.5))));
}
function code(x)
	t_0 = Float64(x * x) ^ 2.5
	return abs(fma(Float64((pi ^ -0.5) * Float64(Float64(t_0 * x) * x)), 0.047619047619047616, Float64(fma(t_0, 0.2, fma((Float64(x * x) ^ 1.5), 0.6666666666666666, Float64(abs(x) * 2.0))) * (pi ^ -0.5))))
end
code[x_] := Block[{t$95$0 = N[Power[N[(x * x), $MachinePrecision], 2.5], $MachinePrecision]}, N[Abs[N[(N[(N[Power[Pi, -0.5], $MachinePrecision] * N[(N[(t$95$0 * x), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision] * 0.047619047619047616 + N[(N[(t$95$0 * 0.2 + N[(N[Power[N[(x * x), $MachinePrecision], 1.5], $MachinePrecision] * 0.6666666666666666 + N[(N[Abs[x], $MachinePrecision] * 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[Power[Pi, -0.5], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := {\left(x \cdot x\right)}^{2.5}\\
\left|\mathsf{fma}\left({\pi}^{-0.5} \cdot \left(\left(t\_0 \cdot x\right) \cdot x\right), 0.047619047619047616, \mathsf{fma}\left(t\_0, 0.2, \mathsf{fma}\left({\left(x \cdot x\right)}^{1.5}, 0.6666666666666666, \left|x\right| \cdot 2\right)\right) \cdot {\pi}^{-0.5}\right)\right|
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left|\frac{1}{\sqrt{\pi}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  2. Add Preprocessing
  3. Applied rewrites99.8%

    \[\leadsto \left|\color{blue}{\mathsf{fma}\left({\pi}^{-0.5} \cdot \left(\left({\left(x \cdot x\right)}^{2.5} \cdot x\right) \cdot x\right), 0.047619047619047616, \mathsf{fma}\left({\left(x \cdot x\right)}^{2.5}, 0.2, \mathsf{fma}\left({\left(x \cdot x\right)}^{1.5}, 0.6666666666666666, \left|x\right| \cdot 2\right)\right) \cdot {\pi}^{-0.5}\right)}\right| \]
  4. Add Preprocessing

Alternative 2: 99.8% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\\ t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\ \left|\frac{-1}{\sqrt{\pi} - 0}\right| \cdot \left|\left(-1 \cdot \frac{1}{21}\right) \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right) - \left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot t\_1\right)\right| \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (* (* (* -1.0 x) x) (* -1.0 (fabs x))))
        (t_1 (* (* t_0 (fabs x)) (fabs x))))
   (*
    (fabs (/ -1.0 (- (sqrt PI) 0.0)))
    (fabs
     (-
      (* (* -1.0 (/ 1.0 21.0)) (* (* t_1 (fabs x)) (fabs x)))
      (-
       (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0))
       (* (* -1.0 (/ 1.0 5.0)) t_1)))))))
double code(double x) {
	double t_0 = ((-1.0 * x) * x) * (-1.0 * fabs(x));
	double t_1 = (t_0 * fabs(x)) * fabs(x);
	return fabs((-1.0 / (sqrt(((double) M_PI)) - 0.0))) * fabs((((-1.0 * (1.0 / 21.0)) * ((t_1 * fabs(x)) * fabs(x))) - (((2.0 * fabs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1))));
}
public static double code(double x) {
	double t_0 = ((-1.0 * x) * x) * (-1.0 * Math.abs(x));
	double t_1 = (t_0 * Math.abs(x)) * Math.abs(x);
	return Math.abs((-1.0 / (Math.sqrt(Math.PI) - 0.0))) * Math.abs((((-1.0 * (1.0 / 21.0)) * ((t_1 * Math.abs(x)) * Math.abs(x))) - (((2.0 * Math.abs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1))));
}
def code(x):
	t_0 = ((-1.0 * x) * x) * (-1.0 * math.fabs(x))
	t_1 = (t_0 * math.fabs(x)) * math.fabs(x)
	return math.fabs((-1.0 / (math.sqrt(math.pi) - 0.0))) * math.fabs((((-1.0 * (1.0 / 21.0)) * ((t_1 * math.fabs(x)) * math.fabs(x))) - (((2.0 * math.fabs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1))))
function code(x)
	t_0 = Float64(Float64(Float64(-1.0 * x) * x) * Float64(-1.0 * abs(x)))
	t_1 = Float64(Float64(t_0 * abs(x)) * abs(x))
	return Float64(abs(Float64(-1.0 / Float64(sqrt(pi) - 0.0))) * abs(Float64(Float64(Float64(-1.0 * Float64(1.0 / 21.0)) * Float64(Float64(t_1 * abs(x)) * abs(x))) - Float64(Float64(Float64(2.0 * abs(x)) + Float64(Float64(2.0 / 3.0) * t_0)) - Float64(Float64(-1.0 * Float64(1.0 / 5.0)) * t_1)))))
end
function tmp = code(x)
	t_0 = ((-1.0 * x) * x) * (-1.0 * abs(x));
	t_1 = (t_0 * abs(x)) * abs(x);
	tmp = abs((-1.0 / (sqrt(pi) - 0.0))) * abs((((-1.0 * (1.0 / 21.0)) * ((t_1 * abs(x)) * abs(x))) - (((2.0 * abs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1))));
end
code[x_] := Block[{t$95$0 = N[(N[(N[(-1.0 * x), $MachinePrecision] * x), $MachinePrecision] * N[(-1.0 * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]}, N[(N[Abs[N[(-1.0 / N[(N[Sqrt[Pi], $MachinePrecision] - 0.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * N[Abs[N[(N[(N[(-1.0 * N[(1.0 / 21.0), $MachinePrecision]), $MachinePrecision] * N[(N[(t$95$1 * N[Abs[x], $MachinePrecision]), $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - 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 * N[(1.0 / 5.0), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|\frac{-1}{\sqrt{\pi} - 0}\right| \cdot \left|\left(-1 \cdot \frac{1}{21}\right) \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right) - \left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot t\_1\right)\right|
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left|\frac{1}{\sqrt{\pi}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  2. Add Preprocessing
  3. Final simplification99.8%

    \[\leadsto \left|\frac{-1}{\sqrt{\pi} - 0}\right| \cdot \left|\left(-1 \cdot \frac{1}{21}\right) \cdot \left(\left(\left(\left(\left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) - \left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right)\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot \left(\left(\left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  4. Add Preprocessing

Alternative 3: 98.8% accurate, N/A× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\\ t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\ \left|e^{\log \left({\pi}^{0.5}\right) \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot t\_1\right) - \left(-1 \cdot \frac{1}{21}\right) \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
 (let* ((t_0 (* (* (* -1.0 x) x) (* -1.0 (fabs x))))
        (t_1 (* (* t_0 (fabs x)) (fabs x))))
   (fabs
    (*
     (exp (* (log (pow PI 0.5)) -1.0))
     (-
      (- (+ (* 2.0 (fabs x)) (* (/ 2.0 3.0) t_0)) (* (* -1.0 (/ 1.0 5.0)) t_1))
      (* (* -1.0 (/ 1.0 21.0)) (* (* t_1 (fabs x)) (fabs x))))))))
double code(double x) {
	double t_0 = ((-1.0 * x) * x) * (-1.0 * fabs(x));
	double t_1 = (t_0 * fabs(x)) * fabs(x);
	return fabs((exp((log(pow(((double) M_PI), 0.5)) * -1.0)) * ((((2.0 * fabs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1)) - ((-1.0 * (1.0 / 21.0)) * ((t_1 * fabs(x)) * fabs(x))))));
}
public static double code(double x) {
	double t_0 = ((-1.0 * x) * x) * (-1.0 * Math.abs(x));
	double t_1 = (t_0 * Math.abs(x)) * Math.abs(x);
	return Math.abs((Math.exp((Math.log(Math.pow(Math.PI, 0.5)) * -1.0)) * ((((2.0 * Math.abs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1)) - ((-1.0 * (1.0 / 21.0)) * ((t_1 * Math.abs(x)) * Math.abs(x))))));
}
def code(x):
	t_0 = ((-1.0 * x) * x) * (-1.0 * math.fabs(x))
	t_1 = (t_0 * math.fabs(x)) * math.fabs(x)
	return math.fabs((math.exp((math.log(math.pow(math.pi, 0.5)) * -1.0)) * ((((2.0 * math.fabs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1)) - ((-1.0 * (1.0 / 21.0)) * ((t_1 * math.fabs(x)) * math.fabs(x))))))
function code(x)
	t_0 = Float64(Float64(Float64(-1.0 * x) * x) * Float64(-1.0 * abs(x)))
	t_1 = Float64(Float64(t_0 * abs(x)) * abs(x))
	return abs(Float64(exp(Float64(log((pi ^ 0.5)) * -1.0)) * Float64(Float64(Float64(Float64(2.0 * abs(x)) + Float64(Float64(2.0 / 3.0) * t_0)) - Float64(Float64(-1.0 * Float64(1.0 / 5.0)) * t_1)) - Float64(Float64(-1.0 * Float64(1.0 / 21.0)) * Float64(Float64(t_1 * abs(x)) * abs(x))))))
end
function tmp = code(x)
	t_0 = ((-1.0 * x) * x) * (-1.0 * abs(x));
	t_1 = (t_0 * abs(x)) * abs(x);
	tmp = abs((exp((log((pi ^ 0.5)) * -1.0)) * ((((2.0 * abs(x)) + ((2.0 / 3.0) * t_0)) - ((-1.0 * (1.0 / 5.0)) * t_1)) - ((-1.0 * (1.0 / 21.0)) * ((t_1 * abs(x)) * abs(x))))));
end
code[x_] := Block[{t$95$0 = N[(N[(N[(-1.0 * x), $MachinePrecision] * x), $MachinePrecision] * N[(-1.0 * N[Abs[x], $MachinePrecision]), $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[Exp[N[(N[Log[N[Power[Pi, 0.5], $MachinePrecision]], $MachinePrecision] * -1.0), $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 * N[(1.0 / 5.0), $MachinePrecision]), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] - N[(N[(-1.0 * N[(1.0 / 21.0), $MachinePrecision]), $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(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\\
t_1 := \left(t\_0 \cdot \left|x\right|\right) \cdot \left|x\right|\\
\left|e^{\log \left({\pi}^{0.5}\right) \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot t\_0\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot t\_1\right) - \left(-1 \cdot \frac{1}{21}\right) \cdot \left(\left(t\_1 \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right|
\end{array}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\left|\frac{1}{\sqrt{\pi}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. lift-/.f64N/A

      \[\leadsto \left|\color{blue}{\frac{1}{\sqrt{\pi}}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    2. inv-powN/A

      \[\leadsto \left|\color{blue}{{\left(\sqrt{\pi}\right)}^{-1}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    3. pow-to-expN/A

      \[\leadsto \left|\color{blue}{e^{\log \left(\sqrt{\pi}\right) \cdot -1}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    4. lower-exp.f64N/A

      \[\leadsto \left|\color{blue}{e^{\log \left(\sqrt{\pi}\right) \cdot -1}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    5. lower-*.f64N/A

      \[\leadsto \left|e^{\color{blue}{\log \left(\sqrt{\pi}\right) \cdot -1}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    6. lower-log.f6498.8

      \[\leadsto \left|e^{\color{blue}{\log \left(\sqrt{\pi}\right)} \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    7. lift-PI.f64N/A

      \[\leadsto \left|e^{\log \left(\sqrt{\color{blue}{\mathsf{PI}\left(\right)}}\right) \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    8. lift-sqrt.f64N/A

      \[\leadsto \left|e^{\log \color{blue}{\left(\sqrt{\mathsf{PI}\left(\right)}\right)} \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    9. pow1/2N/A

      \[\leadsto \left|e^{\log \color{blue}{\left({\mathsf{PI}\left(\right)}^{\frac{1}{2}}\right)} \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    10. lower-pow.f64N/A

      \[\leadsto \left|e^{\log \color{blue}{\left({\mathsf{PI}\left(\right)}^{\frac{1}{2}}\right)} \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
    11. lift-PI.f6498.8

      \[\leadsto \left|e^{\log \left({\color{blue}{\pi}}^{0.5}\right) \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  4. Applied rewrites98.8%

    \[\leadsto \left|\color{blue}{e^{\log \left({\pi}^{0.5}\right) \cdot -1}} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{5} \cdot \left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) + \frac{1}{21} \cdot \left(\left(\left(\left(\left(\left(\left|x\right| \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  5. Final simplification98.8%

    \[\leadsto \left|e^{\log \left({\pi}^{0.5}\right) \cdot -1} \cdot \left(\left(\left(2 \cdot \left|x\right| + \frac{2}{3} \cdot \left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right)\right) - \left(-1 \cdot \frac{1}{5}\right) \cdot \left(\left(\left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right) - \left(-1 \cdot \frac{1}{21}\right) \cdot \left(\left(\left(\left(\left(\left(\left(-1 \cdot x\right) \cdot x\right) \cdot \left(-1 \cdot \left|x\right|\right)\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right) \cdot \left|x\right|\right)\right)\right| \]
  6. Add Preprocessing

Reproduce

?
herbie shell --seed 2025065 
(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)))))))