| Alternative 1 | |
|---|---|
| Error | 0.4 |
| 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.000000000005)
(+ x (/ y (- 1.1283791670955126 (* x y))))
(+ x (/ (/ y 1.1283791670955126) (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.000000000005) {
tmp = x + (y / (1.1283791670955126 - (x * y)));
} else {
tmp = x + ((y / 1.1283791670955126) / 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.000000000005d0) then
tmp = x + (y / (1.1283791670955126d0 - (x * y)))
else
tmp = x + ((y / 1.1283791670955126d0) / 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.000000000005) {
tmp = x + (y / (1.1283791670955126 - (x * y)));
} else {
tmp = x + ((y / 1.1283791670955126) / 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.000000000005: tmp = x + (y / (1.1283791670955126 - (x * y))) else: tmp = x + ((y / 1.1283791670955126) / 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.000000000005) tmp = Float64(x + Float64(y / Float64(1.1283791670955126 - Float64(x * y)))); else tmp = Float64(x + Float64(Float64(y / 1.1283791670955126) / 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.000000000005) tmp = x + (y / (1.1283791670955126 - (x * y))); else tmp = x + ((y / 1.1283791670955126) / 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.000000000005], N[(x + N[(y / N[(1.1283791670955126 - N[(x * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / 1.1283791670955126), $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.000000000005:\\
\;\;\;\;x + \frac{y}{1.1283791670955126 - x \cdot y}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{\frac{y}{1.1283791670955126}}{e^{z}}\\
\end{array}
Results
| Original | 2.7 |
|---|---|
| Target | 0.0 |
| Herbie | 0.4 |
if (exp.f64 z) < 0.0Initial program 7.5
Simplified0.0
[Start]7.5 | \[ x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
|---|---|
--rgt-identity [<=]7.5 | \[ \color{blue}{\left(x - 0\right)} + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
associate-+l- [=>]7.5 | \[ \color{blue}{x - \left(0 - \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}
\] |
sub-neg [=>]7.5 | \[ \color{blue}{x + \left(-\left(0 - \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)\right)}
\] |
+-lft-identity [<=]7.5 | \[ x + \left(-\left(0 - \color{blue}{\left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}\right)\right)
\] |
sub0-neg [=>]7.5 | \[ x + \left(-\color{blue}{\left(-\left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)\right)}\right)
\] |
neg-mul-1 [=>]7.5 | \[ x + \left(-\color{blue}{-1 \cdot \left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}\right)
\] |
distribute-lft-neg-in [=>]7.5 | \[ x + \color{blue}{\left(--1\right) \cdot \left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}
\] |
+-lft-identity [=>]7.5 | \[ x + \left(--1\right) \cdot \color{blue}{\frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
associate-*r/ [=>]7.5 | \[ x + \color{blue}{\frac{\left(--1\right) \cdot y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
sub-neg [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{1.1283791670955126 \cdot e^{z} + \left(-x \cdot y\right)}}
\] |
+-commutative [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{\left(-x \cdot y\right) + 1.1283791670955126 \cdot e^{z}}}
\] |
neg-sub0 [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{\left(0 - x \cdot y\right)} + 1.1283791670955126 \cdot e^{z}}
\] |
associate-+l- [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{0 - \left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
sub0-neg [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{-\left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
neg-mul-1 [=>]7.5 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{-1 \cdot \left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
times-frac [=>]7.5 | \[ x + \color{blue}{\frac{--1}{-1} \cdot \frac{y}{x \cdot y - 1.1283791670955126 \cdot e^{z}}}
\] |
Taylor expanded in x around inf 0.0
if 0.0 < (exp.f64 z) < 1.000000000005Initial program 0.1
Taylor expanded in z around 0 0.4
if 1.000000000005 < (exp.f64 z) Initial program 3.4
Simplified0.0
[Start]3.4 | \[ x + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
|---|---|
--rgt-identity [<=]3.4 | \[ \color{blue}{\left(x - 0\right)} + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}
\] |
associate-+l- [=>]3.4 | \[ \color{blue}{x - \left(0 - \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}
\] |
sub-neg [=>]3.4 | \[ \color{blue}{x + \left(-\left(0 - \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)\right)}
\] |
+-lft-identity [<=]3.4 | \[ x + \left(-\left(0 - \color{blue}{\left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}\right)\right)
\] |
sub0-neg [=>]3.4 | \[ x + \left(-\color{blue}{\left(-\left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)\right)}\right)
\] |
neg-mul-1 [=>]3.4 | \[ x + \left(-\color{blue}{-1 \cdot \left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}\right)
\] |
distribute-lft-neg-in [=>]3.4 | \[ x + \color{blue}{\left(--1\right) \cdot \left(0 + \frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}\right)}
\] |
+-lft-identity [=>]3.4 | \[ x + \left(--1\right) \cdot \color{blue}{\frac{y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
associate-*r/ [=>]3.4 | \[ x + \color{blue}{\frac{\left(--1\right) \cdot y}{1.1283791670955126 \cdot e^{z} - x \cdot y}}
\] |
sub-neg [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{1.1283791670955126 \cdot e^{z} + \left(-x \cdot y\right)}}
\] |
+-commutative [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{\left(-x \cdot y\right) + 1.1283791670955126 \cdot e^{z}}}
\] |
neg-sub0 [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{\left(0 - x \cdot y\right)} + 1.1283791670955126 \cdot e^{z}}
\] |
associate-+l- [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{0 - \left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
sub0-neg [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{-\left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
neg-mul-1 [=>]3.4 | \[ x + \frac{\left(--1\right) \cdot y}{\color{blue}{-1 \cdot \left(x \cdot y - 1.1283791670955126 \cdot e^{z}\right)}}
\] |
times-frac [=>]3.4 | \[ x + \color{blue}{\frac{--1}{-1} \cdot \frac{y}{x \cdot y - 1.1283791670955126 \cdot e^{z}}}
\] |
Taylor expanded in y around 0 0.6
Applied egg-rr0.6
Final simplification0.4
| Alternative 1 | |
|---|---|
| Error | 0.4 |
| Cost | 19912 |
| Alternative 2 | |
|---|---|
| Error | 0.2 |
| Cost | 13896 |
| Alternative 3 | |
|---|---|
| Error | 0.0 |
| Cost | 13376 |
| Alternative 4 | |
|---|---|
| Error | 18.8 |
| Cost | 1248 |
| Alternative 5 | |
|---|---|
| Error | 18.8 |
| Cost | 1248 |
| Alternative 6 | |
|---|---|
| Error | 9.5 |
| Cost | 1104 |
| Alternative 7 | |
|---|---|
| Error | 18.0 |
| Cost | 984 |
| Alternative 8 | |
|---|---|
| Error | 9.5 |
| Cost | 848 |
| Alternative 9 | |
|---|---|
| Error | 0.3 |
| Cost | 840 |
| Alternative 10 | |
|---|---|
| Error | 19.5 |
| Cost | 720 |
| Alternative 11 | |
|---|---|
| Error | 19.3 |
| Cost | 64 |
herbie shell --seed 2023018
(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)))))