
(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 (<= y -5.5e+105)
1.0
(if (<= y -1.16e+73)
(/ x (- y))
(if (<= y -6e+15) 1.0 (if (<= y 520000000.0) (/ x (- 1.0 y)) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -5.5e+105) {
tmp = 1.0;
} else if (y <= -1.16e+73) {
tmp = x / -y;
} else if (y <= -6e+15) {
tmp = 1.0;
} else if (y <= 520000000.0) {
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 <= (-5.5d+105)) then
tmp = 1.0d0
else if (y <= (-1.16d+73)) then
tmp = x / -y
else if (y <= (-6d+15)) then
tmp = 1.0d0
else if (y <= 520000000.0d0) 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 <= -5.5e+105) {
tmp = 1.0;
} else if (y <= -1.16e+73) {
tmp = x / -y;
} else if (y <= -6e+15) {
tmp = 1.0;
} else if (y <= 520000000.0) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.5e+105: tmp = 1.0 elif y <= -1.16e+73: tmp = x / -y elif y <= -6e+15: tmp = 1.0 elif y <= 520000000.0: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.5e+105) tmp = 1.0; elseif (y <= -1.16e+73) tmp = Float64(x / Float64(-y)); elseif (y <= -6e+15) tmp = 1.0; elseif (y <= 520000000.0) 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 <= -5.5e+105) tmp = 1.0; elseif (y <= -1.16e+73) tmp = x / -y; elseif (y <= -6e+15) tmp = 1.0; elseif (y <= 520000000.0) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.5e+105], 1.0, If[LessEqual[y, -1.16e+73], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -6e+15], 1.0, If[LessEqual[y, 520000000.0], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+105}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.16 \cdot 10^{+73}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -6 \cdot 10^{+15}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 520000000:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.49999999999999979e105 or -1.16000000000000007e73 < y < -6e15 or 5.2e8 < y Initial program 100.0%
Taylor expanded in y around inf 77.6%
if -5.49999999999999979e105 < y < -1.16000000000000007e73Initial program 99.9%
Taylor expanded in x around inf 67.6%
Taylor expanded in y around inf 67.6%
associate-*r/67.6%
neg-mul-167.6%
Simplified67.6%
if -6e15 < y < 5.2e8Initial program 100.0%
Taylor expanded in x around inf 74.2%
Final simplification75.4%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (- 1.0 y))))
(if (<= x -3e+35)
t_0
(if (<= x 3.5e-83)
(/ y (+ y -1.0))
(if (<= x 50000.0) x (if (<= x 9.5e+68) 1.0 t_0))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (x <= -3e+35) {
tmp = t_0;
} else if (x <= 3.5e-83) {
tmp = y / (y + -1.0);
} else if (x <= 50000.0) {
tmp = x;
} else if (x <= 9.5e+68) {
tmp = 1.0;
} 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) :: tmp
t_0 = x / (1.0d0 - y)
if (x <= (-3d+35)) then
tmp = t_0
else if (x <= 3.5d-83) then
tmp = y / (y + (-1.0d0))
else if (x <= 50000.0d0) then
tmp = x
else if (x <= 9.5d+68) then
tmp = 1.0d0
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (x <= -3e+35) {
tmp = t_0;
} else if (x <= 3.5e-83) {
tmp = y / (y + -1.0);
} else if (x <= 50000.0) {
tmp = x;
} else if (x <= 9.5e+68) {
tmp = 1.0;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) tmp = 0 if x <= -3e+35: tmp = t_0 elif x <= 3.5e-83: tmp = y / (y + -1.0) elif x <= 50000.0: tmp = x elif x <= 9.5e+68: tmp = 1.0 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (x <= -3e+35) tmp = t_0; elseif (x <= 3.5e-83) tmp = Float64(y / Float64(y + -1.0)); elseif (x <= 50000.0) tmp = x; elseif (x <= 9.5e+68) tmp = 1.0; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (1.0 - y); tmp = 0.0; if (x <= -3e+35) tmp = t_0; elseif (x <= 3.5e-83) tmp = y / (y + -1.0); elseif (x <= 50000.0) tmp = x; elseif (x <= 9.5e+68) tmp = 1.0; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -3e+35], t$95$0, If[LessEqual[x, 3.5e-83], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 50000.0], x, If[LessEqual[x, 9.5e+68], 1.0, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
\mathbf{if}\;x \leq -3 \cdot 10^{+35}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.5 \cdot 10^{-83}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;x \leq 50000:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 9.5 \cdot 10^{+68}:\\
\;\;\;\;1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.99999999999999991e35 or 9.50000000000000069e68 < x Initial program 100.0%
Taylor expanded in x around inf 85.0%
if -2.99999999999999991e35 < x < 3.5000000000000003e-83Initial program 100.0%
Taylor expanded in x around 0 78.5%
neg-mul-178.5%
distribute-neg-frac278.5%
neg-sub078.5%
associate--r-78.5%
metadata-eval78.5%
Simplified78.5%
if 3.5000000000000003e-83 < x < 5e4Initial program 100.0%
Taylor expanded in y around 0 65.3%
if 5e4 < x < 9.50000000000000069e68Initial program 100.0%
Taylor expanded in y around inf 79.4%
Final simplification80.5%
(FPCore (x y)
:precision binary64
(if (<= y -5.5e+105)
1.0
(if (<= y -7.9e+71)
(/ x (- y))
(if (<= y -2.3e-19) 1.0 (if (<= y 1.0) x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -5.5e+105) {
tmp = 1.0;
} else if (y <= -7.9e+71) {
tmp = x / -y;
} else if (y <= -2.3e-19) {
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 <= (-5.5d+105)) then
tmp = 1.0d0
else if (y <= (-7.9d+71)) then
tmp = x / -y
else if (y <= (-2.3d-19)) 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 <= -5.5e+105) {
tmp = 1.0;
} else if (y <= -7.9e+71) {
tmp = x / -y;
} else if (y <= -2.3e-19) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.5e+105: tmp = 1.0 elif y <= -7.9e+71: tmp = x / -y elif y <= -2.3e-19: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.5e+105) tmp = 1.0; elseif (y <= -7.9e+71) tmp = Float64(x / Float64(-y)); elseif (y <= -2.3e-19) 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 <= -5.5e+105) tmp = 1.0; elseif (y <= -7.9e+71) tmp = x / -y; elseif (y <= -2.3e-19) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.5e+105], 1.0, If[LessEqual[y, -7.9e+71], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -2.3e-19], 1.0, If[LessEqual[y, 1.0], x, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.5 \cdot 10^{+105}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -7.9 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -2.3 \cdot 10^{-19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.49999999999999979e105 or -7.90000000000000028e71 < y < -2.2999999999999998e-19 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 74.8%
if -5.49999999999999979e105 < y < -7.90000000000000028e71Initial program 99.9%
Taylor expanded in x around inf 67.6%
Taylor expanded in y around inf 67.6%
associate-*r/67.6%
neg-mul-167.6%
Simplified67.6%
if -2.2999999999999998e-19 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.0%
Final simplification74.6%
(FPCore (x y) :precision binary64 (if (or (<= y -2400000000.0) (not (<= y 28000.0))) (+ 1.0 (/ (- 1.0 x) y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -2400000000.0) || !(y <= 28000.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-2400000000.0d0)) .or. (.not. (y <= 28000.0d0))) then
tmp = 1.0d0 + ((1.0d0 - x) / y)
else
tmp = x / (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -2400000000.0) || !(y <= 28000.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2400000000.0) or not (y <= 28000.0): tmp = 1.0 + ((1.0 - x) / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2400000000.0) || !(y <= 28000.0)) tmp = Float64(1.0 + Float64(Float64(1.0 - x) / y)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -2400000000.0) || ~((y <= 28000.0))) tmp = 1.0 + ((1.0 - x) / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2400000000.0], N[Not[LessEqual[y, 28000.0]], $MachinePrecision]], N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2400000000 \lor \neg \left(y \leq 28000\right):\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -2.4e9 or 28000 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
div-sub100.0%
Simplified100.0%
if -2.4e9 < y < 28000Initial program 100.0%
Taylor expanded in x around inf 74.2%
Final simplification86.7%
(FPCore (x y) :precision binary64 (if (<= y -2.3e-19) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-19) {
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 <= (-2.3d-19)) 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 <= -2.3e-19) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e-19: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e-19) 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 <= -2.3e-19) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e-19], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-19}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.2999999999999998e-19 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 71.0%
if -2.2999999999999998e-19 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.0%
Final simplification73.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 37.5%
Final simplification37.5%
herbie shell --seed 2024048
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))