
(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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -390.0)
t_0
(if (<= y -4.6e-84)
(/ y (+ y -1.0))
(if (<= y 3500000.0) (/ x (- 1.0 y)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -390.0) {
tmp = t_0;
} else if (y <= -4.6e-84) {
tmp = y / (y + -1.0);
} else if (y <= 3500000.0) {
tmp = x / (1.0 - y);
} 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 = 1.0d0 + ((1.0d0 - x) / y)
if (y <= (-390.0d0)) then
tmp = t_0
else if (y <= (-4.6d-84)) then
tmp = y / (y + (-1.0d0))
else if (y <= 3500000.0d0) then
tmp = x / (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -390.0) {
tmp = t_0;
} else if (y <= -4.6e-84) {
tmp = y / (y + -1.0);
} else if (y <= 3500000.0) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((1.0 - x) / y) tmp = 0 if y <= -390.0: tmp = t_0 elif y <= -4.6e-84: tmp = y / (y + -1.0) elif y <= 3500000.0: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(1.0 - x) / y)) tmp = 0.0 if (y <= -390.0) tmp = t_0; elseif (y <= -4.6e-84) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 3500000.0) tmp = Float64(x / Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((1.0 - x) / y); tmp = 0.0; if (y <= -390.0) tmp = t_0; elseif (y <= -4.6e-84) tmp = y / (y + -1.0); elseif (y <= 3500000.0) tmp = x / (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -390.0], t$95$0, If[LessEqual[y, -4.6e-84], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3500000.0], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -390:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -4.6 \cdot 10^{-84}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 3500000:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -390 or 3.5e6 < y Initial program 100.0%
Taylor expanded in y around inf 99.7%
+-commutative99.7%
mul-1-neg99.7%
sub-neg99.7%
div-sub99.7%
Simplified99.7%
if -390 < y < -4.59999999999999961e-84Initial program 100.0%
Taylor expanded in x around 0 66.3%
neg-mul-166.3%
distribute-neg-frac266.3%
neg-sub066.3%
associate--r-66.3%
metadata-eval66.3%
Simplified66.3%
if -4.59999999999999961e-84 < y < 3.5e6Initial program 100.0%
Taylor expanded in x around inf 80.3%
Final simplification89.0%
(FPCore (x y) :precision binary64 (if (or (<= y -3.5e-84) (not (<= y 6.3e-74))) (/ y (+ y -1.0)) x))
double code(double x, double y) {
double tmp;
if ((y <= -3.5e-84) || !(y <= 6.3e-74)) {
tmp = y / (y + -1.0);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-3.5d-84)) .or. (.not. (y <= 6.3d-74))) then
tmp = y / (y + (-1.0d0))
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3.5e-84) || !(y <= 6.3e-74)) {
tmp = y / (y + -1.0);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3.5e-84) or not (y <= 6.3e-74): tmp = y / (y + -1.0) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3.5e-84) || !(y <= 6.3e-74)) tmp = Float64(y / Float64(y + -1.0)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3.5e-84) || ~((y <= 6.3e-74))) tmp = y / (y + -1.0); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3.5e-84], N[Not[LessEqual[y, 6.3e-74]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.5 \cdot 10^{-84} \lor \neg \left(y \leq 6.3 \cdot 10^{-74}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.5000000000000001e-84 or 6.30000000000000003e-74 < y Initial program 100.0%
Taylor expanded in x around 0 70.0%
neg-mul-170.0%
distribute-neg-frac270.0%
neg-sub070.0%
associate--r-70.0%
metadata-eval70.0%
Simplified70.0%
if -3.5000000000000001e-84 < y < 6.30000000000000003e-74Initial program 100.0%
Taylor expanded in y around 0 85.1%
Final simplification75.9%
(FPCore (x y) :precision binary64 (if (<= y -9e+82) 1.0 (if (<= y 3.5e+75) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -9e+82) {
tmp = 1.0;
} else if (y <= 3.5e+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 <= (-9d+82)) then
tmp = 1.0d0
else if (y <= 3.5d+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 <= -9e+82) {
tmp = 1.0;
} else if (y <= 3.5e+75) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e+82: tmp = 1.0 elif y <= 3.5e+75: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -9e+82) tmp = 1.0; elseif (y <= 3.5e+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 <= -9e+82) tmp = 1.0; elseif (y <= 3.5e+75) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e+82], 1.0, If[LessEqual[y, 3.5e+75], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{+82}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+75}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.9999999999999993e82 or 3.4999999999999998e75 < y Initial program 100.0%
Taylor expanded in y around inf 78.4%
if -8.9999999999999993e82 < y < 3.4999999999999998e75Initial program 100.0%
Taylor expanded in x around inf 72.6%
(FPCore (x y) :precision binary64 (if (<= y -6.5e-5) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -6.5e-5) {
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 <= (-6.5d-5)) 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 <= -6.5e-5) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.5e-5: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.5e-5) 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 <= -6.5e-5) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.5e-5], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{-5}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.49999999999999943e-5 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 69.7%
if -6.49999999999999943e-5 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.1%
(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.0%
herbie shell --seed 2024100
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))