
(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 (or (<= y -1020000.0) (not (<= y 400000000.0))) (+ 1.0 (/ (+ x -1.0) y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -1020000.0) || !(y <= 400000000.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 <= (-1020000.0d0)) .or. (.not. (y <= 400000000.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 <= -1020000.0) || !(y <= 400000000.0)) {
tmp = 1.0 + ((x + -1.0) / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1020000.0) or not (y <= 400000000.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 <= -1020000.0) || !(y <= 400000000.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 <= -1020000.0) || ~((y <= 400000000.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, -1020000.0], N[Not[LessEqual[y, 400000000.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 -1020000 \lor \neg \left(y \leq 400000000\right):\\
\;\;\;\;1 + \frac{x + -1}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -1.02e6 or 4e8 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
associate--l+100.0%
+-commutative100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
if -1.02e6 < y < 4e8Initial program 100.0%
Taylor expanded in x around inf 80.8%
+-commutative80.8%
Simplified80.8%
Final simplification89.2%
(FPCore (x y) :precision binary64 (if (or (<= x -5.6e-8) (not (<= x 1.1e-12))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -5.6e-8) || !(x <= 1.1e-12)) {
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 <= (-5.6d-8)) .or. (.not. (x <= 1.1d-12))) 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 <= -5.6e-8) || !(x <= 1.1e-12)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -5.6e-8) or not (x <= 1.1e-12): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -5.6e-8) || !(x <= 1.1e-12)) 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 <= -5.6e-8) || ~((x <= 1.1e-12))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -5.6e-8], N[Not[LessEqual[x, 1.1e-12]], $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 -5.6 \cdot 10^{-8} \lor \neg \left(x \leq 1.1 \cdot 10^{-12}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -5.5999999999999999e-8 or 1.09999999999999996e-12 < x Initial program 100.0%
Taylor expanded in x around inf 80.7%
+-commutative80.7%
Simplified80.7%
if -5.5999999999999999e-8 < x < 1.09999999999999996e-12Initial program 100.0%
Taylor expanded in x around 0 79.0%
+-commutative79.0%
Simplified79.0%
Final simplification80.0%
(FPCore (x y) :precision binary64 (if (or (<= y -2150000.0) (not (<= y 480000000.0))) (+ 1.0 (/ x y)) (/ x (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -2150000.0) || !(y <= 480000000.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 <= (-2150000.0d0)) .or. (.not. (y <= 480000000.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 <= -2150000.0) || !(y <= 480000000.0)) {
tmp = 1.0 + (x / y);
} else {
tmp = x / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -2150000.0) or not (y <= 480000000.0): tmp = 1.0 + (x / y) else: tmp = x / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -2150000.0) || !(y <= 480000000.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 <= -2150000.0) || ~((y <= 480000000.0))) tmp = 1.0 + (x / y); else tmp = x / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -2150000.0], N[Not[LessEqual[y, 480000000.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 -2150000 \lor \neg \left(y \leq 480000000\right):\\
\;\;\;\;1 + \frac{x}{y}\\
\mathbf{else}:\\
\;\;\;\;\frac{x}{y + 1}\\
\end{array}
\end{array}
if y < -2.15e6 or 4.8e8 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
+-commutative100.0%
associate--l+100.0%
+-commutative100.0%
associate--r-100.0%
div-sub100.0%
Simplified100.0%
Taylor expanded in x around inf 98.8%
neg-mul-198.8%
distribute-neg-frac98.8%
Simplified98.8%
if -2.15e6 < y < 4.8e8Initial program 100.0%
Taylor expanded in x around inf 80.8%
+-commutative80.8%
Simplified80.8%
Final simplification88.7%
(FPCore (x y) :precision binary64 (if (<= y -1.65e+22) 1.0 (if (<= y 7.2e+58) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.65e+22) {
tmp = 1.0;
} else if (y <= 7.2e+58) {
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 <= (-1.65d+22)) then
tmp = 1.0d0
else if (y <= 7.2d+58) 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 <= -1.65e+22) {
tmp = 1.0;
} else if (y <= 7.2e+58) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.65e+22: tmp = 1.0 elif y <= 7.2e+58: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.65e+22) tmp = 1.0; elseif (y <= 7.2e+58) 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 <= -1.65e+22) tmp = 1.0; elseif (y <= 7.2e+58) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.65e+22], 1.0, If[LessEqual[y, 7.2e+58], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+22}:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{+58}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.6499999999999999e22 or 7.19999999999999993e58 < y Initial program 100.0%
Taylor expanded in y around inf 76.6%
if -1.6499999999999999e22 < y < 7.19999999999999993e58Initial program 100.0%
Taylor expanded in x around inf 79.2%
+-commutative79.2%
Simplified79.2%
Final simplification78.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.36e-14) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.36e-14) {
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.36d-14) 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.36e-14) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.36e-14: 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.36e-14) 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.36e-14) 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.36e-14], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.36 \cdot 10^{-14}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.36e-14 < y Initial program 100.0%
Taylor expanded in y around inf 73.0%
if -1 < y < 1.36e-14Initial program 100.0%
Taylor expanded in y around 0 80.8%
Final simplification77.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 34.6%
Final simplification34.6%
herbie shell --seed 2023321
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))