
(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 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -3800000.0)
t_0
(if (<= y -5.6e-43)
(/ y (+ y -1.0))
(if (<= y 3200.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 <= -3800000.0) {
tmp = t_0;
} else if (y <= -5.6e-43) {
tmp = y / (y + -1.0);
} else if (y <= 3200.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 <= (-3800000.0d0)) then
tmp = t_0
else if (y <= (-5.6d-43)) then
tmp = y / (y + (-1.0d0))
else if (y <= 3200.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 <= -3800000.0) {
tmp = t_0;
} else if (y <= -5.6e-43) {
tmp = y / (y + -1.0);
} else if (y <= 3200.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 <= -3800000.0: tmp = t_0 elif y <= -5.6e-43: tmp = y / (y + -1.0) elif y <= 3200.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 <= -3800000.0) tmp = t_0; elseif (y <= -5.6e-43) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 3200.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 <= -3800000.0) tmp = t_0; elseif (y <= -5.6e-43) tmp = y / (y + -1.0); elseif (y <= 3200.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, -3800000.0], t$95$0, If[LessEqual[y, -5.6e-43], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3200.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 -3800000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -5.6 \cdot 10^{-43}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 3200:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -3.8e6 or 3200 < y Initial program 99.9%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
associate-+r+98.5%
mul-1-neg98.5%
unsub-neg98.5%
div-sub98.5%
unsub-neg98.5%
mul-1-neg98.5%
+-commutative98.5%
metadata-eval98.5%
distribute-lft-in98.5%
metadata-eval98.5%
sub-neg98.5%
associate-*r/98.5%
+-commutative98.5%
associate-*r/98.5%
sub-neg98.5%
metadata-eval98.5%
distribute-lft-in98.5%
metadata-eval98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
if -3.8e6 < y < -5.5999999999999996e-43Initial program 100.0%
Taylor expanded in x around 0 74.6%
metadata-eval74.6%
times-frac74.6%
*-lft-identity74.6%
neg-mul-174.6%
neg-sub074.6%
associate--r-74.6%
metadata-eval74.6%
Simplified74.6%
if -5.5999999999999996e-43 < y < 3200Initial program 100.0%
Taylor expanded in x around inf 80.0%
Final simplification88.3%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -10500000.0)
t_0
(if (<= y -3.5e-43)
(/ y (+ y -1.0))
(if (<= y 3000.0) (/ x (- 1.0 y)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -10500000.0) {
tmp = t_0;
} else if (y <= -3.5e-43) {
tmp = y / (y + -1.0);
} else if (y <= 3000.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 - (x / y)
if (y <= (-10500000.0d0)) then
tmp = t_0
else if (y <= (-3.5d-43)) then
tmp = y / (y + (-1.0d0))
else if (y <= 3000.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 - (x / y);
double tmp;
if (y <= -10500000.0) {
tmp = t_0;
} else if (y <= -3.5e-43) {
tmp = y / (y + -1.0);
} else if (y <= 3000.0) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if y <= -10500000.0: tmp = t_0 elif y <= -3.5e-43: tmp = y / (y + -1.0) elif y <= 3000.0: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -10500000.0) tmp = t_0; elseif (y <= -3.5e-43) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 3000.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 - (x / y); tmp = 0.0; if (y <= -10500000.0) tmp = t_0; elseif (y <= -3.5e-43) tmp = y / (y + -1.0); elseif (y <= 3000.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[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -10500000.0], t$95$0, If[LessEqual[y, -3.5e-43], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3000.0], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -10500000:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3.5 \cdot 10^{-43}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 3000:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t_0\\
\end{array}
\end{array}
if y < -1.05e7 or 3e3 < y Initial program 99.9%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
associate-+r+98.5%
mul-1-neg98.5%
unsub-neg98.5%
div-sub98.5%
unsub-neg98.5%
mul-1-neg98.5%
+-commutative98.5%
metadata-eval98.5%
distribute-lft-in98.5%
metadata-eval98.5%
sub-neg98.5%
associate-*r/98.5%
+-commutative98.5%
associate-*r/98.5%
sub-neg98.5%
metadata-eval98.5%
distribute-lft-in98.5%
metadata-eval98.5%
+-commutative98.5%
mul-1-neg98.5%
unsub-neg98.5%
Simplified98.5%
Taylor expanded in x around inf 97.6%
neg-mul-197.6%
distribute-neg-frac97.6%
Simplified97.6%
if -1.05e7 < y < -3.49999999999999997e-43Initial program 100.0%
Taylor expanded in x around 0 74.6%
metadata-eval74.6%
times-frac74.6%
*-lft-identity74.6%
neg-mul-174.6%
neg-sub074.6%
associate--r-74.6%
metadata-eval74.6%
Simplified74.6%
if -3.49999999999999997e-43 < y < 3e3Initial program 100.0%
Taylor expanded in x around inf 80.0%
Final simplification87.9%
(FPCore (x y) :precision binary64 (if (<= y -2.15e+50) 1.0 (if (<= y 6e+35) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.15e+50) {
tmp = 1.0;
} else if (y <= 6e+35) {
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 <= (-2.15d+50)) then
tmp = 1.0d0
else if (y <= 6d+35) 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 <= -2.15e+50) {
tmp = 1.0;
} else if (y <= 6e+35) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.15e+50: tmp = 1.0 elif y <= 6e+35: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.15e+50) tmp = 1.0; elseif (y <= 6e+35) 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 <= -2.15e+50) tmp = 1.0; elseif (y <= 6e+35) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.15e+50], 1.0, If[LessEqual[y, 6e+35], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{+50}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+35}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.1499999999999999e50 or 5.99999999999999981e35 < y Initial program 99.9%
Taylor expanded in y around inf 89.1%
if -2.1499999999999999e50 < y < 5.99999999999999981e35Initial program 100.0%
Taylor expanded in x around inf 74.5%
Final simplification80.2%
(FPCore (x y) :precision binary64 (if (<= y -2.5e-43) (/ y (+ y -1.0)) (if (<= y 6.6e+35) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.5e-43) {
tmp = y / (y + -1.0);
} else if (y <= 6.6e+35) {
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 <= (-2.5d-43)) then
tmp = y / (y + (-1.0d0))
else if (y <= 6.6d+35) 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 <= -2.5e-43) {
tmp = y / (y + -1.0);
} else if (y <= 6.6e+35) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e-43: tmp = y / (y + -1.0) elif y <= 6.6e+35: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e-43) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 6.6e+35) 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 <= -2.5e-43) tmp = y / (y + -1.0); elseif (y <= 6.6e+35) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e-43], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6.6e+35], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-43}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 6.6 \cdot 10^{+35}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.50000000000000009e-43Initial program 100.0%
Taylor expanded in x around 0 82.7%
metadata-eval82.7%
times-frac82.7%
*-lft-identity82.7%
neg-mul-182.7%
neg-sub082.7%
associate--r-82.7%
metadata-eval82.7%
Simplified82.7%
if -2.50000000000000009e-43 < y < 6.6000000000000003e35Initial program 100.0%
Taylor expanded in x around inf 78.2%
if 6.6000000000000003e35 < y Initial program 99.8%
Taylor expanded in y around inf 87.8%
Final simplification81.3%
(FPCore (x y) :precision binary64 (if (<= y -5.8e-26) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -5.8e-26) {
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.8d-26)) 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.8e-26) {
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.8e-26: 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.8e-26) 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.8e-26) 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.8e-26], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.8 \cdot 10^{-26}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.7999999999999996e-26 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 78.8%
if -5.7999999999999996e-26 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.6%
Final simplification77.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 39.3%
Final simplification39.3%
herbie shell --seed 2023274
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))