
(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 -2.65e+87)
1.0
(if (<= y -5.8e+71)
(/ x y)
(if (<= y -1.0)
1.0
(if (<= y 0.0052) (+ x y) (if (<= y 1.7e+93) (/ x (+ y 1.0)) 1.0))))))
double code(double x, double y) {
double tmp;
if (y <= -2.65e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.0052) {
tmp = x + y;
} else if (y <= 1.7e+93) {
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.65d+87)) then
tmp = 1.0d0
else if (y <= (-5.8d+71)) then
tmp = x / y
else if (y <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 0.0052d0) then
tmp = x + y
else if (y <= 1.7d+93) 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.65e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.0052) {
tmp = x + y;
} else if (y <= 1.7e+93) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.65e+87: tmp = 1.0 elif y <= -5.8e+71: tmp = x / y elif y <= -1.0: tmp = 1.0 elif y <= 0.0052: tmp = x + y elif y <= 1.7e+93: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.65e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = Float64(x / y); elseif (y <= -1.0) tmp = 1.0; elseif (y <= 0.0052) tmp = Float64(x + y); elseif (y <= 1.7e+93) 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.65e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = x / y; elseif (y <= -1.0) tmp = 1.0; elseif (y <= 0.0052) tmp = x + y; elseif (y <= 1.7e+93) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.65e+87], 1.0, If[LessEqual[y, -5.8e+71], N[(x / y), $MachinePrecision], If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.0052], N[(x + y), $MachinePrecision], If[LessEqual[y, 1.7e+93], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{+87}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.0052:\\
\;\;\;\;x + y\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{+93}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.65000000000000002e87 or -5.80000000000000014e71 < y < -1 or 1.7e93 < y Initial program 100.0%
Taylor expanded in y around inf 79.1%
if -2.65000000000000002e87 < y < -5.80000000000000014e71Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
if -1 < y < 0.0051999999999999998Initial program 100.0%
clear-num99.8%
associate-/r/100.0%
Applied egg-rr100.0%
flip-+99.9%
associate-/r/100.0%
metadata-eval100.0%
fma-neg100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 98.2%
if 0.0051999999999999998 < y < 1.7e93Initial program 100.0%
Taylor expanded in x around inf 86.2%
+-commutative86.2%
Simplified86.2%
Final simplification89.7%
(FPCore (x y)
:precision binary64
(if (<= y -2.9e+87)
1.0
(if (<= y -5.8e+71)
(/ x y)
(if (or (<= y -7e-12) (not (<= y 1.1e-12))) (/ y (+ y 1.0)) (+ x y)))))
double code(double x, double y) {
double tmp;
if (y <= -2.9e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if ((y <= -7e-12) || !(y <= 1.1e-12)) {
tmp = y / (y + 1.0);
} else {
tmp = x + 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.9d+87)) then
tmp = 1.0d0
else if (y <= (-5.8d+71)) then
tmp = x / y
else if ((y <= (-7d-12)) .or. (.not. (y <= 1.1d-12))) then
tmp = y / (y + 1.0d0)
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.9e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if ((y <= -7e-12) || !(y <= 1.1e-12)) {
tmp = y / (y + 1.0);
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.9e+87: tmp = 1.0 elif y <= -5.8e+71: tmp = x / y elif (y <= -7e-12) or not (y <= 1.1e-12): tmp = y / (y + 1.0) else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.9e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = Float64(x / y); elseif ((y <= -7e-12) || !(y <= 1.1e-12)) tmp = Float64(y / Float64(y + 1.0)); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.9e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = x / y; elseif ((y <= -7e-12) || ~((y <= 1.1e-12))) tmp = y / (y + 1.0); else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.9e+87], 1.0, If[LessEqual[y, -5.8e+71], N[(x / y), $MachinePrecision], If[Or[LessEqual[y, -7e-12], N[Not[LessEqual[y, 1.1e-12]], $MachinePrecision]], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], N[(x + y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+87}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -7 \cdot 10^{-12} \lor \neg \left(y \leq 1.1 \cdot 10^{-12}\right):\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -2.8999999999999998e87Initial program 100.0%
Taylor expanded in y around inf 81.5%
if -2.8999999999999998e87 < y < -5.80000000000000014e71Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
if -5.80000000000000014e71 < y < -7.0000000000000001e-12 or 1.09999999999999996e-12 < y Initial program 100.0%
Taylor expanded in x around 0 75.9%
+-commutative75.9%
Simplified75.9%
if -7.0000000000000001e-12 < y < 1.09999999999999996e-12Initial program 100.0%
clear-num99.8%
associate-/r/100.0%
Applied egg-rr100.0%
flip-+100.0%
associate-/r/100.0%
metadata-eval100.0%
fma-neg100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 99.8%
Final simplification89.2%
(FPCore (x y)
:precision binary64
(if (<= y -1.6e+89)
1.0
(if (<= y -5.8e+71)
(/ x y)
(if (<= y -1.0) 1.0 (if (<= y 1.85e+45) (+ x y) 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -1.6e+89) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.85e+45) {
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.6d+89)) then
tmp = 1.0d0
else if (y <= (-5.8d+71)) then
tmp = x / y
else if (y <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 1.85d+45) 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.6e+89) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.85e+45) {
tmp = x + y;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e+89: tmp = 1.0 elif y <= -5.8e+71: tmp = x / y elif y <= -1.0: tmp = 1.0 elif y <= 1.85e+45: tmp = x + y else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e+89) tmp = 1.0; elseif (y <= -5.8e+71) tmp = Float64(x / y); elseif (y <= -1.0) tmp = 1.0; elseif (y <= 1.85e+45) tmp = Float64(x + y); else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e+89) tmp = 1.0; elseif (y <= -5.8e+71) tmp = x / y; elseif (y <= -1.0) tmp = 1.0; elseif (y <= 1.85e+45) tmp = x + y; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e+89], 1.0, If[LessEqual[y, -5.8e+71], N[(x / y), $MachinePrecision], If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.85e+45], N[(x + y), $MachinePrecision], 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{+89}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.85 \cdot 10^{+45}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.59999999999999994e89 or -5.80000000000000014e71 < y < -1 or 1.84999999999999989e45 < y Initial program 100.0%
Taylor expanded in y around inf 77.9%
if -1.59999999999999994e89 < y < -5.80000000000000014e71Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
if -1 < y < 1.84999999999999989e45Initial program 100.0%
clear-num99.7%
associate-/r/100.0%
Applied egg-rr100.0%
flip-+99.9%
associate-/r/100.0%
metadata-eval100.0%
fma-neg100.0%
metadata-eval100.0%
sub-neg100.0%
metadata-eval100.0%
Applied egg-rr100.0%
Taylor expanded in y around 0 95.6%
Final simplification87.9%
(FPCore (x y)
:precision binary64
(if (<= y -2.5e+87)
1.0
(if (<= y -5.8e+71)
(/ x y)
(if (<= y -1.0) 1.0 (if (<= y 1.1e-12) x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -2.5e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.1e-12) {
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.5d+87)) then
tmp = 1.0d0
else if (y <= (-5.8d+71)) then
tmp = x / y
else if (y <= (-1.0d0)) then
tmp = 1.0d0
else if (y <= 1.1d-12) 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.5e+87) {
tmp = 1.0;
} else if (y <= -5.8e+71) {
tmp = x / y;
} else if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.1e-12) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e+87: tmp = 1.0 elif y <= -5.8e+71: tmp = x / y elif y <= -1.0: tmp = 1.0 elif y <= 1.1e-12: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = Float64(x / y); elseif (y <= -1.0) tmp = 1.0; elseif (y <= 1.1e-12) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5e+87) tmp = 1.0; elseif (y <= -5.8e+71) tmp = x / y; elseif (y <= -1.0) tmp = 1.0; elseif (y <= 1.1e-12) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e+87], 1.0, If[LessEqual[y, -5.8e+71], N[(x / y), $MachinePrecision], If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.1e-12], x, 1.0]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{+87}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.8 \cdot 10^{+71}:\\
\;\;\;\;\frac{x}{y}\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.4999999999999999e87 or -5.80000000000000014e71 < y < -1 or 1.09999999999999996e-12 < y Initial program 100.0%
Taylor expanded in y around inf 73.8%
if -2.4999999999999999e87 < y < -5.80000000000000014e71Initial program 100.0%
Taylor expanded in x around inf 100.0%
+-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 100.0%
if -1 < y < 1.09999999999999996e-12Initial program 100.0%
Taylor expanded in y around 0 76.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.1e-12) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.1e-12) {
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 <= 1.1d-12) 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 <= 1.1e-12) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.1e-12: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 1.1e-12) 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 <= 1.1e-12) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 1.1e-12], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-12}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.09999999999999996e-12 < y Initial program 100.0%
Taylor expanded in y around inf 70.5%
if -1 < y < 1.09999999999999996e-12Initial 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 36.6%
herbie shell --seed 2024103
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))