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

Percentage Accurate: 100.0% → 99.6%
Time: 7.0s
Alternatives: 1
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 1 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, 4.3× speedup?

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

\\
\frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \frac{1.875}{{x}^{6}}\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. Step-by-step derivation
    1. associate-+l+100.0%

      \[\leadsto \left(\frac{1}{\sqrt{\pi}} \cdot e^{\left|x\right| \cdot \left|x\right|}\right) \cdot \color{blue}{\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) + \left(\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) + \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)\right)} \]
  3. Simplified100.0%

    \[\leadsto \color{blue}{\frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \left(\frac{1.875}{{x}^{6}} + \frac{0.5 + \frac{0.75}{x \cdot x}}{x \cdot x}\right)\right)} \]
  4. Taylor expanded in x around inf 100.0%

    \[\leadsto \frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \left(\frac{1.875}{{x}^{6}} + \color{blue}{\frac{0.5}{{x}^{2}}}\right)\right) \]
  5. Step-by-step derivation
    1. unpow2100.0%

      \[\leadsto \frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \left(\frac{1.875}{{x}^{6}} + \frac{0.5}{\color{blue}{x \cdot x}}\right)\right) \]
  6. Simplified100.0%

    \[\leadsto \frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \left(\frac{1.875}{{x}^{6}} + \color{blue}{\frac{0.5}{x \cdot x}}\right)\right) \]
  7. Taylor expanded in x around 0 100.0%

    \[\leadsto \frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \color{blue}{\frac{1.875}{{x}^{6}}}\right) \]
  8. Final simplification100.0%

    \[\leadsto \frac{\frac{e^{x \cdot x}}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(1 + \frac{1.875}{{x}^{6}}\right) \]

Reproduce

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