
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
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
public static double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
def code(x, y): return ((x * 2.0) * y) / (x - y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function tmp = code(x, y) tmp = ((x * 2.0) * y) / (x - y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (* (* x 2.0) y) (- x y)))
double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
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
public static double code(double x, double y) {
return ((x * 2.0) * y) / (x - y);
}
def code(x, y): return ((x * 2.0) * y) / (x - y)
function code(x, y) return Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) end
function tmp = code(x, y) tmp = ((x * 2.0) * y) / (x - y); end
code[x_, y_] := N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{\left(x \cdot 2\right) \cdot y}{x - y}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y -2.5e+101) (/ (* x 2.0) (/ (- x y) y)) (if (<= y 4e+67) (* 2.0 (/ y (- 1.0 (/ y x)))) (* (/ y (- x y)) (+ x x)))))
double code(double x, double y) {
double tmp;
if (y <= -2.5e+101) {
tmp = (x * 2.0) / ((x - y) / y);
} else if (y <= 4e+67) {
tmp = 2.0 * (y / (1.0 - (y / x)));
} else {
tmp = (y / (x - y)) * (x + x);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.5d+101)) then
tmp = (x * 2.0d0) / ((x - y) / y)
else if (y <= 4d+67) then
tmp = 2.0d0 * (y / (1.0d0 - (y / x)))
else
tmp = (y / (x - y)) * (x + x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.5e+101) {
tmp = (x * 2.0) / ((x - y) / y);
} else if (y <= 4e+67) {
tmp = 2.0 * (y / (1.0 - (y / x)));
} else {
tmp = (y / (x - y)) * (x + x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e+101: tmp = (x * 2.0) / ((x - y) / y) elif y <= 4e+67: tmp = 2.0 * (y / (1.0 - (y / x))) else: tmp = (y / (x - y)) * (x + x) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e+101) tmp = Float64(Float64(x * 2.0) / Float64(Float64(x - y) / y)); elseif (y <= 4e+67) tmp = Float64(2.0 * Float64(y / Float64(1.0 - Float64(y / x)))); else tmp = Float64(Float64(y / Float64(x - y)) * Float64(x + x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5e+101) tmp = (x * 2.0) / ((x - y) / y); elseif (y <= 4e+67) tmp = 2.0 * (y / (1.0 - (y / x))); else tmp = (y / (x - y)) * (x + x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e+101], N[(N[(x * 2.0), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4e+67], N[(2.0 * N[(y / N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision] * N[(x + x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+101}:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+67}:\\
\;\;\;\;2 \cdot \frac{y}{1 - \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{x - y} \cdot \left(x + x\right)\\
\end{array}
\end{array}
if y < -2.49999999999999994e101Initial program 60.4%
associate-/l*100.0%
Simplified100.0%
if -2.49999999999999994e101 < y < 3.99999999999999993e67Initial program 79.0%
*-commutative79.0%
associate-/l*99.9%
associate-/r*99.9%
associate-/r/99.9%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
if 3.99999999999999993e67 < y Initial program 71.9%
associate-/l*99.9%
Simplified99.9%
clear-num99.6%
associate-/r/100.0%
clear-num100.0%
add-log-exp5.0%
exp-lft-sqr5.0%
log-prod5.0%
add-log-exp12.3%
add-log-exp100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e+172) (not (<= y 1e+184))) (* x -2.0) (* 2.0 (/ y (- 1.0 (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e+172) || !(y <= 1e+184)) {
tmp = x * -2.0;
} else {
tmp = 2.0 * (y / (1.0 - (y / x)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.4d+172)) .or. (.not. (y <= 1d+184))) then
tmp = x * (-2.0d0)
else
tmp = 2.0d0 * (y / (1.0d0 - (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.4e+172) || !(y <= 1e+184)) {
tmp = x * -2.0;
} else {
tmp = 2.0 * (y / (1.0 - (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e+172) or not (y <= 1e+184): tmp = x * -2.0 else: tmp = 2.0 * (y / (1.0 - (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e+172) || !(y <= 1e+184)) tmp = Float64(x * -2.0); else tmp = Float64(2.0 * Float64(y / Float64(1.0 - Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e+172) || ~((y <= 1e+184))) tmp = x * -2.0; else tmp = 2.0 * (y / (1.0 - (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e+172], N[Not[LessEqual[y, 1e+184]], $MachinePrecision]], N[(x * -2.0), $MachinePrecision], N[(2.0 * N[(y / N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+172} \lor \neg \left(y \leq 10^{+184}\right):\\
\;\;\;\;x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{y}{1 - \frac{y}{x}}\\
\end{array}
\end{array}
if y < -1.4e172 or 1.00000000000000002e184 < y Initial program 62.9%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in x around 0 93.3%
*-commutative93.3%
Simplified93.3%
if -1.4e172 < y < 1.00000000000000002e184Initial program 77.7%
*-commutative77.7%
associate-/l*98.0%
associate-/r*98.0%
associate-/r/98.0%
div-sub98.0%
*-inverses98.0%
Simplified98.0%
Final simplification97.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.1e+73) (not (<= y 2.8e+67))) (* (/ y (- x y)) (+ x x)) (* 2.0 (/ y (- 1.0 (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -1.1e+73) || !(y <= 2.8e+67)) {
tmp = (y / (x - y)) * (x + x);
} else {
tmp = 2.0 * (y / (1.0 - (y / x)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-1.1d+73)) .or. (.not. (y <= 2.8d+67))) then
tmp = (y / (x - y)) * (x + x)
else
tmp = 2.0d0 * (y / (1.0d0 - (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.1e+73) || !(y <= 2.8e+67)) {
tmp = (y / (x - y)) * (x + x);
} else {
tmp = 2.0 * (y / (1.0 - (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.1e+73) or not (y <= 2.8e+67): tmp = (y / (x - y)) * (x + x) else: tmp = 2.0 * (y / (1.0 - (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.1e+73) || !(y <= 2.8e+67)) tmp = Float64(Float64(y / Float64(x - y)) * Float64(x + x)); else tmp = Float64(2.0 * Float64(y / Float64(1.0 - Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.1e+73) || ~((y <= 2.8e+67))) tmp = (y / (x - y)) * (x + x); else tmp = 2.0 * (y / (1.0 - (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.1e+73], N[Not[LessEqual[y, 2.8e+67]], $MachinePrecision]], N[(N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision] * N[(x + x), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(y / N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.1 \cdot 10^{+73} \lor \neg \left(y \leq 2.8 \cdot 10^{+67}\right):\\
\;\;\;\;\frac{y}{x - y} \cdot \left(x + x\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \frac{y}{1 - \frac{y}{x}}\\
\end{array}
\end{array}
if y < -1.1e73 or 2.7999999999999998e67 < y Initial program 65.8%
associate-/l*99.9%
Simplified99.9%
clear-num99.7%
associate-/r/100.0%
clear-num100.0%
add-log-exp5.1%
exp-lft-sqr5.1%
log-prod5.1%
add-log-exp11.7%
add-log-exp100.0%
Applied egg-rr100.0%
if -1.1e73 < y < 2.7999999999999998e67Initial program 79.8%
*-commutative79.8%
associate-/l*100.0%
associate-/r*100.0%
associate-/r/100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -2.5e+69) (* x -2.0) (if (<= y 1.66e-71) (* y 2.0) (* x -2.0))))
double code(double x, double y) {
double tmp;
if (y <= -2.5e+69) {
tmp = x * -2.0;
} else if (y <= 1.66e-71) {
tmp = y * 2.0;
} else {
tmp = x * -2.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-2.5d+69)) then
tmp = x * (-2.0d0)
else if (y <= 1.66d-71) then
tmp = y * 2.0d0
else
tmp = x * (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.5e+69) {
tmp = x * -2.0;
} else if (y <= 1.66e-71) {
tmp = y * 2.0;
} else {
tmp = x * -2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e+69: tmp = x * -2.0 elif y <= 1.66e-71: tmp = y * 2.0 else: tmp = x * -2.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e+69) tmp = Float64(x * -2.0); elseif (y <= 1.66e-71) tmp = Float64(y * 2.0); else tmp = Float64(x * -2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5e+69) tmp = x * -2.0; elseif (y <= 1.66e-71) tmp = y * 2.0; else tmp = x * -2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e+69], N[(x * -2.0), $MachinePrecision], If[LessEqual[y, 1.66e-71], N[(y * 2.0), $MachinePrecision], N[(x * -2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+69}:\\
\;\;\;\;x \cdot -2\\
\mathbf{elif}\;y \leq 1.66 \cdot 10^{-71}:\\
\;\;\;\;y \cdot 2\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2\\
\end{array}
\end{array}
if y < -2.50000000000000018e69 or 1.6599999999999999e-71 < y Initial program 72.1%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in x around 0 77.1%
*-commutative77.1%
Simplified77.1%
if -2.50000000000000018e69 < y < 1.6599999999999999e-71Initial program 76.9%
*-commutative76.9%
associate-/l*100.0%
associate-/r*100.0%
associate-/r/100.0%
div-sub100.0%
*-inverses100.0%
Simplified100.0%
Taylor expanded in y around 0 73.7%
Final simplification75.3%
(FPCore (x y) :precision binary64 (* x -2.0))
double code(double x, double y) {
return x * -2.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x * (-2.0d0)
end function
public static double code(double x, double y) {
return x * -2.0;
}
def code(x, y): return x * -2.0
function code(x, y) return Float64(x * -2.0) end
function tmp = code(x, y) tmp = x * -2.0; end
code[x_, y_] := N[(x * -2.0), $MachinePrecision]
\begin{array}{l}
\\
x \cdot -2
\end{array}
Initial program 74.6%
associate-/l*89.7%
Simplified89.7%
Taylor expanded in x around 0 51.3%
*-commutative51.3%
Simplified51.3%
Final simplification51.3%
(FPCore (x y) :precision binary64 -1.0)
double code(double x, double y) {
return -1.0;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -1.0d0
end function
public static double code(double x, double y) {
return -1.0;
}
def code(x, y): return -1.0
function code(x, y) return -1.0 end
function tmp = code(x, y) tmp = -1.0; end
code[x_, y_] := -1.0
\begin{array}{l}
\\
-1
\end{array}
Initial program 74.6%
associate-/l*89.7%
Simplified89.7%
clear-num89.5%
associate-/r/89.5%
clear-num90.0%
add-log-exp5.9%
exp-lft-sqr5.7%
log-prod6.1%
add-log-exp12.4%
add-log-exp90.0%
Applied egg-rr90.0%
Taylor expanded in y around 0 49.8%
Simplified3.8%
Final simplification3.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* (/ (* 2.0 x) (- x y)) y)))
(if (< x -1.7210442634149447e+81)
t_0
(if (< x 83645045635564430.0) (/ (* x 2.0) (/ (- x y) y)) t_0))))
double code(double x, double y) {
double t_0 = ((2.0 * x) / (x - y)) * y;
double tmp;
if (x < -1.7210442634149447e+81) {
tmp = t_0;
} else if (x < 83645045635564430.0) {
tmp = (x * 2.0) / ((x - y) / y);
} else {
tmp = t_0;
}
return tmp;
}
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 = ((2.0d0 * x) / (x - y)) * y
if (x < (-1.7210442634149447d+81)) then
tmp = t_0
else if (x < 83645045635564430.0d0) then
tmp = (x * 2.0d0) / ((x - y) / y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = ((2.0 * x) / (x - y)) * y;
double tmp;
if (x < -1.7210442634149447e+81) {
tmp = t_0;
} else if (x < 83645045635564430.0) {
tmp = (x * 2.0) / ((x - y) / y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = ((2.0 * x) / (x - y)) * y tmp = 0 if x < -1.7210442634149447e+81: tmp = t_0 elif x < 83645045635564430.0: tmp = (x * 2.0) / ((x - y) / y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(Float64(Float64(2.0 * x) / Float64(x - y)) * y) tmp = 0.0 if (x < -1.7210442634149447e+81) tmp = t_0; elseif (x < 83645045635564430.0) tmp = Float64(Float64(x * 2.0) / Float64(Float64(x - y) / y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = ((2.0 * x) / (x - y)) * y; tmp = 0.0; if (x < -1.7210442634149447e+81) tmp = t_0; elseif (x < 83645045635564430.0) tmp = (x * 2.0) / ((x - y) / y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(N[(N[(2.0 * x), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]}, If[Less[x, -1.7210442634149447e+81], t$95$0, If[Less[x, 83645045635564430.0], N[(N[(x * 2.0), $MachinePrecision] / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{2 \cdot x}{x - y} \cdot y\\
\mathbf{if}\;x < -1.7210442634149447 \cdot 10^{+81}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;x < 83645045635564430:\\
\;\;\;\;\frac{x \cdot 2}{\frac{x - y}{y}}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
herbie shell --seed 2023275
(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)))