
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (- x y) (- 1.0 y)))
double code(double x, double y) {
return (x - y) / (1.0 - y);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x - y) / (1.0d0 - y)
end function
public static double code(double x, double y) {
return (x - y) / (1.0 - y);
}
def code(x, y): return (x - y) / (1.0 - y)
function code(x, y) return Float64(Float64(x - y) / Float64(1.0 - y)) end
function tmp = code(x, y) tmp = (x - y) / (1.0 - y); end
code[x_, y_] := N[(N[(x - y), $MachinePrecision] / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x - y}{1 - y}
\end{array}
(FPCore (x y) :precision binary64 (+ (/ x (- 1.0 y)) (/ y (+ y -1.0))))
double code(double x, double y) {
return (x / (1.0 - y)) + (y / (y + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x / (1.0d0 - y)) + (y / (y + (-1.0d0)))
end function
public static double code(double x, double y) {
return (x / (1.0 - y)) + (y / (y + -1.0));
}
def code(x, y): return (x / (1.0 - y)) + (y / (y + -1.0))
function code(x, y) return Float64(Float64(x / Float64(1.0 - y)) + Float64(y / Float64(y + -1.0))) end
function tmp = code(x, y) tmp = (x / (1.0 - y)) + (y / (y + -1.0)); end
code[x_, y_] := N[(N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision] + N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x}{1 - y} + \frac{y}{y + -1}
\end{array}
Initial program 100.0%
div-sub100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))) (t_1 (/ y (+ y -1.0))))
(if (<= y -15500.0)
t_0
(if (<= y -1.35e-62)
t_1
(if (<= y 2.55e-132)
x
(if (<= y 3.4e-105) t_1 (if (<= y 3.05) (/ x (- 1.0 y)) t_0)))))))
double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double t_1 = y / (y + -1.0);
double tmp;
if (y <= -15500.0) {
tmp = t_0;
} else if (y <= -1.35e-62) {
tmp = t_1;
} else if (y <= 2.55e-132) {
tmp = x;
} else if (y <= 3.4e-105) {
tmp = t_1;
} else if (y <= 3.05) {
tmp = x / (1.0 - 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 + ((1.0d0 - x) / y)
t_1 = y / (y + (-1.0d0))
if (y <= (-15500.0d0)) then
tmp = t_0
else if (y <= (-1.35d-62)) then
tmp = t_1
else if (y <= 2.55d-132) then
tmp = x
else if (y <= 3.4d-105) then
tmp = t_1
else if (y <= 3.05d0) then
tmp = x / (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double t_1 = y / (y + -1.0);
double tmp;
if (y <= -15500.0) {
tmp = t_0;
} else if (y <= -1.35e-62) {
tmp = t_1;
} else if (y <= 2.55e-132) {
tmp = x;
} else if (y <= 3.4e-105) {
tmp = t_1;
} else if (y <= 3.05) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((1.0 - x) / y) t_1 = y / (y + -1.0) tmp = 0 if y <= -15500.0: tmp = t_0 elif y <= -1.35e-62: tmp = t_1 elif y <= 2.55e-132: tmp = x elif y <= 3.4e-105: tmp = t_1 elif y <= 3.05: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(1.0 - x) / y)) t_1 = Float64(y / Float64(y + -1.0)) tmp = 0.0 if (y <= -15500.0) tmp = t_0; elseif (y <= -1.35e-62) tmp = t_1; elseif (y <= 2.55e-132) tmp = x; elseif (y <= 3.4e-105) tmp = t_1; elseif (y <= 3.05) tmp = Float64(x / Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((1.0 - x) / y); t_1 = y / (y + -1.0); tmp = 0.0; if (y <= -15500.0) tmp = t_0; elseif (y <= -1.35e-62) tmp = t_1; elseif (y <= 2.55e-132) tmp = x; elseif (y <= 3.4e-105) tmp = t_1; elseif (y <= 3.05) tmp = x / (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -15500.0], t$95$0, If[LessEqual[y, -1.35e-62], t$95$1, If[LessEqual[y, 2.55e-132], x, If[LessEqual[y, 3.4e-105], t$95$1, If[LessEqual[y, 3.05], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1 - x}{y}\\
t_1 := \frac{y}{y + -1}\\
\mathbf{if}\;y \leq -15500:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-132}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-105}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.05:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -15500 or 3.0499999999999998 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
sub-neg98.7%
div-sub98.7%
Simplified98.7%
if -15500 < y < -1.3500000000000001e-62 or 2.55000000000000003e-132 < y < 3.39999999999999992e-105Initial program 100.0%
Taylor expanded in x around 0 70.5%
neg-mul-170.5%
distribute-neg-frac270.5%
neg-sub070.5%
associate--r-70.5%
metadata-eval70.5%
Simplified70.5%
if -1.3500000000000001e-62 < y < 2.55000000000000003e-132Initial program 100.0%
Taylor expanded in y around 0 87.6%
if 3.39999999999999992e-105 < y < 3.0499999999999998Initial program 100.0%
Taylor expanded in x around inf 69.6%
Final simplification89.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))) (t_1 (/ y (+ y -1.0))))
(if (<= y -29000000.0)
t_0
(if (<= y -1.45e-62)
t_1
(if (<= y 2.55e-132)
x
(if (<= y 3.45e-105) t_1 (if (<= y 3.05) (/ x (- 1.0 y)) t_0)))))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double t_1 = y / (y + -1.0);
double tmp;
if (y <= -29000000.0) {
tmp = t_0;
} else if (y <= -1.45e-62) {
tmp = t_1;
} else if (y <= 2.55e-132) {
tmp = x;
} else if (y <= 3.45e-105) {
tmp = t_1;
} else if (y <= 3.05) {
tmp = x / (1.0 - 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
t_1 = y / (y + (-1.0d0))
if (y <= (-29000000.0d0)) then
tmp = t_0
else if (y <= (-1.45d-62)) then
tmp = t_1
else if (y <= 2.55d-132) then
tmp = x
else if (y <= 3.45d-105) then
tmp = t_1
else if (y <= 3.05d0) then
tmp = x / (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double t_1 = y / (y + -1.0);
double tmp;
if (y <= -29000000.0) {
tmp = t_0;
} else if (y <= -1.45e-62) {
tmp = t_1;
} else if (y <= 2.55e-132) {
tmp = x;
} else if (y <= 3.45e-105) {
tmp = t_1;
} else if (y <= 3.05) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) t_1 = y / (y + -1.0) tmp = 0 if y <= -29000000.0: tmp = t_0 elif y <= -1.45e-62: tmp = t_1 elif y <= 2.55e-132: tmp = x elif y <= 3.45e-105: tmp = t_1 elif y <= 3.05: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) t_1 = Float64(y / Float64(y + -1.0)) tmp = 0.0 if (y <= -29000000.0) tmp = t_0; elseif (y <= -1.45e-62) tmp = t_1; elseif (y <= 2.55e-132) tmp = x; elseif (y <= 3.45e-105) tmp = t_1; elseif (y <= 3.05) tmp = Float64(x / Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); t_1 = y / (y + -1.0); tmp = 0.0; if (y <= -29000000.0) tmp = t_0; elseif (y <= -1.45e-62) tmp = t_1; elseif (y <= 2.55e-132) tmp = x; elseif (y <= 3.45e-105) tmp = t_1; elseif (y <= 3.05) tmp = x / (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -29000000.0], t$95$0, If[LessEqual[y, -1.45e-62], t$95$1, If[LessEqual[y, 2.55e-132], x, If[LessEqual[y, 3.45e-105], t$95$1, If[LessEqual[y, 3.05], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
t_1 := \frac{y}{y + -1}\\
\mathbf{if}\;y \leq -29000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.45 \cdot 10^{-62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.55 \cdot 10^{-132}:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 3.45 \cdot 10^{-105}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3.05:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.9e7 or 3.0499999999999998 < y Initial program 100.0%
Taylor expanded in y around inf 98.7%
+-commutative98.7%
mul-1-neg98.7%
sub-neg98.7%
div-sub98.7%
Simplified98.7%
Taylor expanded in x around inf 98.2%
neg-mul-198.2%
distribute-neg-frac298.2%
Simplified98.2%
if -2.9e7 < y < -1.44999999999999993e-62 or 2.55000000000000003e-132 < y < 3.45000000000000014e-105Initial program 100.0%
Taylor expanded in x around 0 70.5%
neg-mul-170.5%
distribute-neg-frac270.5%
neg-sub070.5%
associate--r-70.5%
metadata-eval70.5%
Simplified70.5%
if -1.44999999999999993e-62 < y < 2.55000000000000003e-132Initial program 100.0%
Taylor expanded in y around 0 87.6%
if 3.45000000000000014e-105 < y < 3.0499999999999998Initial program 100.0%
Taylor expanded in x around inf 69.6%
Final simplification89.5%
(FPCore (x y)
:precision binary64
(if (or (<= y -1.4e-62)
(not
(or (<= y 2.55e-132) (and (not (<= y 3.4e-105)) (<= y 5.2e-49)))))
(/ y (+ y -1.0))
x))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e-62) || !((y <= 2.55e-132) || (!(y <= 3.4e-105) && (y <= 5.2e-49)))) {
tmp = y / (y + -1.0);
} else {
tmp = 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-62)) .or. (.not. (y <= 2.55d-132) .or. (.not. (y <= 3.4d-105)) .and. (y <= 5.2d-49))) then
tmp = y / (y + (-1.0d0))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.4e-62) || !((y <= 2.55e-132) || (!(y <= 3.4e-105) && (y <= 5.2e-49)))) {
tmp = y / (y + -1.0);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e-62) or not ((y <= 2.55e-132) or (not (y <= 3.4e-105) and (y <= 5.2e-49))): tmp = y / (y + -1.0) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e-62) || !((y <= 2.55e-132) || (!(y <= 3.4e-105) && (y <= 5.2e-49)))) tmp = Float64(y / Float64(y + -1.0)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e-62) || ~(((y <= 2.55e-132) || (~((y <= 3.4e-105)) && (y <= 5.2e-49))))) tmp = y / (y + -1.0); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e-62], N[Not[Or[LessEqual[y, 2.55e-132], And[N[Not[LessEqual[y, 3.4e-105]], $MachinePrecision], LessEqual[y, 5.2e-49]]]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{-62} \lor \neg \left(y \leq 2.55 \cdot 10^{-132} \lor \neg \left(y \leq 3.4 \cdot 10^{-105}\right) \land y \leq 5.2 \cdot 10^{-49}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1.40000000000000001e-62 or 2.55000000000000003e-132 < y < 3.39999999999999992e-105 or 5.1999999999999999e-49 < y Initial program 100.0%
Taylor expanded in x around 0 72.0%
neg-mul-172.0%
distribute-neg-frac272.0%
neg-sub072.0%
associate--r-72.0%
metadata-eval72.0%
Simplified72.0%
if -1.40000000000000001e-62 < y < 2.55000000000000003e-132 or 3.39999999999999992e-105 < y < 5.1999999999999999e-49Initial program 100.0%
Taylor expanded in y around 0 87.3%
Final simplification78.2%
(FPCore (x y) :precision binary64 (if (<= y -2.4e+23) 1.0 (if (<= y 5.8e+23) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.4e+23) {
tmp = 1.0;
} else if (y <= 5.8e+23) {
tmp = x / (1.0 - y);
} else {
tmp = 1.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.4d+23)) then
tmp = 1.0d0
else if (y <= 5.8d+23) then
tmp = x / (1.0d0 - y)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.4e+23) {
tmp = 1.0;
} else if (y <= 5.8e+23) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.4e+23: tmp = 1.0 elif y <= 5.8e+23: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.4e+23) tmp = 1.0; elseif (y <= 5.8e+23) tmp = Float64(x / Float64(1.0 - y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.4e+23) tmp = 1.0; elseif (y <= 5.8e+23) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.4e+23], 1.0, If[LessEqual[y, 5.8e+23], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+23}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+23}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.4e23 or 5.80000000000000025e23 < y Initial program 100.0%
Taylor expanded in y around inf 75.7%
if -2.4e23 < y < 5.80000000000000025e23Initial program 100.0%
Taylor expanded in x around inf 73.4%
(FPCore (x y) :precision binary64 (if (<= y -90000000000000.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -90000000000000.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-90000000000000.0d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -90000000000000.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -90000000000000.0: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -90000000000000.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -90000000000000.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -90000000000000.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -90000000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9e13 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 73.0%
if -9e13 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.6%
(FPCore (x y) :precision binary64 (/ (- y x) (+ y -1.0)))
double code(double x, double y) {
return (y - x) / (y + -1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y - x) / (y + (-1.0d0))
end function
public static double code(double x, double y) {
return (y - x) / (y + -1.0);
}
def code(x, y): return (y - x) / (y + -1.0)
function code(x, y) return Float64(Float64(y - x) / Float64(y + -1.0)) end
function tmp = code(x, y) tmp = (y - x) / (y + -1.0); end
code[x_, y_] := N[(N[(y - x), $MachinePrecision] / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{y - x}{y + -1}
\end{array}
Initial program 100.0%
Final simplification100.0%
(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 100.0%
Taylor expanded in y around inf 35.5%
herbie shell --seed 2024085
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))