
(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 (or (<= y -3800000000.0) (not (<= y 350.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -3800000000.0) || !(y <= 350.0)) {
tmp = 1.0 + ((x + -1.0) / 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 <= (-3800000000.0d0)) .or. (.not. (y <= 350.0d0))) then
tmp = 1.0d0 + ((x + (-1.0d0)) / 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 <= -3800000000.0) || !(y <= 350.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3800000000.0) or not (y <= 350.0): tmp = 1.0 + ((x + -1.0) / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -3800000000.0) || !(y <= 350.0)) tmp = Float64(1.0 + Float64(Float64(x + -1.0) / y)); else tmp = Float64(x / Float64(y + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3800000000.0) || ~((y <= 350.0))) tmp = 1.0 + ((x + -1.0) / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3800000000.0], N[Not[LessEqual[y, 350.0]], $MachinePrecision]], N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3800000000 \lor \neg \left(y \leq 350\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -3.8e9 or 350 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
associate--l+99.3%
div-sub99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
if -3.8e9 < y < 350Initial program 100.0%
Taylor expanded in x around inf 78.1%
+-commutative78.1%
Simplified78.1%
Final simplification88.9%
(FPCore (x y) :precision binary64 (if (<= y -8e+84) 1.0 (if (<= y -2.8e-9) (/ x y) (if (<= y 19.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -8e+84) {
tmp = 1.0;
} else if (y <= -2.8e-9) {
tmp = x / y;
} else if (y <= 19.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 <= (-8d+84)) then
tmp = 1.0d0
else if (y <= (-2.8d-9)) then
tmp = x / y
else if (y <= 19.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 <= -8e+84) {
tmp = 1.0;
} else if (y <= -2.8e-9) {
tmp = x / y;
} else if (y <= 19.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8e+84: tmp = 1.0 elif y <= -2.8e-9: tmp = x / y elif y <= 19.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -8e+84) tmp = 1.0; elseif (y <= -2.8e-9) tmp = Float64(x / y); elseif (y <= 19.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8e+84) tmp = 1.0; elseif (y <= -2.8e-9) tmp = x / y; elseif (y <= 19.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8e+84], 1.0, If[LessEqual[y, -2.8e-9], N[(x / y), $MachinePrecision], If[LessEqual[y, 19.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+84}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -2.8 \cdot 10^{-9}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq 19:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -8.00000000000000046e84 or 19 < y Initial program 100.0%
Taylor expanded in y around inf 81.7%
if -8.00000000000000046e84 < y < -2.79999999999999984e-9Initial program 99.8%
Taylor expanded in x around inf 62.7%
+-commutative62.7%
Simplified62.7%
Taylor expanded in y around inf 54.0%
if -2.79999999999999984e-9 < y < 19Initial program 100.0%
Taylor expanded in y around 0 76.9%
(FPCore (x y) :precision binary64 (if (<= y -7.4e+86) 1.0 (if (<= y 17.0) (/ x (+ y 1.0)) (/ y (+ y 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -7.4e+86) {
tmp = 1.0;
} else if (y <= 17.0) {
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 <= (-7.4d+86)) then
tmp = 1.0d0
else if (y <= 17.0d0) 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 <= -7.4e+86) {
tmp = 1.0;
} else if (y <= 17.0) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.4e+86: tmp = 1.0 elif y <= 17.0: tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -7.4e+86) tmp = 1.0; elseif (y <= 17.0) 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 <= -7.4e+86) tmp = 1.0; elseif (y <= 17.0) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.4e+86], 1.0, If[LessEqual[y, 17.0], 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 -7.4 \cdot 10^{+86}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 17:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if y < -7.39999999999999983e86Initial program 100.0%
Taylor expanded in y around inf 82.2%
if -7.39999999999999983e86 < y < 17Initial program 100.0%
Taylor expanded in x around inf 76.4%
+-commutative76.4%
Simplified76.4%
if 17 < y Initial program 100.0%
Taylor expanded in x around 0 83.4%
+-commutative83.4%
Simplified83.4%
(FPCore (x y) :precision binary64 (if (<= y -3.4e+83) 1.0 (if (<= y 450.0) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -3.4e+83) {
tmp = 1.0;
} else if (y <= 450.0) {
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 <= (-3.4d+83)) then
tmp = 1.0d0
else if (y <= 450.0d0) 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 <= -3.4e+83) {
tmp = 1.0;
} else if (y <= 450.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3.4e+83: tmp = 1.0 elif y <= 450.0: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -3.4e+83) tmp = 1.0; elseif (y <= 450.0) 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 <= -3.4e+83) tmp = 1.0; elseif (y <= 450.0) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3.4e+83], 1.0, If[LessEqual[y, 450.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.4 \cdot 10^{+83}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 450:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -3.3999999999999998e83 or 450 < y Initial program 100.0%
Taylor expanded in y around inf 81.7%
if -3.3999999999999998e83 < y < 450Initial program 100.0%
Taylor expanded in x around inf 76.4%
+-commutative76.4%
Simplified76.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 7.6) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 7.6) {
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 <= 7.6d0) 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 <= 7.6) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 7.6: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 7.6) 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 <= 7.6) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 7.6], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.6:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 7.5999999999999996 < y Initial program 100.0%
Taylor expanded in y around inf 75.8%
if -1 < y < 7.5999999999999996Initial program 100.0%
Taylor expanded in y around 0 76.3%
(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 41.2%
herbie shell --seed 2024135
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))