
(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 5 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
(let* ((t_0 (* 2.0 (/ x (+ (/ x y) -1.0))))
(t_1 (/ (* (* x 2.0) y) (- x y)))
(t_2 (/ (* x (* 2.0 y)) (- x y))))
(if (<= t_1 -1e-45)
t_0
(if (<= t_1 -5e-305)
t_2
(if (<= t_1 0.0)
(* x (* 2.0 (/ y (- x y))))
(if (<= t_1 2e+75) t_2 t_0))))))
double code(double x, double y) {
double t_0 = 2.0 * (x / ((x / y) + -1.0));
double t_1 = ((x * 2.0) * y) / (x - y);
double t_2 = (x * (2.0 * y)) / (x - y);
double tmp;
if (t_1 <= -1e-45) {
tmp = t_0;
} else if (t_1 <= -5e-305) {
tmp = t_2;
} else if (t_1 <= 0.0) {
tmp = x * (2.0 * (y / (x - y)));
} else if (t_1 <= 2e+75) {
tmp = t_2;
} 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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_0 = 2.0d0 * (x / ((x / y) + (-1.0d0)))
t_1 = ((x * 2.0d0) * y) / (x - y)
t_2 = (x * (2.0d0 * y)) / (x - y)
if (t_1 <= (-1d-45)) then
tmp = t_0
else if (t_1 <= (-5d-305)) then
tmp = t_2
else if (t_1 <= 0.0d0) then
tmp = x * (2.0d0 * (y / (x - y)))
else if (t_1 <= 2d+75) then
tmp = t_2
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) + -1.0));
double t_1 = ((x * 2.0) * y) / (x - y);
double t_2 = (x * (2.0 * y)) / (x - y);
double tmp;
if (t_1 <= -1e-45) {
tmp = t_0;
} else if (t_1 <= -5e-305) {
tmp = t_2;
} else if (t_1 <= 0.0) {
tmp = x * (2.0 * (y / (x - y)));
} else if (t_1 <= 2e+75) {
tmp = t_2;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 2.0 * (x / ((x / y) + -1.0)) t_1 = ((x * 2.0) * y) / (x - y) t_2 = (x * (2.0 * y)) / (x - y) tmp = 0 if t_1 <= -1e-45: tmp = t_0 elif t_1 <= -5e-305: tmp = t_2 elif t_1 <= 0.0: tmp = x * (2.0 * (y / (x - y))) elif t_1 <= 2e+75: tmp = t_2 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0))) t_1 = Float64(Float64(Float64(x * 2.0) * y) / Float64(x - y)) t_2 = Float64(Float64(x * Float64(2.0 * y)) / Float64(x - y)) tmp = 0.0 if (t_1 <= -1e-45) tmp = t_0; elseif (t_1 <= -5e-305) tmp = t_2; elseif (t_1 <= 0.0) tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y)))); elseif (t_1 <= 2e+75) tmp = t_2; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 2.0 * (x / ((x / y) + -1.0)); t_1 = ((x * 2.0) * y) / (x - y); t_2 = (x * (2.0 * y)) / (x - y); tmp = 0.0; if (t_1 <= -1e-45) tmp = t_0; elseif (t_1 <= -5e-305) tmp = t_2; elseif (t_1 <= 0.0) tmp = x * (2.0 * (y / (x - y))); elseif (t_1 <= 2e+75) tmp = t_2; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x * N[(2.0 * y), $MachinePrecision]), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$1, -1e-45], t$95$0, If[LessEqual[t$95$1, -5e-305], t$95$2, If[LessEqual[t$95$1, 0.0], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[t$95$1, 2e+75], t$95$2, t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 2 \cdot \frac{x}{\frac{x}{y} + -1}\\
t_1 := \frac{\left(x \cdot 2\right) \cdot y}{x - y}\\
t_2 := \frac{x \cdot \left(2 \cdot y\right)}{x - y}\\
\mathbf{if}\;t\_1 \leq -1 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;t\_1 \leq -5 \cdot 10^{-305}:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 \leq 0:\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\
\mathbf{elif}\;t\_1 \leq 2 \cdot 10^{+75}:\\
\;\;\;\;t\_2\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -9.99999999999999984e-46 or 1.99999999999999985e75 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) Initial program 48.8%
associate-/l*98.6%
associate-*l*98.7%
Simplified98.7%
associate-*r/98.7%
associate-/l*50.0%
add-log-exp12.8%
*-un-lft-identity12.8%
log-prod12.8%
metadata-eval12.8%
add-log-exp50.0%
associate-/l*98.7%
associate-*r/98.7%
Applied egg-rr98.7%
+-lft-identity98.7%
associate-*r*98.6%
associate-*r/48.8%
associate-*l/97.4%
associate-/r/98.7%
*-commutative98.7%
associate-/l*98.7%
div-sub98.8%
sub-neg98.8%
*-inverses98.8%
metadata-eval98.8%
Simplified98.8%
if -9.99999999999999984e-46 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < -4.99999999999999985e-305 or 0.0 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < 1.99999999999999985e75Initial program 99.3%
associate-*l*99.3%
Simplified99.3%
if -4.99999999999999985e-305 < (/.f64 (*.f64 (*.f64 x #s(literal 2 binary64)) y) (-.f64 x y)) < 0.0Initial program 8.2%
associate-/l*99.8%
associate-*l*99.8%
Simplified99.8%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (or (<= y -6.5e-163) (not (<= y 2.06e-140))) (* 2.0 (/ x (+ (/ x y) -1.0))) (* 2.0 y)))
double code(double x, double y) {
double tmp;
if ((y <= -6.5e-163) || !(y <= 2.06e-140)) {
tmp = 2.0 * (x / ((x / y) + -1.0));
} else {
tmp = 2.0 * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-6.5d-163)) .or. (.not. (y <= 2.06d-140))) then
tmp = 2.0d0 * (x / ((x / y) + (-1.0d0)))
else
tmp = 2.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -6.5e-163) || !(y <= 2.06e-140)) {
tmp = 2.0 * (x / ((x / y) + -1.0));
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.5e-163) or not (y <= 2.06e-140): tmp = 2.0 * (x / ((x / y) + -1.0)) else: tmp = 2.0 * y return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.5e-163) || !(y <= 2.06e-140)) tmp = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0))); else tmp = Float64(2.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.5e-163) || ~((y <= 2.06e-140))) tmp = 2.0 * (x / ((x / y) + -1.0)); else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.5e-163], N[Not[LessEqual[y, 2.06e-140]], $MachinePrecision]], N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-163} \lor \neg \left(y \leq 2.06 \cdot 10^{-140}\right):\\
\;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if y < -6.4999999999999999e-163 or 2.06e-140 < y Initial program 76.1%
associate-/l*98.3%
associate-*l*98.3%
Simplified98.3%
associate-*r/98.3%
associate-/l*76.1%
add-log-exp8.4%
*-un-lft-identity8.4%
log-prod8.4%
metadata-eval8.4%
add-log-exp76.1%
associate-/l*98.3%
associate-*r/98.3%
Applied egg-rr98.3%
+-lft-identity98.3%
associate-*r*98.3%
associate-*r/76.1%
associate-*l/86.1%
associate-/r/98.0%
*-commutative98.0%
associate-/l*98.0%
div-sub98.0%
sub-neg98.0%
*-inverses98.0%
metadata-eval98.0%
Simplified98.0%
if -6.4999999999999999e-163 < y < 2.06e-140Initial program 69.7%
associate-/l*62.5%
associate-*l*62.6%
Simplified62.6%
Taylor expanded in x around inf 87.8%
*-commutative87.8%
Simplified87.8%
Final simplification95.6%
(FPCore (x y) :precision binary64 (if (<= y -1.05e-162) (* 2.0 (/ x (+ (/ x y) -1.0))) (if (<= y 2.1e-145) (* 2.0 y) (* x (* 2.0 (/ y (- x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -1.05e-162) {
tmp = 2.0 * (x / ((x / y) + -1.0));
} else if (y <= 2.1e-145) {
tmp = 2.0 * y;
} else {
tmp = x * (2.0 * (y / (x - y)));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-1.05d-162)) then
tmp = 2.0d0 * (x / ((x / y) + (-1.0d0)))
else if (y <= 2.1d-145) then
tmp = 2.0d0 * y
else
tmp = x * (2.0d0 * (y / (x - y)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.05e-162) {
tmp = 2.0 * (x / ((x / y) + -1.0));
} else if (y <= 2.1e-145) {
tmp = 2.0 * y;
} else {
tmp = x * (2.0 * (y / (x - y)));
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e-162: tmp = 2.0 * (x / ((x / y) + -1.0)) elif y <= 2.1e-145: tmp = 2.0 * y else: tmp = x * (2.0 * (y / (x - y))) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e-162) tmp = Float64(2.0 * Float64(x / Float64(Float64(x / y) + -1.0))); elseif (y <= 2.1e-145) tmp = Float64(2.0 * y); else tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.05e-162) tmp = 2.0 * (x / ((x / y) + -1.0)); elseif (y <= 2.1e-145) tmp = 2.0 * y; else tmp = x * (2.0 * (y / (x - y))); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e-162], N[(2.0 * N[(x / N[(N[(x / y), $MachinePrecision] + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 2.1e-145], N[(2.0 * y), $MachinePrecision], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-162}:\\
\;\;\;\;2 \cdot \frac{x}{\frac{x}{y} + -1}\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{-145}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\
\end{array}
\end{array}
if y < -1.05e-162Initial program 78.6%
associate-/l*98.9%
associate-*l*98.9%
Simplified98.9%
associate-*r/98.9%
associate-/l*78.6%
add-log-exp11.3%
*-un-lft-identity11.3%
log-prod11.3%
metadata-eval11.3%
add-log-exp78.6%
associate-/l*98.9%
associate-*r/98.9%
Applied egg-rr98.9%
+-lft-identity98.9%
associate-*r*98.9%
associate-*r/78.6%
associate-*l/87.6%
associate-/r/99.0%
*-commutative99.0%
associate-/l*99.0%
div-sub99.1%
sub-neg99.1%
*-inverses99.1%
metadata-eval99.1%
Simplified99.1%
if -1.05e-162 < y < 2.09999999999999991e-145Initial program 69.7%
associate-/l*62.5%
associate-*l*62.6%
Simplified62.6%
Taylor expanded in x around inf 87.8%
*-commutative87.8%
Simplified87.8%
if 2.09999999999999991e-145 < y Initial program 73.3%
associate-/l*97.7%
associate-*l*97.7%
Simplified97.7%
Final simplification95.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.56e-12) (not (<= x 3.9e+133))) (* 2.0 y) (* x -2.0)))
double code(double x, double y) {
double tmp;
if ((x <= -1.56e-12) || !(x <= 3.9e+133)) {
tmp = 2.0 * y;
} 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 ((x <= (-1.56d-12)) .or. (.not. (x <= 3.9d+133))) then
tmp = 2.0d0 * y
else
tmp = x * (-2.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.56e-12) || !(x <= 3.9e+133)) {
tmp = 2.0 * y;
} else {
tmp = x * -2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.56e-12) or not (x <= 3.9e+133): tmp = 2.0 * y else: tmp = x * -2.0 return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.56e-12) || !(x <= 3.9e+133)) tmp = Float64(2.0 * y); else tmp = Float64(x * -2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.56e-12) || ~((x <= 3.9e+133))) tmp = 2.0 * y; else tmp = x * -2.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.56e-12], N[Not[LessEqual[x, 3.9e+133]], $MachinePrecision]], N[(2.0 * y), $MachinePrecision], N[(x * -2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.56 \cdot 10^{-12} \lor \neg \left(x \leq 3.9 \cdot 10^{+133}\right):\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2\\
\end{array}
\end{array}
if x < -1.56000000000000002e-12 or 3.90000000000000014e133 < x Initial program 68.6%
associate-/l*76.7%
associate-*l*76.8%
Simplified76.8%
Taylor expanded in x around inf 77.6%
*-commutative77.6%
Simplified77.6%
if -1.56000000000000002e-12 < x < 3.90000000000000014e133Initial program 78.9%
associate-/l*99.3%
associate-*l*99.3%
Simplified99.3%
Taylor expanded in x around 0 74.8%
Final simplification76.0%
(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.9%
associate-*l*90.0%
Simplified90.0%
Taylor expanded in x around 0 52.9%
Final simplification52.9%
(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 2024067
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, B"
:precision binary64
:alt
(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)))