
(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 7 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 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))) (t_1 (/ x (- 1.0 y))))
(if (<= y -740.0)
t_0
(if (<= y 6.2e-30)
t_1
(if (<= y 2e-15) (/ y (+ y -1.0)) (if (<= y 13500.0) t_1 t_0))))))
double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double t_1 = x / (1.0 - y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 6.2e-30) {
tmp = t_1;
} else if (y <= 2e-15) {
tmp = y / (y + -1.0);
} else if (y <= 13500.0) {
tmp = t_1;
} 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 = x / (1.0d0 - y)
if (y <= (-740.0d0)) then
tmp = t_0
else if (y <= 6.2d-30) then
tmp = t_1
else if (y <= 2d-15) then
tmp = y / (y + (-1.0d0))
else if (y <= 13500.0d0) then
tmp = t_1
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 = x / (1.0 - y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 6.2e-30) {
tmp = t_1;
} else if (y <= 2e-15) {
tmp = y / (y + -1.0);
} else if (y <= 13500.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((1.0 - x) / y) t_1 = x / (1.0 - y) tmp = 0 if y <= -740.0: tmp = t_0 elif y <= 6.2e-30: tmp = t_1 elif y <= 2e-15: tmp = y / (y + -1.0) elif y <= 13500.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(1.0 - x) / y)) t_1 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (y <= -740.0) tmp = t_0; elseif (y <= 6.2e-30) tmp = t_1; elseif (y <= 2e-15) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 13500.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((1.0 - x) / y); t_1 = x / (1.0 - y); tmp = 0.0; if (y <= -740.0) tmp = t_0; elseif (y <= 6.2e-30) tmp = t_1; elseif (y <= 2e-15) tmp = y / (y + -1.0); elseif (y <= 13500.0) tmp = t_1; 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[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -740.0], t$95$0, If[LessEqual[y, 6.2e-30], t$95$1, If[LessEqual[y, 2e-15], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 13500.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1 - x}{y}\\
t_1 := \frac{x}{1 - y}\\
\mathbf{if}\;y \leq -740:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-30}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 2 \cdot 10^{-15}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 13500:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -740 or 13500 < y Initial program 100.0%
Taylor expanded in y around inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
div-sub99.6%
Simplified99.6%
if -740 < y < 6.19999999999999982e-30 or 2.0000000000000002e-15 < y < 13500Initial program 100.0%
Taylor expanded in x around inf 79.9%
if 6.19999999999999982e-30 < y < 2.0000000000000002e-15Initial program 100.0%
Taylor expanded in x around 0 100.0%
metadata-eval100.0%
times-frac100.0%
*-lft-identity100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification89.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))) (t_1 (/ x (- 1.0 y))))
(if (<= y -740.0)
t_0
(if (<= y 2.3e-29)
t_1
(if (<= y 3.05e-15)
(/ y (+ y -1.0))
(if (<= y 300000000.0) t_1 t_0))))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double t_1 = x / (1.0 - y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 2.3e-29) {
tmp = t_1;
} else if (y <= 3.05e-15) {
tmp = y / (y + -1.0);
} else if (y <= 300000000.0) {
tmp = t_1;
} 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 = x / (1.0d0 - y)
if (y <= (-740.0d0)) then
tmp = t_0
else if (y <= 2.3d-29) then
tmp = t_1
else if (y <= 3.05d-15) then
tmp = y / (y + (-1.0d0))
else if (y <= 300000000.0d0) then
tmp = t_1
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 = x / (1.0 - y);
double tmp;
if (y <= -740.0) {
tmp = t_0;
} else if (y <= 2.3e-29) {
tmp = t_1;
} else if (y <= 3.05e-15) {
tmp = y / (y + -1.0);
} else if (y <= 300000000.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) t_1 = x / (1.0 - y) tmp = 0 if y <= -740.0: tmp = t_0 elif y <= 2.3e-29: tmp = t_1 elif y <= 3.05e-15: tmp = y / (y + -1.0) elif y <= 300000000.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) t_1 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (y <= -740.0) tmp = t_0; elseif (y <= 2.3e-29) tmp = t_1; elseif (y <= 3.05e-15) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 300000000.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); t_1 = x / (1.0 - y); tmp = 0.0; if (y <= -740.0) tmp = t_0; elseif (y <= 2.3e-29) tmp = t_1; elseif (y <= 3.05e-15) tmp = y / (y + -1.0); elseif (y <= 300000000.0) tmp = t_1; 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[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -740.0], t$95$0, If[LessEqual[y, 2.3e-29], t$95$1, If[LessEqual[y, 3.05e-15], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 300000000.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
t_1 := \frac{x}{1 - y}\\
\mathbf{if}\;y \leq -740:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 2.3 \cdot 10^{-29}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq 3.05 \cdot 10^{-15}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 300000000:\\
\;\;\;\;t_1\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -740 or 3e8 < y Initial program 100.0%
Taylor expanded in y around inf 99.6%
+-commutative99.6%
mul-1-neg99.6%
unsub-neg99.6%
div-sub99.6%
Simplified99.6%
Taylor expanded in x around inf 98.4%
neg-mul-198.4%
distribute-neg-frac98.4%
Simplified98.4%
if -740 < y < 2.29999999999999991e-29 or 3.04999999999999986e-15 < y < 3e8Initial program 100.0%
Taylor expanded in x around inf 79.9%
if 2.29999999999999991e-29 < y < 3.04999999999999986e-15Initial program 100.0%
Taylor expanded in x around 0 100.0%
metadata-eval100.0%
times-frac100.0%
*-lft-identity100.0%
neg-mul-1100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
Simplified100.0%
Final simplification88.9%
(FPCore (x y) :precision binary64 (if (or (<= y -4.2e-28) (not (<= y 9e-29))) (/ y (+ y -1.0)) x))
double code(double x, double y) {
double tmp;
if ((y <= -4.2e-28) || !(y <= 9e-29)) {
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 <= (-4.2d-28)) .or. (.not. (y <= 9d-29))) 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 <= -4.2e-28) || !(y <= 9e-29)) {
tmp = y / (y + -1.0);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.2e-28) or not (y <= 9e-29): tmp = y / (y + -1.0) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.2e-28) || !(y <= 9e-29)) 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 <= -4.2e-28) || ~((y <= 9e-29))) tmp = y / (y + -1.0); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.2e-28], N[Not[LessEqual[y, 9e-29]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.2 \cdot 10^{-28} \lor \neg \left(y \leq 9 \cdot 10^{-29}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.20000000000000013e-28 or 8.9999999999999996e-29 < y Initial program 100.0%
Taylor expanded in x around 0 79.3%
metadata-eval79.3%
times-frac79.3%
*-lft-identity79.3%
neg-mul-179.3%
neg-sub079.3%
associate--r-79.3%
metadata-eval79.3%
Simplified79.3%
if -4.20000000000000013e-28 < y < 8.9999999999999996e-29Initial program 100.0%
Taylor expanded in y around 0 81.1%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (<= y -740.0) 1.0 (if (<= y 9.2e+26) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -740.0) {
tmp = 1.0;
} else if (y <= 9.2e+26) {
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 <= (-740.0d0)) then
tmp = 1.0d0
else if (y <= 9.2d+26) 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 <= -740.0) {
tmp = 1.0;
} else if (y <= 9.2e+26) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -740.0: tmp = 1.0 elif y <= 9.2e+26: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -740.0) tmp = 1.0; elseif (y <= 9.2e+26) 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 <= -740.0) tmp = 1.0; elseif (y <= 9.2e+26) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -740.0], 1.0, If[LessEqual[y, 9.2e+26], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -740:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 9.2 \cdot 10^{+26}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -740 or 9.2000000000000002e26 < y Initial program 100.0%
Taylor expanded in y around inf 80.5%
if -740 < y < 9.2000000000000002e26Initial program 100.0%
Taylor expanded in x around inf 76.9%
Final simplification78.5%
(FPCore (x y) :precision binary64 (if (<= y -600.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -600.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 <= (-600.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 <= -600.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 <= -600.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 <= -600.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 <= -600.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, -600.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -600:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -600 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 80.0%
if -600 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.3%
Final simplification77.4%
(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 39.1%
Final simplification39.1%
herbie shell --seed 2024018
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))