
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
(FPCore (x y) :precision binary64 (/ (+ x y) (+ y 1.0)))
double code(double x, double y) {
return (x + y) / (y + 1.0);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (x + y) / (y + 1.0d0)
end function
public static double code(double x, double y) {
return (x + y) / (y + 1.0);
}
def code(x, y): return (x + y) / (y + 1.0)
function code(x, y) return Float64(Float64(x + y) / Float64(y + 1.0)) end
function tmp = code(x, y) tmp = (x + y) / (y + 1.0); end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{x + y}{y + 1}
\end{array}
Initial program 100.0%
(FPCore (x y) :precision binary64 (if (<= y -9.8e+63) 1.0 (if (<= y -7500.0) (/ x y) (if (<= y 4.3e-5) (- x (* x y)) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -9.8e+63) {
tmp = 1.0;
} else if (y <= -7500.0) {
tmp = x / y;
} else if (y <= 4.3e-5) {
tmp = x - (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 <= (-9.8d+63)) then
tmp = 1.0d0
else if (y <= (-7500.0d0)) then
tmp = x / y
else if (y <= 4.3d-5) then
tmp = x - (x * y)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9.8e+63) {
tmp = 1.0;
} else if (y <= -7500.0) {
tmp = x / y;
} else if (y <= 4.3e-5) {
tmp = x - (x * y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9.8e+63: tmp = 1.0 elif y <= -7500.0: tmp = x / y elif y <= 4.3e-5: tmp = x - (x * y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -9.8e+63) tmp = 1.0; elseif (y <= -7500.0) tmp = Float64(x / y); elseif (y <= 4.3e-5) tmp = Float64(x - Float64(x * y)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9.8e+63) tmp = 1.0; elseif (y <= -7500.0) tmp = x / y; elseif (y <= 4.3e-5) tmp = x - (x * y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9.8e+63], 1.0, If[LessEqual[y, -7500.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 4.3e-5], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9.8 \cdot 10^{+63}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -7500:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-5}:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -9.7999999999999994e63 or 4.3000000000000002e-5 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -9.7999999999999994e63 < y < -7500Initial program 100.0%
Taylor expanded in x around inf 67.8%
+-commutative67.8%
Simplified67.8%
Taylor expanded in y around inf 64.9%
if -7500 < y < 4.3000000000000002e-5Initial program 100.0%
Taylor expanded in x around inf 84.5%
+-commutative84.5%
Simplified84.5%
Taylor expanded in y around 0 83.9%
mul-1-neg83.9%
unsub-neg83.9%
Simplified83.9%
(FPCore (x y) :precision binary64 (if (<= y -2.15e+67) 1.0 (if (<= y -7500.0) (/ x y) (if (<= y 4.3e-5) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -2.15e+67) {
tmp = 1.0;
} else if (y <= -7500.0) {
tmp = x / y;
} else if (y <= 4.3e-5) {
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.15d+67)) then
tmp = 1.0d0
else if (y <= (-7500.0d0)) then
tmp = x / y
else if (y <= 4.3d-5) 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.15e+67) {
tmp = 1.0;
} else if (y <= -7500.0) {
tmp = x / y;
} else if (y <= 4.3e-5) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.15e+67: tmp = 1.0 elif y <= -7500.0: tmp = x / y elif y <= 4.3e-5: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.15e+67) tmp = 1.0; elseif (y <= -7500.0) tmp = Float64(x / y); elseif (y <= 4.3e-5) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.15e+67) tmp = 1.0; elseif (y <= -7500.0) tmp = x / y; elseif (y <= 4.3e-5) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.15e+67], 1.0, If[LessEqual[y, -7500.0], N[(x / y), $MachinePrecision], If[LessEqual[y, 4.3e-5], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.15 \cdot 10^{+67}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -7500:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.1500000000000001e67 or 4.3000000000000002e-5 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -2.1500000000000001e67 < y < -7500Initial program 100.0%
Taylor expanded in x around inf 67.8%
+-commutative67.8%
Simplified67.8%
Taylor expanded in y around inf 64.9%
if -7500 < y < 4.3000000000000002e-5Initial program 100.0%
Taylor expanded in y around 0 83.1%
(FPCore (x y) :precision binary64 (if (<= y -1.6e+59) 1.0 (if (<= y 4.3e-5) (/ x (+ y 1.0)) (/ y (+ y 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.6e+59) {
tmp = 1.0;
} else if (y <= 4.3e-5) {
tmp = x / (y + 1.0);
} 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 <= (-1.6d+59)) then
tmp = 1.0d0
else if (y <= 4.3d-5) then
tmp = x / (y + 1.0d0)
else
tmp = y / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.6e+59) {
tmp = 1.0;
} else if (y <= 4.3e-5) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e+59: tmp = 1.0 elif y <= 4.3e-5: tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e+59) tmp = 1.0; elseif (y <= 4.3e-5) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(y / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e+59) tmp = 1.0; elseif (y <= 4.3e-5) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e+59], 1.0, If[LessEqual[y, 4.3e-5], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+59}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-5}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if y < -1.59999999999999991e59Initial program 100.0%
Taylor expanded in y around inf 73.7%
if -1.59999999999999991e59 < y < 4.3000000000000002e-5Initial program 100.0%
Taylor expanded in x around inf 82.8%
+-commutative82.8%
Simplified82.8%
if 4.3000000000000002e-5 < y Initial program 100.0%
Taylor expanded in x around 0 81.0%
+-commutative81.0%
Simplified81.0%
(FPCore (x y) :precision binary64 (if (<= y -2.3e+63) 1.0 (if (<= y 1.02e+63) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.3e+63) {
tmp = 1.0;
} else if (y <= 1.02e+63) {
tmp = x / (y + 1.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) :: tmp
if (y <= (-2.3d+63)) then
tmp = 1.0d0
else if (y <= 1.02d+63) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.3e+63) {
tmp = 1.0;
} else if (y <= 1.02e+63) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.3e+63: tmp = 1.0 elif y <= 1.02e+63: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.3e+63) tmp = 1.0; elseif (y <= 1.02e+63) tmp = Float64(x / Float64(y + 1.0)); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.3e+63) tmp = 1.0; elseif (y <= 1.02e+63) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.3e+63], 1.0, If[LessEqual[y, 1.02e+63], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.3 \cdot 10^{+63}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.02 \cdot 10^{+63}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.29999999999999993e63 or 1.02e63 < y Initial program 100.0%
Taylor expanded in y around inf 81.1%
if -2.29999999999999993e63 < y < 1.02e63Initial program 100.0%
Taylor expanded in x around inf 79.1%
+-commutative79.1%
Simplified79.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 4.3e-5) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 4.3e-5) {
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.0d0)) then
tmp = 1.0d0
else if (y <= 4.3d-5) 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.0) {
tmp = 1.0;
} else if (y <= 4.3e-5) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 4.3e-5: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 4.3e-5) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = 1.0; elseif (y <= 4.3e-5) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 4.3e-5], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-5}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 4.3000000000000002e-5 < y Initial program 100.0%
Taylor expanded in y around inf 70.4%
if -1 < y < 4.3000000000000002e-5Initial program 100.0%
Taylor expanded in y around 0 83.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 36.8%
herbie shell --seed 2024181
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))