
(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 (<= x -2.5e+75)
(* y (/ (* x 2.0) (- x y)))
(if (<= x 3.8e-27)
(* x (/ (* 2.0 y) (- x y)))
(/ y (fma (/ y x) -0.5 0.5)))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e+75) {
tmp = y * ((x * 2.0) / (x - y));
} else if (x <= 3.8e-27) {
tmp = x * ((2.0 * y) / (x - y));
} else {
tmp = y / fma((y / x), -0.5, 0.5);
}
return tmp;
}
function code(x, y) tmp = 0.0 if (x <= -2.5e+75) tmp = Float64(y * Float64(Float64(x * 2.0) / Float64(x - y))); elseif (x <= 3.8e-27) tmp = Float64(x * Float64(Float64(2.0 * y) / Float64(x - y))); else tmp = Float64(y / fma(Float64(y / x), -0.5, 0.5)); end return tmp end
code[x_, y_] := If[LessEqual[x, -2.5e+75], N[(y * N[(N[(x * 2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.8e-27], N[(x * N[(N[(2.0 * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y / N[(N[(y / x), $MachinePrecision] * -0.5 + 0.5), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+75}:\\
\;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-27}:\\
\;\;\;\;x \cdot \frac{2 \cdot y}{x - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{\mathsf{fma}\left(\frac{y}{x}, -0.5, 0.5\right)}\\
\end{array}
\end{array}
if x < -2.5000000000000001e75Initial program 73.3%
associate-*l/100.0%
Simplified100.0%
if -2.5000000000000001e75 < x < 3.8e-27Initial program 82.6%
associate-/l*99.9%
associate-*r/99.9%
Simplified99.9%
expm1-log1p-u29.6%
expm1-udef2.3%
associate-/r/2.3%
*-commutative2.3%
Applied egg-rr2.3%
expm1-def29.6%
expm1-log1p99.7%
*-commutative99.7%
associate-*l/100.0%
Simplified100.0%
if 3.8e-27 < x Initial program 70.4%
*-commutative70.4%
associate-/l*100.0%
div-sub100.0%
sub-neg100.0%
+-commutative100.0%
distribute-neg-frac100.0%
neg-mul-1100.0%
*-commutative100.0%
times-frac100.0%
metadata-eval100.0%
metadata-eval100.0%
metadata-eval100.0%
*-inverses100.0%
associate-/r*100.0%
*-commutative100.0%
associate-/r*100.0%
*-inverses100.0%
*-inverses100.0%
associate-/r*100.0%
*-commutative100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -2.5e+75) (not (<= x 4e-32))) (* y (/ (* x 2.0) (- x y))) (* x (/ (* 2.0 y) (- x y)))))
double code(double x, double y) {
double tmp;
if ((x <= -2.5e+75) || !(x <= 4e-32)) {
tmp = y * ((x * 2.0) / (x - 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 ((x <= (-2.5d+75)) .or. (.not. (x <= 4d-32))) then
tmp = y * ((x * 2.0d0) / (x - 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 ((x <= -2.5e+75) || !(x <= 4e-32)) {
tmp = y * ((x * 2.0) / (x - y));
} else {
tmp = x * ((2.0 * y) / (x - y));
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.5e+75) or not (x <= 4e-32): tmp = y * ((x * 2.0) / (x - y)) else: tmp = x * ((2.0 * y) / (x - y)) return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.5e+75) || !(x <= 4e-32)) tmp = Float64(y * Float64(Float64(x * 2.0) / Float64(x - y))); else tmp = Float64(x * Float64(Float64(2.0 * y) / Float64(x - y))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.5e+75) || ~((x <= 4e-32))) tmp = y * ((x * 2.0) / (x - y)); else tmp = x * ((2.0 * y) / (x - y)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.5e+75], N[Not[LessEqual[x, 4e-32]], $MachinePrecision]], N[(y * N[(N[(x * 2.0), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(N[(2.0 * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{+75} \lor \neg \left(x \leq 4 \cdot 10^{-32}\right):\\
\;\;\;\;y \cdot \frac{x \cdot 2}{x - y}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \frac{2 \cdot y}{x - y}\\
\end{array}
\end{array}
if x < -2.5000000000000001e75 or 4.00000000000000022e-32 < x Initial program 71.8%
associate-*l/100.0%
Simplified100.0%
if -2.5000000000000001e75 < x < 4.00000000000000022e-32Initial program 82.6%
associate-/l*99.9%
associate-*r/99.9%
Simplified99.9%
expm1-log1p-u29.6%
expm1-udef2.3%
associate-/r/2.3%
*-commutative2.3%
Applied egg-rr2.3%
expm1-def29.6%
expm1-log1p99.7%
*-commutative99.7%
associate-*l/100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -3.2e+75) (* 2.0 y) (if (<= x 1.4e+151) (* x (/ 2.0 (/ (- x y) y))) (* 2.0 y))))
double code(double x, double y) {
double tmp;
if (x <= -3.2e+75) {
tmp = 2.0 * y;
} else if (x <= 1.4e+151) {
tmp = x * (2.0 / ((x - y) / y));
} 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 (x <= (-3.2d+75)) then
tmp = 2.0d0 * y
else if (x <= 1.4d+151) then
tmp = x * (2.0d0 / ((x - y) / y))
else
tmp = 2.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -3.2e+75) {
tmp = 2.0 * y;
} else if (x <= 1.4e+151) {
tmp = x * (2.0 / ((x - y) / y));
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -3.2e+75: tmp = 2.0 * y elif x <= 1.4e+151: tmp = x * (2.0 / ((x - y) / y)) else: tmp = 2.0 * y return tmp
function code(x, y) tmp = 0.0 if (x <= -3.2e+75) tmp = Float64(2.0 * y); elseif (x <= 1.4e+151) tmp = Float64(x * Float64(2.0 / Float64(Float64(x - y) / y))); else tmp = Float64(2.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -3.2e+75) tmp = 2.0 * y; elseif (x <= 1.4e+151) tmp = x * (2.0 / ((x - y) / y)); else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -3.2e+75], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 1.4e+151], N[(x * N[(2.0 / N[(N[(x - y), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.2 \cdot 10^{+75}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 1.4 \cdot 10^{+151}:\\
\;\;\;\;x \cdot \frac{2}{\frac{x - y}{y}}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if x < -3.19999999999999985e75 or 1.39999999999999994e151 < x Initial program 69.4%
associate-/l*69.6%
associate-*r/69.5%
Simplified69.5%
Taylor expanded in x around inf 89.4%
if -3.19999999999999985e75 < x < 1.39999999999999994e151Initial program 82.0%
associate-/l*99.4%
associate-*r/99.3%
Simplified99.3%
Final simplification95.8%
(FPCore (x y) :precision binary64 (if (<= x -1.7e+154) (* 2.0 y) (if (<= x 1.2e+151) (* x (/ (* 2.0 y) (- x y))) (* 2.0 y))))
double code(double x, double y) {
double tmp;
if (x <= -1.7e+154) {
tmp = 2.0 * y;
} else if (x <= 1.2e+151) {
tmp = x * ((2.0 * y) / (x - y));
} 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 (x <= (-1.7d+154)) then
tmp = 2.0d0 * y
else if (x <= 1.2d+151) then
tmp = x * ((2.0d0 * y) / (x - y))
else
tmp = 2.0d0 * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.7e+154) {
tmp = 2.0 * y;
} else if (x <= 1.2e+151) {
tmp = x * ((2.0 * y) / (x - y));
} else {
tmp = 2.0 * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.7e+154: tmp = 2.0 * y elif x <= 1.2e+151: tmp = x * ((2.0 * y) / (x - y)) else: tmp = 2.0 * y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.7e+154) tmp = Float64(2.0 * y); elseif (x <= 1.2e+151) tmp = Float64(x * Float64(Float64(2.0 * y) / Float64(x - y))); else tmp = Float64(2.0 * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.7e+154) tmp = 2.0 * y; elseif (x <= 1.2e+151) tmp = x * ((2.0 * y) / (x - y)); else tmp = 2.0 * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.7e+154], N[(2.0 * y), $MachinePrecision], If[LessEqual[x, 1.2e+151], N[(x * N[(N[(2.0 * y), $MachinePrecision] / N[(x - y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(2.0 * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.7 \cdot 10^{+154}:\\
\;\;\;\;2 \cdot y\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{+151}:\\
\;\;\;\;x \cdot \frac{2 \cdot y}{x - y}\\
\mathbf{else}:\\
\;\;\;\;2 \cdot y\\
\end{array}
\end{array}
if x < -1.69999999999999987e154 or 1.20000000000000005e151 < x Initial program 65.0%
associate-/l*66.4%
associate-*r/66.2%
Simplified66.2%
Taylor expanded in x around inf 90.7%
if -1.69999999999999987e154 < x < 1.20000000000000005e151Initial program 82.6%
associate-/l*98.0%
associate-*r/97.9%
Simplified97.9%
expm1-log1p-u36.7%
expm1-udef2.6%
associate-/r/2.6%
*-commutative2.6%
Applied egg-rr2.6%
expm1-def36.6%
expm1-log1p97.7%
*-commutative97.7%
associate-*l/98.0%
Simplified98.0%
Final simplification95.9%
(FPCore (x y) :precision binary64 (if (<= y -6.5e+28) (* x -2.0) (if (<= y 8e+56) (* 2.0 y) (* x -2.0))))
double code(double x, double y) {
double tmp;
if (y <= -6.5e+28) {
tmp = x * -2.0;
} else if (y <= 8e+56) {
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 (y <= (-6.5d+28)) then
tmp = x * (-2.0d0)
else if (y <= 8d+56) 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 (y <= -6.5e+28) {
tmp = x * -2.0;
} else if (y <= 8e+56) {
tmp = 2.0 * y;
} else {
tmp = x * -2.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.5e+28: tmp = x * -2.0 elif y <= 8e+56: tmp = 2.0 * y else: tmp = x * -2.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.5e+28) tmp = Float64(x * -2.0); elseif (y <= 8e+56) 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 (y <= -6.5e+28) tmp = x * -2.0; elseif (y <= 8e+56) tmp = 2.0 * y; else tmp = x * -2.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.5e+28], N[(x * -2.0), $MachinePrecision], If[LessEqual[y, 8e+56], N[(2.0 * y), $MachinePrecision], N[(x * -2.0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+28}:\\
\;\;\;\;x \cdot -2\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+56}:\\
\;\;\;\;2 \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot -2\\
\end{array}
\end{array}
if y < -6.5000000000000001e28 or 8.00000000000000074e56 < y Initial program 69.4%
associate-/l*100.0%
associate-*r/99.9%
Simplified99.9%
Taylor expanded in x around 0 76.1%
if -6.5000000000000001e28 < y < 8.00000000000000074e56Initial program 83.7%
associate-/l*80.8%
associate-*r/80.6%
Simplified80.6%
Taylor expanded in x around inf 75.9%
Final simplification76.0%
(FPCore (x y) :precision binary64 (* 2.0 y))
double code(double x, double y) {
return 2.0 * y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = 2.0d0 * y
end function
public static double code(double x, double y) {
return 2.0 * y;
}
def code(x, y): return 2.0 * y
function code(x, y) return Float64(2.0 * y) end
function tmp = code(x, y) tmp = 2.0 * y; end
code[x_, y_] := N[(2.0 * y), $MachinePrecision]
\begin{array}{l}
\\
2 \cdot y
\end{array}
Initial program 77.6%
associate-/l*89.0%
associate-*r/88.8%
Simplified88.8%
Taylor expanded in x around inf 54.9%
Final simplification54.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 2023174
(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)))