
(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 6 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 (/ x (- 1.0 y))))
(if (<= x -9.4e-15)
t_0
(if (<= x 7.3e-40)
(/ y (+ y -1.0))
(if (<= x 1650.0)
x
(if (<= x 2.2e+28)
1.0
(if (or (<= x 5.6e+144) (not (<= x 1.65e+170))) t_0 1.0)))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (x <= -9.4e-15) {
tmp = t_0;
} else if (x <= 7.3e-40) {
tmp = y / (y + -1.0);
} else if (x <= 1650.0) {
tmp = x;
} else if (x <= 2.2e+28) {
tmp = 1.0;
} else if ((x <= 5.6e+144) || !(x <= 1.65e+170)) {
tmp = t_0;
} 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 = x / (1.0d0 - y)
if (x <= (-9.4d-15)) then
tmp = t_0
else if (x <= 7.3d-40) then
tmp = y / (y + (-1.0d0))
else if (x <= 1650.0d0) then
tmp = x
else if (x <= 2.2d+28) then
tmp = 1.0d0
else if ((x <= 5.6d+144) .or. (.not. (x <= 1.65d+170))) then
tmp = t_0
else
tmp = 1.0d0
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 <= -9.4e-15) {
tmp = t_0;
} else if (x <= 7.3e-40) {
tmp = y / (y + -1.0);
} else if (x <= 1650.0) {
tmp = x;
} else if (x <= 2.2e+28) {
tmp = 1.0;
} else if ((x <= 5.6e+144) || !(x <= 1.65e+170)) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) tmp = 0 if x <= -9.4e-15: tmp = t_0 elif x <= 7.3e-40: tmp = y / (y + -1.0) elif x <= 1650.0: tmp = x elif x <= 2.2e+28: tmp = 1.0 elif (x <= 5.6e+144) or not (x <= 1.65e+170): tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (x <= -9.4e-15) tmp = t_0; elseif (x <= 7.3e-40) tmp = Float64(y / Float64(y + -1.0)); elseif (x <= 1650.0) tmp = x; elseif (x <= 2.2e+28) tmp = 1.0; elseif ((x <= 5.6e+144) || !(x <= 1.65e+170)) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (1.0 - y); tmp = 0.0; if (x <= -9.4e-15) tmp = t_0; elseif (x <= 7.3e-40) tmp = y / (y + -1.0); elseif (x <= 1650.0) tmp = x; elseif (x <= 2.2e+28) tmp = 1.0; elseif ((x <= 5.6e+144) || ~((x <= 1.65e+170))) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -9.4e-15], t$95$0, If[LessEqual[x, 7.3e-40], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 1650.0], x, If[LessEqual[x, 2.2e+28], 1.0, If[Or[LessEqual[x, 5.6e+144], N[Not[LessEqual[x, 1.65e+170]], $MachinePrecision]], t$95$0, 1.0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
\mathbf{if}\;x \leq -9.4 \cdot 10^{-15}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.3 \cdot 10^{-40}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;x \leq 1650:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 2.2 \cdot 10^{+28}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 5.6 \cdot 10^{+144} \lor \neg \left(x \leq 1.65 \cdot 10^{+170}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -9.3999999999999997e-15 or 2.19999999999999986e28 < x < 5.60000000000000013e144 or 1.65000000000000012e170 < x Initial program 100.0%
Taylor expanded in x around inf 84.4%
if -9.3999999999999997e-15 < x < 7.30000000000000005e-40Initial program 100.0%
Taylor expanded in x around 0 80.2%
metadata-eval80.2%
times-frac80.2%
*-lft-identity80.2%
neg-mul-180.2%
neg-sub080.2%
associate--r-80.2%
metadata-eval80.2%
Simplified80.2%
if 7.30000000000000005e-40 < x < 1650Initial program 100.0%
Taylor expanded in y around 0 72.9%
if 1650 < x < 2.19999999999999986e28 or 5.60000000000000013e144 < x < 1.65000000000000012e170Initial program 99.9%
Taylor expanded in y around inf 89.4%
Final simplification82.2%
(FPCore (x y) :precision binary64 (if (or (<= y -1600.0) (not (<= y 7000000000000.0))) (+ 1.0 (/ (- 1.0 x) y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -1600.0) || !(y <= 7000000000000.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 <= (-1600.0d0)) .or. (.not. (y <= 7000000000000.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 <= -1600.0) || !(y <= 7000000000000.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1600.0) or not (y <= 7000000000000.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 <= -1600.0) || !(y <= 7000000000000.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 <= -1600.0) || ~((y <= 7000000000000.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, -1600.0], N[Not[LessEqual[y, 7000000000000.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 -1600 \lor \neg \left(y \leq 7000000000000\right):\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -1600 or 7e12 < 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 -1600 < y < 7e12Initial program 100.0%
Taylor expanded in x around inf 70.8%
Final simplification84.7%
(FPCore (x y) :precision binary64 (if (<= y -1.08e+58) 1.0 (if (<= y 2.9e+49) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.08e+58) {
tmp = 1.0;
} else if (y <= 2.9e+49) {
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.08d+58)) then
tmp = 1.0d0
else if (y <= 2.9d+49) 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.08e+58) {
tmp = 1.0;
} else if (y <= 2.9e+49) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.08e+58: tmp = 1.0 elif y <= 2.9e+49: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.08e+58) tmp = 1.0; elseif (y <= 2.9e+49) 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.08e+58) tmp = 1.0; elseif (y <= 2.9e+49) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.08e+58], 1.0, If[LessEqual[y, 2.9e+49], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.08 \cdot 10^{+58}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+49}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.0799999999999999e58 or 2.9e49 < y Initial program 100.0%
Taylor expanded in y around inf 78.1%
if -1.0799999999999999e58 < y < 2.9e49Initial program 100.0%
Taylor expanded in x around inf 68.1%
Final simplification72.1%
(FPCore (x y) :precision binary64 (if (<= y -7.5e-27) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7.5e-27) {
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 <= (-7.5d-27)) 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 <= -7.5e-27) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.5e-27: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7.5e-27) 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 <= -7.5e-27) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.5e-27], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-27}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7.50000000000000029e-27 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 68.3%
if -7.50000000000000029e-27 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.2%
Final simplification70.2%
(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.1%
Final simplification37.1%
herbie shell --seed 2024040
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))