
(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 (or (<= y -4e-37) (not (<= y 6e-55))) (/ (* x -2.0) (- 1.0 (/ x y))) (* y (/ (* x 2.0) (- x y)))))
double code(double x, double y) {
double tmp;
if ((y <= -4e-37) || !(y <= 6e-55)) {
tmp = (x * -2.0) / (1.0 - (x / y));
} else {
tmp = y * ((x * 2.0) / (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 <= (-4d-37)) .or. (.not. (y <= 6d-55))) then
tmp = (x * (-2.0d0)) / (1.0d0 - (x / y))
else
tmp = y * ((x * 2.0d0) / (x - y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4e-37) || !(y <= 6e-55)) {
tmp = (x * -2.0) / (1.0 - (x / y));
} else {
tmp = y * ((x * 2.0) / (x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4e-37) or not (y <= 6e-55): tmp = (x * -2.0) / (1.0 - (x / y)) else: tmp = y * ((x * 2.0) / (x - y)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -4e-37) || !(y <= 6e-55)) tmp = Float64(Float64(x * -2.0) / Float64(1.0 - Float64(x / y))); else tmp = Float64(y * Float64(Float64(x * 2.0) / Float64(x - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4e-37) || ~((y <= 6e-55))) tmp = (x * -2.0) / (1.0 - (x / y)); else tmp = y * ((x * 2.0) / (x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4e-37], N[Not[LessEqual[y, 6e-55]], $MachinePrecision]], N[(N[(x * -2.0), $MachinePrecision] / N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * N[(N[(x * 2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4 \cdot 10^{-37} \lor \neg \left(y \leq 6 \cdot 10^{-55}\right):\\
\;\;\;\;\frac{x \cdot -2}{1 - \frac{x}{y}}\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\
\end{array}
\end{array}
if y < -4.00000000000000027e-37 or 6.00000000000000033e-55 < y Initial program 80.7%
*-lft-identity80.7%
metadata-eval80.7%
times-frac80.7%
neg-mul-180.7%
sub-neg80.7%
+-commutative80.7%
distribute-neg-out80.7%
remove-double-neg80.7%
sub-neg80.7%
associate-*r*80.7%
neg-mul-180.7%
distribute-lft-neg-out80.7%
associate-/l*99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
metadata-eval99.9%
div-sub99.9%
*-inverses99.9%
Simplified99.9%
if -4.00000000000000027e-37 < y < 6.00000000000000033e-55Initial program 73.3%
associate-*l/99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y) :precision binary64 (if (or (<= y -4.4e+77) (not (<= y 2.2e+67))) (* (* x 2.0) (- -1.0 (/ x y))) (* y 2.0)))
double code(double x, double y) {
double tmp;
if ((y <= -4.4e+77) || !(y <= 2.2e+67)) {
tmp = (x * 2.0) * (-1.0 - (x / y));
} 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 <= (-4.4d+77)) .or. (.not. (y <= 2.2d+67))) then
tmp = (x * 2.0d0) * ((-1.0d0) - (x / y))
else
tmp = y * 2.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -4.4e+77) || !(y <= 2.2e+67)) {
tmp = (x * 2.0) * (-1.0 - (x / y));
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.4e+77) or not (y <= 2.2e+67): tmp = (x * 2.0) * (-1.0 - (x / y)) else: tmp = y * 2.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.4e+77) || !(y <= 2.2e+67)) tmp = Float64(Float64(x * 2.0) * Float64(-1.0 - Float64(x / y))); else tmp = Float64(y * 2.0); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -4.4e+77) || ~((y <= 2.2e+67))) tmp = (x * 2.0) * (-1.0 - (x / y)); else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.4e+77], N[Not[LessEqual[y, 2.2e+67]], $MachinePrecision]], N[(N[(x * 2.0), $MachinePrecision] * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+77} \lor \neg \left(y \leq 2.2 \cdot 10^{+67}\right):\\
\;\;\;\;\left(x \cdot 2\right) \cdot \left(-1 - \frac{x}{y}\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -4.4000000000000001e77 or 2.2e67 < y Initial program 74.1%
associate-*l/64.9%
div-inv64.9%
associate-*l*99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 85.3%
sub-neg85.3%
metadata-eval85.3%
+-commutative85.3%
mul-1-neg85.3%
unsub-neg85.3%
Simplified85.3%
if -4.4000000000000001e77 < y < 2.2e67Initial program 80.8%
associate-*l/99.1%
Simplified99.1%
Taylor expanded in x around inf 76.4%
Final simplification80.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.55e-145) (not (<= x 5e-162))) (* y (/ 2.0 (- 1.0 (/ y x)))) (* (* x 2.0) (- -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if ((x <= -1.55e-145) || !(x <= 5e-162)) {
tmp = y * (2.0 / (1.0 - (y / x)));
} else {
tmp = (x * 2.0) * (-1.0 - (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.55d-145)) .or. (.not. (x <= 5d-162))) then
tmp = y * (2.0d0 / (1.0d0 - (y / x)))
else
tmp = (x * 2.0d0) * ((-1.0d0) - (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.55e-145) || !(x <= 5e-162)) {
tmp = y * (2.0 / (1.0 - (y / x)));
} else {
tmp = (x * 2.0) * (-1.0 - (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.55e-145) or not (x <= 5e-162): tmp = y * (2.0 / (1.0 - (y / x))) else: tmp = (x * 2.0) * (-1.0 - (x / y)) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.55e-145) || !(x <= 5e-162)) tmp = Float64(y * Float64(2.0 / Float64(1.0 - Float64(y / x)))); else tmp = Float64(Float64(x * 2.0) * Float64(-1.0 - Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.55e-145) || ~((x <= 5e-162))) tmp = y * (2.0 / (1.0 - (y / x))); else tmp = (x * 2.0) * (-1.0 - (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.55e-145], N[Not[LessEqual[x, 5e-162]], $MachinePrecision]], N[(y * N[(2.0 / N[(1.0 - N[(y / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 2.0), $MachinePrecision] * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.55 \cdot 10^{-145} \lor \neg \left(x \leq 5 \cdot 10^{-162}\right):\\
\;\;\;\;y \cdot \frac{2}{1 - \frac{y}{x}}\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \left(-1 - \frac{x}{y}\right)\\
\end{array}
\end{array}
if x < -1.55e-145 or 5.00000000000000014e-162 < x Initial program 79.0%
associate-*l/96.3%
Simplified96.3%
expm1-log1p-u95.1%
expm1-udef65.5%
*-commutative65.5%
*-un-lft-identity65.5%
times-frac65.5%
metadata-eval65.5%
Applied egg-rr65.5%
expm1-def95.1%
expm1-log1p96.3%
associate-*r/96.3%
associate-/l*95.8%
div-sub95.9%
*-inverses95.9%
Simplified95.9%
if -1.55e-145 < x < 5.00000000000000014e-162Initial program 74.4%
associate-*l/46.7%
div-inv46.6%
associate-*l*99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.9%
sub-neg93.9%
metadata-eval93.9%
+-commutative93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
Final simplification95.4%
(FPCore (x y) :precision binary64 (if (or (<= x -5.6e-145) (not (<= x 2.65e-163))) (* y (/ (* x 2.0) (- x y))) (* (* x 2.0) (- -1.0 (/ x y)))))
double code(double x, double y) {
double tmp;
if ((x <= -5.6e-145) || !(x <= 2.65e-163)) {
tmp = y * ((x * 2.0) / (x - y));
} else {
tmp = (x * 2.0) * (-1.0 - (x / y));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-5.6d-145)) .or. (.not. (x <= 2.65d-163))) then
tmp = y * ((x * 2.0d0) / (x - y))
else
tmp = (x * 2.0d0) * ((-1.0d0) - (x / y))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5.6e-145) || !(x <= 2.65e-163)) {
tmp = y * ((x * 2.0) / (x - y));
} else {
tmp = (x * 2.0) * (-1.0 - (x / y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.6e-145) or not (x <= 2.65e-163): tmp = y * ((x * 2.0) / (x - y)) else: tmp = (x * 2.0) * (-1.0 - (x / y)) return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.6e-145) || !(x <= 2.65e-163)) tmp = Float64(y * Float64(Float64(x * 2.0) / Float64(x - y))); else tmp = Float64(Float64(x * 2.0) * Float64(-1.0 - Float64(x / y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5.6e-145) || ~((x <= 2.65e-163))) tmp = y * ((x * 2.0) / (x - y)); else tmp = (x * 2.0) * (-1.0 - (x / y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.6e-145], N[Not[LessEqual[x, 2.65e-163]], $MachinePrecision]], N[(y * N[(N[(x * 2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(x * 2.0), $MachinePrecision] * N[(-1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.6 \cdot 10^{-145} \lor \neg \left(x \leq 2.65 \cdot 10^{-163}\right):\\
\;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\
\mathbf{else}:\\
\;\;\;\;\left(x \cdot 2\right) \cdot \left(-1 - \frac{x}{y}\right)\\
\end{array}
\end{array}
if x < -5.6000000000000002e-145 or 2.65000000000000008e-163 < x Initial program 79.0%
associate-*l/96.3%
Simplified96.3%
if -5.6000000000000002e-145 < x < 2.65000000000000008e-163Initial program 74.4%
associate-*l/46.7%
div-inv46.6%
associate-*l*99.7%
Applied egg-rr99.7%
Taylor expanded in x around 0 93.9%
sub-neg93.9%
metadata-eval93.9%
+-commutative93.9%
mul-1-neg93.9%
unsub-neg93.9%
Simplified93.9%
Final simplification95.7%
(FPCore (x y) :precision binary64 (if (or (<= y -29500000.0) (not (<= y 5.2e+67))) (* x -2.0) (* y 2.0)))
double code(double x, double y) {
double tmp;
if ((y <= -29500000.0) || !(y <= 5.2e+67)) {
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 <= (-29500000.0d0)) .or. (.not. (y <= 5.2d+67))) 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 <= -29500000.0) || !(y <= 5.2e+67)) {
tmp = x * -2.0;
} else {
tmp = y * 2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -29500000.0) or not (y <= 5.2e+67): tmp = x * -2.0 else: tmp = y * 2.0 return tmp
function code(x, y) tmp = 0.0 if ((y <= -29500000.0) || !(y <= 5.2e+67)) 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 <= -29500000.0) || ~((y <= 5.2e+67))) tmp = x * -2.0; else tmp = y * 2.0; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -29500000.0], N[Not[LessEqual[y, 5.2e+67]], $MachinePrecision]], N[(x * -2.0), $MachinePrecision], N[(y * 2.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -29500000 \lor \neg \left(y \leq 5.2 \cdot 10^{+67}\right):\\
\;\;\;\;x \cdot -2\\
\mathbf{else}:\\
\;\;\;\;y \cdot 2\\
\end{array}
\end{array}
if y < -2.95e7 or 5.2000000000000001e67 < y Initial program 77.0%
associate-*l/68.0%
Simplified68.0%
Taylor expanded in x around 0 80.9%
if -2.95e7 < y < 5.2000000000000001e67Initial program 78.8%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 79.1%
Final simplification80.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 77.9%
associate-*l/84.3%
Simplified84.3%
Taylor expanded in x around 0 50.9%
Final simplification50.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 2024036
(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)))