
(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 -0.0025) (not (<= y 5.4e-6))) (/ y (+ y 1.0)) (+ x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y <= -0.0025) || !(y <= 5.4e-6)) {
tmp = y / (y + 1.0);
} else {
tmp = x + (y * (1.0 - x));
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-0.0025d0)) .or. (.not. (y <= 5.4d-6))) then
tmp = y / (y + 1.0d0)
else
tmp = x + (y * (1.0d0 - x))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -0.0025) || !(y <= 5.4e-6)) {
tmp = y / (y + 1.0);
} else {
tmp = x + (y * (1.0 - x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -0.0025) or not (y <= 5.4e-6): tmp = y / (y + 1.0) else: tmp = x + (y * (1.0 - x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -0.0025) || !(y <= 5.4e-6)) tmp = Float64(y / Float64(y + 1.0)); else tmp = Float64(x + Float64(y * Float64(1.0 - x))); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -0.0025) || ~((y <= 5.4e-6))) tmp = y / (y + 1.0); else tmp = x + (y * (1.0 - x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -0.0025], N[Not[LessEqual[y, 5.4e-6]], $MachinePrecision]], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0025 \lor \neg \left(y \leq 5.4 \cdot 10^{-6}\right):\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -0.00250000000000000005 or 5.39999999999999997e-6 < y Initial program 100.0%
Taylor expanded in x around 0 72.2%
+-commutative72.2%
Simplified72.2%
if -0.00250000000000000005 < y < 5.39999999999999997e-6Initial program 99.9%
Taylor expanded in y around 0 99.5%
Final simplification85.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.5e+59) (not (<= x 2.1e+19))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -1.5e+59) || !(x <= 2.1e+19)) {
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 ((x <= (-1.5d+59)) .or. (.not. (x <= 2.1d+19))) 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 ((x <= -1.5e+59) || !(x <= 2.1e+19)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.5e+59) or not (x <= 2.1e+19): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.5e+59) || !(x <= 2.1e+19)) 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 ((x <= -1.5e+59) || ~((x <= 2.1e+19))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.5e+59], N[Not[LessEqual[x, 2.1e+19]], $MachinePrecision]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+59} \lor \neg \left(x \leq 2.1 \cdot 10^{+19}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -1.5e59 or 2.1e19 < x Initial program 100.0%
Taylor expanded in x around inf 79.8%
+-commutative79.8%
Simplified79.8%
if -1.5e59 < x < 2.1e19Initial program 100.0%
Taylor expanded in x around 0 73.8%
+-commutative73.8%
Simplified73.8%
Final simplification76.7%
(FPCore (x y) :precision binary64 (if (<= y -5.2e+97) 1.0 (if (<= y 150000000000.0) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -5.2e+97) {
tmp = 1.0;
} else if (y <= 150000000000.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 <= (-5.2d+97)) then
tmp = 1.0d0
else if (y <= 150000000000.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 <= -5.2e+97) {
tmp = 1.0;
} else if (y <= 150000000000.0) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.2e+97: tmp = 1.0 elif y <= 150000000000.0: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -5.2e+97) tmp = 1.0; elseif (y <= 150000000000.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 <= -5.2e+97) tmp = 1.0; elseif (y <= 150000000000.0) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.2e+97], 1.0, If[LessEqual[y, 150000000000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+97}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 150000000000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -5.2e97 or 1.5e11 < y Initial program 100.0%
Taylor expanded in y around inf 76.9%
if -5.2e97 < y < 1.5e11Initial program 100.0%
Taylor expanded in x around inf 73.2%
+-commutative73.2%
Simplified73.2%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.000165) (* x (- 1.0 y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.000165) {
tmp = x * (1.0 - 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 <= 0.000165d0) then
tmp = x * (1.0d0 - 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 <= 0.000165) {
tmp = x * (1.0 - y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.000165: tmp = x * (1.0 - y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.000165) tmp = Float64(x * Float64(1.0 - 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 <= 0.000165) tmp = x * (1.0 - y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.000165], N[(x * N[(1.0 - y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.000165:\\
\;\;\;\;x \cdot \left(1 - y\right)\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.65e-4 < y Initial program 100.0%
Taylor expanded in y around inf 68.8%
if -1 < y < 1.65e-4Initial program 99.9%
Taylor expanded in x around inf 77.2%
+-commutative77.2%
Simplified77.2%
Taylor expanded in y around 0 76.7%
+-commutative76.7%
mul-1-neg76.7%
remove-double-neg76.7%
distribute-neg-out76.7%
neg-mul-176.7%
*-commutative76.7%
distribute-lft-in76.7%
distribute-rgt-neg-in76.7%
sub0-neg76.7%
metadata-eval76.7%
sub-neg76.7%
associate-+l-76.7%
neg-sub076.7%
+-commutative76.7%
unsub-neg76.7%
Simplified76.7%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.000165) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.000165) {
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.000165d0) 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.000165) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.000165: 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.000165) 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.000165) 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.000165], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.000165:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.65e-4 < y Initial program 100.0%
Taylor expanded in y around inf 68.8%
if -1 < y < 1.65e-4Initial program 99.9%
Taylor expanded in y around 0 76.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 37.2%
herbie shell --seed 2024116
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))