
(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 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -14500000000.0)
t_0
(if (<= y -8.4e-36)
(/ y (+ y -1.0))
(if (<= y 7.0) (/ x (- 1.0 y)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -14500000000.0) {
tmp = t_0;
} else if (y <= -8.4e-36) {
tmp = y / (y + -1.0);
} else if (y <= 7.0) {
tmp = x / (1.0 - y);
} 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) :: tmp
t_0 = 1.0d0 + ((1.0d0 - x) / y)
if (y <= (-14500000000.0d0)) then
tmp = t_0
else if (y <= (-8.4d-36)) then
tmp = y / (y + (-1.0d0))
else if (y <= 7.0d0) then
tmp = x / (1.0d0 - y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((1.0 - x) / y);
double tmp;
if (y <= -14500000000.0) {
tmp = t_0;
} else if (y <= -8.4e-36) {
tmp = y / (y + -1.0);
} else if (y <= 7.0) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((1.0 - x) / y) tmp = 0 if y <= -14500000000.0: tmp = t_0 elif y <= -8.4e-36: tmp = y / (y + -1.0) elif y <= 7.0: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(1.0 - x) / y)) tmp = 0.0 if (y <= -14500000000.0) tmp = t_0; elseif (y <= -8.4e-36) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 7.0) tmp = Float64(x / Float64(1.0 - y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((1.0 - x) / y); tmp = 0.0; if (y <= -14500000000.0) tmp = t_0; elseif (y <= -8.4e-36) tmp = y / (y + -1.0); elseif (y <= 7.0) tmp = x / (1.0 - y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(1.0 - x), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -14500000000.0], t$95$0, If[LessEqual[y, -8.4e-36], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 7.0], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{1 - x}{y}\\
\mathbf{if}\;y \leq -14500000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -8.4 \cdot 10^{-36}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 7:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.45e10 or 7 < y Initial program 100.0%
Taylor expanded in y around inf 98.8%
+-commutative98.8%
mul-1-neg98.8%
sub-neg98.8%
div-sub98.8%
Simplified98.8%
if -1.45e10 < y < -8.39999999999999964e-36Initial program 99.7%
Taylor expanded in x around 0 78.9%
neg-mul-178.9%
distribute-neg-frac278.9%
neg-sub078.9%
associate--r-78.9%
metadata-eval78.9%
Simplified78.9%
if -8.39999999999999964e-36 < y < 7Initial program 100.0%
Taylor expanded in x around inf 80.5%
Final simplification89.5%
(FPCore (x y) :precision binary64 (if (<= y -4.5e-7) 1.0 (if (<= y 0.00019) x (if (<= y 1.8e+119) (/ x (- y)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-7) {
tmp = 1.0;
} else if (y <= 0.00019) {
tmp = x;
} else if (y <= 1.8e+119) {
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 <= (-4.5d-7)) then
tmp = 1.0d0
else if (y <= 0.00019d0) then
tmp = x
else if (y <= 1.8d+119) 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 <= -4.5e-7) {
tmp = 1.0;
} else if (y <= 0.00019) {
tmp = x;
} else if (y <= 1.8e+119) {
tmp = x / -y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e-7: tmp = 1.0 elif y <= 0.00019: tmp = x elif y <= 1.8e+119: tmp = x / -y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e-7) tmp = 1.0; elseif (y <= 0.00019) tmp = x; elseif (y <= 1.8e+119) tmp = Float64(x / Float64(-y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.5e-7) tmp = 1.0; elseif (y <= 0.00019) tmp = x; elseif (y <= 1.8e+119) tmp = x / -y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e-7], 1.0, If[LessEqual[y, 0.00019], x, If[LessEqual[y, 1.8e+119], N[(x / (-y)), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.00019:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+119}:\\
\;\;\;\;\frac{x}{-y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.4999999999999998e-7 or 1.80000000000000001e119 < y Initial program 100.0%
Taylor expanded in y around inf 83.9%
if -4.4999999999999998e-7 < y < 1.9000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 78.2%
if 1.9000000000000001e-4 < y < 1.80000000000000001e119Initial program 99.9%
Taylor expanded in x around inf 64.6%
Taylor expanded in y around inf 64.1%
mul-1-neg64.1%
distribute-neg-frac264.1%
Simplified64.1%
Final simplification79.2%
(FPCore (x y) :precision binary64 (if (or (<= y -8.4e-36) (not (<= y 1.8e+119))) (/ y (+ y -1.0)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -8.4e-36) || !(y <= 1.8e+119)) {
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 <= (-8.4d-36)) .or. (.not. (y <= 1.8d+119))) 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 <= -8.4e-36) || !(y <= 1.8e+119)) {
tmp = y / (y + -1.0);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8.4e-36) or not (y <= 1.8e+119): tmp = y / (y + -1.0) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -8.4e-36) || !(y <= 1.8e+119)) 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 <= -8.4e-36) || ~((y <= 1.8e+119))) tmp = y / (y + -1.0); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -8.4e-36], N[Not[LessEqual[y, 1.8e+119]], $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 -8.4 \cdot 10^{-36} \lor \neg \left(y \leq 1.8 \cdot 10^{+119}\right):\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -8.39999999999999964e-36 or 1.80000000000000001e119 < y Initial program 99.9%
Taylor expanded in x around 0 84.9%
neg-mul-184.9%
distribute-neg-frac284.9%
neg-sub084.9%
associate--r-84.9%
metadata-eval84.9%
Simplified84.9%
if -8.39999999999999964e-36 < y < 1.80000000000000001e119Initial program 100.0%
Taylor expanded in x around inf 78.3%
Final simplification81.2%
(FPCore (x y) :precision binary64 (if (<= y -8.5e+53) 1.0 (if (<= y 1.8e+119) (/ x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -8.5e+53) {
tmp = 1.0;
} else if (y <= 1.8e+119) {
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 <= (-8.5d+53)) then
tmp = 1.0d0
else if (y <= 1.8d+119) 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 <= -8.5e+53) {
tmp = 1.0;
} else if (y <= 1.8e+119) {
tmp = x / (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.5e+53: tmp = 1.0 elif y <= 1.8e+119: tmp = x / (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -8.5e+53) tmp = 1.0; elseif (y <= 1.8e+119) 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 <= -8.5e+53) tmp = 1.0; elseif (y <= 1.8e+119) tmp = x / (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.5e+53], 1.0, If[LessEqual[y, 1.8e+119], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.5 \cdot 10^{+53}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+119}:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.5000000000000002e53 or 1.80000000000000001e119 < y Initial program 100.0%
Taylor expanded in y around inf 88.4%
if -8.5000000000000002e53 < y < 1.80000000000000001e119Initial program 100.0%
Taylor expanded in x around inf 74.7%
Final simplification79.9%
(FPCore (x y) :precision binary64 (if (<= y -4.5e-7) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-7) {
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 <= (-4.5d-7)) 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 <= -4.5e-7) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e-7: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e-7) 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 <= -4.5e-7) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e-7], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-7}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -4.4999999999999998e-7 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 73.8%
if -4.4999999999999998e-7 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.6%
Final simplification75.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 39.3%
Final simplification39.3%
herbie shell --seed 2024075
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))