
(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 6 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 -240000.0)
t_0
(if (<= y 4.2e-129)
(/ x (+ y 1.0))
(if (<= y 94000.0) (/ y (+ y 1.0)) t_0)))))
double code(double x, double y) {
double t_0 = 1.0 + ((x + -1.0) / y);
double tmp;
if (y <= -240000.0) {
tmp = t_0;
} else if (y <= 4.2e-129) {
tmp = x / (y + 1.0);
} else if (y <= 94000.0) {
tmp = y / (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 <= (-240000.0d0)) then
tmp = t_0
else if (y <= 4.2d-129) then
tmp = x / (y + 1.0d0)
else if (y <= 94000.0d0) then
tmp = y / (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 <= -240000.0) {
tmp = t_0;
} else if (y <= 4.2e-129) {
tmp = x / (y + 1.0);
} else if (y <= 94000.0) {
tmp = y / (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 <= -240000.0: tmp = t_0 elif y <= 4.2e-129: tmp = x / (y + 1.0) elif y <= 94000.0: tmp = y / (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 <= -240000.0) tmp = t_0; elseif (y <= 4.2e-129) tmp = Float64(x / Float64(y + 1.0)); elseif (y <= 94000.0) tmp = Float64(y / 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 <= -240000.0) tmp = t_0; elseif (y <= 4.2e-129) tmp = x / (y + 1.0); elseif (y <= 94000.0) tmp = y / (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, -240000.0], t$95$0, If[LessEqual[y, 4.2e-129], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 94000.0], N[(y / 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 -240000:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-129}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{elif}\;y \leq 94000:\\
\;\;\;\;\frac{y}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -2.4e5 or 94000 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
associate--l+99.3%
div-sub99.3%
sub-neg99.3%
metadata-eval99.3%
Simplified99.3%
if -2.4e5 < y < 4.2e-129Initial program 100.0%
Taylor expanded in x around inf 78.8%
+-commutative78.8%
Simplified78.8%
if 4.2e-129 < y < 94000Initial program 100.0%
Taylor expanded in x around 0 58.5%
+-commutative58.5%
Simplified58.5%
Final simplification84.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.26e+42) (not (<= x 4e-14))) (/ x (+ y 1.0)) (/ y (+ y 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -1.26e+42) || !(x <= 4e-14)) {
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.26d+42)) .or. (.not. (x <= 4d-14))) 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.26e+42) || !(x <= 4e-14)) {
tmp = x / (y + 1.0);
} else {
tmp = y / (y + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.26e+42) or not (x <= 4e-14): tmp = x / (y + 1.0) else: tmp = y / (y + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.26e+42) || !(x <= 4e-14)) 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.26e+42) || ~((x <= 4e-14))) tmp = x / (y + 1.0); else tmp = y / (y + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.26e+42], N[Not[LessEqual[x, 4e-14]], $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.26 \cdot 10^{+42} \lor \neg \left(x \leq 4 \cdot 10^{-14}\right):\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;\frac{y}{y + 1}\\
\end{array}
\end{array}
if x < -1.26e42 or 4e-14 < x Initial program 100.0%
Taylor expanded in x around inf 86.2%
+-commutative86.2%
Simplified86.2%
if -1.26e42 < x < 4e-14Initial program 100.0%
Taylor expanded in x around 0 75.5%
+-commutative75.5%
Simplified75.5%
Final simplification80.1%
(FPCore (x y) :precision binary64 (if (<= y -19000000.0) 1.0 (if (<= y 1.42e+25) (/ x (+ y 1.0)) 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -19000000.0) {
tmp = 1.0;
} else if (y <= 1.42e+25) {
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 <= (-19000000.0d0)) then
tmp = 1.0d0
else if (y <= 1.42d+25) 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 <= -19000000.0) {
tmp = 1.0;
} else if (y <= 1.42e+25) {
tmp = x / (y + 1.0);
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -19000000.0: tmp = 1.0 elif y <= 1.42e+25: tmp = x / (y + 1.0) else: tmp = 1.0 return tmp
function code(x, y) tmp = 0.0 if (y <= -19000000.0) tmp = 1.0; elseif (y <= 1.42e+25) 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 <= -19000000.0) tmp = 1.0; elseif (y <= 1.42e+25) tmp = x / (y + 1.0); else tmp = 1.0; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -19000000.0], 1.0, If[LessEqual[y, 1.42e+25], N[(x / N[(y + 1.0), $MachinePrecision]), $MachinePrecision], 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -19000000:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.42 \cdot 10^{+25}:\\
\;\;\;\;\frac{x}{y + 1}\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1.9e7 or 1.4199999999999999e25 < y Initial program 100.0%
Taylor expanded in y around inf 78.7%
if -1.9e7 < y < 1.4199999999999999e25Initial program 100.0%
Taylor expanded in x around inf 69.9%
+-commutative69.9%
Simplified69.9%
Final simplification73.4%
(FPCore (x y) :precision binary64 (if (<= y -1.0) 1.0 (if (<= y 1.7e-10) x 1.0)))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = 1.0;
} else if (y <= 1.7e-10) {
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.7d-10) 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.7e-10) {
tmp = x;
} else {
tmp = 1.0;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = 1.0 elif y <= 1.7e-10: 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.7e-10) 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.7e-10) 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.7e-10], x, 1.0]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;1\\
\mathbf{elif}\;y \leq 1.7 \cdot 10^{-10}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;1\\
\end{array}
\end{array}
if y < -1 or 1.70000000000000007e-10 < y Initial program 100.0%
Taylor expanded in y around inf 71.5%
if -1 < y < 1.70000000000000007e-10Initial program 100.0%
Taylor expanded in y around 0 71.3%
Final simplification71.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 33.7%
Final simplification33.7%
herbie shell --seed 2024066
(FPCore (x y)
:name "Data.Colour.SRGB:invTransferFunction from colour-2.3.3"
:precision binary64
(/ (+ x y) (+ y 1.0)))