
(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 -1.0) 1.0 (if (<= y 1.0) x (if (<= y 5.8e+71) (/ x y) 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.0) {
tmp = x;
} else if (y <= 5.8e+71) {
tmp = 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 <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 1.0d0) then
tmp = x
else if (y <= 5.8d+71) then
tmp = x / y
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 <= 1.0) {
tmp = x;
} else if (y <= 5.8e+71) {
tmp = x / y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.0: tmp = x elif y <= 5.8e+71: tmp = x / y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.0) tmp = x; elseif (y <= 5.8e+71) tmp = Float64(x / y); 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 <= 1.0) tmp = x; elseif (y <= 5.8e+71) tmp = x / y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.0], x, If[LessEqual[y, 5.8e+71], N[(x / y), $MachinePrecision], 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;x\\
\mathbf{elif}\;y \leq 5.8 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 5.80000000000000014e71 < y Initial program 100.0%
Taylor expanded in y around inf 81.9%
if -1 < y < 1Initial program 100.0%
Taylor expanded in y around 0 73.4%
if 1 < y < 5.80000000000000014e71Initial program 100.0%
Taylor expanded in x around inf 64.0%
+-commutative64.0%
Simplified64.0%
Taylor expanded in y around inf 62.6%
(FPCore (x y) :precision binary64 (if (<= y -2.5e+26) (+ 1.0 (/ x y)) (if (<= y 470.0) (/ x (+ y 1.0)) (+ 1.0 (/ (+ x -1.0) y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.5e+26) {
tmp = 1.0 + (x / y);
} else if (y <= 470.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 <= (-2.5d+26)) then
tmp = 1.0d0 + (x / y)
else if (y <= 470.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 <= -2.5e+26) {
tmp = 1.0 + (x / y);
} else if (y <= 470.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0 + ((x + -1.0) / y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e+26: tmp = 1.0 + (x / y) elif y <= 470.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 <= -2.5e+26) tmp = Float64(1.0 + Float64(x / y)); elseif (y <= 470.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 <= -2.5e+26) tmp = 1.0 + (x / y); elseif (y <= 470.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, -2.5e+26], N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 470.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 -2.5 \cdot 10^{+26}:\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{elif}\;y \leq 470:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\end{array}
\end{array}
if y < -2.5e26Initial program 100.0%
Taylor expanded in y around inf 100.0%
associate--l+100.0%
div-sub100.0%
sub-neg100.0%
metadata-eval100.0%
Simplified100.0%
Taylor expanded in x around inf 100.0%
if -2.5e26 < y < 470Initial program 100.0%
Taylor expanded in x around inf 74.5%
+-commutative74.5%
Simplified74.5%
if 470 < y Initial program 100.0%
Taylor expanded in y around inf 98.5%
associate--l+98.5%
div-sub98.5%
sub-neg98.5%
metadata-eval98.5%
Simplified98.5%
(FPCore (x y) :precision binary64 (if (or (<= y -2.5e+26) (not (<= y 470.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -2.5e+26) || !(y <= 470.0)) {
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 <= (-2.5d+26)) .or. (.not. (y <= 470.0d0))) 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 <= -2.5e+26) || !(y <= 470.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2.5e+26) or not (y <= 470.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2.5e+26) || !(y <= 470.0)) 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 <= -2.5e+26) || ~((y <= 470.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2.5e+26], N[Not[LessEqual[y, 470.0]], $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 -2.5 \cdot 10^{+26} \lor \neg \left(y \leq 470\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -2.5e26 or 470 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
associate--l+99.4%
div-sub99.4%
sub-neg99.4%
metadata-eval99.4%
Simplified99.4%
Taylor expanded in x around inf 99.2%
if -2.5e26 < y < 470Initial program 100.0%
Taylor expanded in x around inf 74.5%
+-commutative74.5%
Simplified74.5%
Final simplification86.0%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.1e-18))) (+ 1.0 (/ x y)) x))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 2.1e-18)) {
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 <= 2.1d-18))) 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 <= 2.1e-18)) {
tmp = 1.0 + (x / y);
} else {
tmp = x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 2.1e-18): tmp = 1.0 + (x / y) else: tmp = x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.1e-18)) 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 <= 2.1e-18))) 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, 2.1e-18]], $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 2.1 \cdot 10^{-18}\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -1 or 2.1e-18 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
associate--l+95.9%
div-sub95.9%
sub-neg95.9%
metadata-eval95.9%
Simplified95.9%
Taylor expanded in x around inf 95.7%
if -1 < y < 2.1e-18Initial program 100.0%
Taylor expanded in y around 0 75.0%
Final simplification85.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.5) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.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 <= 0.5d0) 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.5) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.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 <= 0.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 <= 0.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, 0.5], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.5:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.5 < y Initial program 100.0%
Taylor expanded in y around inf 76.0%
if -1 < y < 0.5Initial program 100.0%
Taylor expanded in y around 0 73.4%
(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.9%
herbie shell --seed 2024086
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))