
(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 (<= y -1.2)
1.0
(if (or (<= y 2.4e+30) (and (not (<= y 1.1e+61)) (<= y 1e+96)))
(/ x (+ y 1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.2) {
tmp = 1.0;
} else if ((y <= 2.4e+30) || (!(y <= 1.1e+61) && (y <= 1e+96))) {
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.2d0)) then
tmp = 1.0d0
else if ((y <= 2.4d+30) .or. (.not. (y <= 1.1d+61)) .and. (y <= 1d+96)) 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.2) {
tmp = 1.0;
} else if ((y <= 2.4e+30) || (!(y <= 1.1e+61) && (y <= 1e+96))) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.2: tmp = 1.0 elif (y <= 2.4e+30) or (not (y <= 1.1e+61) and (y <= 1e+96)): tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.2) tmp = 1.0; elseif ((y <= 2.4e+30) || (!(y <= 1.1e+61) && (y <= 1e+96))) 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.2) tmp = 1.0; elseif ((y <= 2.4e+30) || (~((y <= 1.1e+61)) && (y <= 1e+96))) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.2], 1.0, If[Or[LessEqual[y, 2.4e+30], And[N[Not[LessEqual[y, 1.1e+61]], $MachinePrecision], LessEqual[y, 1e+96]]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.2:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 2.4 \cdot 10^{+30} \lor \neg \left(y \leq 1.1 \cdot 10^{+61}\right) \land y \leq 10^{+96}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.19999999999999996 or 2.3999999999999999e30 < y < 1.1e61 or 1.00000000000000005e96 < y Initial program 100.0%
Taylor expanded in y around inf 82.6%
if -1.19999999999999996 < y < 2.3999999999999999e30 or 1.1e61 < y < 1.00000000000000005e96Initial program 100.0%
Taylor expanded in x around inf 72.5%
+-commutative72.5%
Simplified72.5%
Final simplification77.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.4e-72)
(/ y (+ y 1.0))
(if (or (<= y 2.1e+30) (and (not (<= y 1.55e+61)) (<= y 1e+96)))
(/ x (+ y 1.0))
1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2.4e-72) {
tmp = y / (y + 1.0);
} else if ((y <= 2.1e+30) || (!(y <= 1.55e+61) && (y <= 1e+96))) {
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.4d-72)) then
tmp = y / (y + 1.0d0)
else if ((y <= 2.1d+30) .or. (.not. (y <= 1.55d+61)) .and. (y <= 1d+96)) 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.4e-72) {
tmp = y / (y + 1.0);
} else if ((y <= 2.1e+30) || (!(y <= 1.55e+61) && (y <= 1e+96))) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.4e-72: tmp = y / (y + 1.0) elif (y <= 2.1e+30) or (not (y <= 1.55e+61) and (y <= 1e+96)): tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2.4e-72) tmp = Float64(y / Float64(y + 1.0)); elseif ((y <= 2.1e+30) || (!(y <= 1.55e+61) && (y <= 1e+96))) 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.4e-72) tmp = y / (y + 1.0); elseif ((y <= 2.1e+30) || (~((y <= 1.55e+61)) && (y <= 1e+96))) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.4e-72], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[Or[LessEqual[y, 2.1e+30], And[N[Not[LessEqual[y, 1.55e+61]], $MachinePrecision], LessEqual[y, 1e+96]]], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-72}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 2.1 \cdot 10^{+30} \lor \neg \left(y \leq 1.55 \cdot 10^{+61}\right) \land y \leq 10^{+96}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.4e-72Initial program 100.0%
Taylor expanded in x around 0 78.5%
+-commutative78.5%
Simplified78.5%
if -2.4e-72 < y < 2.1e30 or 1.55e61 < y < 1.00000000000000005e96Initial program 100.0%
Taylor expanded in x around inf 79.0%
+-commutative79.0%
Simplified79.0%
if 2.1e30 < y < 1.55e61 or 1.00000000000000005e96 < y Initial program 100.0%
Taylor expanded in y around inf 82.6%
Final simplification79.4%
(FPCore (x y) :precision binary64 (if (or (<= y -9.5e-10) (not (<= y 3.05e-5))) (/ y (+ y 1.0)) (+ x (* y (- 1.0 x)))))
double code(double x, double y) {
double tmp;
if ((y <= -9.5e-10) || !(y <= 3.05e-5)) {
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 <= (-9.5d-10)) .or. (.not. (y <= 3.05d-5))) 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 <= -9.5e-10) || !(y <= 3.05e-5)) {
tmp = y / (y + 1.0);
} else {
tmp = x + (y * (1.0 - x));
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9.5e-10) or not (y <= 3.05e-5): tmp = y / (y + 1.0) else: tmp = x + (y * (1.0 - x)) return tmp
function code(x, y) tmp = 0.0 if ((y <= -9.5e-10) || !(y <= 3.05e-5)) 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 <= -9.5e-10) || ~((y <= 3.05e-5))) tmp = y / (y + 1.0); else tmp = x + (y * (1.0 - x)); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9.5e-10], N[Not[LessEqual[y, 3.05e-5]], $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 -9.5 \cdot 10^{-10} \lor \neg \left(y \leq 3.05 \cdot 10^{-5}\right):\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(1 - x\right)\\
\end{array}
\end{array}
if y < -9.50000000000000028e-10 or 3.04999999999999994e-5 < y Initial program 100.0%
Taylor expanded in x around 0 78.2%
+-commutative78.2%
Simplified78.2%
if -9.50000000000000028e-10 < y < 3.04999999999999994e-5Initial program 100.0%
Taylor expanded in y around 0 99.7%
Final simplification88.9%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.92) (- x (* x y)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.92) {
tmp = x - (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 <= 0.92d0) then
tmp = x - (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 <= 0.92) {
tmp = x - (x * y);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.92: tmp = x - (x * y) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 0.92) tmp = Float64(x - 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 <= 0.92) tmp = x - (x * y); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 0.92], N[(x - N[(x * y), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.92:\\
\;\;\;\;x - x \cdot y\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.92000000000000004 < y Initial program 100.0%
Taylor expanded in y around inf 76.3%
if -1 < y < 0.92000000000000004Initial program 100.0%
Taylor expanded in y around 0 98.9%
Taylor expanded in x around inf 72.0%
neg-mul-172.0%
sub-neg72.0%
distribute-rgt-out--72.0%
*-lft-identity72.0%
Simplified72.0%
Final simplification74.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 0.46) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 0.46) {
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.46d0) 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.46) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 0.46: 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.46) 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.46) 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.46], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 0.46:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 0.46000000000000002 < y Initial program 100.0%
Taylor expanded in y around inf 76.3%
if -1 < y < 0.46000000000000002Initial program 100.0%
Taylor expanded in y around 0 71.3%
Final simplification73.8%
(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 39.7%
Final simplification39.7%
herbie shell --seed 2023275
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))