
(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
(if (or (<= x -5.7e+22)
(not
(or (<= x -2.25e-51) (and (not (<= x -2.2e-108)) (<= x 1.3e+34)))))
(/ x (- 1.0 y))
(/ y (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -5.7e+22) || !((x <= -2.25e-51) || (!(x <= -2.2e-108) && (x <= 1.3e+34)))) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-5.7d+22)) .or. (.not. (x <= (-2.25d-51)) .or. (.not. (x <= (-2.2d-108))) .and. (x <= 1.3d+34))) then
tmp = x / (1.0d0 - y)
else
tmp = y / (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -5.7e+22) || !((x <= -2.25e-51) || (!(x <= -2.2e-108) && (x <= 1.3e+34)))) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.7e+22) or not ((x <= -2.25e-51) or (not (x <= -2.2e-108) and (x <= 1.3e+34))): tmp = x / (1.0 - y) else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.7e+22) || !((x <= -2.25e-51) || (!(x <= -2.2e-108) && (x <= 1.3e+34)))) tmp = Float64(x / Float64(1.0 - y)); else tmp = Float64(y / Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -5.7e+22) || ~(((x <= -2.25e-51) || (~((x <= -2.2e-108)) && (x <= 1.3e+34))))) tmp = x / (1.0 - y); else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.7e+22], N[Not[Or[LessEqual[x, -2.25e-51], And[N[Not[LessEqual[x, -2.2e-108]], $MachinePrecision], LessEqual[x, 1.3e+34]]]], $MachinePrecision]], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.7 \cdot 10^{+22} \lor \neg \left(x \leq -2.25 \cdot 10^{-51} \lor \neg \left(x \leq -2.2 \cdot 10^{-108}\right) \land x \leq 1.3 \cdot 10^{+34}\right):\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if x < -5.69999999999999979e22 or -2.24999999999999987e-51 < x < -2.2000000000000001e-108 or 1.29999999999999999e34 < x Initial program 100.0%
Taylor expanded in x around inf 79.5%
if -5.69999999999999979e22 < x < -2.24999999999999987e-51 or -2.2000000000000001e-108 < x < 1.29999999999999999e34Initial program 100.0%
Taylor expanded in x around 0 80.1%
neg-mul-180.1%
distribute-neg-frac280.1%
neg-sub080.1%
associate--r-80.1%
metadata-eval80.1%
Simplified80.1%
Final simplification79.8%
(FPCore (x y)
:precision binary64
(if (<= y -1.4e+20)
1.0
(if (or (<= y 6e+14) (and (not (<= y 5.2e+38)) (<= y 2.9e+75)))
(/ x (- 1.0 y))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.4e+20) {
tmp = 1.0;
} else if ((y <= 6e+14) || (!(y <= 5.2e+38) && (y <= 2.9e+75))) {
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.4d+20)) then
tmp = 1.0d0
else if ((y <= 6d+14) .or. (.not. (y <= 5.2d+38)) .and. (y <= 2.9d+75)) 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.4e+20) {
tmp = 1.0;
} else if ((y <= 6e+14) || (!(y <= 5.2e+38) && (y <= 2.9e+75))) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.4e+20: tmp = 1.0 elif (y <= 6e+14) or (not (y <= 5.2e+38) and (y <= 2.9e+75)): tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.4e+20) tmp = 1.0; elseif ((y <= 6e+14) || (!(y <= 5.2e+38) && (y <= 2.9e+75))) 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.4e+20) tmp = 1.0; elseif ((y <= 6e+14) || (~((y <= 5.2e+38)) && (y <= 2.9e+75))) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.4e+20], 1.0, If[Or[LessEqual[y, 6e+14], And[N[Not[LessEqual[y, 5.2e+38]], $MachinePrecision], LessEqual[y, 2.9e+75]]], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+20}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+14} \lor \neg \left(y \leq 5.2 \cdot 10^{+38}\right) \land y \leq 2.9 \cdot 10^{+75}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.4e20 or 6e14 < y < 5.1999999999999998e38 or 2.8999999999999998e75 < y Initial program 100.0%
Taylor expanded in y around inf 82.0%
if -1.4e20 < y < 6e14 or 5.1999999999999998e38 < y < 2.8999999999999998e75Initial program 100.0%
Taylor expanded in x around inf 77.2%
Final simplification79.6%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ y (+ y -1.0))))
(if (<= y -0.000175)
t_0
(if (<= y 0.00026)
(+ x (* y (+ x -1.0)))
(if (<= y 4.5e+37) t_0 (if (<= y 5.4e+75) (/ x (- 1.0 y)) 1.0))))))
double code(double x, double y) {
double t_0 = y / (y + -1.0);
double tmp;
if (y <= -0.000175) {
tmp = t_0;
} else if (y <= 0.00026) {
tmp = x + (y * (x + -1.0));
} else if (y <= 4.5e+37) {
tmp = t_0;
} else if (y <= 5.4e+75) {
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) :: t_0
real(8) :: tmp
t_0 = y / (y + (-1.0d0))
if (y <= (-0.000175d0)) then
tmp = t_0
else if (y <= 0.00026d0) then
tmp = x + (y * (x + (-1.0d0)))
else if (y <= 4.5d+37) then
tmp = t_0
else if (y <= 5.4d+75) 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 t_0 = y / (y + -1.0);
double tmp;
if (y <= -0.000175) {
tmp = t_0;
} else if (y <= 0.00026) {
tmp = x + (y * (x + -1.0));
} else if (y <= 4.5e+37) {
tmp = t_0;
} else if (y <= 5.4e+75) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = y / (y + -1.0) tmp = 0 if y <= -0.000175: tmp = t_0 elif y <= 0.00026: tmp = x + (y * (x + -1.0)) elif y <= 4.5e+37: tmp = t_0 elif y <= 5.4e+75: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(y / Float64(y + -1.0)) tmp = 0.0 if (y <= -0.000175) tmp = t_0; elseif (y <= 0.00026) tmp = Float64(x + Float64(y * Float64(x + -1.0))); elseif (y <= 4.5e+37) tmp = t_0; elseif (y <= 5.4e+75) tmp = Float64(x / Float64(1.0 - y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = y / (y + -1.0); tmp = 0.0; if (y <= -0.000175) tmp = t_0; elseif (y <= 0.00026) tmp = x + (y * (x + -1.0)); elseif (y <= 4.5e+37) tmp = t_0; elseif (y <= 5.4e+75) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.000175], t$95$0, If[LessEqual[y, 0.00026], N[(x + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 4.5e+37], t$95$0, If[LessEqual[y, 5.4e+75], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{y}{y + -1}\\
\mathbf{if}\;y \leq -0.000175:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00026:\\
\;\;\;\;x + y \cdot \left(x + -1\right)\\
\mathbf{elif}\;y \leq 4.5 \cdot 10^{+37}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+75}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.74999999999999998e-4 or 2.59999999999999977e-4 < y < 4.49999999999999962e37Initial program 100.0%
Taylor expanded in x around 0 77.9%
neg-mul-177.9%
distribute-neg-frac277.9%
neg-sub077.9%
associate--r-77.9%
metadata-eval77.9%
Simplified77.9%
if -1.74999999999999998e-4 < y < 2.59999999999999977e-4Initial 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%
if 4.49999999999999962e37 < y < 5.39999999999999996e75Initial program 100.0%
Taylor expanded in x around inf 89.1%
if 5.39999999999999996e75 < y Initial program 100.0%
Taylor expanded in y around inf 80.5%
Final simplification87.9%
(FPCore (x y) :precision binary64 (if (<= y -0.82) 1.0 (if (<= y 1.0) (+ x (* x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.82) {
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.82d0)) 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.82) {
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.82: 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.82) 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.82) 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.82], 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.82:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.819999999999999951 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 72.9%
if -0.819999999999999951 < y < 1Initial program 100.0%
Taylor expanded in x around inf 78.9%
Taylor expanded in y around 0 78.4%
Final simplification75.3%
(FPCore (x y) :precision binary64 (if (<= y -1020.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1020.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 <= (-1020.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 <= -1020.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 <= -1020.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 <= -1020.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 <= -1020.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, -1020.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1020:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1020 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 73.4%
if -1020 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.0%
Final simplification74.9%
(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 43.8%
Final simplification43.8%
herbie shell --seed 2024057
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))