
(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 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
(if (<= y -0.0115)
(/ y (+ y -1.0))
(if (<= y 7.1e-9)
(+ x (* y (+ x -1.0)))
(if (<= y 6.4e+42) (/ x (- 1.0 y)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -0.0115) {
tmp = y / (y + -1.0);
} else if (y <= 7.1e-9) {
tmp = x + (y * (x + -1.0));
} else if (y <= 6.4e+42) {
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 <= (-0.0115d0)) then
tmp = y / (y + (-1.0d0))
else if (y <= 7.1d-9) then
tmp = x + (y * (x + (-1.0d0)))
else if (y <= 6.4d+42) 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 <= -0.0115) {
tmp = y / (y + -1.0);
} else if (y <= 7.1e-9) {
tmp = x + (y * (x + -1.0));
} else if (y <= 6.4e+42) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.0115: tmp = y / (y + -1.0) elif y <= 7.1e-9: tmp = x + (y * (x + -1.0)) elif y <= 6.4e+42: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.0115) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 7.1e-9) tmp = Float64(x + Float64(y * Float64(x + -1.0))); elseif (y <= 6.4e+42) 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 <= -0.0115) tmp = y / (y + -1.0); elseif (y <= 7.1e-9) tmp = x + (y * (x + -1.0)); elseif (y <= 6.4e+42) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.0115], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.1e-9], N[(x + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.4e+42], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0115:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 7.1 \cdot 10^{-9}:\\
\;\;\;\;x + y \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+42}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.0115Initial program 100.0%
Taylor expanded in x around 0 73.9%
neg-mul-173.9%
distribute-neg-frac273.9%
neg-sub073.9%
associate--r-73.9%
metadata-eval73.9%
Simplified73.9%
if -0.0115 < y < 7.09999999999999988e-9Initial program 100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
if 7.09999999999999988e-9 < y < 6.40000000000000004e42Initial program 100.0%
Taylor expanded in x around inf 75.8%
if 6.40000000000000004e42 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
Final simplification87.6%
(FPCore (x y)
:precision binary64
(if (<= y -0.00045)
(/ 1.0 (/ (+ y -1.0) y))
(if (<= y 7.1e-9)
(+ x (* y (+ x -1.0)))
(if (<= y 1.9e+43) (/ x (- 1.0 y)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -0.00045) {
tmp = 1.0 / ((y + -1.0) / y);
} else if (y <= 7.1e-9) {
tmp = x + (y * (x + -1.0));
} else if (y <= 1.9e+43) {
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 <= (-0.00045d0)) then
tmp = 1.0d0 / ((y + (-1.0d0)) / y)
else if (y <= 7.1d-9) then
tmp = x + (y * (x + (-1.0d0)))
else if (y <= 1.9d+43) 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 <= -0.00045) {
tmp = 1.0 / ((y + -1.0) / y);
} else if (y <= 7.1e-9) {
tmp = x + (y * (x + -1.0));
} else if (y <= 1.9e+43) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.00045: tmp = 1.0 / ((y + -1.0) / y) elif y <= 7.1e-9: tmp = x + (y * (x + -1.0)) elif y <= 1.9e+43: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.00045) tmp = Float64(1.0 / Float64(Float64(y + -1.0) / y)); elseif (y <= 7.1e-9) tmp = Float64(x + Float64(y * Float64(x + -1.0))); elseif (y <= 1.9e+43) 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 <= -0.00045) tmp = 1.0 / ((y + -1.0) / y); elseif (y <= 7.1e-9) tmp = x + (y * (x + -1.0)); elseif (y <= 1.9e+43) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.00045], N[(1.0 / N[(N[(y + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.1e-9], N[(x + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.9e+43], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00045:\\
\;\;\;\;\frac{1}{\frac{y + -1}{y}}\\
\mathbf{elif}\;y \leq 7.1 \cdot 10^{-9}:\\
\;\;\;\;x + y \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 1.9 \cdot 10^{+43}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.4999999999999999e-4Initial program 100.0%
clear-num99.9%
associate-/r/99.6%
Applied egg-rr99.6%
associate-*l/100.0%
*-un-lft-identity100.0%
clear-num99.9%
Applied egg-rr99.9%
Taylor expanded in x around 0 73.9%
associate-*r/73.9%
neg-mul-173.9%
neg-sub073.9%
associate--r-73.9%
metadata-eval73.9%
Simplified73.9%
if -4.4999999999999999e-4 < y < 7.09999999999999988e-9Initial program 100.0%
Taylor expanded in y around 0 99.2%
mul-1-neg99.2%
unsub-neg99.2%
mul-1-neg99.2%
sub-neg99.2%
Simplified99.2%
if 7.09999999999999988e-9 < y < 1.90000000000000004e43Initial program 100.0%
Taylor expanded in x around inf 75.8%
if 1.90000000000000004e43 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
Final simplification87.6%
(FPCore (x y) :precision binary64 (if (<= y -0.31) 1.0 (if (<= y 1.0) (+ x (* x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.31) {
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.31d0)) 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.31) {
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.31: 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.31) 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.31) 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.31], 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.31:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.309999999999999998 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 72.3%
if -0.309999999999999998 < y < 1Initial program 100.0%
Taylor expanded in x around inf 76.6%
Taylor expanded in y around 0 76.2%
Final simplification74.2%
(FPCore (x y) :precision binary64 (if (<= y -8.8e+19) 1.0 (if (<= y 4e+42) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -8.8e+19) {
tmp = 1.0;
} else if (y <= 4e+42) {
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 <= (-8.8d+19)) then
tmp = 1.0d0
else if (y <= 4d+42) 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 <= -8.8e+19) {
tmp = 1.0;
} else if (y <= 4e+42) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.8e+19: tmp = 1.0 elif y <= 4e+42: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -8.8e+19) tmp = 1.0; elseif (y <= 4e+42) 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 <= -8.8e+19) tmp = 1.0; elseif (y <= 4e+42) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.8e+19], 1.0, If[LessEqual[y, 4e+42], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.8 \cdot 10^{+19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+42}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.8e19 or 4.00000000000000018e42 < y Initial program 100.0%
Taylor expanded in y around inf 77.3%
if -8.8e19 < y < 4.00000000000000018e42Initial program 100.0%
Taylor expanded in x around inf 75.8%
Final simplification76.5%
(FPCore (x y) :precision binary64 (if (<= y -3.8e-53) (/ y (+ y -1.0)) (if (<= y 4.2e+43) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.8e-53) {
tmp = y / (y + -1.0);
} else if (y <= 4.2e+43) {
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 <= (-3.8d-53)) then
tmp = y / (y + (-1.0d0))
else if (y <= 4.2d+43) 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 <= -3.8e-53) {
tmp = y / (y + -1.0);
} else if (y <= 4.2e+43) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.8e-53: tmp = y / (y + -1.0) elif y <= 4.2e+43: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.8e-53) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 4.2e+43) 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 <= -3.8e-53) tmp = y / (y + -1.0); elseif (y <= 4.2e+43) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.8e-53], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.2e+43], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.8 \cdot 10^{-53}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{+43}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.7999999999999998e-53Initial program 99.9%
Taylor expanded in x around 0 70.8%
neg-mul-170.8%
distribute-neg-frac270.8%
neg-sub070.8%
associate--r-70.8%
metadata-eval70.8%
Simplified70.8%
if -3.7999999999999998e-53 < y < 4.20000000000000003e43Initial program 100.0%
Taylor expanded in x around inf 79.1%
if 4.20000000000000003e43 < y Initial program 100.0%
Taylor expanded in y around inf 79.5%
Final simplification77.0%
(FPCore (x y) :precision binary64 (if (<= y -0.2) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.2) {
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.2d0)) 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.2) {
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.2: 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.2) 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.2) 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.2], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.2:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.20000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 72.3%
if -0.20000000000000001 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.9%
Final simplification73.6%
(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 38.5%
Final simplification38.5%
herbie shell --seed 2024077
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))