| Alternative 1 | |
|---|---|
| Error | 1.2 |
| Cost | 7172 |
\[\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-40}:\\
\;\;\;\;\frac{1}{y} + x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{{\left(\frac{y}{z + y}\right)}^{y}}{y}\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (+ x (/ (exp (* y (log (/ y (+ z y))))) y)))
(FPCore (x y z) :precision binary64 (if (<= y 5e-40) (+ (/ 1.0 y) x) (+ x (/ 1.0 (/ y (pow (/ y (+ y z)) y))))))
double code(double x, double y, double z) {
return x + (exp((y * log((y / (z + y))))) / y);
}
double code(double x, double y, double z) {
double tmp;
if (y <= 5e-40) {
tmp = (1.0 / y) + x;
} else {
tmp = x + (1.0 / (y / pow((y / (y + z)), y)));
}
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 + (exp((y * log((y / (z + y))))) / 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 (y <= 5d-40) then
tmp = (1.0d0 / y) + x
else
tmp = x + (1.0d0 / (y / ((y / (y + z)) ** y)))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return x + (Math.exp((y * Math.log((y / (z + y))))) / y);
}
public static double code(double x, double y, double z) {
double tmp;
if (y <= 5e-40) {
tmp = (1.0 / y) + x;
} else {
tmp = x + (1.0 / (y / Math.pow((y / (y + z)), y)));
}
return tmp;
}
def code(x, y, z): return x + (math.exp((y * math.log((y / (z + y))))) / y)
def code(x, y, z): tmp = 0 if y <= 5e-40: tmp = (1.0 / y) + x else: tmp = x + (1.0 / (y / math.pow((y / (y + z)), y))) return tmp
function code(x, y, z) return Float64(x + Float64(exp(Float64(y * log(Float64(y / Float64(z + y))))) / y)) end
function code(x, y, z) tmp = 0.0 if (y <= 5e-40) tmp = Float64(Float64(1.0 / y) + x); else tmp = Float64(x + Float64(1.0 / Float64(y / (Float64(y / Float64(y + z)) ^ y)))); end return tmp end
function tmp = code(x, y, z) tmp = x + (exp((y * log((y / (z + y))))) / y); end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= 5e-40) tmp = (1.0 / y) + x; else tmp = x + (1.0 / (y / ((y / (y + z)) ^ y))); end tmp_2 = tmp; end
code[x_, y_, z_] := N[(x + N[(N[Exp[N[(y * N[Log[N[(y / N[(z + y), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]
code[x_, y_, z_] := If[LessEqual[y, 5e-40], N[(N[(1.0 / y), $MachinePrecision] + x), $MachinePrecision], N[(x + N[(1.0 / N[(y / N[Power[N[(y / N[(y + z), $MachinePrecision]), $MachinePrecision], y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
x + \frac{e^{y \cdot \log \left(\frac{y}{z + y}\right)}}{y}
\begin{array}{l}
\mathbf{if}\;y \leq 5 \cdot 10^{-40}:\\
\;\;\;\;\frac{1}{y} + x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{1}{\frac{y}{{\left(\frac{y}{y + z}\right)}^{y}}}\\
\end{array}
Results
| Original | 5.9 |
|---|---|
| Target | 1.0 |
| Herbie | 1.2 |
if y < 4.99999999999999965e-40Initial program 8.1
Taylor expanded in z around 0 1.0
if 4.99999999999999965e-40 < y Initial program 1.4
Applied egg-rr1.4
Simplified1.4
[Start]1.4 | \[ x + \left(\frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y} + \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}\right)
\] |
|---|---|
rational.json-simplify-6 [<=]1.4 | \[ x + \left(\color{blue}{1 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}} + \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}\right)
\] |
rational.json-simplify-2 [<=]1.4 | \[ x + \left(\color{blue}{\frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y} \cdot 1} + \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}\right)
\] |
rational.json-simplify-6 [<=]1.4 | \[ x + \left(\frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y} \cdot 1 + \color{blue}{1 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}}\right)
\] |
rational.json-simplify-51 [=>]1.4 | \[ x + \color{blue}{\frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y} \cdot \left(1 + 1\right)}
\] |
metadata-eval [=>]1.4 | \[ x + \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y} \cdot \color{blue}{2}
\] |
rational.json-simplify-2 [<=]1.4 | \[ x + \color{blue}{2 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + y}}
\] |
rational.json-simplify-7 [<=]1.4 | \[ x + 2 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{y + \color{blue}{\frac{y}{1}}}
\] |
rational.json-simplify-30 [<=]1.4 | \[ x + 2 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{\color{blue}{\left(1 + 1\right) \cdot \frac{y}{1}}}
\] |
metadata-eval [=>]1.4 | \[ x + 2 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{\color{blue}{2} \cdot \frac{y}{1}}
\] |
rational.json-simplify-7 [=>]1.4 | \[ x + 2 \cdot \frac{{\left(\frac{y}{y + z}\right)}^{y}}{2 \cdot \color{blue}{y}}
\] |
rational.json-simplify-47 [<=]1.4 | \[ x + 2 \cdot \color{blue}{\frac{\frac{{\left(\frac{y}{y + z}\right)}^{y}}{2}}{y}}
\] |
rational.json-simplify-44 [=>]1.4 | \[ x + 2 \cdot \color{blue}{\frac{\frac{{\left(\frac{y}{y + z}\right)}^{y}}{y}}{2}}
\] |
rational.json-simplify-7 [<=]1.4 | \[ x + 2 \cdot \frac{\frac{{\left(\frac{y}{y + z}\right)}^{y}}{\color{blue}{\frac{y}{1}}}}{2}
\] |
rational.json-simplify-61 [=>]1.4 | \[ x + 2 \cdot \frac{\color{blue}{\frac{1}{\frac{y}{{\left(\frac{y}{y + z}\right)}^{y}}}}}{2}
\] |
rational.json-simplify-44 [=>]1.4 | \[ x + 2 \cdot \color{blue}{\frac{\frac{1}{2}}{\frac{y}{{\left(\frac{y}{y + z}\right)}^{y}}}}
\] |
metadata-eval [=>]1.4 | \[ x + 2 \cdot \frac{\color{blue}{0.5}}{\frac{y}{{\left(\frac{y}{y + z}\right)}^{y}}}
\] |
rational.json-simplify-1 [=>]1.4 | \[ x + 2 \cdot \frac{0.5}{\frac{y}{{\left(\frac{y}{\color{blue}{z + y}}\right)}^{y}}}
\] |
Applied egg-rr1.4
Final simplification1.2
| Alternative 1 | |
|---|---|
| Error | 1.2 |
| Cost | 7172 |
| Alternative 2 | |
|---|---|
| Error | 14.1 |
| Cost | 456 |
| Alternative 3 | |
|---|---|
| Error | 2.2 |
| Cost | 320 |
| Alternative 4 | |
|---|---|
| Error | 28.6 |
| Cost | 64 |
herbie shell --seed 2023069
(FPCore (x y z)
:name "Numeric.SpecFunctions:invIncompleteBetaWorker from math-functions-0.1.5.2, G"
:precision binary64
:herbie-target
(if (< (/ y (+ z y)) 7.11541576e-315) (+ x (/ (exp (/ -1.0 z)) y)) (+ x (/ (exp (log (pow (/ y (+ y z)) y))) y)))
(+ x (/ (exp (* y (log (/ y (+ z y))))) y)))