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

?

Percentage Accurate: 99.8% → 99.8%
Time: 11.7s
Precision: binary64
Cost: 85888

?

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

Local Percentage Accuracy?

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.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

The accuracy (vertical axis) and speed (horizontal axis) of each of Herbie's proposed alternatives. Up and to the right is better. Each dot represents an alternative program; the red square represents the initial program.

Bogosity?

Bogosity

Try it out?

Your Program's Arguments

Results

Enter valid numbers for all inputs

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. Final simplification99.8%

    \[\leadsto \left|\frac{1}{\sqrt{\pi}} \cdot \left(\left(\left(2 \cdot \left|x\right| + 0.6666666666666666 \cdot \left(\left|x\right| \cdot \left(x \cdot x\right)\right)\right) + 0.2 \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(x \cdot x\right)\right)\right)\right)\right) + 0.047619047619047616 \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(\left|x\right| \cdot \left(x \cdot x\right)\right)\right)\right)\right)\right)\right)\right| \]

Alternatives

Alternative 1
Accuracy99.8%
Cost53760
\[\begin{array}{l} t_0 := \left(x \cdot x\right) \cdot \left(x \cdot x\right)\\ \left|\frac{1}{\sqrt{\pi}} \cdot \left(\left(\mathsf{fma}\left(2, \left|x\right|, 0.6666666666666666 \cdot \left(\left|x\right| \cdot \left(x \cdot x\right)\right)\right) + 0.2 \cdot \left(\left|x\right| \cdot t_0\right)\right) + 0.047619047619047616 \cdot \left(\left|x\right| \cdot \left(\left(x \cdot x\right) \cdot t_0\right)\right)\right)\right| \end{array} \]
Alternative 2
Accuracy99.4%
Cost39552
\[\left|\frac{x}{\sqrt{\pi}} \cdot \left(\left(2 + 0.6666666666666666 \cdot \left(x \cdot x\right)\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
Alternative 3
Accuracy98.5%
Cost39168
\[\left|\frac{x}{\sqrt{\pi}} \cdot \left(2 + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
Alternative 4
Accuracy98.3%
Cost32448
\[\left|\frac{\mathsf{fma}\left(2, x, 0.047619047619047616 \cdot {x}^{7}\right)}{\sqrt{\pi}}\right| \]
Alternative 5
Accuracy99.1%
Cost26436
\[\begin{array}{l} \mathbf{if}\;x \leq -2.2:\\ \;\;\;\;\left|{x}^{7} \cdot \frac{0.047619047619047616}{\sqrt{\pi}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|\sqrt{\frac{1}{\pi}} \cdot \left(2 \cdot x + 0.6666666666666666 \cdot {x}^{3}\right)\right|\\ \end{array} \]
Alternative 6
Accuracy96.3%
Cost26052
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85:\\ \;\;\;\;\left|\sqrt{{x}^{14} \cdot \frac{0.0022675736961451248}{\pi}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 7
Accuracy98.8%
Cost26052
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85:\\ \;\;\;\;\left|{x}^{7} \cdot \frac{0.047619047619047616}{\sqrt{\pi}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 8
Accuracy83.2%
Cost19716
\[\begin{array}{l} \mathbf{if}\;x \leq -5 \cdot 10^{-46}:\\ \;\;\;\;\left|\sqrt{\frac{x \cdot 4}{\frac{\pi}{x}}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 9
Accuracy83.4%
Cost19716
\[\begin{array}{l} \mathbf{if}\;x \leq -0.5:\\ \;\;\;\;\left|x \cdot \frac{x \cdot 4}{\sqrt{\pi}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 10
Accuracy67.4%
Cost19456
\[\left|x \cdot \frac{2}{\sqrt{\pi}}\right| \]

Reproduce?

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