
(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 8 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 -3.95e-7)
1.0
(if (<= y -9.8e-27)
(- y)
(if (<= y 1.0) x (if (<= y 7.8e+127) (/ (- x) y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -9.8e-27) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 7.8e+127) {
tmp = -x / 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 <= (-3.95d-7)) then
tmp = 1.0d0
else if (y <= (-9.8d-27)) then
tmp = -y
else if (y <= 1.0d0) then
tmp = x
else if (y <= 7.8d+127) then
tmp = -x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -9.8e-27) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 7.8e+127) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.95e-7: tmp = 1.0 elif y <= -9.8e-27: tmp = -y elif y <= 1.0: tmp = x elif y <= 7.8e+127: tmp = -x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.95e-7) tmp = 1.0; elseif (y <= -9.8e-27) tmp = Float64(-y); elseif (y <= 1.0) tmp = x; elseif (y <= 7.8e+127) tmp = Float64(Float64(-x) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.95e-7) tmp = 1.0; elseif (y <= -9.8e-27) tmp = -y; elseif (y <= 1.0) tmp = x; elseif (y <= 7.8e+127) tmp = -x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.95e-7], 1.0, If[LessEqual[y, -9.8e-27], (-y), If[LessEqual[y, 1.0], x, If[LessEqual[y, 7.8e+127], N[((-x) / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.95 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -9.8 \cdot 10^{-27}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.94999999999999977e-7 or 7.79999999999999962e127 < y Initial program 100.0%
Taylor expanded in y around inf 79.4%
if -3.94999999999999977e-7 < y < -9.79999999999999952e-27Initial program 100.0%
Taylor expanded in x around 0 91.0%
metadata-eval91.0%
times-frac91.0%
*-lft-identity91.0%
neg-mul-191.0%
neg-sub091.0%
associate--r-91.0%
metadata-eval91.0%
Simplified91.0%
Taylor expanded in y around 0 84.4%
neg-mul-184.4%
Simplified84.4%
if -9.79999999999999952e-27 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.4%
if 1 < y < 7.79999999999999962e127Initial program 100.0%
Taylor expanded in x around inf 61.4%
Taylor expanded in y around inf 60.4%
associate-*r/60.4%
neg-mul-160.4%
Simplified60.4%
Final simplification76.2%
(FPCore (x y)
:precision binary64
(if (<= y -3.95e-7)
1.0
(if (<= y -4.8e-24)
(* y (- -1.0 y))
(if (<= y 1.0) x (if (<= y 7.8e+127) (/ (- x) y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -4.8e-24) {
tmp = y * (-1.0 - y);
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 7.8e+127) {
tmp = -x / 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 <= (-3.95d-7)) then
tmp = 1.0d0
else if (y <= (-4.8d-24)) then
tmp = y * ((-1.0d0) - y)
else if (y <= 1.0d0) then
tmp = x
else if (y <= 7.8d+127) then
tmp = -x / y
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -4.8e-24) {
tmp = y * (-1.0 - y);
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 7.8e+127) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.95e-7: tmp = 1.0 elif y <= -4.8e-24: tmp = y * (-1.0 - y) elif y <= 1.0: tmp = x elif y <= 7.8e+127: tmp = -x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.95e-7) tmp = 1.0; elseif (y <= -4.8e-24) tmp = Float64(y * Float64(-1.0 - y)); elseif (y <= 1.0) tmp = x; elseif (y <= 7.8e+127) tmp = Float64(Float64(-x) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3.95e-7) tmp = 1.0; elseif (y <= -4.8e-24) tmp = y * (-1.0 - y); elseif (y <= 1.0) tmp = x; elseif (y <= 7.8e+127) tmp = -x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.95e-7], 1.0, If[LessEqual[y, -4.8e-24], N[(y * N[(-1.0 - y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], x, If[LessEqual[y, 7.8e+127], N[((-x) / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.95 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -4.8 \cdot 10^{-24}:\\
\;\;\;\;y \cdot \left(-1 - y\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.94999999999999977e-7 or 7.79999999999999962e127 < y Initial program 100.0%
Taylor expanded in y around inf 79.4%
if -3.94999999999999977e-7 < y < -4.7999999999999996e-24Initial program 100.0%
Taylor expanded in x around 0 91.0%
metadata-eval91.0%
times-frac91.0%
*-lft-identity91.0%
neg-mul-191.0%
neg-sub091.0%
associate--r-91.0%
metadata-eval91.0%
Simplified91.0%
Taylor expanded in y around 0 91.0%
mul-1-neg91.0%
unpow291.0%
distribute-lft-neg-in91.0%
distribute-rgt-in91.0%
sub-neg91.0%
Simplified91.0%
if -4.7999999999999996e-24 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.4%
if 1 < y < 7.79999999999999962e127Initial program 100.0%
Taylor expanded in x around inf 61.4%
Taylor expanded in y around inf 60.4%
associate-*r/60.4%
neg-mul-160.4%
Simplified60.4%
Final simplification76.4%
(FPCore (x y) :precision binary64 (if (<= y -7000000000.0) 1.0 (if (<= y 7.8e+127) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -7000000000.0) {
tmp = 1.0;
} else if (y <= 7.8e+127) {
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 <= (-7000000000.0d0)) then
tmp = 1.0d0
else if (y <= 7.8d+127) 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 <= -7000000000.0) {
tmp = 1.0;
} else if (y <= 7.8e+127) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7000000000.0: tmp = 1.0 elif y <= 7.8e+127: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -7000000000.0) tmp = 1.0; elseif (y <= 7.8e+127) 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 <= -7000000000.0) tmp = 1.0; elseif (y <= 7.8e+127) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7000000000.0], 1.0, If[LessEqual[y, 7.8e+127], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7000000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -7e9 or 7.79999999999999962e127 < y Initial program 100.0%
Taylor expanded in y around inf 80.8%
if -7e9 < y < 7.79999999999999962e127Initial program 100.0%
Taylor expanded in x around inf 72.1%
Final simplification75.6%
(FPCore (x y) :precision binary64 (if (<= y -4.6e-25) (/ y (+ y -1.0)) (if (<= y 7.8e+127) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.6e-25) {
tmp = y / (y + -1.0);
} else if (y <= 7.8e+127) {
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 <= (-4.6d-25)) then
tmp = y / (y + (-1.0d0))
else if (y <= 7.8d+127) 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 <= -4.6e-25) {
tmp = y / (y + -1.0);
} else if (y <= 7.8e+127) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.6e-25: tmp = y / (y + -1.0) elif y <= 7.8e+127: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.6e-25) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 7.8e+127) 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 <= -4.6e-25) tmp = y / (y + -1.0); elseif (y <= 7.8e+127) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.6e-25], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.8e+127], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.6 \cdot 10^{-25}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{+127}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.5999999999999998e-25Initial program 100.0%
Taylor expanded in x around 0 78.9%
metadata-eval78.9%
times-frac78.9%
*-lft-identity78.9%
neg-mul-178.9%
neg-sub078.9%
associate--r-78.9%
metadata-eval78.9%
Simplified78.9%
if -4.5999999999999998e-25 < y < 7.79999999999999962e127Initial program 100.0%
Taylor expanded in x around inf 74.6%
if 7.79999999999999962e127 < y Initial program 100.0%
Taylor expanded in y around inf 82.9%
Final simplification77.1%
(FPCore (x y) :precision binary64 (if (<= y -3.95e-7) 1.0 (if (<= y -2.55e-24) (- y) (if (<= y 1.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -2.55e-24) {
tmp = -y;
} 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 <= (-3.95d-7)) then
tmp = 1.0d0
else if (y <= (-2.55d-24)) then
tmp = -y
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 <= -3.95e-7) {
tmp = 1.0;
} else if (y <= -2.55e-24) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.95e-7: tmp = 1.0 elif y <= -2.55e-24: tmp = -y elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.95e-7) tmp = 1.0; elseif (y <= -2.55e-24) tmp = Float64(-y); 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 <= -3.95e-7) tmp = 1.0; elseif (y <= -2.55e-24) tmp = -y; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.95e-7], 1.0, If[LessEqual[y, -2.55e-24], (-y), If[LessEqual[y, 1.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.95 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.55 \cdot 10^{-24}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.94999999999999977e-7 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 69.3%
if -3.94999999999999977e-7 < y < -2.55000000000000013e-24Initial program 100.0%
Taylor expanded in x around 0 91.0%
metadata-eval91.0%
times-frac91.0%
*-lft-identity91.0%
neg-mul-191.0%
neg-sub091.0%
associate--r-91.0%
metadata-eval91.0%
Simplified91.0%
Taylor expanded in y around 0 84.4%
neg-mul-184.4%
Simplified84.4%
if -2.55000000000000013e-24 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.4%
Final simplification73.3%
(FPCore (x y) :precision binary64 (if (<= y -29.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -29.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 <= (-29.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 <= -29.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 <= -29.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 <= -29.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 <= -29.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, -29.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -29:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -29 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 70.3%
if -29 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.2%
Final simplification71.7%
(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 38.4%
Final simplification38.4%
herbie shell --seed 2023293
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))