
(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%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ (- 1.0 x) y))))
(if (<= y -0.48)
t_0
(if (<= y -1.3e-52)
(/ y (+ y -1.0))
(if (<= y 13.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 <= -0.48) {
tmp = t_0;
} else if (y <= -1.3e-52) {
tmp = y / (y + -1.0);
} else if (y <= 13.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 <= (-0.48d0)) then
tmp = t_0
else if (y <= (-1.3d-52)) then
tmp = y / (y + (-1.0d0))
else if (y <= 13.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 <= -0.48) {
tmp = t_0;
} else if (y <= -1.3e-52) {
tmp = y / (y + -1.0);
} else if (y <= 13.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 <= -0.48: tmp = t_0 elif y <= -1.3e-52: tmp = y / (y + -1.0) elif y <= 13.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 <= -0.48) tmp = t_0; elseif (y <= -1.3e-52) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 13.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 <= -0.48) tmp = t_0; elseif (y <= -1.3e-52) tmp = y / (y + -1.0); elseif (y <= 13.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, -0.48], t$95$0, If[LessEqual[y, -1.3e-52], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 13.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 -0.48:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.3 \cdot 10^{-52}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 13:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.47999999999999998 or 13 < y Initial program 100.0%
Taylor expanded in y around inf 97.8%
+-commutative97.8%
mul-1-neg97.8%
sub-neg97.8%
div-sub97.8%
Simplified97.8%
if -0.47999999999999998 < y < -1.2999999999999999e-52Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
Simplified100.0%
if -1.2999999999999999e-52 < y < 13Initial program 100.0%
Taylor expanded in x around inf 78.2%
Final simplification88.5%
(FPCore (x y)
:precision binary64
(let* ((t_0 (- 1.0 (/ x y))))
(if (<= y -5800000000.0)
t_0
(if (<= y -1.35e-52)
(/ y (+ y -1.0))
(if (<= y 13.0) (/ x (- 1.0 y)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -5800000000.0) {
tmp = t_0;
} else if (y <= -1.35e-52) {
tmp = y / (y + -1.0);
} else if (y <= 13.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 - (x / y)
if (y <= (-5800000000.0d0)) then
tmp = t_0
else if (y <= (-1.35d-52)) then
tmp = y / (y + (-1.0d0))
else if (y <= 13.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 - (x / y);
double tmp;
if (y <= -5800000000.0) {
tmp = t_0;
} else if (y <= -1.35e-52) {
tmp = y / (y + -1.0);
} else if (y <= 13.0) {
tmp = x / (1.0 - y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if y <= -5800000000.0: tmp = t_0 elif y <= -1.35e-52: tmp = y / (y + -1.0) elif y <= 13.0: tmp = x / (1.0 - y) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -5800000000.0) tmp = t_0; elseif (y <= -1.35e-52) tmp = Float64(y / Float64(y + -1.0)); elseif (y <= 13.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 - (x / y); tmp = 0.0; if (y <= -5800000000.0) tmp = t_0; elseif (y <= -1.35e-52) tmp = y / (y + -1.0); elseif (y <= 13.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[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5800000000.0], t$95$0, If[LessEqual[y, -1.35e-52], N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 13.0], N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -5800000000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-52}:\\
\;\;\;\;\frac{y}{y + -1}\\
\mathbf{elif}\;y \leq 13:\\
\;\;\;\;\frac{x}{1 - y}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -5.8e9 or 13 < 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%
Taylor expanded in x around inf 97.9%
mul-1-neg97.9%
Simplified97.9%
Taylor expanded in x around 0 97.9%
mul-1-neg97.9%
sub-neg97.9%
Simplified97.9%
if -5.8e9 < y < -1.35000000000000005e-52Initial program 100.0%
Taylor expanded in x around 0 87.9%
neg-mul-187.9%
distribute-neg-frac287.9%
neg-sub087.9%
associate--r-87.9%
metadata-eval87.9%
Simplified87.9%
if -1.35000000000000005e-52 < y < 13Initial program 100.0%
Taylor expanded in x around inf 78.2%
Final simplification88.1%
(FPCore (x y) :precision binary64 (let* ((t_0 (- 1.0 (/ x y)))) (if (<= y -0.095) t_0 (if (<= y -1.35e-52) (- y) (if (<= y 1.0) x t_0)))))
double code(double x, double y) {
double t_0 = 1.0 - (x / y);
double tmp;
if (y <= -0.095) {
tmp = t_0;
} else if (y <= -1.35e-52) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} 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 - (x / y)
if (y <= (-0.095d0)) then
tmp = t_0
else if (y <= (-1.35d-52)) then
tmp = -y
else if (y <= 1.0d0) then
tmp = x
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 tmp;
if (y <= -0.095) {
tmp = t_0;
} else if (y <= -1.35e-52) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 - (x / y) tmp = 0 if y <= -0.095: tmp = t_0 elif y <= -1.35e-52: tmp = -y elif y <= 1.0: tmp = x else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 - Float64(x / y)) tmp = 0.0 if (y <= -0.095) tmp = t_0; elseif (y <= -1.35e-52) tmp = Float64(-y); elseif (y <= 1.0) tmp = x; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 - (x / y); tmp = 0.0; if (y <= -0.095) tmp = t_0; elseif (y <= -1.35e-52) tmp = -y; elseif (y <= 1.0) tmp = x; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 - N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.095], t$95$0, If[LessEqual[y, -1.35e-52], (-y), If[LessEqual[y, 1.0], x, t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 - \frac{x}{y}\\
\mathbf{if}\;y \leq -0.095:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-52}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.095000000000000001 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 97.8%
+-commutative97.8%
mul-1-neg97.8%
sub-neg97.8%
div-sub97.8%
Simplified97.8%
Taylor expanded in x around inf 97.1%
mul-1-neg97.1%
Simplified97.1%
Taylor expanded in x around 0 97.1%
mul-1-neg97.1%
sub-neg97.1%
Simplified97.1%
if -0.095000000000000001 < y < -1.35000000000000005e-52Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 78.3%
neg-mul-178.3%
Simplified78.3%
if -1.35000000000000005e-52 < y < 1Initial program 100.0%
Taylor expanded in y around 0 78.1%
(FPCore (x y) :precision binary64 (if (<= y -0.48) 1.0 (if (<= y -1.35e-52) (- y) (if (<= y 1.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -0.48) {
tmp = 1.0;
} else if (y <= -1.35e-52) {
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 <= (-0.48d0)) then
tmp = 1.0d0
else if (y <= (-1.35d-52)) 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 <= -0.48) {
tmp = 1.0;
} else if (y <= -1.35e-52) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.48: tmp = 1.0 elif y <= -1.35e-52: tmp = -y elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -0.48) tmp = 1.0; elseif (y <= -1.35e-52) 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 <= -0.48) tmp = 1.0; elseif (y <= -1.35e-52) tmp = -y; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.48], 1.0, If[LessEqual[y, -1.35e-52], (-y), If[LessEqual[y, 1.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.48:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -1.35 \cdot 10^{-52}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -0.47999999999999998 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 70.3%
if -0.47999999999999998 < y < -1.35000000000000005e-52Initial program 100.0%
Taylor expanded in x around 0 100.0%
neg-mul-1100.0%
distribute-neg-frac2100.0%
neg-sub0100.0%
associate--r-100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in y around 0 78.3%
neg-mul-178.3%
Simplified78.3%
if -1.35000000000000005e-52 < y < 1Initial program 100.0%
Taylor expanded in y around 0 78.1%
(FPCore (x y) :precision binary64 (if (or (<= y -5400000.0) (not (<= y 13.0))) (- 1.0 (/ x y)) (/ x (- 1.0 y))))
double code(double x, double y) {
double tmp;
if ((y <= -5400000.0) || !(y <= 13.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 <= (-5400000.0d0)) .or. (.not. (y <= 13.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 <= -5400000.0) || !(y <= 13.0)) {
tmp = 1.0 - (x / y);
} else {
tmp = x / (1.0 - y);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5400000.0) or not (y <= 13.0): tmp = 1.0 - (x / y) else: tmp = x / (1.0 - y) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5400000.0) || !(y <= 13.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 <= -5400000.0) || ~((y <= 13.0))) tmp = 1.0 - (x / y); else tmp = x / (1.0 - y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5400000.0], N[Not[LessEqual[y, 13.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 -5400000 \lor \neg \left(y \leq 13\right):\\
\;\;\;\;1 - \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{1 - y}\\
\end{array}
\end{array}
if y < -5.4e6 or 13 < 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%
Taylor expanded in x around inf 97.7%
mul-1-neg97.7%
Simplified97.7%
Taylor expanded in x around 0 97.7%
mul-1-neg97.7%
sub-neg97.7%
Simplified97.7%
if -5.4e6 < y < 13Initial program 100.0%
Taylor expanded in x around inf 74.9%
Final simplification86.1%
(FPCore (x y) :precision binary64 (if (<= y -1.35e-52) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.35e-52) {
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 <= (-1.35d-52)) 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 <= -1.35e-52) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.35e-52: tmp = 1.0 elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.35e-52) 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 <= -1.35e-52) tmp = 1.0; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.35e-52], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.35 \cdot 10^{-52}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.35000000000000005e-52 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 67.6%
if -1.35000000000000005e-52 < y < 1Initial program 100.0%
Taylor expanded in y around 0 78.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 36.9%
herbie shell --seed 2024135
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))