
(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%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -650000.0) (+ 1.0 (/ x y)) (if (<= y 425.0) (/ x (+ y 1.0)) (+ 1.0 (/ (+ x -1.0) y)))))
double code(double x, double y) {
double tmp;
if (y <= -650000.0) {
tmp = 1.0 + (x / y);
} else if (y <= 425.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 + ((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 <= (-650000.0d0)) then
tmp = 1.0d0 + (x / y)
else if (y <= 425.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = 1.0d0 + ((x + (-1.0d0)) / y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -650000.0) {
tmp = 1.0 + (x / y);
} else if (y <= 425.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 + ((x + -1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -650000.0: tmp = 1.0 + (x / y) elif y <= 425.0: tmp = x / (y + 1.0) else: tmp = 1.0 + ((x + -1.0) / y) return tmp
function code(x, y) tmp = 0.0 if (y <= -650000.0) tmp = Float64(1.0 + Float64(x / y)); elseif (y <= 425.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -650000.0) tmp = 1.0 + (x / y); elseif (y <= 425.0) tmp = x / (y + 1.0); else tmp = 1.0 + ((x + -1.0) / y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -650000.0], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 425.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -650000:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;y \leq 425:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\end{array}
\end{array}
if y < -6.5e5Initial program 100.0%
Taylor expanded in x around inf 84.8%
Taylor expanded in y around inf 99.7%
Taylor expanded in y around inf 100.0%
if -6.5e5 < y < 425Initial program 100.0%
Taylor expanded in x around inf 78.5%
+-commutative78.5%
Simplified78.5%
if 425 < y Initial program 100.0%
Taylor expanded in y around inf 99.2%
associate--l+99.2%
div-sub99.2%
sub-neg99.2%
metadata-eval99.2%
Simplified99.2%
Final simplification89.2%
(FPCore (x y) :precision binary64 (if (<= y -5.6e+82) 1.0 (if (<= y -3.9e+21) (/ x y) (if (<= y 0.007) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -5.6e+82) {
tmp = 1.0;
} else if (y <= -3.9e+21) {
tmp = x / y;
} else if (y <= 0.007) {
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 <= (-5.6d+82)) then
tmp = 1.0d0
else if (y <= (-3.9d+21)) then
tmp = x / y
else if (y <= 0.007d0) 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 <= -5.6e+82) {
tmp = 1.0;
} else if (y <= -3.9e+21) {
tmp = x / y;
} else if (y <= 0.007) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.6e+82: tmp = 1.0 elif y <= -3.9e+21: tmp = x / y elif y <= 0.007: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.6e+82) tmp = 1.0; elseif (y <= -3.9e+21) tmp = Float64(x / y); elseif (y <= 0.007) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5.6e+82) tmp = 1.0; elseif (y <= -3.9e+21) tmp = x / y; elseif (y <= 0.007) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.6e+82], 1.0, If[LessEqual[y, -3.9e+21], N[(x / y), $MachinePrecision], If[LessEqual[y, 0.007], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.6 \cdot 10^{+82}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -3.9 \cdot 10^{+21}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 0.007:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.6000000000000001e82 or 0.00700000000000000015 < y Initial program 100.0%
Taylor expanded in y around inf 75.5%
if -5.6000000000000001e82 < y < -3.9e21Initial program 100.0%
Taylor expanded in x around inf 80.7%
+-commutative80.7%
Simplified80.7%
Taylor expanded in y around inf 80.7%
if -3.9e21 < y < 0.00700000000000000015Initial program 100.0%
Taylor expanded in y around 0 77.5%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.007))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.007)) {
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 <= (-1.0d0)) .or. (.not. (y <= 0.007d0))) 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 <= -1.0) || !(y <= 0.007)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.007): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.007)) 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 <= -1.0) || ~((y <= 0.007))) tmp = 1.0 + (x / y); else tmp = x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.007]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.007\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 0.00700000000000000015 < y Initial program 100.0%
Taylor expanded in x around inf 84.5%
Taylor expanded in y around inf 98.6%
Taylor expanded in y around inf 98.8%
if -1 < y < 0.00700000000000000015Initial program 100.0%
Taylor expanded in y around 0 78.1%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (or (<= y -5800.0) (not (<= y 0.007))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -5800.0) || !(y <= 0.007)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (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 <= (-5800.0d0)) .or. (.not. (y <= 0.007d0))) then
tmp = 1.0d0 + (x / y)
else
tmp = x / (y + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -5800.0) || !(y <= 0.007)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5800.0) or not (y <= 0.007): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -5800.0) || !(y <= 0.007)) tmp = Float64(1.0 + Float64(x / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5800.0) || ~((y <= 0.007))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5800.0], N[Not[LessEqual[y, 0.007]], $MachinePrecision]], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5800 \lor \neg \left(y \leq 0.007\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -5800 or 0.00700000000000000015 < y Initial program 100.0%
Taylor expanded in x around inf 84.5%
Taylor expanded in y around inf 98.6%
Taylor expanded in y around inf 98.8%
if -5800 < y < 0.00700000000000000015Initial program 100.0%
Taylor expanded in x around inf 79.0%
+-commutative79.0%
Simplified79.0%
Final simplification89.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.007) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.007) {
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 <= 0.007d0) 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 <= 0.007) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.007: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.007) 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 <= 0.007) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.007], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.007:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.00700000000000000015 < y Initial program 100.0%
Taylor expanded in y around inf 71.6%
if -1 < y < 0.00700000000000000015Initial program 100.0%
Taylor expanded in y around 0 78.1%
Final simplification74.8%
(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 38.4%
Final simplification38.4%
herbie shell --seed 2024095
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))