
(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 -1.38e+32)
1.0
(if (or (<= y 82.0) (and (not (<= y 1.5e+67)) (<= y 3e+109)))
(/ x (- 1.0 y))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.38e+32) {
tmp = 1.0;
} else if ((y <= 82.0) || (!(y <= 1.5e+67) && (y <= 3e+109))) {
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 <= (-1.38d+32)) then
tmp = 1.0d0
else if ((y <= 82.0d0) .or. (.not. (y <= 1.5d+67)) .and. (y <= 3d+109)) 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 <= -1.38e+32) {
tmp = 1.0;
} else if ((y <= 82.0) || (!(y <= 1.5e+67) && (y <= 3e+109))) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.38e+32: tmp = 1.0 elif (y <= 82.0) or (not (y <= 1.5e+67) and (y <= 3e+109)): tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.38e+32) tmp = 1.0; elseif ((y <= 82.0) || (!(y <= 1.5e+67) && (y <= 3e+109))) 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 <= -1.38e+32) tmp = 1.0; elseif ((y <= 82.0) || (~((y <= 1.5e+67)) && (y <= 3e+109))) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.38e+32], 1.0, If[Or[LessEqual[y, 82.0], And[N[Not[LessEqual[y, 1.5e+67]], $MachinePrecision], LessEqual[y, 3e+109]]], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.38 \cdot 10^{+32}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 82 \lor \neg \left(y \leq 1.5 \cdot 10^{+67}\right) \land y \leq 3 \cdot 10^{+109}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.38e32 or 82 < y < 1.50000000000000005e67 or 3.00000000000000015e109 < y Initial program 100.0%
Taylor expanded in y around inf 83.2%
if -1.38e32 < y < 82 or 1.50000000000000005e67 < y < 3.00000000000000015e109Initial program 100.0%
Taylor expanded in x around inf 76.2%
Final simplification79.4%
(FPCore (x y)
:precision binary64
(if (<= y -2.8e+32)
1.0
(if (or (<= y 4.3e-60) (and (not (<= y 6.8e+67)) (<= y 6e+110)))
(/ x (- 1.0 y))
(/ y (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.8e+32) {
tmp = 1.0;
} else if ((y <= 4.3e-60) || (!(y <= 6.8e+67) && (y <= 6e+110))) {
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 (y <= (-2.8d+32)) then
tmp = 1.0d0
else if ((y <= 4.3d-60) .or. (.not. (y <= 6.8d+67)) .and. (y <= 6d+110)) 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 (y <= -2.8e+32) {
tmp = 1.0;
} else if ((y <= 4.3e-60) || (!(y <= 6.8e+67) && (y <= 6e+110))) {
tmp = x / (1.0 - y);
} else {
tmp = y / (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.8e+32: tmp = 1.0 elif (y <= 4.3e-60) or (not (y <= 6.8e+67) and (y <= 6e+110)): tmp = x / (1.0 - y) else: tmp = y / (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -2.8e+32) tmp = 1.0; elseif ((y <= 4.3e-60) || (!(y <= 6.8e+67) && (y <= 6e+110))) 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 (y <= -2.8e+32) tmp = 1.0; elseif ((y <= 4.3e-60) || (~((y <= 6.8e+67)) && (y <= 6e+110))) tmp = x / (1.0 - y); else tmp = y / (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.8e+32], 1.0, If[Or[LessEqual[y, 4.3e-60], And[N[Not[LessEqual[y, 6.8e+67]], $MachinePrecision], LessEqual[y, 6e+110]]], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.8 \cdot 10^{+32}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-60} \lor \neg \left(y \leq 6.8 \cdot 10^{+67}\right) \land y \leq 6 \cdot 10^{+110}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + -1}\\
\end{array}
\end{array}
if y < -2.8e32Initial program 100.0%
Taylor expanded in y around inf 82.2%
if -2.8e32 < y < 4.3000000000000001e-60 or 6.8000000000000003e67 < y < 6.00000000000000014e110Initial program 100.0%
Taylor expanded in x around inf 79.8%
if 4.3000000000000001e-60 < y < 6.8000000000000003e67 or 6.00000000000000014e110 < y Initial program 100.0%
Taylor expanded in x around 0 81.9%
metadata-eval81.9%
times-frac81.9%
*-lft-identity81.9%
neg-mul-181.9%
neg-sub081.9%
associate--r-81.9%
metadata-eval81.9%
Simplified81.9%
Final simplification81.0%
(FPCore (x y)
:precision binary64
(if (<= y -550.0)
1.0
(if (<= y 1.0)
x
(if (<= y 8.5e+67) 1.0 (if (<= y 2.95e+109) (/ (- x) y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -550.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 8.5e+67) {
tmp = 1.0;
} else if (y <= 2.95e+109) {
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 <= (-550.0d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x
else if (y <= 8.5d+67) then
tmp = 1.0d0
else if (y <= 2.95d+109) 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 <= -550.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 8.5e+67) {
tmp = 1.0;
} else if (y <= 2.95e+109) {
tmp = -x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -550.0: tmp = 1.0 elif y <= 1.0: tmp = x elif y <= 8.5e+67: tmp = 1.0 elif y <= 2.95e+109: tmp = -x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -550.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; elseif (y <= 8.5e+67) tmp = 1.0; elseif (y <= 2.95e+109) tmp = Float64(Float64(-x) / y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -550.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; elseif (y <= 8.5e+67) tmp = 1.0; elseif (y <= 2.95e+109) tmp = -x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -550.0], 1.0, If[LessEqual[y, 1.0], x, If[LessEqual[y, 8.5e+67], 1.0, If[LessEqual[y, 2.95e+109], N[((-x) / y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -550:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+67}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.95 \cdot 10^{+109}:\\
\;\;\;\;\frac{-x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -550 or 1 < y < 8.50000000000000038e67 or 2.9499999999999999e109 < y Initial program 100.0%
Taylor expanded in y around inf 81.0%
if -550 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.2%
if 8.50000000000000038e67 < y < 2.9499999999999999e109Initial program 100.0%
Taylor expanded in x around inf 80.7%
Taylor expanded in y around inf 80.7%
neg-mul-180.7%
distribute-neg-frac80.7%
Simplified80.7%
Final simplification77.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1850.0) (not (<= y 82.0))) (+ 1.0 (/ (- 1.0 x) y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -1850.0) || !(y <= 82.0)) {
tmp = 1.0 + ((1.0 - x) / 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 <= (-1850.0d0)) .or. (.not. (y <= 82.0d0))) then
tmp = 1.0d0 + ((1.0d0 - x) / 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 <= -1850.0) || !(y <= 82.0)) {
tmp = 1.0 + ((1.0 - x) / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1850.0) or not (y <= 82.0): tmp = 1.0 + ((1.0 - x) / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -1850.0) || !(y <= 82.0)) tmp = Float64(1.0 + Float64(Float64(1.0 - x) / y)); else tmp = Float64(x / Float64(1.0 - y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1850.0) || ~((y <= 82.0))) tmp = 1.0 + ((1.0 - x) / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1850.0], N[Not[LessEqual[y, 82.0]], $MachinePrecision]], N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1850 \lor \neg \left(y \leq 82\right):\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -1850 or 82 < y Initial program 100.0%
Taylor expanded in y around inf 98.9%
+-commutative98.9%
mul-1-neg98.9%
unsub-neg98.9%
div-sub98.9%
Simplified98.9%
if -1850 < y < 82Initial program 100.0%
Taylor expanded in x around inf 76.6%
Final simplification88.0%
(FPCore (x y) :precision binary64 (if (<= y -920.0) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -920.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 <= (-920.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 <= -920.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 <= -920.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 <= -920.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 <= -920.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, -920.0], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -920:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -920 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 76.6%
if -920 < y < 1Initial program 100.0%
Taylor expanded in y around 0 74.2%
Final simplification75.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.3%
Final simplification41.3%
herbie shell --seed 2024027
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))