| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 19912 |

(FPCore (x y z) :precision binary64 (+ x (/ y (- (* 1.1283791670955126 (exp z)) (* x y)))))
(FPCore (x y z)
:precision binary64
(if (<= (exp z) 0.0)
(+ x (/ -1.0 x))
(if (<= (exp z) 1.0)
(+ x (/ y (- 1.1283791670955126 (* x y))))
(+ x (/ (* y 0.8862269254527579) (exp z))))))double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * exp(z)) - (x * y)));
}
double code(double x, double y, double z) {
double tmp;
if (exp(z) <= 0.0) {
tmp = x + (-1.0 / x);
} else if (exp(z) <= 1.0) {
tmp = x + (y / (1.1283791670955126 - (x * y)));
} else {
tmp = x + ((y * 0.8862269254527579) / exp(z));
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x + (y / ((1.1283791670955126d0 * exp(z)) - (x * y)))
end function
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (exp(z) <= 0.0d0) then
tmp = x + ((-1.0d0) / x)
else if (exp(z) <= 1.0d0) then
tmp = x + (y / (1.1283791670955126d0 - (x * y)))
else
tmp = x + ((y * 0.8862269254527579d0) / exp(z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return x + (y / ((1.1283791670955126 * Math.exp(z)) - (x * y)));
}
public static double code(double x, double y, double z) {
double tmp;
if (Math.exp(z) <= 0.0) {
tmp = x + (-1.0 / x);
} else if (Math.exp(z) <= 1.0) {
tmp = x + (y / (1.1283791670955126 - (x * y)));
} else {
tmp = x + ((y * 0.8862269254527579) / Math.exp(z));
}
return tmp;
}
def code(x, y, z): return x + (y / ((1.1283791670955126 * math.exp(z)) - (x * y)))
def code(x, y, z): tmp = 0 if math.exp(z) <= 0.0: tmp = x + (-1.0 / x) elif math.exp(z) <= 1.0: tmp = x + (y / (1.1283791670955126 - (x * y))) else: tmp = x + ((y * 0.8862269254527579) / math.exp(z)) return tmp
function code(x, y, z) return Float64(x + Float64(y / Float64(Float64(1.1283791670955126 * exp(z)) - Float64(x * y)))) end
function code(x, y, z) tmp = 0.0 if (exp(z) <= 0.0) tmp = Float64(x + Float64(-1.0 / x)); elseif (exp(z) <= 1.0) tmp = Float64(x + Float64(y / Float64(1.1283791670955126 - Float64(x * y)))); else tmp = Float64(x + Float64(Float64(y * 0.8862269254527579) / exp(z))); end return tmp end
function tmp = code(x, y, z) tmp = x + (y / ((1.1283791670955126 * exp(z)) - (x * y))); end
function tmp_2 = code(x, y, z) tmp = 0.0; if (exp(z) <= 0.0) tmp = x + (-1.0 / x); elseif (exp(z) <= 1.0) tmp = x + (y / (1.1283791670955126 - (x * y))); else tmp = x + ((y * 0.8862269254527579) / exp(z)); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(x + N[(y / N[(N[(1.1283791670955126 * N[Exp[z], $MachinePrecision]), $MachinePrecision] - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[N[Exp[z], $MachinePrecision], 0.0], N[(x + N[(-1.0 / x), $MachinePrecision]), $MachinePrecision], If[LessEqual[N[Exp[z], $MachinePrecision], 1.0], N[(x + N[(y / N[(1.1283791670955126 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y * 0.8862269254527579), $MachinePrecision] / N[Exp[z], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\begin{array}{l}
\mathbf{if}\;e^{z} \leq 0:\\
\;\;\;\;x + \frac{-1}{x}\\
\mathbf{elif}\;e^{z} \leq 1:\\
\;\;\;\;x + \frac{y}{1.1283791670955126 - x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y \cdot 0.8862269254527579}{e^{z}}\\
\end{array}
Herbie found 13 alternatives:
| Alternative | Accuracy | Speedup |
|---|
Results
| Original | 95.6% |
|---|---|
| Target | 99.9% |
| Herbie | 99.3% |
if (exp.f64 z) < 0.0Initial program 85.6%
Simplified100.0%
[Start]85.6% | \[ x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
|---|---|
*-lft-identity [<=]85.6% | \[ x + \color{blue}{1 \cdot \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
metadata-eval [<=]85.6% | \[ x + \color{blue}{\frac{-1}{-1}} \cdot \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
times-frac [<=]85.6% | \[ x + \color{blue}{\frac{-1 \cdot y}{-1 \cdot \left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
neg-mul-1 [<=]85.6% | \[ x + \frac{-1 \cdot y}{\color{blue}{-\left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
sub0-neg [<=]85.4% | \[ x + \frac{-1 \cdot y}{\color{blue}{0 - \left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
associate-+l- [<=]85.4% | \[ x + \frac{-1 \cdot y}{\color{blue}{\left(0 - 1.1283791670955126 \cdot e^{z}\right) + x \cdot y}}
\] |
neg-sub0 [<=]85.8% | \[ x + \frac{-1 \cdot y}{\color{blue}{\left(-1.1283791670955126 \cdot e^{z}\right)} + x \cdot y}
\] |
+-commutative [<=]85.8% | \[ x + \frac{-1 \cdot y}{\color{blue}{x \cdot y + \left(-1.1283791670955126 \cdot e^{z}\right)}}
\] |
sub-neg [<=]85.8% | \[ x + \frac{-1 \cdot y}{\color{blue}{x \cdot y - 1.1283791670955126 \cdot e^{z}}}
\] |
associate-/l* [=>]86.0% | \[ x + \color{blue}{\frac{-1}{\frac{x \cdot y - 1.1283791670955126 \cdot e^{z}}{y}}}
\] |
div-sub [=>]85.9% | \[ x + \frac{-1}{\color{blue}{\frac{x \cdot y}{y} - \frac{1.1283791670955126 \cdot e^{z}}{y}}}
\] |
associate-*r/ [<=]100.0% | \[ x + \frac{-1}{\color{blue}{x \cdot \frac{y}{y}} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
*-inverses [=>]100.0% | \[ x + \frac{-1}{x \cdot \color{blue}{1} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
*-rgt-identity [=>]100.0% | \[ x + \frac{-1}{\color{blue}{x} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
associate-*l/ [<=]100.0% | \[ x + \frac{-1}{x - \color{blue}{\frac{1.1283791670955126}{y} \cdot e^{z}}}
\] |
cancel-sign-sub-inv [=>]100.0% | \[ x + \frac{-1}{\color{blue}{x + \left(-\frac{1.1283791670955126}{y}\right) \cdot e^{z}}}
\] |
distribute-lft-neg-in [<=]100.0% | \[ x + \frac{-1}{x + \color{blue}{\left(-\frac{1.1283791670955126}{y} \cdot e^{z}\right)}}
\] |
distribute-rgt-neg-in [=>]100.0% | \[ x + \frac{-1}{x + \color{blue}{\frac{1.1283791670955126}{y} \cdot \left(-e^{z}\right)}}
\] |
associate-*l/ [=>]100.0% | \[ x + \frac{-1}{x + \color{blue}{\frac{1.1283791670955126 \cdot \left(-e^{z}\right)}{y}}}
\] |
distribute-rgt-neg-in [<=]100.0% | \[ x + \frac{-1}{x + \frac{\color{blue}{-1.1283791670955126 \cdot e^{z}}}{y}}
\] |
Taylor expanded in y around inf 100.0%
if 0.0 < (exp.f64 z) < 1Initial program 99.9%
Taylor expanded in z around 0 99.9%
if 1 < (exp.f64 z) Initial program 91.3%
Simplified100.0%
[Start]91.3% | \[ x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
|---|---|
*-lft-identity [<=]91.3% | \[ x + \color{blue}{1 \cdot \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
metadata-eval [<=]91.3% | \[ x + \color{blue}{\frac{-1}{-1}} \cdot \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
times-frac [<=]91.3% | \[ x + \color{blue}{\frac{-1 \cdot y}{-1 \cdot \left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
neg-mul-1 [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{-\left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
sub0-neg [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{0 - \left(1.1283791670955126 \cdot e^{z} - x \cdot y\right)}}
\] |
associate-+l- [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{\left(0 - 1.1283791670955126 \cdot e^{z}\right) + x \cdot y}}
\] |
neg-sub0 [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{\left(-1.1283791670955126 \cdot e^{z}\right)} + x \cdot y}
\] |
+-commutative [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{x \cdot y + \left(-1.1283791670955126 \cdot e^{z}\right)}}
\] |
sub-neg [<=]91.3% | \[ x + \frac{-1 \cdot y}{\color{blue}{x \cdot y - 1.1283791670955126 \cdot e^{z}}}
\] |
associate-/l* [=>]91.3% | \[ x + \color{blue}{\frac{-1}{\frac{x \cdot y - 1.1283791670955126 \cdot e^{z}}{y}}}
\] |
div-sub [=>]91.3% | \[ x + \frac{-1}{\color{blue}{\frac{x \cdot y}{y} - \frac{1.1283791670955126 \cdot e^{z}}{y}}}
\] |
associate-*r/ [<=]100.0% | \[ x + \frac{-1}{\color{blue}{x \cdot \frac{y}{y}} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
*-inverses [=>]100.0% | \[ x + \frac{-1}{x \cdot \color{blue}{1} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
*-rgt-identity [=>]100.0% | \[ x + \frac{-1}{\color{blue}{x} - \frac{1.1283791670955126 \cdot e^{z}}{y}}
\] |
associate-*l/ [<=]100.0% | \[ x + \frac{-1}{x - \color{blue}{\frac{1.1283791670955126}{y} \cdot e^{z}}}
\] |
cancel-sign-sub-inv [=>]100.0% | \[ x + \frac{-1}{\color{blue}{x + \left(-\frac{1.1283791670955126}{y}\right) \cdot e^{z}}}
\] |
distribute-lft-neg-in [<=]100.0% | \[ x + \frac{-1}{x + \color{blue}{\left(-\frac{1.1283791670955126}{y} \cdot e^{z}\right)}}
\] |
distribute-rgt-neg-in [=>]100.0% | \[ x + \frac{-1}{x + \color{blue}{\frac{1.1283791670955126}{y} \cdot \left(-e^{z}\right)}}
\] |
associate-*l/ [=>]100.0% | \[ x + \frac{-1}{x + \color{blue}{\frac{1.1283791670955126 \cdot \left(-e^{z}\right)}{y}}}
\] |
distribute-rgt-neg-in [<=]100.0% | \[ x + \frac{-1}{x + \frac{\color{blue}{-1.1283791670955126 \cdot e^{z}}}{y}}
\] |
Taylor expanded in y around 0 100.0%
Simplified100.0%
[Start]100.0% | \[ x + 0.8862269254527579 \cdot \frac{y}{e^{z}}
\] |
|---|---|
*-commutative [=>]100.0% | \[ x + \color{blue}{\frac{y}{e^{z}} \cdot 0.8862269254527579}
\] |
associate-*l/ [=>]100.0% | \[ x + \color{blue}{\frac{y \cdot 0.8862269254527579}{e^{z}}}
\] |
Final simplification99.9%
| Alternative 1 | |
|---|---|
| Accuracy | 99.3% |
| Cost | 19912 |
| Alternative 2 | |
|---|---|
| Accuracy | 99.9% |
| Cost | 13376 |
| Alternative 3 | |
|---|---|
| Accuracy | 96.2% |
| Cost | 1476 |
| Alternative 4 | |
|---|---|
| Accuracy | 95.4% |
| Cost | 1220 |
| Alternative 5 | |
|---|---|
| Accuracy | 93.4% |
| Cost | 964 |
| Alternative 6 | |
|---|---|
| Accuracy | 92.4% |
| Cost | 840 |
| Alternative 7 | |
|---|---|
| Accuracy | 92.4% |
| Cost | 840 |
| Alternative 8 | |
|---|---|
| Accuracy | 92.4% |
| Cost | 840 |
| Alternative 9 | |
|---|---|
| Accuracy | 74.4% |
| Cost | 717 |
| Alternative 10 | |
|---|---|
| Accuracy | 79.5% |
| Cost | 712 |
| Alternative 11 | |
|---|---|
| Accuracy | 71.4% |
| Cost | 585 |
| Alternative 12 | |
|---|---|
| Accuracy | 75.1% |
| Cost | 584 |
| Alternative 13 | |
|---|---|
| Accuracy | 14.4% |
| Cost | 192 |
herbie shell --seed 2023165
(FPCore (x y z)
:name "Numeric.SpecFunctions:invErfc from math-functions-0.1.5.2, A"
:precision binary64
:herbie-target
(+ x (/ 1.0 (- (* (/ 1.1283791670955126 y) (exp z)) x)))
(+ x (/ y (- (* 1.1283791670955126 (exp z)) (* x y)))))