
(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 -6.8e+134)
1.0
(if (<= y -6.2e+59)
(/ x (- y))
(if (<= y -0.017) 1.0 (if (<= y 6.2e+38) (/ x (- 1.0 y)) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -6.8e+134) {
tmp = 1.0;
} else if (y <= -6.2e+59) {
tmp = x / -y;
} else if (y <= -0.017) {
tmp = 1.0;
} else if (y <= 6.2e+38) {
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 <= (-6.8d+134)) then
tmp = 1.0d0
else if (y <= (-6.2d+59)) then
tmp = x / -y
else if (y <= (-0.017d0)) then
tmp = 1.0d0
else if (y <= 6.2d+38) 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 <= -6.8e+134) {
tmp = 1.0;
} else if (y <= -6.2e+59) {
tmp = x / -y;
} else if (y <= -0.017) {
tmp = 1.0;
} else if (y <= 6.2e+38) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6.8e+134: tmp = 1.0 elif y <= -6.2e+59: tmp = x / -y elif y <= -0.017: tmp = 1.0 elif y <= 6.2e+38: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -6.8e+134) tmp = 1.0; elseif (y <= -6.2e+59) tmp = Float64(x / Float64(-y)); elseif (y <= -0.017) tmp = 1.0; elseif (y <= 6.2e+38) 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 <= -6.8e+134) tmp = 1.0; elseif (y <= -6.2e+59) tmp = x / -y; elseif (y <= -0.017) tmp = 1.0; elseif (y <= 6.2e+38) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6.8e+134], 1.0, If[LessEqual[y, -6.2e+59], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -0.017], 1.0, If[LessEqual[y, 6.2e+38], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.8 \cdot 10^{+134}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{+59}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -0.017:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+38}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.80000000000000035e134 or -6.20000000000000029e59 < y < -0.017000000000000001 or 6.20000000000000035e38 < y Initial program 100.0%
Taylor expanded in y around inf 76.6%
if -6.80000000000000035e134 < y < -6.20000000000000029e59Initial program 100.0%
Taylor expanded in x around inf 72.2%
Taylor expanded in y around inf 72.2%
associate-*r/72.2%
neg-mul-172.2%
Simplified72.2%
if -0.017000000000000001 < y < 6.20000000000000035e38Initial program 100.0%
Taylor expanded in x around inf 75.8%
Final simplification76.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -3.8e+24)
t_0
(if (<= y -3.6e-21)
(/ y (+ y -1.0))
(if (<= y 3.1e+14) (/ 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 <= -3.8e+24) {
tmp = t_0;
} else if (y <= -3.6e-21) {
tmp = y / (y + -1.0);
} else if (y <= 3.1e+14) {
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 <= (-3.8d+24)) then
tmp = t_0
else if (y <= (-3.6d-21)) then
tmp = y / (y + (-1.0d0))
else if (y <= 3.1d+14) 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 <= -3.8e+24) {
tmp = t_0;
} else if (y <= -3.6e-21) {
tmp = y / (y + -1.0);
} else if (y <= 3.1e+14) {
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 <= -3.8e+24: tmp = t_0 elif y <= -3.6e-21: tmp = y / (y + -1.0) elif y <= 3.1e+14: 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 <= -3.8e+24) tmp = t_0; elseif (y <= -3.6e-21) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 3.1e+14) 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 <= -3.8e+24) tmp = t_0; elseif (y <= -3.6e-21) tmp = y / (y + -1.0); elseif (y <= 3.1e+14) 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, -3.8e+24], t$95$0, If[LessEqual[y, -3.6e-21], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3.1e+14], 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 -3.8 \cdot 10^{+24}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -3.6 \cdot 10^{-21}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 3.1 \cdot 10^{+14}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -3.80000000000000015e24 or 3.1e14 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
sub-neg100.0%
div-sub100.0%
Simplified100.0%
if -3.80000000000000015e24 < y < -3.59999999999999989e-21Initial program 99.8%
Taylor expanded in x around 0 88.2%
neg-mul-188.2%
distribute-neg-frac288.2%
neg-sub088.2%
associate--r-88.2%
metadata-eval88.2%
Simplified88.2%
if -3.59999999999999989e-21 < y < 3.1e14Initial program 100.0%
Taylor expanded in x around inf 78.0%
Final simplification89.4%
(FPCore (x y)
:precision binary64
(if (<= y -6.5e+134)
1.0
(if (<= y -1.2e+61)
(/ x (- y))
(if (<= y -0.017) 1.0 (if (<= y 1.0) x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -6.5e+134) {
tmp = 1.0;
} else if (y <= -1.2e+61) {
tmp = x / -y;
} else if (y <= -0.017) {
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+134)) then
tmp = 1.0d0
else if (y <= (-1.2d+61)) then
tmp = x / -y
else if (y <= (-0.017d0)) 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+134) {
tmp = 1.0;
} else if (y <= -1.2e+61) {
tmp = x / -y;
} else if (y <= -0.017) {
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+134: tmp = 1.0 elif y <= -1.2e+61: tmp = x / -y elif y <= -0.017: 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+134) tmp = 1.0; elseif (y <= -1.2e+61) tmp = Float64(x / Float64(-y)); elseif (y <= -0.017) 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+134) tmp = 1.0; elseif (y <= -1.2e+61) tmp = x / -y; elseif (y <= -0.017) 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+134], 1.0, If[LessEqual[y, -1.2e+61], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -0.017], 1.0, If[LessEqual[y, 1.0], x, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.5 \cdot 10^{+134}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.2 \cdot 10^{+61}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -0.017:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -6.5e134 or -1.1999999999999999e61 < y < -0.017000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 74.4%
if -6.5e134 < y < -1.1999999999999999e61Initial program 100.0%
Taylor expanded in x around inf 72.2%
Taylor expanded in y around inf 72.2%
associate-*r/72.2%
neg-mul-172.2%
Simplified72.2%
if -0.017000000000000001 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.8%
Final simplification74.5%
(FPCore (x y) :precision binary64 (if (or (<= x -1.02e+140) (not (<= x 1.28e+70))) (/ x (- 1.0 y)) (/ y (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -1.02e+140) || !(x <= 1.28e+70)) {
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 <= (-1.02d+140)) .or. (.not. (x <= 1.28d+70))) 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 <= -1.02e+140) || !(x <= 1.28e+70)) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.02e+140) or not (x <= 1.28e+70): tmp = x / (1.0 - y) else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.02e+140) || !(x <= 1.28e+70)) 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 <= -1.02e+140) || ~((x <= 1.28e+70))) tmp = x / (1.0 - y); else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.02e+140], N[Not[LessEqual[x, 1.28e+70]], $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 -1.02 \cdot 10^{+140} \lor \neg \left(x \leq 1.28 \cdot 10^{+70}\right):\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if x < -1.02000000000000007e140 or 1.27999999999999994e70 < x Initial program 100.0%
Taylor expanded in x around inf 84.9%
if -1.02000000000000007e140 < x < 1.27999999999999994e70Initial program 100.0%
Taylor expanded in x around 0 74.3%
neg-mul-174.3%
distribute-neg-frac274.3%
neg-sub074.3%
associate--r-74.3%
metadata-eval74.3%
Simplified74.3%
Final simplification78.3%
(FPCore (x y) :precision binary64 (if (<= y -0.017) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.017) {
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 <= (-0.017d0)) 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 <= -0.017) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.017: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.017) 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 <= -0.017) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.017], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.017:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.017000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 71.2%
if -0.017000000000000001 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.8%
Final simplification72.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 39.9%
Final simplification39.9%
herbie shell --seed 2024083
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))