Jmat.Real.erfi, branch x greater than or equal to 5

Percentage Accurate: 100.0% → 99.6%
Time: 13.3s
Alternatives: 5
Speedup: N/A×

Specification

?
\[x \geq 0.5\]
\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\left|x\right|}\\ t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\ t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\ \left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 1.0 (fabs x)))
        (t_1 (* (* t_0 t_0) t_0))
        (t_2 (* (* t_1 t_0) t_0)))
   (*
    (* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x))))
    (+
     (+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
     (* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))
double code(double x) {
	double t_0 = 1.0 / fabs(x);
	double t_1 = (t_0 * t_0) * t_0;
	double t_2 = (t_1 * t_0) * t_0;
	return ((1.0 / sqrt(((double) M_PI))) * exp((fabs(x) * fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
public static double code(double x) {
	double t_0 = 1.0 / Math.abs(x);
	double t_1 = (t_0 * t_0) * t_0;
	double t_2 = (t_1 * t_0) * t_0;
	return ((1.0 / Math.sqrt(Math.PI)) * Math.exp((Math.abs(x) * Math.abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
def code(x):
	t_0 = 1.0 / math.fabs(x)
	t_1 = (t_0 * t_0) * t_0
	t_2 = (t_1 * t_0) * t_0
	return ((1.0 / math.sqrt(math.pi)) * math.exp((math.fabs(x) * math.fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)))
function code(x)
	t_0 = Float64(1.0 / abs(x))
	t_1 = Float64(Float64(t_0 * t_0) * t_0)
	t_2 = Float64(Float64(t_1 * t_0) * t_0)
	return Float64(Float64(Float64(1.0 / sqrt(pi)) * exp(Float64(abs(x) * abs(x)))) * Float64(Float64(Float64(t_0 + Float64(Float64(1.0 / 2.0) * t_1)) + Float64(Float64(3.0 / 4.0) * t_2)) + Float64(Float64(15.0 / 8.0) * Float64(Float64(t_2 * t_0) * t_0))))
end
function tmp = code(x)
	t_0 = 1.0 / abs(x);
	t_1 = (t_0 * t_0) * t_0;
	t_2 = (t_1 * t_0) * t_0;
	tmp = ((1.0 / sqrt(pi)) * exp((abs(x) * abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(t$95$0 + N[(N[(1.0 / 2.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(3.0 / 4.0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(15.0 / 8.0), $MachinePrecision] * N[(N[(t$95$2 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\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 5 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: 100.0% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \frac{1}{\left|x\right|}\\ t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\ t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\ \left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right) \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (/ 1.0 (fabs x)))
        (t_1 (* (* t_0 t_0) t_0))
        (t_2 (* (* t_1 t_0) t_0)))
   (*
    (* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x))))
    (+
     (+ (+ t_0 (* (/ 1.0 2.0) t_1)) (* (/ 3.0 4.0) t_2))
     (* (/ 15.0 8.0) (* (* t_2 t_0) t_0))))))
double code(double x) {
	double t_0 = 1.0 / fabs(x);
	double t_1 = (t_0 * t_0) * t_0;
	double t_2 = (t_1 * t_0) * t_0;
	return ((1.0 / sqrt(((double) M_PI))) * exp((fabs(x) * fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
public static double code(double x) {
	double t_0 = 1.0 / Math.abs(x);
	double t_1 = (t_0 * t_0) * t_0;
	double t_2 = (t_1 * t_0) * t_0;
	return ((1.0 / Math.sqrt(Math.PI)) * Math.exp((Math.abs(x) * Math.abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
}
def code(x):
	t_0 = 1.0 / math.fabs(x)
	t_1 = (t_0 * t_0) * t_0
	t_2 = (t_1 * t_0) * t_0
	return ((1.0 / math.sqrt(math.pi)) * math.exp((math.fabs(x) * math.fabs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)))
function code(x)
	t_0 = Float64(1.0 / abs(x))
	t_1 = Float64(Float64(t_0 * t_0) * t_0)
	t_2 = Float64(Float64(t_1 * t_0) * t_0)
	return Float64(Float64(Float64(1.0 / sqrt(pi)) * exp(Float64(abs(x) * abs(x)))) * Float64(Float64(Float64(t_0 + Float64(Float64(1.0 / 2.0) * t_1)) + Float64(Float64(3.0 / 4.0) * t_2)) + Float64(Float64(15.0 / 8.0) * Float64(Float64(t_2 * t_0) * t_0))))
end
function tmp = code(x)
	t_0 = 1.0 / abs(x);
	t_1 = (t_0 * t_0) * t_0;
	t_2 = (t_1 * t_0) * t_0;
	tmp = ((1.0 / sqrt(pi)) * exp((abs(x) * abs(x)))) * (((t_0 + ((1.0 / 2.0) * t_1)) + ((3.0 / 4.0) * t_2)) + ((15.0 / 8.0) * ((t_2 * t_0) * t_0)));
end
code[x_] := Block[{t$95$0 = N[(1.0 / N[Abs[x], $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(t$95$0 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, Block[{t$95$2 = N[(N[(t$95$1 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]}, N[(N[(N[(1.0 / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision] * N[Exp[N[(N[Abs[x], $MachinePrecision] * N[Abs[x], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] * N[(N[(N[(t$95$0 + N[(N[(1.0 / 2.0), $MachinePrecision] * t$95$1), $MachinePrecision]), $MachinePrecision] + N[(N[(3.0 / 4.0), $MachinePrecision] * t$95$2), $MachinePrecision]), $MachinePrecision] + N[(N[(15.0 / 8.0), $MachinePrecision] * N[(N[(t$95$2 * t$95$0), $MachinePrecision] * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \frac{1}{\left|x\right|}\\
t_1 := \left(t\_0 \cdot t\_0\right) \cdot t\_0\\
t_2 := \left(t\_1 \cdot t\_0\right) \cdot t\_0\\
\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(t\_0 + \frac{1}{2} \cdot t\_1\right) + \frac{3}{4} \cdot t\_2\right) + \frac{15}{8} \cdot \left(\left(t\_2 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}

Alternative 1: 99.6% accurate, 5.1× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{{x}^{3}}{\sqrt{\pi}}\right)\right) \end{array} \]
(FPCore (x)
 :precision binary64
 (* 0.5 (log1p (expm1 (/ (pow x 3.0) (sqrt PI))))))
double code(double x) {
	return 0.5 * log1p(expm1((pow(x, 3.0) / sqrt(((double) M_PI)))));
}
public static double code(double x) {
	return 0.5 * Math.log1p(Math.expm1((Math.pow(x, 3.0) / Math.sqrt(Math.PI))));
}
def code(x):
	return 0.5 * math.log1p(math.expm1((math.pow(x, 3.0) / math.sqrt(math.pi))))
function code(x)
	return Float64(0.5 * log1p(expm1(Float64((x ^ 3.0) / sqrt(pi)))))
end
code[x_] := N[(0.5 * N[Log[1 + N[(Exp[N[(N[Power[x, 3.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{{x}^{3}}{\sqrt{\pi}}\right)\right)
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(\frac{1}{\left|x\right|} + \frac{1}{2} \cdot \left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{3}{4} \cdot \left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{15}{8} \cdot \left(\left(\left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x \cdot x}}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.75, {\left(\frac{1}{\left|x\right|}\right)}^{5}, \mathsf{fma}\left(1.875, {\left(\frac{1}{\left|x\right|}\right)}^{7}, \frac{1 + \frac{0.5}{x \cdot x}}{\left|x\right|}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 1.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)} \]
  5. Step-by-step derivation
    1. associate-*l/1.8%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{1 \cdot \sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
    2. *-lft-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\frac{1}{\pi}}}}{{x}^{2} \cdot \left|x\right|} \]
  6. Simplified1.8%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
  7. Step-by-step derivation
    1. /-rgt-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\frac{{x}^{2} \cdot \left|x\right|}{1}}} \]
    2. expm1-log1p-u1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2} \cdot \left|x\right|}{1}\right)\right)}} \]
    3. /-rgt-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{{x}^{2} \cdot \left|x\right|}\right)\right)} \]
    4. add-sqr-sqrt1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)\right)} \]
    5. fabs-sqr1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}\right)\right)} \]
    6. add-sqr-sqrt1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \color{blue}{x}\right)\right)} \]
    7. pow-plus1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{{x}^{\left(2 + 1\right)}}\right)\right)} \]
    8. metadata-eval1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\color{blue}{3}}\right)\right)} \]
  8. Applied egg-rr1.8%

    \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{3}\right)\right)}} \]
  9. Step-by-step derivation
    1. log1p-expm1-u1.8%

      \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{3}\right)\right)}\right)\right)} \]
    2. div-inv1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\sqrt{\frac{1}{\pi}} \cdot \frac{1}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{3}\right)\right)}}\right)\right) \]
    3. inv-pow1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt{\frac{1}{\pi}} \cdot \color{blue}{{\left(\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{3}\right)\right)\right)}^{-1}}\right)\right) \]
    4. expm1-log1p-u1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt{\frac{1}{\pi}} \cdot {\color{blue}{\left({x}^{3}\right)}}^{-1}\right)\right) \]
    5. pow-to-exp1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt{\frac{1}{\pi}} \cdot {\color{blue}{\left(e^{\log x \cdot 3}\right)}}^{-1}\right)\right) \]
    6. *-commutative1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt{\frac{1}{\pi}} \cdot {\left(e^{\color{blue}{3 \cdot \log x}}\right)}^{-1}\right)\right) \]
    7. exp-prod1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sqrt{\frac{1}{\pi}} \cdot \color{blue}{e^{\left(3 \cdot \log x\right) \cdot -1}}\right)\right) \]
    8. sqrt-div1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{\sqrt{1}}{\sqrt{\pi}}} \cdot e^{\left(3 \cdot \log x\right) \cdot -1}\right)\right) \]
    9. metadata-eval1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\color{blue}{1}}{\sqrt{\pi}} \cdot e^{\left(3 \cdot \log x\right) \cdot -1}\right)\right) \]
    10. associate-*l/1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\color{blue}{\frac{1 \cdot e^{\left(3 \cdot \log x\right) \cdot -1}}{\sqrt{\pi}}}\right)\right) \]
    11. *-un-lft-identity1.8%

      \[\leadsto 0.5 \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\frac{\color{blue}{e^{\left(3 \cdot \log x\right) \cdot -1}}}{\sqrt{\pi}}\right)\right) \]
  10. Applied egg-rr100.0%

    \[\leadsto 0.5 \cdot \color{blue}{\mathsf{log1p}\left(\mathsf{expm1}\left(\frac{{x}^{3}}{\sqrt{\pi}}\right)\right)} \]
  11. Add Preprocessing

