
(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
(if (<= y -1.7e+59)
1.0
(if (<= y -4e+26)
(/ (- x) y)
(if (<= y -3.0)
1.0
(if (<= y -3.8e-63)
(* y (- -1.0 y))
(if (<= y 1.0) (* x (+ y 1.0)) 1.0))))))
double code(double x, double y) {
double tmp;
if (y <= -1.7e+59) {
tmp = 1.0;
} else if (y <= -4e+26) {
tmp = -x / y;
} else if (y <= -3.0) {
tmp = 1.0;
} else if (y <= -3.8e-63) {
tmp = y * (-1.0 - y);
} else if (y <= 1.0) {
tmp = x * (y + 1.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) :: tmp
if (y <= (-1.7d+59)) then
tmp = 1.0d0
else if (y <= (-4d+26)) then
tmp = -x / y
else if (y <= (-3.0d0)) then
tmp = 1.0d0
else if (y <= (-3.8d-63)) then
tmp = y * ((-1.0d0) - y)
else if (y <= 1.0d0) then
tmp = x * (y + 1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.7e+59) {
tmp = 1.0;
} else if (y <= -4e+26) {
tmp = -x / y;
} else if (y <= -3.0) {
tmp = 1.0;
} else if (y <= -3.8e-63) {
tmp = y * (-1.0 - y);
} else if (y <= 1.0) {
tmp = x * (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.7e+59: tmp = 1.0 elif y <= -4e+26: tmp = -x / y elif y <= -3.0: tmp = 1.0 elif y <= -3.8e-63: tmp = y * (-1.0 - y) elif y <= 1.0: tmp = x * (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.7e+59) tmp = 1.0; elseif (y <= -4e+26) tmp = Float64(Float64(-x) / y); elseif (y <= -3.0) tmp = 1.0; elseif (y <= -3.8e-63) tmp = Float64(y * Float64(-1.0 - y)); elseif (y <= 1.0) tmp = Float64(x * Float64(y + 1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.7e+59) tmp = 1.0; elseif (y <= -4e+26) tmp = -x / y; elseif (y <= -3.0) tmp = 1.0; elseif (y <= -3.8e-63) tmp = y * (-1.0 - y); elseif (y <= 1.0) tmp = x * (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.7e+59], 1.0, If[LessEqual[y, -4e+26], N[((-x) / y), $MachinePrecision], If[LessEqual[y, -3.0], 1.0, If[LessEqual[y, -3.8e-63], N[(y * N[(-1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(x * N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+59}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -4 \cdot 10^{+26}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq -3:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -3.8 \cdot 10^{-63}:\\
\;\;\;\;y \cdot \left(-1 - y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x \cdot \left(y + 1\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.70000000000000003e59 or -4.00000000000000019e26 < y < -3 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 78.6%
if -1.70000000000000003e59 < y < -4.00000000000000019e26Initial program 100.0%
Taylor expanded in x around inf 78.5%
Taylor expanded in y around inf 78.5%
associate-*r/78.5%
neg-mul-178.5%
Simplified78.5%
if -3 < y < -3.80000000000000017e-63Initial program 99.9%
Taylor expanded in x around 0 59.3%
neg-mul-159.3%
distribute-neg-frac259.3%
neg-sub059.3%
associate--r-59.3%
metadata-eval59.3%
Simplified59.3%
Taylor expanded in y around 0 59.6%
sub-neg59.6%
metadata-eval59.6%
neg-mul-159.6%
+-commutative59.6%
sub-neg59.6%
Simplified59.6%
if -3.80000000000000017e-63 < y < 1Initial program 100.0%
Taylor expanded in x around inf 71.1%
Taylor expanded in y around 0 71.1%
*-commutative71.1%
distribute-rgt1-in71.1%
Applied egg-rr71.1%
Final simplification74.5%
(FPCore (x y)
:precision binary64
(if (<= y -4.8e+58)
1.0
(if (<= y -3.4e+27)
(/ (- x) y)
(if (or (<= y -3.9e-63) (not (<= y 5e-79)))
(/ y (+ y -1.0))
(/ x (- 1.0 y))))))
double code(double x, double y) {
double tmp;
if (y <= -4.8e+58) {
tmp = 1.0;
} else if (y <= -3.4e+27) {
tmp = -x / y;
} else if ((y <= -3.9e-63) || !(y <= 5e-79)) {
tmp = y / (y + -1.0);
} 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 <= (-4.8d+58)) then
tmp = 1.0d0
else if (y <= (-3.4d+27)) then
tmp = -x / y
else if ((y <= (-3.9d-63)) .or. (.not. (y <= 5d-79))) then
tmp = y / (y + (-1.0d0))
else
tmp = x / (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.8e+58) {
tmp = 1.0;
} else if (y <= -3.4e+27) {
tmp = -x / y;
} else if ((y <= -3.9e-63) || !(y <= 5e-79)) {
tmp = y / (y + -1.0);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.8e+58: tmp = 1.0 elif y <= -3.4e+27: tmp = -x / y elif (y <= -3.9e-63) or not (y <= 5e-79): tmp = y / (y + -1.0) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if (y <= -4.8e+58) tmp = 1.0; elseif (y <= -3.4e+27) tmp = Float64(Float64(-x) / y); elseif ((y <= -3.9e-63) || !(y <= 5e-79)) tmp = Float64(y / Float64(y + -1.0)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.8e+58) tmp = 1.0; elseif (y <= -3.4e+27) tmp = -x / y; elseif ((y <= -3.9e-63) || ~((y <= 5e-79))) tmp = y / (y + -1.0); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.8e+58], 1.0, If[LessEqual[y, -3.4e+27], N[((-x) / y), $MachinePrecision], If[Or[LessEqual[y, -3.9e-63], N[Not[LessEqual[y, 5e-79]], $MachinePrecision]], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.8 \cdot 10^{+58}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -3.4 \cdot 10^{+27}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{-63} \lor \neg \left(y \leq 5 \cdot 10^{-79}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -4.8e58Initial program 100.0%
Taylor expanded in y around inf 79.6%
if -4.8e58 < y < -3.4e27Initial program 100.0%
Taylor expanded in x around inf 78.5%
Taylor expanded in y around inf 78.5%
associate-*r/78.5%
neg-mul-178.5%
Simplified78.5%
if -3.4e27 < y < -3.90000000000000022e-63 or 4.99999999999999999e-79 < y Initial program 100.0%
Taylor expanded in x around 0 73.4%
neg-mul-173.4%
distribute-neg-frac273.4%
neg-sub073.4%
associate--r-73.4%
metadata-eval73.4%
Simplified73.4%
if -3.90000000000000022e-63 < y < 4.99999999999999999e-79Initial program 100.0%
Taylor expanded in x around inf 75.0%
Final simplification75.5%
(FPCore (x y)
:precision binary64
(if (<= y -1.45e+58)
1.0
(if (<= y -7.5e+26)
(/ (- x) y)
(if (<= y -14.5) 1.0 (if (<= y 1.0) x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.45e+58) {
tmp = 1.0;
} else if (y <= -7.5e+26) {
tmp = -x / y;
} else if (y <= -14.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 <= (-1.45d+58)) then
tmp = 1.0d0
else if (y <= (-7.5d+26)) then
tmp = -x / y
else if (y <= (-14.5d0)) 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 <= -1.45e+58) {
tmp = 1.0;
} else if (y <= -7.5e+26) {
tmp = -x / y;
} else if (y <= -14.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 <= -1.45e+58: tmp = 1.0 elif y <= -7.5e+26: tmp = -x / y elif y <= -14.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 <= -1.45e+58) tmp = 1.0; elseif (y <= -7.5e+26) tmp = Float64(Float64(-x) / y); elseif (y <= -14.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 <= -1.45e+58) tmp = 1.0; elseif (y <= -7.5e+26) tmp = -x / y; elseif (y <= -14.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, -1.45e+58], 1.0, If[LessEqual[y, -7.5e+26], N[((-x) / y), $MachinePrecision], If[LessEqual[y, -14.5], 1.0, If[LessEqual[y, 1.0], x, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{+58}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -7.5 \cdot 10^{+26}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{elif}\;y \leq -14.5:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.45000000000000001e58 or -7.49999999999999941e26 < y < -14.5 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 78.6%
if -1.45000000000000001e58 < y < -7.49999999999999941e26Initial program 100.0%
Taylor expanded in x around inf 78.5%
Taylor expanded in y around inf 78.5%
associate-*r/78.5%
neg-mul-178.5%
Simplified78.5%
if -14.5 < y < 1Initial program 100.0%
Taylor expanded in y around 0 67.2%
Final simplification73.2%
(FPCore (x y) :precision binary64 (if (<= y -18.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -18.0) {
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 <= (-18.0d0)) 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 <= -18.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -18.0: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -18.0) 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 <= -18.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -18.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -18:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -18 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 75.1%
if -18 < y < 1Initial program 100.0%
Taylor expanded in y around 0 67.2%
Final simplification71.4%
(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 41.9%
Final simplification41.9%
herbie shell --seed 2024050
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))