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

?

Percentage Accurate: 99.8% → 99.9%
Time: 9.6s
Precision: binary64
Cost: 39616

?

\[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| \]
\[\left|\left({\pi}^{-0.5} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
(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
 (fabs
  (*
   (* (pow PI -0.5) x)
   (+
    (fma 0.6666666666666666 (* x x) 2.0)
    (+ (* 0.2 (pow x 4.0)) (* 0.047619047619047616 (pow x 6.0)))))))
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) {
	return fabs(((pow(((double) M_PI), -0.5) * x) * (fma(0.6666666666666666, (x * x), 2.0) + ((0.2 * pow(x, 4.0)) + (0.047619047619047616 * pow(x, 6.0))))));
}
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)
	return abs(Float64(Float64((pi ^ -0.5) * x) * Float64(fma(0.6666666666666666, Float64(x * x), 2.0) + Float64(Float64(0.2 * (x ^ 4.0)) + Float64(0.047619047619047616 * (x ^ 6.0))))))
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_] := N[Abs[N[(N[(N[Power[Pi, -0.5], $MachinePrecision] * x), $MachinePrecision] * N[(N[(0.6666666666666666 * N[(x * x), $MachinePrecision] + 2.0), $MachinePrecision] + N[(N[(0.2 * N[Power[x, 4.0], $MachinePrecision]), $MachinePrecision] + N[(0.047619047619047616 * N[Power[x, 6.0], $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|
\left|\left({\pi}^{-0.5} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right|

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.

Herbie found 11 alternatives:

AlternativeAccuracySpeedup

Accuracy vs Speed

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.

Bogosity?

Bogosity

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. Simplified99.4%

    \[\leadsto \color{blue}{\left|\frac{\left|x\right|}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right|} \]
    Step-by-step derivation

    [Start]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| \]

    associate-*l/ [=>]99.4%

    \[ \left|\color{blue}{\frac{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)}{\sqrt{\pi}}}\right| \]
  3. Applied egg-rr99.9%

    \[\leadsto \left|\color{blue}{\left(\left|x\right| \cdot \frac{1}{\sqrt{\pi}}\right)} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
    Step-by-step derivation

    [Start]99.4%

    \[ \left|\frac{\left|x\right|}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    div-inv [=>]99.9%

    \[ \left|\color{blue}{\left(\left|x\right| \cdot \frac{1}{\sqrt{\pi}}\right)} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
  4. Simplified99.4%

    \[\leadsto \left|\color{blue}{\frac{x}{\sqrt{\pi}}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
    Step-by-step derivation

    [Start]99.9%

    \[ \left|\left(\left|x\right| \cdot \frac{1}{\sqrt{\pi}}\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    associate-*r/ [=>]99.4%

    \[ \left|\color{blue}{\frac{\left|x\right| \cdot 1}{\sqrt{\pi}}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    *-rgt-identity [=>]99.4%

    \[ \left|\frac{\color{blue}{\left|x\right|}}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    unpow1 [<=]99.4%

    \[ \left|\frac{\left|\color{blue}{{x}^{1}}\right|}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    sqr-pow [=>]31.0%

    \[ \left|\frac{\left|\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}\right|}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    fabs-sqr [=>]31.0%

    \[ \left|\frac{\color{blue}{{x}^{\left(\frac{1}{2}\right)} \cdot {x}^{\left(\frac{1}{2}\right)}}}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    sqr-pow [<=]99.4%

    \[ \left|\frac{\color{blue}{{x}^{1}}}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    unpow1 [=>]99.4%

    \[ \left|\frac{\color{blue}{x}}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \mathsf{fma}\left(0.2, {x}^{4}, 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
  5. Taylor expanded in x around 0 99.4%

    \[\leadsto \left|\frac{x}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \color{blue}{\left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)}\right)\right| \]
  6. Applied egg-rr99.9%

    \[\leadsto \left|\color{blue}{\left({\pi}^{-0.5} \cdot x\right)} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
    Step-by-step derivation

    [Start]99.4%

    \[ \left|\frac{x}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    clear-num [=>]99.3%

    \[ \left|\color{blue}{\frac{1}{\frac{\sqrt{\pi}}{x}}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    associate-/r/ [=>]99.9%

    \[ \left|\color{blue}{\left(\frac{1}{\sqrt{\pi}} \cdot x\right)} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    pow1/2 [=>]99.9%

    \[ \left|\left(\frac{1}{\color{blue}{{\pi}^{0.5}}} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    pow-flip [=>]99.9%

    \[ \left|\left(\color{blue}{{\pi}^{\left(-0.5\right)}} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

    metadata-eval [=>]99.9%

    \[ \left|\left({\pi}^{\color{blue}{-0.5}} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
  7. Final simplification99.9%

    \[\leadsto \left|\left({\pi}^{-0.5} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]

Alternatives

Alternative 1
Accuracy99.9%
Cost39616
\[\left|\left({\pi}^{-0.5} \cdot x\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + \left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right)\right)\right| \]
Alternative 2
Accuracy99.4%
Cost33280
\[\left|\frac{x}{\sqrt{\pi}} \cdot \left(\left(0.2 \cdot {x}^{4} + 0.047619047619047616 \cdot {x}^{6}\right) + \left(2 + 0.6666666666666666 \cdot \left(x \cdot x\right)\right)\right)\right| \]
Alternative 3
Accuracy99.3%
Cost32960
\[\left|\left(x \cdot \sqrt{\frac{1}{\pi}}\right) \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + 0.047619047619047616 \cdot {x}^{6}\right)\right| \]
Alternative 4
Accuracy98.8%
Cost32832
\[\left|\frac{x}{\sqrt{\pi}} \cdot \left(\mathsf{fma}\left(0.6666666666666666, x \cdot x, 2\right) + 0.047619047619047616 \cdot {x}^{6}\right)\right| \]
Alternative 5
Accuracy99.0%
Cost26180
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85:\\ \;\;\;\;\left|0.047619047619047616 \cdot \left(\sqrt{\frac{1}{\pi}} \cdot {x}^{7}\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 6
Accuracy99.0%
Cost26180
\[\begin{array}{l} \mathbf{if}\;x \leq -1.85:\\ \;\;\;\;\left|\sqrt{\frac{1}{\pi}} \cdot \left(0.047619047619047616 \cdot {x}^{7}\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 7
Accuracy98.5%
Cost26176
\[\left|\frac{x}{\sqrt{\pi}} \cdot \left(2 + 0.047619047619047616 \cdot {x}^{6}\right)\right| \]
Alternative 8
Accuracy94.4%
Cost26052
\[\begin{array}{l} \mathbf{if}\;x \leq -1.75:\\ \;\;\;\;\left|\sqrt{\frac{{x}^{6}}{\pi} \cdot 0.4444444444444444}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 9
Accuracy89.0%
Cost19972
\[\begin{array}{l} \mathbf{if}\;x \leq -1.75:\\ \;\;\;\;\left|0.6666666666666666 \cdot \left(\sqrt{\frac{1}{\pi}} \cdot \left(x \cdot \left(x \cdot x\right)\right)\right)\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 10
Accuracy83.4%
Cost19716
\[\begin{array}{l} \mathbf{if}\;x \leq -2 \cdot 10^{-8}:\\ \;\;\;\;\left|\sqrt{\frac{x \cdot \left(x \cdot 4\right)}{\pi}}\right|\\ \mathbf{else}:\\ \;\;\;\;\left|x \cdot \frac{2}{\sqrt{\pi}}\right|\\ \end{array} \]
Alternative 11
Accuracy68.1%
Cost19456
\[\left|x \cdot \frac{2}{\sqrt{\pi}}\right| \]

Reproduce?

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