Alternative 2: 82.8% accurate, 6.8× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\sqrt{{x}^{-6}}} \end{array} \]
(FPCore (x)
 :precision binary64
 (* 0.5 (/ (sqrt (/ 1.0 PI)) (sqrt (pow x -6.0)))))
double code(double x) {
	return 0.5 * (sqrt((1.0 / ((double) M_PI))) / sqrt(pow(x, -6.0)));
}
public static double code(double x) {
	return 0.5 * (Math.sqrt((1.0 / Math.PI)) / Math.sqrt(Math.pow(x, -6.0)));
}
def code(x):
	return 0.5 * (math.sqrt((1.0 / math.pi)) / math.sqrt(math.pow(x, -6.0)))
function code(x)
	return Float64(0.5 * Float64(sqrt(Float64(1.0 / pi)) / sqrt((x ^ -6.0))))
end
function tmp = code(x)
	tmp = 0.5 * (sqrt((1.0 / pi)) / sqrt((x ^ -6.0)));
end
code[x_] := N[(0.5 * N[(N[Sqrt[N[(1.0 / Pi), $MachinePrecision]], $MachinePrecision] / N[Sqrt[N[Power[x, -6.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\sqrt{{x}^{-6}}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(\frac{1}{\left|x\right|} + \frac{1}{2} \cdot \left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{3}{4} \cdot \left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{15}{8} \cdot \left(\left(\left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x \cdot x}}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.75, {\left(\frac{1}{\left|x\right|}\right)}^{5}, \mathsf{fma}\left(1.875, {\left(\frac{1}{\left|x\right|}\right)}^{7}, \frac{1 + \frac{0.5}{x \cdot x}}{\left|x\right|}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 1.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)} \]
  5. Step-by-step derivation
    1. associate-*l/1.8%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{1 \cdot \sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
    2. *-lft-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\frac{1}{\pi}}}}{{x}^{2} \cdot \left|x\right|} \]
  6. Simplified1.8%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
  7. Step-by-step derivation
    1. /-rgt-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\frac{{x}^{2} \cdot \left|x\right|}{1}}} \]
    2. expm1-log1p-u1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\frac{{x}^{2} \cdot \left|x\right|}{1}\right)\right)}} \]
    3. /-rgt-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{{x}^{2} \cdot \left|x\right|}\right)\right)} \]
    4. add-sqr-sqrt1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \left|\color{blue}{\sqrt{x} \cdot \sqrt{x}}\right|\right)\right)} \]
    5. fabs-sqr1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \color{blue}{\left(\sqrt{x} \cdot \sqrt{x}\right)}\right)\right)} \]
    6. add-sqr-sqrt1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{2} \cdot \color{blue}{x}\right)\right)} \]
    7. pow-plus1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left(\color{blue}{{x}^{\left(2 + 1\right)}}\right)\right)} \]
    8. metadata-eval1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{\color{blue}{3}}\right)\right)} \]
  8. Applied egg-rr1.8%

    \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{3}\right)\right)}} \]
  9. Step-by-step derivation
    1. expm1-log1p-u1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{{x}^{3}}} \]
    2. pow-to-exp1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{e^{\log x \cdot 3}}} \]
    3. *-commutative1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\color{blue}{3 \cdot \log x}}} \]
    4. add-sqr-sqrt1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\color{blue}{\sqrt{3 \cdot \log x} \cdot \sqrt{3 \cdot \log x}}}} \]
    5. sqrt-unprod1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\color{blue}{\sqrt{\left(3 \cdot \log x\right) \cdot \left(3 \cdot \log x\right)}}}} \]
    6. *-un-lft-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\sqrt{\color{blue}{1 \cdot \left(\left(3 \cdot \log x\right) \cdot \left(3 \cdot \log x\right)\right)}}}} \]
    7. metadata-eval1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\sqrt{\color{blue}{\left(-1 \cdot -1\right)} \cdot \left(\left(3 \cdot \log x\right) \cdot \left(3 \cdot \log x\right)\right)}}} \]
    8. swap-sqr1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\sqrt{\color{blue}{\left(-1 \cdot \left(3 \cdot \log x\right)\right) \cdot \left(-1 \cdot \left(3 \cdot \log x\right)\right)}}}} \]
    9. *-commutative1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\sqrt{\color{blue}{\left(\left(3 \cdot \log x\right) \cdot -1\right)} \cdot \left(-1 \cdot \left(3 \cdot \log x\right)\right)}}} \]
    10. *-commutative1.8%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\sqrt{\left(\left(3 \cdot \log x\right) \cdot -1\right) \cdot \color{blue}{\left(\left(3 \cdot \log x\right) \cdot -1\right)}}}} \]
    11. sqrt-unprod0.0%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\color{blue}{\sqrt{\left(3 \cdot \log x\right) \cdot -1} \cdot \sqrt{\left(3 \cdot \log x\right) \cdot -1}}}} \]
    12. add-sqr-sqrt72.0%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{e^{\color{blue}{\left(3 \cdot \log x\right) \cdot -1}}} \]
    13. add-sqr-sqrt72.0%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\sqrt{e^{\left(3 \cdot \log x\right) \cdot -1}} \cdot \sqrt{e^{\left(3 \cdot \log x\right) \cdot -1}}}} \]
    14. sqrt-unprod85.0%

      \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\sqrt{e^{\left(3 \cdot \log x\right) \cdot -1} \cdot e^{\left(3 \cdot \log x\right) \cdot -1}}}} \]
  10. Applied egg-rr85.0%

    \[\leadsto 0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{\color{blue}{\sqrt{{x}^{-6}}}} \]
  11. Add Preprocessing

