
(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%
(FPCore (x y) :precision binary64 (if (or (<= y -7e-8) (not (<= y 1.06e-8))) (/ y (+ y -1.0)) (+ x (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if ((y <= -7e-8) || !(y <= 1.06e-8)) {
tmp = y / (y + -1.0);
} else {
tmp = x + (y * (x + -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 <= (-7d-8)) .or. (.not. (y <= 1.06d-8))) then
tmp = y / (y + (-1.0d0))
else
tmp = x + (y * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7e-8) || !(y <= 1.06e-8)) {
tmp = y / (y + -1.0);
} else {
tmp = x + (y * (x + -1.0));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7e-8) or not (y <= 1.06e-8): tmp = y / (y + -1.0) else: tmp = x + (y * (x + -1.0)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7e-8) || !(y <= 1.06e-8)) tmp = Float64(y / Float64(y + -1.0)); else tmp = Float64(x + Float64(y * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7e-8) || ~((y <= 1.06e-8))) tmp = y / (y + -1.0); else tmp = x + (y * (x + -1.0)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7e-8], N[Not[LessEqual[y, 1.06e-8]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7 \cdot 10^{-8} \lor \neg \left(y \leq 1.06 \cdot 10^{-8}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -7.00000000000000048e-8 or 1.06000000000000006e-8 < y Initial program 100.0%
Taylor expanded in x around 0 76.9%
neg-mul-176.9%
distribute-neg-frac276.9%
neg-sub076.9%
associate--r-76.9%
metadata-eval76.9%
Simplified76.9%
if -7.00000000000000048e-8 < y < 1.06000000000000006e-8Initial program 100.0%
Taylor expanded in y around 0 99.5%
mul-1-neg99.5%
unsub-neg99.5%
mul-1-neg99.5%
sub-neg99.5%
Simplified99.5%
Final simplification87.9%
(FPCore (x y) :precision binary64 (if (or (<= y -2.2e-11) (not (<= y 1.85e-16))) (/ y (+ y -1.0)) (+ x (* x y))))
double code(double x, double y) {
double tmp;
if ((y <= -2.2e-11) || !(y <= 1.85e-16)) {
tmp = y / (y + -1.0);
} else {
tmp = x + (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 <= (-2.2d-11)) .or. (.not. (y <= 1.85d-16))) then
tmp = y / (y + (-1.0d0))
else
tmp = x + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2.2e-11) || !(y <= 1.85e-16)) {
tmp = y / (y + -1.0);
} else {
tmp = x + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.2e-11) or not (y <= 1.85e-16): tmp = y / (y + -1.0) else: tmp = x + (x * y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.2e-11) || !(y <= 1.85e-16)) tmp = Float64(y / Float64(y + -1.0)); else tmp = Float64(x + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2.2e-11) || ~((y <= 1.85e-16))) tmp = y / (y + -1.0); else tmp = x + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.2e-11], N[Not[LessEqual[y, 1.85e-16]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.2 \cdot 10^{-11} \lor \neg \left(y \leq 1.85 \cdot 10^{-16}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;x + x \cdot y\\
\end{array}
\end{array}
if y < -2.2000000000000002e-11 or 1.85e-16 < y Initial program 100.0%
Taylor expanded in x around 0 76.6%
neg-mul-176.6%
distribute-neg-frac276.6%
neg-sub076.6%
associate--r-76.6%
metadata-eval76.6%
Simplified76.6%
if -2.2000000000000002e-11 < y < 1.85e-16Initial program 100.0%
Taylor expanded in x around inf 72.9%
Taylor expanded in y around 0 72.9%
Final simplification74.8%
(FPCore (x y) :precision binary64 (if (<= y -1.05e+56) 1.0 (if (<= y 1.9e+65) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.05e+56) {
tmp = 1.0;
} else if (y <= 1.9e+65) {
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 <= (-1.05d+56)) then
tmp = 1.0d0
else if (y <= 1.9d+65) 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 <= -1.05e+56) {
tmp = 1.0;
} else if (y <= 1.9e+65) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e+56: tmp = 1.0 elif y <= 1.9e+65: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e+56) tmp = 1.0; elseif (y <= 1.9e+65) 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 <= -1.05e+56) tmp = 1.0; elseif (y <= 1.9e+65) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e+56], 1.0, If[LessEqual[y, 1.9e+65], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{+56}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+65}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.05000000000000009e56 or 1.90000000000000006e65 < y Initial program 100.0%
Taylor expanded in y around inf 84.3%
if -1.05000000000000009e56 < y < 1.90000000000000006e65Initial program 100.0%
Taylor expanded in x around inf 67.5%
(FPCore (x y) :precision binary64 (if (<= y -0.005) 1.0 (if (<= y 1.0) (+ x (* x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.005) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x + (x * 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 <= (-0.005d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x + (x * y)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -0.005) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x + (x * y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.005: tmp = 1.0 elif y <= 1.0: tmp = x + (x * y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.005) tmp = 1.0; elseif (y <= 1.0) tmp = Float64(x + Float64(x * y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -0.005) tmp = 1.0; elseif (y <= 1.0) tmp = x + (x * y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.005], 1.0, If[LessEqual[y, 1.0], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.005:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.0050000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 75.4%
if -0.0050000000000000001 < y < 1Initial program 100.0%
Taylor expanded in x around inf 71.0%
Taylor expanded in y around 0 71.0%
(FPCore (x y) :precision binary64 (if (<= y -0.0058) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.0058) {
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 <= (-0.0058d0)) 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 <= -0.0058) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.0058: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.0058) 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 <= -0.0058) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.0058], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0058:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.0058 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 75.4%
if -0.0058 < y < 1Initial program 100.0%
Taylor expanded in y around 0 70.5%
(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.8%
herbie shell --seed 2024191
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))