
(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 6 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 (/ x (- 1.0 y))) (t_1 (/ y (+ y -1.0))))
(if (<= x -4.9e-27)
t_0
(if (<= x 2.3e-104)
t_1
(if (<= x 3e-56) x (if (<= x 1.6e-23) t_1 t_0))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double t_1 = y / (y + -1.0);
double tmp;
if (x <= -4.9e-27) {
tmp = t_0;
} else if (x <= 2.3e-104) {
tmp = t_1;
} else if (x <= 3e-56) {
tmp = x;
} else if (x <= 1.6e-23) {
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 = x / (1.0d0 - y)
t_1 = y / (y + (-1.0d0))
if (x <= (-4.9d-27)) then
tmp = t_0
else if (x <= 2.3d-104) then
tmp = t_1
else if (x <= 3d-56) then
tmp = x
else if (x <= 1.6d-23) 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 = x / (1.0 - y);
double t_1 = y / (y + -1.0);
double tmp;
if (x <= -4.9e-27) {
tmp = t_0;
} else if (x <= 2.3e-104) {
tmp = t_1;
} else if (x <= 3e-56) {
tmp = x;
} else if (x <= 1.6e-23) {
tmp = t_1;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) t_1 = y / (y + -1.0) tmp = 0 if x <= -4.9e-27: tmp = t_0 elif x <= 2.3e-104: tmp = t_1 elif x <= 3e-56: tmp = x elif x <= 1.6e-23: tmp = t_1 else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x / Float64(1.0 - y)) t_1 = Float64(y / Float64(y + -1.0)) tmp = 0.0 if (x <= -4.9e-27) tmp = t_0; elseif (x <= 2.3e-104) tmp = t_1; elseif (x <= 3e-56) tmp = x; elseif (x <= 1.6e-23) tmp = t_1; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (1.0 - y); t_1 = y / (y + -1.0); tmp = 0.0; if (x <= -4.9e-27) tmp = t_0; elseif (x <= 2.3e-104) tmp = t_1; elseif (x <= 3e-56) tmp = x; elseif (x <= 1.6e-23) tmp = t_1; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(y / N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4.9e-27], t$95$0, If[LessEqual[x, 2.3e-104], t$95$1, If[LessEqual[x, 3e-56], x, If[LessEqual[x, 1.6e-23], t$95$1, t$95$0]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
t_1 := \frac{y}{y + -1}\\
\mathbf{if}\;x \leq -4.9 \cdot 10^{-27}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{-104}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 3 \cdot 10^{-56}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{-23}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -4.89999999999999976e-27 or 1.59999999999999988e-23 < x Initial program 100.0%
Taylor expanded in x around inf 81.0%
if -4.89999999999999976e-27 < x < 2.2999999999999999e-104 or 2.99999999999999989e-56 < x < 1.59999999999999988e-23Initial program 100.0%
Taylor expanded in x around 0 83.2%
neg-mul-183.2%
distribute-neg-frac283.2%
neg-sub083.2%
associate--r-83.2%
metadata-eval83.2%
Simplified83.2%
if 2.2999999999999999e-104 < x < 2.99999999999999989e-56Initial program 100.0%
Taylor expanded in y around 0 85.4%
Final simplification82.1%
(FPCore (x y)
:precision binary64
(let* ((t_0 (/ x (- 1.0 y))))
(if (<= y -5.2e+107)
1.0
(if (<= y -0.135)
t_0
(if (<= y -5.8e-126) (- y) (if (<= y 2.65e+50) t_0 1.0))))))
double code(double x, double y) {
double t_0 = x / (1.0 - y);
double tmp;
if (y <= -5.2e+107) {
tmp = 1.0;
} else if (y <= -0.135) {
tmp = t_0;
} else if (y <= -5.8e-126) {
tmp = -y;
} else if (y <= 2.65e+50) {
tmp = t_0;
} else {
tmp = 1.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 = x / (1.0d0 - y)
if (y <= (-5.2d+107)) then
tmp = 1.0d0
else if (y <= (-0.135d0)) then
tmp = t_0
else if (y <= (-5.8d-126)) then
tmp = -y
else if (y <= 2.65d+50) then
tmp = t_0
else
tmp = 1.0d0
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 <= -5.2e+107) {
tmp = 1.0;
} else if (y <= -0.135) {
tmp = t_0;
} else if (y <= -5.8e-126) {
tmp = -y;
} else if (y <= 2.65e+50) {
tmp = t_0;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): t_0 = x / (1.0 - y) tmp = 0 if y <= -5.2e+107: tmp = 1.0 elif y <= -0.135: tmp = t_0 elif y <= -5.8e-126: tmp = -y elif y <= 2.65e+50: tmp = t_0 else: tmp = 1.0 return tmp
function code(x, y) t_0 = Float64(x / Float64(1.0 - y)) tmp = 0.0 if (y <= -5.2e+107) tmp = 1.0; elseif (y <= -0.135) tmp = t_0; elseif (y <= -5.8e-126) tmp = Float64(-y); elseif (y <= 2.65e+50) tmp = t_0; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) t_0 = x / (1.0 - y); tmp = 0.0; if (y <= -5.2e+107) tmp = 1.0; elseif (y <= -0.135) tmp = t_0; elseif (y <= -5.8e-126) tmp = -y; elseif (y <= 2.65e+50) tmp = t_0; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x / N[(1.0 - y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -5.2e+107], 1.0, If[LessEqual[y, -0.135], t$95$0, If[LessEqual[y, -5.8e-126], (-y), If[LessEqual[y, 2.65e+50], t$95$0, 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{x}{1 - y}\\
\mathbf{if}\;y \leq -5.2 \cdot 10^{+107}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -0.135:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{-126}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+50}:\\
\;\;\;\;t\_0\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.2000000000000002e107 or 2.6500000000000001e50 < y Initial program 100.0%
Taylor expanded in y around inf 82.1%
if -5.2000000000000002e107 < y < -0.13500000000000001 or -5.79999999999999975e-126 < y < 2.6500000000000001e50Initial program 100.0%
Taylor expanded in x around inf 76.1%
if -0.13500000000000001 < y < -5.79999999999999975e-126Initial program 99.9%
Taylor expanded in x around 0 72.2%
neg-mul-172.2%
distribute-neg-frac272.2%
neg-sub072.2%
associate--r-72.2%
metadata-eval72.2%
Simplified72.2%
Taylor expanded in y around 0 60.8%
neg-mul-160.8%
Simplified60.8%
(FPCore (x y) :precision binary64 (if (<= y -16200000.0) 1.0 (if (<= y -5.8e-126) (- y) (if (<= y 1.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -16200000.0) {
tmp = 1.0;
} else if (y <= -5.8e-126) {
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 <= (-16200000.0d0)) then
tmp = 1.0d0
else if (y <= (-5.8d-126)) 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 <= -16200000.0) {
tmp = 1.0;
} else if (y <= -5.8e-126) {
tmp = -y;
} else if (y <= 1.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -16200000.0: tmp = 1.0 elif y <= -5.8e-126: tmp = -y elif y <= 1.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -16200000.0) tmp = 1.0; elseif (y <= -5.8e-126) 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 <= -16200000.0) tmp = 1.0; elseif (y <= -5.8e-126) tmp = -y; elseif (y <= 1.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -16200000.0], 1.0, If[LessEqual[y, -5.8e-126], (-y), If[LessEqual[y, 1.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16200000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{-126}:\\
\;\;\;\;-y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.62e7 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 69.1%
if -1.62e7 < y < -5.79999999999999975e-126Initial program 99.9%
Taylor expanded in x around 0 66.8%
neg-mul-166.8%
distribute-neg-frac266.8%
neg-sub066.8%
associate--r-66.8%
metadata-eval66.8%
Simplified66.8%
Taylor expanded in y around 0 56.4%
neg-mul-156.4%
Simplified56.4%
if -5.79999999999999975e-126 < y < 1Initial program 100.0%
Taylor expanded in y around 0 75.4%
(FPCore (x y) :precision binary64 (if (<= y -2.3e-18) 1.0 (if (<= y 1.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.3e-18) {
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.3d-18)) 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.3e-18) {
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.3e-18: 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.3e-18) 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.3e-18) 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.3e-18], 1.0, If[LessEqual[y, 1.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{-18}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.3000000000000001e-18 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 65.3%
if -2.3000000000000001e-18 < y < 1Initial program 100.0%
Taylor expanded in y around 0 70.6%
(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 33.4%
herbie shell --seed 2024092
(FPCore (x y)
:name "Diagrams.Trail:splitAtParam from diagrams-lib-1.3.0.3, C"
:precision binary64
(/ (- x y) (- 1.0 y)))