| Alternative 1 | |
|---|---|
| Error | 16.2 |
| Cost | 456 |
\[\begin{array}{l}
\mathbf{if}\;y \leq -50000000000000:\\
\;\;\;\;-2 \cdot x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{-50}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot x\\
\end{array}
\]
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ (* (* x 2.0) y) (- x y))))
(if (<= y -4.9e+151)
(* -2.0 x)
(if (<= y -2.9e-137)
t_0
(if (<= y 1e-201) (* 2.0 y) (if (<= y 1.42e+143) t_0 (* -2.0 x)))))))double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
double code(double x, double y) {
double t_0 = ((x * 2.0) * y) / (x - y);
double tmp;
if (y <= -4.9e+151) {
tmp = -2.0 * x;
} else if (y <= -2.9e-137) {
tmp = t_0;
} else if (y <= 1e-201) {
tmp = 2.0 * y;
} else if (y <= 1.42e+143) {
tmp = t_0;
} else {
tmp = -2.0 * x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * 2.0d0) * y) / (x - y)
end function
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = ((x * 2.0d0) * y) / (x - y)
if (y <= (-4.9d+151)) then
tmp = (-2.0d0) * x
else if (y <= (-2.9d-137)) then
tmp = t_0
else if (y <= 1d-201) then
tmp = 2.0d0 * y
else if (y <= 1.42d+143) then
tmp = t_0
else
tmp = (-2.0d0) * x
end if
code = tmp
end function
public static double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
public static double code(double x, double y) {
double t_0 = ((x * 2.0) * y) / (x - y);
double tmp;
if (y <= -4.9e+151) {
tmp = -2.0 * x;
} else if (y <= -2.9e-137) {
tmp = t_0;
} else if (y <= 1e-201) {
tmp = 2.0 * y;
} else if (y <= 1.42e+143) {
tmp = t_0;
} else {
tmp = -2.0 * x;
}
return tmp;
}
def code(x, y): return ((x * 2.0) * y) / (x - y)
def code(x, y): t_0 = ((x * 2.0) * y) / (x - y) tmp = 0 if y <= -4.9e+151: tmp = -2.0 * x elif y <= -2.9e-137: tmp = t_0 elif y <= 1e-201: tmp = 2.0 * y elif y <= 1.42e+143: tmp = t_0 else: tmp = -2.0 * x return tmp
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function code(x, y) t_0 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) tmp = 0.0 if (y <= -4.9e+151) tmp = Float64(-2.0 * x); elseif (y <= -2.9e-137) tmp = t_0; elseif (y <= 1e-201) tmp = Float64(2.0 * y); elseif (y <= 1.42e+143) tmp = t_0; else tmp = Float64(-2.0 * x); end return tmp end
function tmp = code(x, y) tmp = ((x * 2.0) * y) / (x - y); end
function tmp_2 = code(x, y) t_0 = ((x * 2.0) * y) / (x - y); tmp = 0.0; if (y <= -4.9e+151) tmp = -2.0 * x; elseif (y <= -2.9e-137) tmp = t_0; elseif (y <= 1e-201) tmp = 2.0 * y; elseif (y <= 1.42e+143) tmp = t_0; else tmp = -2.0 * x; end tmp_2 = tmp; end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.9e+151], N[(-2.0 * x), $MachinePrecision], If[LessEqual[y, -2.9e-137], t$95$0, If[LessEqual[y, 1e-201], N[(2.0 * y), $MachinePrecision], If[LessEqual[y, 1.42e+143], t$95$0, N[(-2.0 * x), $MachinePrecision]]]]]]
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\begin{array}{l}
t_0 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
\mathbf{if}\;y \leq -4.9 \cdot 10^{+151}:\\
\;\;\;\;-2 \cdot x\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{-137}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 10^{-201}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{+143}:\\
\;\;\;\;t_0\\
\mathbf{else}:\\
\;\;\;\;-2 \cdot x\\
\end{array}
Results
| Original | 15.4 |
|---|---|
| Target | 0.3 |
| Herbie | 8.3 |
if y < -4.8999999999999999e151 or 1.42e143 < y Initial program 23.9
Taylor expanded in x around 0 9.5
if -4.8999999999999999e151 < y < -2.89999999999999985e-137 or 9.99999999999999946e-202 < y < 1.42e143Initial program 7.9
if -2.89999999999999985e-137 < y < 9.99999999999999946e-202Initial program 22.2
Taylor expanded in x around inf 8.0
Final simplification8.3
| Alternative 1 | |
|---|---|
| Error | 16.2 |
| Cost | 456 |
| Alternative 2 | |
|---|---|
| Error | 32.2 |
| Cost | 192 |
herbie shell --seed 2023077
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, B"
:precision binary64
:herbie-target
(if (< x -1.7210442634149447e+81) (* (/ (* 2.0 x) (- x y)) y) (if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) (* (/ (* 2.0 x) (- x y)) y)))
(/ (* (* x 2.0) y) (- x y)))