| Alternative 1 | |
|---|---|
| Error | 19.2 |
| Cost | 584 |
\[\begin{array}{l}
\mathbf{if}\;z \leq -1.75 \cdot 10^{-94}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 1.66 \cdot 10^{-108}:\\
\;\;\;\;y \cdot \frac{x}{z}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\]
(FPCore (x y z) :precision binary64 (/ (* x (+ y z)) z))
(FPCore (x y z)
:precision binary64
(let* ((t_0 (/ (* x (+ y z)) z)) (t_1 (/ x (/ z (+ y z)))))
(if (<= t_0 -2e+293)
t_1
(if (<= t_0 -1e-41)
t_0
(if (<= t_0 50.0) (* x (/ (+ y z) z)) (if (<= t_0 5e+270) t_0 t_1))))))double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double t_1 = x / (z / (y + z));
double tmp;
if (t_0 <= -2e+293) {
tmp = t_1;
} else if (t_0 <= -1e-41) {
tmp = t_0;
} else if (t_0 <= 50.0) {
tmp = x * ((y + z) / z);
} else if (t_0 <= 5e+270) {
tmp = t_0;
} else {
tmp = t_1;
}
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 + z)) / z
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = (x * (y + z)) / z
t_1 = x / (z / (y + z))
if (t_0 <= (-2d+293)) then
tmp = t_1
else if (t_0 <= (-1d-41)) then
tmp = t_0
else if (t_0 <= 50.0d0) then
tmp = x * ((y + z) / z)
else if (t_0 <= 5d+270) then
tmp = t_0
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
return (x * (y + z)) / z;
}
public static double code(double x, double y, double z) {
double t_0 = (x * (y + z)) / z;
double t_1 = x / (z / (y + z));
double tmp;
if (t_0 <= -2e+293) {
tmp = t_1;
} else if (t_0 <= -1e-41) {
tmp = t_0;
} else if (t_0 <= 50.0) {
tmp = x * ((y + z) / z);
} else if (t_0 <= 5e+270) {
tmp = t_0;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): return (x * (y + z)) / z
def code(x, y, z): t_0 = (x * (y + z)) / z t_1 = x / (z / (y + z)) tmp = 0 if t_0 <= -2e+293: tmp = t_1 elif t_0 <= -1e-41: tmp = t_0 elif t_0 <= 50.0: tmp = x * ((y + z) / z) elif t_0 <= 5e+270: tmp = t_0 else: tmp = t_1 return tmp
function code(x, y, z) return Float64(Float64(x * Float64(y + z)) / z) end
function code(x, y, z) t_0 = Float64(Float64(x * Float64(y + z)) / z) t_1 = Float64(x / Float64(z / Float64(y + z))) tmp = 0.0 if (t_0 <= -2e+293) tmp = t_1; elseif (t_0 <= -1e-41) tmp = t_0; elseif (t_0 <= 50.0) tmp = Float64(x * Float64(Float64(y + z) / z)); elseif (t_0 <= 5e+270) tmp = t_0; else tmp = t_1; end return tmp end
function tmp = code(x, y, z) tmp = (x * (y + z)) / z; end
function tmp_2 = code(x, y, z) t_0 = (x * (y + z)) / z; t_1 = x / (z / (y + z)); tmp = 0.0; if (t_0 <= -2e+293) tmp = t_1; elseif (t_0 <= -1e-41) tmp = t_0; elseif (t_0 <= 50.0) tmp = x * ((y + z) / z); elseif (t_0 <= 5e+270) tmp = t_0; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]
code[x_, y_, z_] := Block[{t$95$0 = N[(N[(x * N[(y + z), $MachinePrecision]), $MachinePrecision] / z), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(z / N[(y + z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, -2e+293], t$95$1, If[LessEqual[t$95$0, -1e-41], t$95$0, If[LessEqual[t$95$0, 50.0], N[(x * N[(N[(y + z), $MachinePrecision] / z), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$0, 5e+270], t$95$0, t$95$1]]]]]]
\frac{x \cdot \left(y + z\right)}{z}
\begin{array}{l}
t_0 := \frac{x \cdot \left(y + z\right)}{z}\\
t_1 := \frac{x}{\frac{z}{y + z}}\\
\mathbf{if}\;t_0 \leq -2 \cdot 10^{+293}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;t_0 \leq -1 \cdot 10^{-41}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;t_0 \leq 50:\\
\;\;\;\;x \cdot \frac{y + z}{z}\\
\mathbf{elif}\;t_0 \leq 5 \cdot 10^{+270}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
Results
| Original | 12.4 |
|---|---|
| Target | 3.0 |
| Herbie | 0.5 |
if (/.f64 (*.f64 x (+.f64 y z)) z) < -1.9999999999999998e293 or 4.99999999999999976e270 < (/.f64 (*.f64 x (+.f64 y z)) z) Initial program 54.5
Simplified2.2
if -1.9999999999999998e293 < (/.f64 (*.f64 x (+.f64 y z)) z) < -1.00000000000000001e-41 or 50 < (/.f64 (*.f64 x (+.f64 y z)) z) < 4.99999999999999976e270Initial program 0.2
if -1.00000000000000001e-41 < (/.f64 (*.f64 x (+.f64 y z)) z) < 50Initial program 7.0
Simplified0.1
Final simplification0.5
| Alternative 1 | |
|---|---|
| Error | 19.2 |
| Cost | 584 |
| Alternative 2 | |
|---|---|
| Error | 3.4 |
| Cost | 580 |
| Alternative 3 | |
|---|---|
| Error | 3.3 |
| Cost | 580 |
| Alternative 4 | |
|---|---|
| Error | 3.3 |
| Cost | 448 |
| Alternative 5 | |
|---|---|
| Error | 25.6 |
| Cost | 64 |
herbie shell --seed 2022343
(FPCore (x y z)
:name "Numeric.SpecFunctions:choose from math-functions-0.1.5.2"
:precision binary64
:herbie-target
(/ x (/ z (+ y z)))
(/ (* x (+ y z)) z))