Alternative 3: 68.0% accurate, 10.1× speedup?

\[\begin{array}{l} \\ \frac{0.5 \cdot {x}^{3}}{\sqrt{\pi}} \end{array} \]
(FPCore (x) :precision binary64 (/ (* 0.5 (pow x 3.0)) (sqrt PI)))
double code(double x) {
	return (0.5 * pow(x, 3.0)) / sqrt(((double) M_PI));
}
public static double code(double x) {
	return (0.5 * Math.pow(x, 3.0)) / Math.sqrt(Math.PI);
}
def code(x):
	return (0.5 * math.pow(x, 3.0)) / math.sqrt(math.pi)
function code(x)
	return Float64(Float64(0.5 * (x ^ 3.0)) / sqrt(pi))
end
function tmp = code(x)
	tmp = (0.5 * (x ^ 3.0)) / sqrt(pi);
end
code[x_] := N[(N[(0.5 * N[Power[x, 3.0], $MachinePrecision]), $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{0.5 \cdot {x}^{3}}{\sqrt{\pi}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(\frac{1}{\left|x\right|} + \frac{1}{2} \cdot \left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{3}{4} \cdot \left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{15}{8} \cdot \left(\left(\left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x \cdot x}}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.75, {\left(\frac{1}{\left|x\right|}\right)}^{5}, \mathsf{fma}\left(1.875, {\left(\frac{1}{\left|x\right|}\right)}^{7}, \frac{1 + \frac{0.5}{x \cdot x}}{\left|x\right|}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 1.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)} \]
  5. Step-by-step derivation
    1. add-exp-log1.8%

      \[\leadsto \color{blue}{e^{\log \left(0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)\right)}} \]
    2. associate-*r*1.8%

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

      \[\leadsto e^{\log \left(\left(0.5 \cdot \frac{1}{{x}^{2} \cdot \left|x\right|}\right) \cdot \color{blue}{\frac{\sqrt{1}}{\sqrt{\pi}}}\right)} \]
    4. metadata-eval1.8%

      \[\leadsto e^{\log \left(\left(0.5 \cdot \frac{1}{{x}^{2} \cdot \left|x\right|}\right) \cdot \frac{\color{blue}{1}}{\sqrt{\pi}}\right)} \]
    5. un-div-inv1.8%

      \[\leadsto e^{\log \color{blue}{\left(\frac{0.5 \cdot \frac{1}{{x}^{2} \cdot \left|x\right|}}{\sqrt{\pi}}\right)}} \]
  6. Applied egg-rr1.8%

    \[\leadsto \color{blue}{e^{\log \left(\frac{{x}^{-3} \cdot 0.5}{\sqrt{\pi}}\right)}} \]
  7. Step-by-step derivation
    1. rem-exp-log1.8%

      \[\leadsto \color{blue}{\frac{{x}^{-3} \cdot 0.5}{\sqrt{\pi}}} \]
  8. Applied egg-rr72.0%

    \[\leadsto \color{blue}{\frac{0.5 \cdot {x}^{3}}{\sqrt{\pi}}} \]
  9. Add Preprocessing

Alternative 4: 1.8% accurate, 10.1× speedup?

\[\begin{array}{l} \\ 0.5 \cdot \frac{{x}^{-3}}{\sqrt{\pi}} \end{array} \]
(FPCore (x) :precision binary64 (* 0.5 (/ (pow x -3.0) (sqrt PI))))
double code(double x) {
	return 0.5 * (pow(x, -3.0) / sqrt(((double) M_PI)));
}
public static double code(double x) {
	return 0.5 * (Math.pow(x, -3.0) / Math.sqrt(Math.PI));
}
def code(x):
	return 0.5 * (math.pow(x, -3.0) / math.sqrt(math.pi))
function code(x)
	return Float64(0.5 * Float64((x ^ -3.0) / sqrt(pi)))
end
function tmp = code(x)
	tmp = 0.5 * ((x ^ -3.0) / sqrt(pi));
end
code[x_] := N[(0.5 * N[(N[Power[x, -3.0], $MachinePrecision] / N[Sqrt[Pi], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
0.5 \cdot \frac{{x}^{-3}}{\sqrt{\pi}}
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(\frac{1}{\left|x\right|} + \frac{1}{2} \cdot \left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{3}{4} \cdot \left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{15}{8} \cdot \left(\left(\left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x \cdot x}}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.75, {\left(\frac{1}{\left|x\right|}\right)}^{5}, \mathsf{fma}\left(1.875, {\left(\frac{1}{\left|x\right|}\right)}^{7}, \frac{1 + \frac{0.5}{x \cdot x}}{\left|x\right|}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 1.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)} \]
  5. Step-by-step derivation
    1. associate-*l/1.8%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{1 \cdot \sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
    2. *-lft-identity1.8%

      \[\leadsto 0.5 \cdot \frac{\color{blue}{\sqrt{\frac{1}{\pi}}}}{{x}^{2} \cdot \left|x\right|} \]
  6. Simplified1.8%

    \[\leadsto \color{blue}{0.5 \cdot \frac{\sqrt{\frac{1}{\pi}}}{{x}^{2} \cdot \left|x\right|}} \]
  7. Applied egg-rr1.8%

    \[\leadsto 0.5 \cdot \color{blue}{\left(0 + \frac{{x}^{-3}}{\sqrt{\pi}}\right)} \]
  8. Step-by-step derivation
    1. +-lft-identity1.8%

      \[\leadsto 0.5 \cdot \color{blue}{\frac{{x}^{-3}}{\sqrt{\pi}}} \]
  9. Simplified1.8%

    \[\leadsto 0.5 \cdot \color{blue}{\frac{{x}^{-3}}{\sqrt{\pi}}} \]
  10. Add Preprocessing

Alternative 5: 1.6% accurate, 2083.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x) :precision binary64 0.0)
double code(double x) {
	return 0.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.0d0
end function
public static double code(double x) {
	return 0.0;
}
def code(x):
	return 0.0
function code(x)
	return 0.0
end
function tmp = code(x)
	tmp = 0.0;
end
code[x_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 100.0%

    \[\left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \left(\left(\left(\frac{1}{\left|x\right|} + \frac{1}{2} \cdot \left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{3}{4} \cdot \left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) + \frac{15}{8} \cdot \left(\left(\left(\left(\left(\left(\frac{1}{\left|x\right|} \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right) \cdot \frac{1}{\left|x\right|}\right)\right) \]
  2. Simplified100.0%

    \[\leadsto \color{blue}{\frac{e^{x \cdot x}}{\sqrt{\pi}} \cdot \mathsf{fma}\left(0.75, {\left(\frac{1}{\left|x\right|}\right)}^{5}, \mathsf{fma}\left(1.875, {\left(\frac{1}{\left|x\right|}\right)}^{7}, \frac{1 + \frac{0.5}{x \cdot x}}{\left|x\right|}\right)\right)} \]
  3. Add Preprocessing
  4. Taylor expanded in x around 0 1.8%

    \[\leadsto \color{blue}{0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)} \]
  5. Step-by-step derivation
    1. expm1-log1p-u1.8%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)\right)\right)} \]
    2. expm1-undefine1.6%

      \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(0.5 \cdot \left(\frac{1}{{x}^{2} \cdot \left|x\right|} \cdot \sqrt{\frac{1}{\pi}}\right)\right)} - 1} \]
  6. Applied egg-rr1.6%

    \[\leadsto \color{blue}{e^{\mathsf{log1p}\left(\frac{{x}^{-3} \cdot 0.5}{\sqrt{\pi}}\right)} - 1} \]
  7. Taylor expanded in x around inf 1.6%

    \[\leadsto \color{blue}{1} - 1 \]
  8. Final simplification1.6%

    \[\leadsto 0 \]
  9. Add Preprocessing

Reproduce

?
herbie shell --seed 2024111 
(FPCore (x)
  :name "Jmat.Real.erfi, branch x greater than or equal to 5"
  :precision binary64
  :pre (>= x 0.5)
  (* (* (/ 1.0 (sqrt PI)) (exp (* (fabs x) (fabs x)))) (+ (+ (+ (/ 1.0 (fabs x)) (* (/ 1.0 2.0) (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 3.0 4.0) (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))))) (* (/ 15.0 8.0) (* (* (* (* (* (* (/ 1.0 (fabs x)) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x))) (/ 1.0 (fabs x)))))))