
(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 9 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 -2.4e+25)
1.0
(if (<= y -1.3e+22)
(/ x (- y))
(if (<= y -0.004) 1.0 (if (<= y 1.0) (+ x (* x y)) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.4e+25) {
tmp = 1.0;
} else if (y <= -1.3e+22) {
tmp = x / -y;
} else if (y <= -0.004) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x + (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 <= (-2.4d+25)) then
tmp = 1.0d0
else if (y <= (-1.3d+22)) then
tmp = x / -y
else if (y <= (-0.004d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x + (x * y)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.4e+25) {
tmp = 1.0;
} else if (y <= -1.3e+22) {
tmp = x / -y;
} else if (y <= -0.004) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x + (x * y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.4e+25: tmp = 1.0 elif y <= -1.3e+22: tmp = x / -y elif y <= -0.004: tmp = 1.0 elif y <= 1.0: tmp = x + (x * y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.4e+25) tmp = 1.0; elseif (y <= -1.3e+22) tmp = Float64(x / Float64(-y)); elseif (y <= -0.004) tmp = 1.0; elseif (y <= 1.0) tmp = Float64(x + Float64(x * y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.4e+25) tmp = 1.0; elseif (y <= -1.3e+22) tmp = x / -y; elseif (y <= -0.004) tmp = 1.0; elseif (y <= 1.0) tmp = x + (x * y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.4e+25], 1.0, If[LessEqual[y, -1.3e+22], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -0.004], 1.0, If[LessEqual[y, 1.0], N[(x + N[(x * y), $MachinePrecision]), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+25}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -0.004:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x + x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.39999999999999996e25 or -1.3e22 < y < -0.0040000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 72.1%
if -2.39999999999999996e25 < y < -1.3e22Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
if -0.0040000000000000001 < y < 1Initial program 100.0%
Taylor expanded in x around inf 76.1%
Taylor expanded in y around 0 74.3%
Final simplification73.8%
(FPCore (x y)
:precision binary64
(if (<= y -2.25e+36)
1.0
(if (<= y -1.25e+22)
(/ x (- y))
(if (<= y -85.0) 1.0 (if (<= y 1.0) x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.25e+36) {
tmp = 1.0;
} else if (y <= -1.25e+22) {
tmp = x / -y;
} else if (y <= -85.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 <= (-2.25d+36)) then
tmp = 1.0d0
else if (y <= (-1.25d+22)) then
tmp = x / -y
else if (y <= (-85.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 <= -2.25e+36) {
tmp = 1.0;
} else if (y <= -1.25e+22) {
tmp = x / -y;
} else if (y <= -85.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 <= -2.25e+36: tmp = 1.0 elif y <= -1.25e+22: tmp = x / -y elif y <= -85.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 <= -2.25e+36) tmp = 1.0; elseif (y <= -1.25e+22) tmp = Float64(x / Float64(-y)); elseif (y <= -85.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 <= -2.25e+36) tmp = 1.0; elseif (y <= -1.25e+22) tmp = x / -y; elseif (y <= -85.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, -2.25e+36], 1.0, If[LessEqual[y, -1.25e+22], N[(x / (-y)), $MachinePrecision], If[LessEqual[y, -85.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.25 \cdot 10^{+36}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{+22}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{elif}\;y \leq -85:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.24999999999999998e36 or -1.2499999999999999e22 < y < -85 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 73.2%
if -2.24999999999999998e36 < y < -1.2499999999999999e22Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 100.0%
neg-mul-1100.0%
distribute-neg-frac100.0%
Simplified100.0%
if -85 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.2%
Final simplification73.2%
(FPCore (x y) :precision binary64 (if (or (<= y -9000.0) (not (<= y 45.0))) (- 1.0 (/ (+ x -1.0) y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -9000.0) || !(y <= 45.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} 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 <= (-9000.0d0)) .or. (.not. (y <= 45.0d0))) then
tmp = 1.0d0 - ((x + (-1.0d0)) / y)
else
tmp = x / (1.0d0 - y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -9000.0) || !(y <= 45.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9000.0) or not (y <= 45.0): tmp = 1.0 - ((x + -1.0) / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -9000.0) || !(y <= 45.0)) tmp = Float64(1.0 - Float64(Float64(x + -1.0) / y)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -9000.0) || ~((y <= 45.0))) tmp = 1.0 - ((x + -1.0) / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9000.0], N[Not[LessEqual[y, 45.0]], $MachinePrecision]], N[(1.0 - N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9000 \lor \neg \left(y \leq 45\right):\\
\;\;\;\;1 - \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -9e3 or 45 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
+-commutative98.5%
mul-1-neg98.5%
sub-neg98.5%
div-sub98.5%
Simplified98.5%
if -9e3 < y < 45Initial program 100.0%
Taylor expanded in x around inf 75.9%
Final simplification86.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (- 1.0 (/ (+ x -1.0) y)) (+ x (* y (+ x -1.0)))))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} else {
tmp = x + (y * (x + -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.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - ((x + (-1.0d0)) / y)
else
tmp = x + (y * (x + (-1.0d0)))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 1.0)) {
tmp = 1.0 - ((x + -1.0) / y);
} else {
tmp = x + (y * (x + -1.0));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 1.0): tmp = 1.0 - ((x + -1.0) / y) else: tmp = x + (y * (x + -1.0)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(Float64(x + -1.0) / y)); else tmp = Float64(x + Float64(y * Float64(x + -1.0))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 1.0))) tmp = 1.0 - ((x + -1.0) / y); else tmp = x + (y * (x + -1.0)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(x + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(x + -1\right)\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 97.2%
+-commutative97.2%
mul-1-neg97.2%
sub-neg97.2%
div-sub97.2%
Simplified97.2%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 97.7%
mul-1-neg97.7%
unsub-neg97.7%
mul-1-neg97.7%
sub-neg97.7%
Simplified97.7%
Final simplification97.5%
(FPCore (x y) :precision binary64 (if (or (<= x -3.4e+36) (not (<= x 5.5e+23))) (/ x (- 1.0 y)) (/ y (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -3.4e+36) || !(x <= 5.5e+23)) {
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 <= (-3.4d+36)) .or. (.not. (x <= 5.5d+23))) 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 <= -3.4e+36) || !(x <= 5.5e+23)) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -3.4e+36) or not (x <= 5.5e+23): tmp = x / (1.0 - y) else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -3.4e+36) || !(x <= 5.5e+23)) 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 <= -3.4e+36) || ~((x <= 5.5e+23))) tmp = x / (1.0 - y); else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -3.4e+36], N[Not[LessEqual[x, 5.5e+23]], $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 -3.4 \cdot 10^{+36} \lor \neg \left(x \leq 5.5 \cdot 10^{+23}\right):\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if x < -3.3999999999999998e36 or 5.50000000000000004e23 < x Initial program 99.9%
Taylor expanded in x around inf 82.6%
if -3.3999999999999998e36 < x < 5.50000000000000004e23Initial program 100.0%
Taylor expanded in x around 0 70.2%
neg-mul-170.2%
distribute-neg-frac270.2%
neg-sub070.2%
associate--r-70.2%
metadata-eval70.2%
Simplified70.2%
Final simplification76.1%
(FPCore (x y) :precision binary64 (if (<= y -4.3e+33) 1.0 (if (<= y 2.25e+70) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.3e+33) {
tmp = 1.0;
} else if (y <= 2.25e+70) {
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.3d+33)) then
tmp = 1.0d0
else if (y <= 2.25d+70) 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.3e+33) {
tmp = 1.0;
} else if (y <= 2.25e+70) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.3e+33: tmp = 1.0 elif y <= 2.25e+70: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.3e+33) tmp = 1.0; elseif (y <= 2.25e+70) 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.3e+33) tmp = 1.0; elseif (y <= 2.25e+70) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.3e+33], 1.0, If[LessEqual[y, 2.25e+70], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.3 \cdot 10^{+33}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.25 \cdot 10^{+70}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.30000000000000028e33 or 2.25e70 < y Initial program 100.0%
Taylor expanded in y around inf 79.3%
if -4.30000000000000028e33 < y < 2.25e70Initial program 100.0%
Taylor expanded in x around inf 73.0%
Final simplification75.4%
(FPCore (x y) :precision binary64 (if (<= y -14.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -14.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 <= (-14.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 <= -14.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 <= -14.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 <= -14.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 <= -14.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, -14.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -14:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -14 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 70.3%
if -14 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.2%
Final simplification71.3%
(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 34.9%
Final simplification34.9%
herbie shell --seed 2024067
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))