| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 39616 |
\[\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|
Herbie found 11 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Initial program 99.8%
Simplified99.4%
[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|
\] |
Applied egg-rr99.9%
[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|
\] |
Simplified99.4%
[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|
\] |
Taylor expanded in x around 0 99.4%
Applied egg-rr99.9%
[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|
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 39616 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.4% |
| Cost | 33280 |
| Alternative 3 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 32960 |
| Alternative 4 | |
|---|---|
| Accuracy | 98.8% |
| Cost | 32832 |
| Alternative 5 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 26180 |
| Alternative 6 | |
|---|---|
| Accuracy | 99.0% |
| Cost | 26180 |
| Alternative 7 | |
|---|---|
| Accuracy | 98.5% |
| Cost | 26176 |
| Alternative 8 | |
|---|---|
| Accuracy | 94.4% |
| Cost | 26052 |
| Alternative 9 | |
|---|---|
| Accuracy | 89.0% |
| Cost | 19972 |
| Alternative 10 | |
|---|---|
| Accuracy | 83.4% |
| Cost | 19716 |
| Alternative 11 | |
|---|---|
| Accuracy | 68.1% |
| Cost | 19456 |
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)))))))