
(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 8 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
(let* ((t_0 (+ 1.0 (/ (+ x -1.0) y))))
(if (<= y -1.85)
t_0
(if (<= y -5.5e-103)
(/ y (+ y 1.0))
(if (<= y 270000.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -1.85) {
tmp = t_0;
} else if (y <= -5.5e-103) {
tmp = y / (y + 1.0);
} else if (y <= 270000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + ((x + (-1.0d0)) / y)
if (y <= (-1.85d0)) then
tmp = t_0
else if (y <= (-5.5d-103)) then
tmp = y / (y + 1.0d0)
else if (y <= 270000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -1.85) {
tmp = t_0;
} else if (y <= -5.5e-103) {
tmp = y / (y + 1.0);
} else if (y <= 270000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + ((x + -1.0) / y) tmp = 0 if y <= -1.85: tmp = t_0 elif y <= -5.5e-103: tmp = y / (y + 1.0) elif y <= 270000.0: tmp = x / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(Float64(x + -1.0) / y)) tmp = 0.0 if (y <= -1.85) tmp = t_0; elseif (y <= -5.5e-103) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 270000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + ((x + -1.0) / y); tmp = 0.0; if (y <= -1.85) tmp = t_0; elseif (y <= -5.5e-103) tmp = y / (y + 1.0); elseif (y <= 270000.0) tmp = x / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(N[(x + -1.0), $MachinePrecision] / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -1.85], t$95$0, If[LessEqual[y, -5.5e-103], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 270000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x + -1}{y}\\
\mathbf{if}\;y \leq -1.85:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-103}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 270000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.8500000000000001 or 2.7e5 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
+-commutative99.3%
associate--l+99.3%
+-commutative99.3%
associate--r-99.3%
div-sub99.3%
Simplified99.3%
if -1.8500000000000001 < y < -5.50000000000000032e-103Initial program 100.0%
Taylor expanded in x around 0 66.3%
+-commutative66.3%
Simplified66.3%
if -5.50000000000000032e-103 < y < 2.7e5Initial program 100.0%
Taylor expanded in x around inf 81.6%
+-commutative81.6%
Simplified81.6%
Final simplification89.8%
(FPCore (x y)
:precision binary64
(let* ((t_0 (+ 1.0 (/ x y))))
(if (<= y -7.4e+21)
t_0
(if (<= y -4.9e-103)
(/ y (+ y 1.0))
(if (<= y 1600000.0) (/ x (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -7.4e+21) {
tmp = t_0;
} else if (y <= -4.9e-103) {
tmp = y / (y + 1.0);
} else if (y <= 1600000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = 1.0d0 + (x / y)
if (y <= (-7.4d+21)) then
tmp = t_0
else if (y <= (-4.9d-103)) then
tmp = y / (y + 1.0d0)
else if (y <= 1600000.0d0) then
tmp = x / (y + 1.0d0)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = 1.0 + (x / y);
double tmp;
if (y <= -7.4e+21) {
tmp = t_0;
} else if (y <= -4.9e-103) {
tmp = y / (y + 1.0);
} else if (y <= 1600000.0) {
tmp = x / (y + 1.0);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = 1.0 + (x / y) tmp = 0 if y <= -7.4e+21: tmp = t_0 elif y <= -4.9e-103: tmp = y / (y + 1.0) elif y <= 1600000.0: tmp = x / (y + 1.0) else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(1.0 + Float64(x / y)) tmp = 0.0 if (y <= -7.4e+21) tmp = t_0; elseif (y <= -4.9e-103) tmp = Float64(y / Float64(y + 1.0)); elseif (y <= 1600000.0) tmp = Float64(x / Float64(y + 1.0)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = 1.0 + (x / y); tmp = 0.0; if (y <= -7.4e+21) tmp = t_0; elseif (y <= -4.9e-103) tmp = y / (y + 1.0); elseif (y <= 1600000.0) tmp = x / (y + 1.0); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(1.0 + N[(x / y), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -7.4e+21], t$95$0, If[LessEqual[y, -4.9e-103], N[(y / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1600000.0], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 1 + \frac{x}{y}\\
\mathbf{if}\;y \leq -7.4 \cdot 10^{+21}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq -4.9 \cdot 10^{-103}:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{elif}\;y \leq 1600000:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -7.4e21 or 1.6e6 < 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 99.9%
neg-mul-199.9%
distribute-neg-frac99.9%
Simplified99.9%
if -7.4e21 < y < -4.89999999999999953e-103Initial program 100.0%
Taylor expanded in x around 0 69.1%
+-commutative69.1%
Simplified69.1%
if -4.89999999999999953e-103 < y < 1.6e6Initial program 100.0%
Taylor expanded in x around inf 81.6%
+-commutative81.6%
Simplified81.6%
Final simplification89.7%
(FPCore (x y) :precision binary64 (if (<= y -1.9) 1.0 (if (<= y -5.5e-103) y (if (<= y 270000.0) x 1.0))))
double code(double x, double y) {
double tmp;
if (y <= -1.9) {
tmp = 1.0;
} else if (y <= -5.5e-103) {
tmp = y;
} else if (y <= 270000.0) {
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.9d0)) then
tmp = 1.0d0
else if (y <= (-5.5d-103)) then
tmp = y
else if (y <= 270000.0d0) 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.9) {
tmp = 1.0;
} else if (y <= -5.5e-103) {
tmp = y;
} else if (y <= 270000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.9: tmp = 1.0 elif y <= -5.5e-103: tmp = y elif y <= 270000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.9) tmp = 1.0; elseif (y <= -5.5e-103) tmp = y; elseif (y <= 270000.0) tmp = x; else tmp = 1.0; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.9) tmp = 1.0; elseif (y <= -5.5e-103) tmp = y; elseif (y <= 270000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.9], 1.0, If[LessEqual[y, -5.5e-103], y, If[LessEqual[y, 270000.0], x, 1.0]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq -5.5 \cdot 10^{-103}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 270000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.8999999999999999 or 2.7e5 < y Initial program 100.0%
Taylor expanded in y around inf 73.2%
if -1.8999999999999999 < y < -5.50000000000000032e-103Initial program 100.0%
Taylor expanded in x around 0 63.2%
+-commutative63.2%
Simplified63.2%
Taylor expanded in y around 0 54.1%
if -5.50000000000000032e-103 < y < 2.7e5Initial program 100.0%
Taylor expanded in y around 0 78.7%
Final simplification73.8%
(FPCore (x y) :precision binary64 (if (or (<= x -19500000.0) (not (<= x 3.1e-20))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -19500000.0) || !(x <= 3.1e-20)) {
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 <= (-19500000.0d0)) .or. (.not. (x <= 3.1d-20))) 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 <= -19500000.0) || !(x <= 3.1e-20)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -19500000.0) or not (x <= 3.1e-20): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -19500000.0) || !(x <= 3.1e-20)) 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 <= -19500000.0) || ~((x <= 3.1e-20))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -19500000.0], N[Not[LessEqual[x, 3.1e-20]], $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 -19500000 \lor \neg \left(x \leq 3.1 \cdot 10^{-20}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -1.95e7 or 3.1e-20 < x Initial program 100.0%
Taylor expanded in x around inf 78.2%
+-commutative78.2%
Simplified78.2%
if -1.95e7 < x < 3.1e-20Initial program 100.0%
Taylor expanded in x around 0 82.3%
+-commutative82.3%
Simplified82.3%
Final simplification80.1%
(FPCore (x y) :precision binary64 (if (<= y -2900000.0) 1.0 (if (<= y 5.2e+38) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -2900000.0) {
tmp = 1.0;
} else if (y <= 5.2e+38) {
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 <= (-2900000.0d0)) then
tmp = 1.0d0
else if (y <= 5.2d+38) 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 <= -2900000.0) {
tmp = 1.0;
} else if (y <= 5.2e+38) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2900000.0: tmp = 1.0 elif y <= 5.2e+38: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -2900000.0) tmp = 1.0; elseif (y <= 5.2e+38) 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 <= -2900000.0) tmp = 1.0; elseif (y <= 5.2e+38) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2900000.0], 1.0, If[LessEqual[y, 5.2e+38], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2900000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 5.2 \cdot 10^{+38}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -2.9e6 or 5.1999999999999998e38 < y Initial program 100.0%
Taylor expanded in y around inf 74.9%
if -2.9e6 < y < 5.1999999999999998e38Initial program 100.0%
Taylor expanded in x around inf 73.7%
+-commutative73.7%
Simplified73.7%
Final simplification74.3%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 270000.0) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 270000.0) {
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 <= 270000.0d0) 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 <= 270000.0) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 270000.0: tmp = x else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = 1.0; elseif (y <= 270000.0) 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 <= 270000.0) tmp = x; else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], 1.0, If[LessEqual[y, 270000.0], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 270000:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 2.7e5 < y Initial program 100.0%
Taylor expanded in y around inf 72.7%
if -1 < y < 2.7e5Initial program 100.0%
Taylor expanded in y around 0 71.1%
Final simplification71.9%
(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 40.5%
Final simplification40.5%
herbie shell --seed 2024027
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))