
(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
(let* ((t_0 (/ x (- 1.0 y))))
(if (<= x -8e-16)
t_0
(if (<= x 7.3e-40)
(/ y (+ y -1.0))
(if (<= x 580.0)
x
(if (<= x 9.6e+27)
1.0
(if (or (<= x 4.6e+144) (not (<= x 1.6e+170))) t_0 1.0)))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (x <= -8e-16) {
tmp = t_0;
} else if (x <= 7.3e-40) {
tmp = y / (y + -1.0);
} else if (x <= 580.0) {
tmp = x;
} else if (x <= 9.6e+27) {
tmp = 1.0;
} else if ((x <= 4.6e+144) || !(x <= 1.6e+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 <= (-8d-16)) then
tmp = t_0
else if (x <= 7.3d-40) then
tmp = y / (y + (-1.0d0))
else if (x <= 580.0d0) then
tmp = x
else if (x <= 9.6d+27) then
tmp = 1.0d0
else if ((x <= 4.6d+144) .or. (.not. (x <= 1.6d+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 <= -8e-16) {
tmp = t_0;
} else if (x <= 7.3e-40) {
tmp = y / (y + -1.0);
} else if (x <= 580.0) {
tmp = x;
} else if (x <= 9.6e+27) {
tmp = 1.0;
} else if ((x <= 4.6e+144) || !(x <= 1.6e+170)) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) tmp = 0 if x <= -8e-16: tmp = t_0 elif x <= 7.3e-40: tmp = y / (y + -1.0) elif x <= 580.0: tmp = x elif x <= 9.6e+27: tmp = 1.0 elif (x <= 4.6e+144) or not (x <= 1.6e+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 <= -8e-16) tmp = t_0; elseif (x <= 7.3e-40) tmp = Float64(y / Float64(y + -1.0)); elseif (x <= 580.0) tmp = x; elseif (x <= 9.6e+27) tmp = 1.0; elseif ((x <= 4.6e+144) || !(x <= 1.6e+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 <= -8e-16) tmp = t_0; elseif (x <= 7.3e-40) tmp = y / (y + -1.0); elseif (x <= 580.0) tmp = x; elseif (x <= 9.6e+27) tmp = 1.0; elseif ((x <= 4.6e+144) || ~((x <= 1.6e+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, -8e-16], t$95$0, If[LessEqual[x, 7.3e-40], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 580.0], x, If[LessEqual[x, 9.6e+27], 1.0, If[Or[LessEqual[x, 4.6e+144], N[Not[LessEqual[x, 1.6e+170]], $MachinePrecision]], t$95$0, 1.0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
\mathbf{if}\;x \leq -8 \cdot 10^{-16}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 7.3 \cdot 10^{-40}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;x \leq 580:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 9.6 \cdot 10^{+27}:\\
\;\;\;\;1\\
\mathbf{elif}\;x \leq 4.6 \cdot 10^{+144} \lor \neg \left(x \leq 1.6 \cdot 10^{+170}\right):\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if x < -7.9999999999999998e-16 or 9.59999999999999991e27 < x < 4.6000000000000003e144 or 1.59999999999999989e170 < x Initial program 100.0%
Taylor expanded in x around inf 84.4%
if -7.9999999999999998e-16 < x < 7.30000000000000005e-40Initial program 100.0%
Taylor expanded in x around 0 80.2%
neg-mul-180.2%
distribute-neg-frac280.2%
neg-sub080.2%
associate--r-80.2%
metadata-eval80.2%
Simplified80.2%
if 7.30000000000000005e-40 < x < 580Initial program 100.0%
Taylor expanded in y around 0 72.9%
if 580 < x < 9.59999999999999991e27 or 4.6000000000000003e144 < x < 1.59999999999999989e170Initial 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 (or (<= y -620.0) (not (<= y 7000000000000.0))) (- 1.0 (/ x y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -620.0) || !(y <= 7000000000000.0)) {
tmp = 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 <= (-620.0d0)) .or. (.not. (y <= 7000000000000.0d0))) then
tmp = 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 <= -620.0) || !(y <= 7000000000000.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -620.0) or not (y <= 7000000000000.0): tmp = 1.0 - (x / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -620.0) || !(y <= 7000000000000.0)) tmp = Float64(1.0 - Float64(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 <= -620.0) || ~((y <= 7000000000000.0))) tmp = 1.0 - (x / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -620.0], N[Not[LessEqual[y, 7000000000000.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -620 \lor \neg \left(y \leq 7000000000000\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -620 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%
Taylor expanded in x around inf 99.1%
neg-mul-199.1%
distribute-neg-frac299.1%
Simplified99.1%
if -620 < y < 7e12Initial program 100.0%
Taylor expanded in x around inf 70.8%
Final simplification84.5%
(FPCore (x y) :precision binary64 (if (<= y -6e+57) 1.0 (if (<= y 4e+48) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6e+57) {
tmp = 1.0;
} else if (y <= 4e+48) {
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 <= (-6d+57)) then
tmp = 1.0d0
else if (y <= 4d+48) 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 <= -6e+57) {
tmp = 1.0;
} else if (y <= 4e+48) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+57: tmp = 1.0 elif y <= 4e+48: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+57) tmp = 1.0; elseif (y <= 4e+48) 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 <= -6e+57) tmp = 1.0; elseif (y <= 4e+48) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+57], 1.0, If[LessEqual[y, 4e+48], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+57}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4 \cdot 10^{+48}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.9999999999999999e57 or 4.00000000000000018e48 < y Initial program 100.0%
Taylor expanded in y around inf 78.1%
if -5.9999999999999999e57 < y < 4.00000000000000018e48Initial 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)))