
(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 (if (or (<= y -2e+77) (not (<= y 3e-36))) (* x (* 2.0 (/ y (- x y)))) (* (/ x (- y x)) (/ y -0.5))))
double code(double x, double y) {
double tmp;
if ((y <= -2e+77) || !(y <= 3e-36)) {
tmp = x * (2.0 * (y / (x - y)));
} else {
tmp = (x / (y - x)) * (y / -0.5);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2d+77)) .or. (.not. (y <= 3d-36))) then
tmp = x * (2.0d0 * (y / (x - y)))
else
tmp = (x / (y - x)) * (y / (-0.5d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2e+77) || !(y <= 3e-36)) {
tmp = x * (2.0 * (y / (x - y)));
} else {
tmp = (x / (y - x)) * (y / -0.5);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2e+77) or not (y <= 3e-36): tmp = x * (2.0 * (y / (x - y))) else: tmp = (x / (y - x)) * (y / -0.5) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2e+77) || !(y <= 3e-36)) tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y)))); else tmp = Float64(Float64(x / Float64(y - x)) * Float64(y / -0.5)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2e+77) || ~((y <= 3e-36))) tmp = x * (2.0 * (y / (x - y))); else tmp = (x / (y - x)) * (y / -0.5); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2e+77], N[Not[LessEqual[y, 3e-36]], $MachinePrecision]], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x / N[(y - x), $MachinePrecision]), $MachinePrecision] * N[(y / -0.5), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+77} \lor \neg \left(y \leq 3 \cdot 10^{-36}\right):\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y - x} \cdot \frac{y}{-0.5}\\
\end{array}
\end{array}
if y < -1.99999999999999997e77 or 3.0000000000000002e-36 < y Initial program 74.7%
associate-/l*99.9%
associate-*l*99.9%
Simplified99.9%
if -1.99999999999999997e77 < y < 3.0000000000000002e-36Initial program 81.1%
sub-neg81.1%
+-commutative81.1%
neg-sub081.1%
associate-+l-81.1%
sub0-neg81.1%
distribute-frac-neg281.1%
distribute-frac-neg81.1%
*-commutative81.1%
associate-*r*81.1%
distribute-rgt-neg-in81.1%
associate-/l*80.9%
*-commutative80.9%
metadata-eval80.9%
Simplified80.9%
clear-num80.9%
un-div-inv81.1%
div-inv81.1%
metadata-eval81.1%
Applied egg-rr81.1%
times-frac100.0%
Simplified100.0%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -9.5e-125) (not (<= y 8.2e-89))) (* x (* 2.0 (/ y (- x y)))) (* 2.0 (+ y (* y (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -9.5e-125) || !(y <= 8.2e-89)) {
tmp = x * (2.0 * (y / (x - y)));
} else {
tmp = 2.0 * (y + (y * (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 <= (-9.5d-125)) .or. (.not. (y <= 8.2d-89))) then
tmp = x * (2.0d0 * (y / (x - y)))
else
tmp = 2.0d0 * (y + (y * (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -9.5e-125) || !(y <= 8.2e-89)) {
tmp = x * (2.0 * (y / (x - y)));
} else {
tmp = 2.0 * (y + (y * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9.5e-125) or not (y <= 8.2e-89): tmp = x * (2.0 * (y / (x - y))) else: tmp = 2.0 * (y + (y * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -9.5e-125) || !(y <= 8.2e-89)) tmp = Float64(x * Float64(2.0 * Float64(y / Float64(x - y)))); else tmp = Float64(2.0 * Float64(y + Float64(y * Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9.5e-125) || ~((y <= 8.2e-89))) tmp = x * (2.0 * (y / (x - y))); else tmp = 2.0 * (y + (y * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9.5e-125], N[Not[LessEqual[y, 8.2e-89]], $MachinePrecision]], N[(x * N[(2.0 * N[(y / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * N[(y + N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.5 \cdot 10^{-125} \lor \neg \left(y \leq 8.2 \cdot 10^{-89}\right):\\
\;\;\;\;x \cdot \left(2 \cdot \frac{y}{x - y}\right)\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(y + y \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -9.50000000000000031e-125 or 8.1999999999999997e-89 < y Initial program 79.0%
associate-/l*97.2%
associate-*l*97.2%
Simplified97.2%
if -9.50000000000000031e-125 < y < 8.1999999999999997e-89Initial program 75.8%
associate-/l*65.5%
associate-*l*65.5%
Simplified65.5%
Taylor expanded in x around inf 89.9%
distribute-lft-out89.9%
Simplified89.9%
unpow289.9%
associate-/l*90.9%
Applied egg-rr90.9%
Final simplification95.2%
(FPCore (x y) :precision binary64 (if (or (<= y -4.5e+51) (not (<= y 4.4e-36))) (* x -2.0) (* 2.0 (+ y (* y (/ y x))))))
double code(double x, double y) {
double tmp;
if ((y <= -4.5e+51) || !(y <= 4.4e-36)) {
tmp = x * -2.0;
} else {
tmp = 2.0 * (y + (y * (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 <= (-4.5d+51)) .or. (.not. (y <= 4.4d-36))) then
tmp = x * (-2.0d0)
else
tmp = 2.0d0 * (y + (y * (y / x)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.5e+51) || !(y <= 4.4e-36)) {
tmp = x * -2.0;
} else {
tmp = 2.0 * (y + (y * (y / x)));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.5e+51) or not (y <= 4.4e-36): tmp = x * -2.0 else: tmp = 2.0 * (y + (y * (y / x))) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.5e+51) || !(y <= 4.4e-36)) tmp = Float64(x * -2.0); else tmp = Float64(2.0 * Float64(y + Float64(y * Float64(y / x)))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.5e+51) || ~((y <= 4.4e-36))) tmp = x * -2.0; else tmp = 2.0 * (y + (y * (y / x))); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.5e+51], N[Not[LessEqual[y, 4.4e-36]], $MachinePrecision]], N[(x * -2.0), $MachinePrecision], N[(2.0 * N[(y + N[(y * N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{+51} \lor \neg \left(y \leq 4.4 \cdot 10^{-36}\right):\\
\;\;\;\;x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;2 \cdot \left(y + y \cdot \frac{y}{x}\right)\\
\end{array}
\end{array}
if y < -4.5e51 or 4.3999999999999999e-36 < y Initial program 75.3%
associate-/l*99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.8%
if -4.5e51 < y < 4.3999999999999999e-36Initial program 80.7%
associate-/l*74.9%
associate-*l*74.9%
Simplified74.9%
Taylor expanded in x around inf 81.4%
distribute-lft-out81.4%
Simplified81.4%
unpow281.4%
associate-/l*82.0%
Applied egg-rr82.0%
Final simplification79.4%
(FPCore (x y) :precision binary64 (if (or (<= y -2.15e+52) (not (<= y 4.2e-36))) (* x -2.0) (* y 2.0)))
double code(double x, double y) {
double tmp;
if ((y <= -2.15e+52) || !(y <= 4.2e-36)) {
tmp = x * -2.0;
} else {
tmp = y * 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.15d+52)) .or. (.not. (y <= 4.2d-36))) then
tmp = x * (-2.0d0)
else
tmp = y * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.15e+52) || !(y <= 4.2e-36)) {
tmp = x * -2.0;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.15e+52) or not (y <= 4.2e-36): tmp = x * -2.0 else: tmp = y * 2.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.15e+52) || !(y <= 4.2e-36)) tmp = Float64(x * -2.0); else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.15e+52) || ~((y <= 4.2e-36))) tmp = x * -2.0; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.15e+52], N[Not[LessEqual[y, 4.2e-36]], $MachinePrecision]], N[(x * -2.0), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{+52} \lor \neg \left(y \leq 4.2 \cdot 10^{-36}\right):\\
\;\;\;\;x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -2.15e52 or 4.19999999999999982e-36 < y Initial program 75.3%
associate-/l*99.9%
associate-*l*99.9%
Simplified99.9%
Taylor expanded in y around inf 76.8%
if -2.15e52 < y < 4.19999999999999982e-36Initial program 80.7%
associate-/l*74.9%
associate-*l*74.9%
Simplified74.9%
Taylor expanded in x around inf 80.8%
*-commutative80.8%
Simplified80.8%
Final simplification78.8%
(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 78.0%
associate-/l*87.4%
associate-*l*87.4%
Simplified87.4%
Taylor expanded in y around inf 48.4%
(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 2024181
(FPCore (x y)
:name "Linear.Projection:perspective from linear-1.19.1.3, B"
:precision binary64
:alt
(! :herbie-platform default (if (< x -1721044263414944700000000000000000000000000000000000000000000000000000000000000000) (* (/ (* 2 x) (- x y)) y) (if (< x 83645045635564430) (/ (* x 2) (/ (- x y) y)) (* (/ (* 2 x) (- x y)) y))))
(/ (* (* x 2.0) y) (- x y)))