
(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 (/ x (- 1.0 y))))
(if (<= y -0.0033)
(- 1.0 (/ x y))
(if (<= y 1.1e-111)
t_0
(if (<= y 0.31)
(/ y (+ y -1.0))
(if (<= y 290.0) t_0 (+ 1.0 (/ (- 1.0 x) y))))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (y <= -0.0033) {
tmp = 1.0 - (x / y);
} else if (y <= 1.1e-111) {
tmp = t_0;
} else if (y <= 0.31) {
tmp = y / (y + -1.0);
} else if (y <= 290.0) {
tmp = t_0;
} else {
tmp = 1.0 + ((1.0 - x) / y);
}
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 = x / (1.0d0 - y)
if (y <= (-0.0033d0)) then
tmp = 1.0d0 - (x / y)
else if (y <= 1.1d-111) then
tmp = t_0
else if (y <= 0.31d0) then
tmp = y / (y + (-1.0d0))
else if (y <= 290.0d0) then
tmp = t_0
else
tmp = 1.0d0 + ((1.0d0 - x) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (y <= -0.0033) {
tmp = 1.0 - (x / y);
} else if (y <= 1.1e-111) {
tmp = t_0;
} else if (y <= 0.31) {
tmp = y / (y + -1.0);
} else if (y <= 290.0) {
tmp = t_0;
} else {
tmp = 1.0 + ((1.0 - x) / y);
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) tmp = 0 if y <= -0.0033: tmp = 1.0 - (x / y) elif y <= 1.1e-111: tmp = t_0 elif y <= 0.31: tmp = y / (y + -1.0) elif y <= 290.0: tmp = t_0 else: tmp = 1.0 + ((1.0 - x) / y) return tmp
function code(x, y) t_0 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (y <= -0.0033) tmp = Float64(1.0 - Float64(x / y)); elseif (y <= 1.1e-111) tmp = t_0; elseif (y <= 0.31) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 290.0) tmp = t_0; else tmp = Float64(1.0 + Float64(Float64(1.0 - x) / y)); end return tmp end
function tmp_2 = code(x, y) t_0 = x / (1.0 - y); tmp = 0.0; if (y <= -0.0033) tmp = 1.0 - (x / y); elseif (y <= 1.1e-111) tmp = t_0; elseif (y <= 0.31) tmp = y / (y + -1.0); elseif (y <= 290.0) tmp = t_0; else tmp = 1.0 + ((1.0 - x) / y); end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0033], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.1e-111], t$95$0, If[LessEqual[y, 0.31], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 290.0], t$95$0, N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
\mathbf{if}\;y \leq -0.0033:\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-111}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.31:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 290:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{1 - x}{y}\\
\end{array}
\end{array}
if y < -0.0033Initial program 100.0%
div-sub100.0%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Taylor expanded in y around -inf 97.0%
mul-1-neg97.0%
unsub-neg97.0%
sub-neg97.0%
metadata-eval97.0%
+-commutative97.0%
Simplified97.0%
Taylor expanded in x around inf 97.2%
if -0.0033 < y < 1.1e-111 or 0.309999999999999998 < y < 290Initial program 100.0%
Taylor expanded in x around inf 79.5%
if 1.1e-111 < y < 0.309999999999999998Initial program 99.9%
Taylor expanded in x around 0 57.3%
metadata-eval57.3%
times-frac57.3%
*-lft-identity57.3%
neg-mul-157.3%
neg-sub057.3%
associate--r-57.3%
metadata-eval57.3%
Simplified57.3%
if 290 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
mul-1-neg100.0%
unsub-neg100.0%
div-sub100.0%
Simplified100.0%
Final simplification86.7%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))) (t_1 (/ x (- 1.0 y))))
(if (<= y -0.0033)
t_0
(if (<= y 5.2e-112)
t_1
(if (<= y 0.92) (/ y (+ y -1.0)) (if (<= y 3350000.0) t_1 t_0))))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double t_1 = x / (1.0 - y);
double tmp;
if (y <= -0.0033) {
tmp = t_0;
} else if (y <= 5.2e-112) {
tmp = t_1;
} else if (y <= 0.92) {
tmp = y / (y + -1.0);
} else if (y <= 3350000.0) {
tmp = t_1;
} 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) :: t_1
real(8) :: tmp
t_0 = 1.0d0 - (x / y)
t_1 = x / (1.0d0 - y)
if (y <= (-0.0033d0)) then
tmp = t_0
else if (y <= 5.2d-112) then
tmp = t_1
else if (y <= 0.92d0) then
tmp = y / (y + (-1.0d0))
else if (y <= 3350000.0d0) then
tmp = t_1
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 t_1 = x / (1.0 - y);
double tmp;
if (y <= -0.0033) {
tmp = t_0;
} else if (y <= 5.2e-112) {
tmp = t_1;
} else if (y <= 0.92) {
tmp = y / (y + -1.0);
} else if (y <= 3350000.0) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) t_1 = x / (1.0 - y) tmp = 0 if y <= -0.0033: tmp = t_0 elif y <= 5.2e-112: tmp = t_1 elif y <= 0.92: tmp = y / (y + -1.0) elif y <= 3350000.0: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) t_1 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (y <= -0.0033) tmp = t_0; elseif (y <= 5.2e-112) tmp = t_1; elseif (y <= 0.92) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 3350000.0) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); t_1 = x / (1.0 - y); tmp = 0.0; if (y <= -0.0033) tmp = t_0; elseif (y <= 5.2e-112) tmp = t_1; elseif (y <= 0.92) tmp = y / (y + -1.0); elseif (y <= 3350000.0) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.0033], t$95$0, If[LessEqual[y, 5.2e-112], t$95$1, If[LessEqual[y, 0.92], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 3350000.0], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
t_1 := \frac{x}{1 - y}\\
\mathbf{if}\;y \leq -0.0033:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{-112}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 0.92:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 3350000:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0033 or 3.35e6 < y Initial program 100.0%
div-sub100.0%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Taylor expanded in y around -inf 98.6%
mul-1-neg98.6%
unsub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in x around inf 98.6%
if -0.0033 < y < 5.19999999999999983e-112 or 0.92000000000000004 < y < 3.35e6Initial program 100.0%
Taylor expanded in x around inf 79.5%
if 5.19999999999999983e-112 < y < 0.92000000000000004Initial program 99.9%
Taylor expanded in x around 0 57.3%
metadata-eval57.3%
times-frac57.3%
*-lft-identity57.3%
neg-mul-157.3%
neg-sub057.3%
associate--r-57.3%
metadata-eval57.3%
Simplified57.3%
Final simplification86.6%
(FPCore (x y) :precision binary64 (if (or (<= y -0.0025) (not (<= y 1.0))) (- 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -0.0025) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-0.0025d0)) .or. (.not. (y <= 1.0d0))) then
tmp = 1.0d0 - (x / y)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.0025) || !(y <= 1.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.0025) or not (y <= 1.0): tmp = 1.0 - (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.0025) || !(y <= 1.0)) tmp = Float64(1.0 - Float64(x / y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.0025) || ~((y <= 1.0))) tmp = 1.0 - (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.0025], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0025 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -0.00250000000000000005 or 1 < y Initial program 100.0%
div-sub100.0%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Taylor expanded in y around -inf 97.3%
mul-1-neg97.3%
unsub-neg97.3%
sub-neg97.3%
metadata-eval97.3%
+-commutative97.3%
Simplified97.3%
Taylor expanded in x around inf 97.3%
if -0.00250000000000000005 < y < 1Initial program 100.0%
Taylor expanded in y around 0 71.1%
Final simplification84.2%
(FPCore (x y) :precision binary64 (if (or (<= y -0.0033) (not (<= y 12200.0))) (- 1.0 (/ x y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -0.0033) || !(y <= 12200.0)) {
tmp = 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 <= (-0.0033d0)) .or. (.not. (y <= 12200.0d0))) then
tmp = 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 <= -0.0033) || !(y <= 12200.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.0033) or not (y <= 12200.0): tmp = 1.0 - (x / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.0033) || !(y <= 12200.0)) tmp = Float64(1.0 - Float64(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 <= -0.0033) || ~((y <= 12200.0))) tmp = 1.0 - (x / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.0033], N[Not[LessEqual[y, 12200.0]], $MachinePrecision]], N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0033 \lor \neg \left(y \leq 12200\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -0.0033 or 12200 < y Initial program 100.0%
div-sub100.0%
div-inv99.9%
fma-neg99.9%
Applied egg-rr99.9%
Taylor expanded in y around -inf 98.6%
mul-1-neg98.6%
unsub-neg98.6%
sub-neg98.6%
metadata-eval98.6%
+-commutative98.6%
Simplified98.6%
Taylor expanded in x around inf 98.6%
if -0.0033 < y < 12200Initial program 100.0%
Taylor expanded in x around inf 71.8%
Final simplification85.0%
(FPCore (x y) :precision binary64 (if (<= y -0.0021) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -0.0021) {
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 <= (-0.0021d0)) 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 <= -0.0021) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.0021: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.0021) 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 <= -0.0021) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.0021], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0021:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.00209999999999999987 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 79.1%
if -0.00209999999999999987 < y < 1Initial program 100.0%
Taylor expanded in y around 0 71.1%
Final simplification75.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 41.4%
Final simplification41.4%
herbie shell --seed 2024031
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))